-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
1 lines (1 loc) 路 3.98 KB
/
index.js
1
(()=>{"use strict";var e={997:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WorldGenerator=void 0;const r=o(871),i=o(9),n=o(128),l=o(6);t.WorldGenerator=class{constructor(e){this.biomes=[],this.config=e}addBiome(e,t){const o=new l.WorldBiome(e,t);return this.biomes.push(o),o}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,o,l;const s=null!==(t=null==e?void 0:e.seed)&&void 0!==t?t:(0,i.generateSeed)(null==e?void 0:e.seedSize),u=[];for(let t=0;t<this.config.height;t++){u[t]=[];for(let i=0;i<this.config.width;i++){const n=(0,r.generateNoise)({config:this.config,seed:s,x:i+(null!==(o=null==e?void 0:e.offsetX)&&void 0!==o?o:0),y:t+(null!==(l=null==e?void 0:e.offsetY)&&void 0!==l?l:0)}),a=this.peakBiome(n);a&&(u[t][i]=a.data)}}return new n.World(u,s)}}},147:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},465:function(e,t,o){var r=this&&this.__createBinding||(Object.create?function(e,t,o,r){void 0===r&&(r=o);var i=Object.getOwnPropertyDescriptor(t,o);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,r,i)}:function(e,t,o,r){void 0===r&&(r=o),e[r]=t[o]}),i=this&&this.__exportStar||function(e,t){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(t,o)||r(t,e,o)};Object.defineProperty(t,"__esModule",{value:!0}),i(o(997),t),i(o(147),t),i(o(128),t),i(o(383),t),i(o(6),t),i(o(346),t),i(o(871),t),i(o(9),t)},871:(e,t)=>{function o(e,t,o=[0,1]){return Math.max(o[0],Math.min(o[1],null!=e?e:t))}function r(e){return.5*(1-Math.cos(e*Math.PI))}function i(e,t,o){const r=t/2,i=Math.abs(r-e),n=r*(1-o);if(i<n)return 1;let l=(i-n)/r/(1-n/r);return l=Math.min(1,Math.max(0,l)),1-function(e){return 3*Math.pow(e,2)-2*Math.pow(e,3)}(l)}Object.defineProperty(t,"__esModule",{value:!0}),t.generateNoise=void 0,t.generateNoise=function(e){var t;const{x:n,y:l,seed:s,config:u}=e,a=Math.round(31*o(u.frequencyChange,.3)+1),d=Math.round(14*(1-o(u.borderSmoothness,.5))+1),h=2-o(u.heightRedistribution,1,[.5,1.5]),c=o(u.falloff,0,[0,.9]),f=null===(t=u.heightAveraging)||void 0===t||t,v=s.length-1,p=n/u.width*a,g=l/u.height*a;let M,m,b,x,_,w=Math.floor(p),y=Math.floor(g),B=p-w,O=g-y,P=0,j=.5;for(let e=0;e<d;e++){let e=w+(y<<4);M=r(B),m=r(O),b=s[e&v],b+=M*(s[e+1&v]-b),x=s[e+16&v],x+=M*(s[e+16+1&v]-x),b+=m*(x-b),e+=256,x=s[e&v],x+=M*(s[e+1&v]-x),_=s[e+16&v],_+=M*(s[e+16+1&v]-_),x+=m*(_-x),P+=b*j,j*=.5,w<<=1,B*=2,B>=1&&(w++,B--),y<<=1,O*=2,O>=1&&(y++,O--)}return f&&(P>.5?P=Math.pow(P,(1.5-P)/1.1):P<.5&&(P=Math.pow(P,1.1*(1.5-P)))),P=Math.pow(P,h),c&&(P*=i(n,u.width,c)*i(l,u.height,c)),P}},9:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.generateSeed=void 0,t.generateSeed=function(e=512){const t=[];for(let o=0;o<e;o++)t.push(Math.random());return t}},6:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WorldBiome=void 0,t.WorldBiome=class{constructor(e,t){var o,r;this.lowerBound=Math.max(0,null!==(o=e.lowerBound)&&void 0!==o?o:0),this.upperBound=Math.min(1,null!==(r=e.upperBound)&&void 0!==r?r:1),this.data=t}}},346:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},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 o=0;o<this.width;o++)if(!1===e({x:o,y:t},this.matrix[t][o]))return}getAt(e){var t,o;return null!==(o=null===(t=this.matrix[e.y])||void 0===t?void 0:t[e.x])&&void 0!==o?o:null}replaceAt(e,t){if(e.y>=this.height||e.x>=this.width)throw Error(`Position [${e.x},${e.y}] is out of world bounds`);this.matrix[e.y][e.x]=t}}},383:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})}},t={},o=function o(r){var i=t[r];if(void 0!==i)return i.exports;var n=t[r]={exports:{}};return e[r].call(n.exports,n,n.exports,o),n.exports}(465);module.exports=o})();