-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
1 lines (1 loc) · 4.23 KB
/
index.js
1
(()=>{"use strict";var e={408:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WorldBiome=void 0,t.WorldBiome=class{constructor(e,t){var r,o;this.lowerBound=Math.max(0,null!==(r=e.lowerBound)&&void 0!==r?r:0),this.upperBound=Math.min(1,null!==(o=e.upperBound)&&void 0!==o?o:1),this.data=t}}},997:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WorldGenerator=void 0;const o=r(871),i=r(9),n=r(128),l=r(408);t.WorldGenerator=class{constructor(e){this.biomes=[],this.config=e}addBiome(e,t){const r=new l.WorldBiome(e,t);return this.biomes.push(r),r}clearBiomes(){this.biomes=[]}getBiomes(){return this.biomes}peakBiome(e){var t;return null!==(t=this.getBiomes().find((t=>e>=t.lowerBound&&e<=t.upperBound)))&&void 0!==t?t:null}generate(e){var t,r,l;const s=null!==(t=null==e?void 0:e.seed)&&void 0!==t?t:i.Seed.generate(null==e?void 0:e.seedSize),a=[];for(let t=0;t<this.config.height;t++){a[t]=[];for(let i=0;i<this.config.width;i++){const n=o.Perlin.generate({config:this.config,seed:s,x:i+(null!==(r=null==e?void 0:e.offsetX)&&void 0!==r?r:0),y:t+(null!==(l=null==e?void 0:e.offsetY)&&void 0!==l?l:0)}),h=this.peakBiome(n);h&&(a[t][i]=h.data)}}return new n.World(a,s)}}},708:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PERLIN_AVG_POWER=t.PERLIN_AMP_FALLOFF=t.PERLIN_ZWRAP=t.PERLIN_ZWRAPB=t.PERLIN_YWRAP=t.PERLIN_YWRAPB=void 0,t.PERLIN_YWRAPB=4,t.PERLIN_YWRAP=1<<t.PERLIN_YWRAPB,t.PERLIN_ZWRAPB=8,t.PERLIN_ZWRAP=1<<t.PERLIN_ZWRAPB,t.PERLIN_AMP_FALLOFF=.5,t.PERLIN_AVG_POWER=1.1},871:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Perlin=void 0;const o=r(708);t.Perlin=class{static generate({x:e,y:t,seed:r,config:i}){const{frequencyChange:n,borderSmoothness:l,heightAveraging:s,heightRedistribution:a,falloff:h}=this.normalizeConfig(i),d=r.length-1,u=e/i.width*n,c=t/i.height*n;let f=Math.floor(u),P=Math.floor(c),g=u-f,m=c-P,v=0,R=.5;for(let e=0;e<l;e++){let e=f+(P<<o.PERLIN_YWRAPB);const t=this.scaledCosine(g),i=this.scaledCosine(m);let n=r[e&d];n+=t*(r[e+1&d]-n);let l=r[e+o.PERLIN_YWRAP&d];l+=t*(r[e+o.PERLIN_YWRAP+1&d]-l),n+=i*(l-n),v+=n*R,R*=o.PERLIN_AMP_FALLOFF,e+=o.PERLIN_ZWRAP,f<<=1,g*=2,g>=1&&(f++,g--),P<<=1,m*=2,m>=1&&(P++,m--)}return s&&(v>.5?v=Math.pow(v,(1.5-v)/o.PERLIN_AVG_POWER):v<.5&&(v=Math.pow(v,(1.5-v)*o.PERLIN_AVG_POWER))),v=Math.pow(v,a),h>0&&(v*=this.heightFalloff(e,i.width,h)*this.heightFalloff(t,i.height,h)),v}static clamp(e,t,r=[0,1]){return Math.max(r[0],Math.min(r[1],null!=e?e:t))}static scaledCosine(e){return.5*(1-Math.cos(e*Math.PI))}static smootherStep(e){return 3*Math.pow(e,2)-2*Math.pow(e,3)}static heightFalloff(e,t,r){const o=t/2,i=Math.abs(o-e),n=o*(1-r);if(i<n)return 1;let l=(i-n)/o/(1-n/o);return l=Math.min(1,Math.max(0,l)),1-this.smootherStep(l)}static normalizeConfig(e){var t;return{frequencyChange:Math.round(31*this.clamp(e.frequencyChange,.3)+1),borderSmoothness:Math.round(14*(1-this.clamp(e.borderSmoothness,.5))+1),heightRedistribution:2-this.clamp(e.heightRedistribution,1,[.5,1.5]),falloff:this.clamp(e.falloff,0,[0,.9]),heightAveraging:null===(t=e.heightAveraging)||void 0===t||t}}}},9:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Seed=void 0,t.Seed=class{static generate(e=512){const t=[];for(let r=0;r<e;r++)t.push(Math.random());return t}}},128:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.World=void 0,t.World=class{constructor(e,t){this.matrix=[],this.width=e[0].length,this.height=e.length,this.matrix=e,this.seed=t}getMatrix(){return this.matrix}each(e){for(let t=0;t<this.height;t++)for(let r=0;r<this.width;r++)if(!1===e({x:r,y:t},this.matrix[t][r]))return}getAt(e){var t,r;return null!==(r=null===(t=this.matrix[e.y])||void 0===t?void 0:t[e.x])&&void 0!==r?r:null}replaceAt(e,t){this.matrix[e.y][e.x]=t}}}},t={};function r(o){var i=t[o];if(void 0!==i)return i.exports;var n=t[o]={exports:{}};return e[o](n,n.exports,r),n.exports}var o={};(()=>{var e=o;Object.defineProperty(e,"__esModule",{value:!0}),e.WorldBiome=e.World=e.WorldGenerator=void 0;var t=r(997);Object.defineProperty(e,"WorldGenerator",{enumerable:!0,get:function(){return t.WorldGenerator}});var i=r(128);Object.defineProperty(e,"World",{enumerable:!0,get:function(){return i.World}});var n=r(408);Object.defineProperty(e,"WorldBiome",{enumerable:!0,get:function(){return n.WorldBiome}})})(),module.exports=o})();