diff --git a/dist/world/biome/index.d.ts b/dist/biome/index.d.ts similarity index 100% rename from dist/world/biome/index.d.ts rename to dist/biome/index.d.ts diff --git a/dist/world/biome/types.d.ts b/dist/biome/types.d.ts similarity index 100% rename from dist/world/biome/types.d.ts rename to dist/biome/types.d.ts diff --git a/dist/generator/index.d.ts b/dist/generator/index.d.ts index c43bf62..855a14a 100644 --- a/dist/generator/index.d.ts +++ b/dist/generator/index.d.ts @@ -1,8 +1,8 @@ import type { WorldGenerationParams } from "./types"; import { World } from "../world"; -import { WorldBiome } from "../world/biome"; +import { WorldBiome } from "../biome"; import type { WorldConfig } from "../world/types"; -import type { WorldBiomeConfig } from "../world/biome/types"; +import type { WorldBiomeConfig } from "../biome/types"; export declare class WorldGenerator { readonly config: WorldConfig; private biomes; diff --git a/dist/index.d.ts b/dist/index.d.ts index 7bbc175..69aff4a 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,8 +1,7 @@ -export * from './generator'; -export * from './generator/types'; -export * from './world'; -export * from './world/types'; -export * from './world/biome'; -export * from './world/biome/types'; -export * from './utils/perlin'; -export * from './utils/seed'; +export { WorldGenerator } from "./generator"; +export { World } from "./world"; +export { WorldBiome } from "./biome"; +import type { WorldConfig, WorldPoint } from "./world/types"; +import type { WorldGenerationParams } from "./generator/types"; +import type { WorldBiomeConfig } from "./biome/types"; +export type { WorldConfig, WorldPoint, WorldGenerationParams, WorldBiomeConfig, }; diff --git a/dist/index.js b/dist/index.js index a0fa8e3..4223dac 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1 +1 @@ -(()=>{"use strict";var e={997:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WorldGenerator=void 0;const i=o(871),r=o(9),n=o(128),s=o(6);t.WorldGenerator=class{constructor(e){this.biomes=[],this.config=e}addBiome(e,t){const o=new s.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,s;const l=null!==(t=null==e?void 0:e.seed)&&void 0!==t?t:r.Seed.generate(null==e?void 0:e.seedSize),a=[];for(let t=0;t{Object.defineProperty(t,"__esModule",{value:!0})},465:function(e,t,o){var i=this&&this.__createBinding||(Object.create?function(e,t,o,i){void 0===i&&(i=o);var r=Object.getOwnPropertyDescriptor(t,o);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,i,r)}:function(e,t,o,i){void 0===i&&(i=o),e[i]=t[o]}),r=this&&this.__exportStar||function(e,t){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(t,o)||i(t,e,o)};Object.defineProperty(t,"__esModule",{value:!0}),r(o(997),t),r(o(147),t),r(o(128),t),r(o(383),t),r(o(6),t),r(o(346),t),r(o(871),t),r(o(9),t)},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<{Object.defineProperty(t,"__esModule",{value:!0}),t.Perlin=void 0;const i=o(708);t.Perlin=class{static generate({x:e,y:t,seed:o,config:r}){const{frequencyChange:n,borderSmoothness:s,heightAveraging:l,heightRedistribution:a,falloff:h}=this.normalizeConfig(r),d=o.length-1,u=e/r.width*n,c=t/r.height*n;let f=Math.floor(u),P=Math.floor(c),_=u-f,g=c-P,v=0,p=.5;for(let e=0;e=1&&(f++,_--),P<<=1,g*=2,g>=1&&(P++,g--)}return l&&(v>.5?v=Math.pow(v,(1.5-v)/i.PERLIN_AVG_POWER):v<.5&&(v=Math.pow(v,(1.5-v)*i.PERLIN_AVG_POWER))),v=Math.pow(v,a),h>0&&(v*=this.heightFalloff(e,r.width,h)*this.heightFalloff(t,r.height,h)),v}static clamp(e,t,o=[0,1]){return Math.max(o[0],Math.min(o[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,o){const i=t/2,r=Math.abs(i-e),n=i*(1-o);if(r{Object.defineProperty(t,"__esModule",{value:!0}),t.Seed=void 0,t.Seed=class{static generate(e=512){const t=[];for(let o=0;o{Object.defineProperty(t,"__esModule",{value:!0}),t.WorldBiome=void 0,t.WorldBiome=class{constructor(e,t){var o,i;this.lowerBound=Math.max(0,null!==(o=e.lowerBound)&&void 0!==o?o:0),this.upperBound=Math.min(1,null!==(i=e.upperBound)&&void 0!==i?i: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{Object.defineProperty(t,"__esModule",{value:!0})}},t={},o=function o(i){var r=t[i];if(void 0!==r)return r.exports;var n=t[i]={exports:{}};return e[i].call(n.exports,n,n.exports,o),n.exports}(465);module.exports=o})(); \ No newline at end of file +(()=>{"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{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<{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=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{Object.defineProperty(t,"__esModule",{value:!0}),t.Seed=void 0,t.Seed=class{static generate(e=512){const t=[];for(let r=0;r{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{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})(); \ No newline at end of file diff --git a/dist/types.d.ts b/dist/types.d.ts deleted file mode 100644 index 33b2a96..0000000 --- a/dist/types.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -export type WorldParams = { - width: number; - height: number; -}; -export type WorldLayerParams = { - /** - * Frequency of biomes change - * Default: 0.3 - * Min: 0.0, Max: 1.0 - */ - frequencyChange?: number; - /** - * Smoothness of biomes borders - * Default: 0.5 - * Min: 0.0, Max: 1.0 - */ - borderSmoothness?: number; - /** - * Redistribution of biomes height - * Default: 1.0 - * Min: 0.5, Max: 1.5 - */ - heightRedistribution?: number; - /** - * Averaging of biomes height - * Default: true - */ - heightAveraging?: boolean; - /** - * Scale of falloff area - * Default: 0.0 - */ - falloff?: number; -}; -export type WorldBiomeParams = { - /** - * Lower biome bound - * Default: 0.0 - * Min: 0.0 - */ - lowerBound?: number; - /** - * Upper biome bound - * Default: 1.0 - * Max: 1.0 - */ - upperBound?: number; -}; -export type WorldGenerationParams = { - /** - * Generation seed - * Default: Autogenerate - */ - seed?: number[]; - /** - * Size of seed array - * Default: 512 - */ - seedSize?: number; -}; -export type WorldBiomePosition = { - x: number; - y: number; -}; diff --git a/dist/utils/clamp.d.ts b/dist/utils/clamp.d.ts deleted file mode 100644 index 4bd87ef..0000000 --- a/dist/utils/clamp.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function clamp(value: number | undefined, defaultValue: number, limit?: [number, number]): number; diff --git a/dist/utils/perlin.d.ts b/dist/utils/perlin.d.ts deleted file mode 100644 index 7b74573..0000000 --- a/dist/utils/perlin.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { WorldLayerParams } from '../types'; -type NoiseParameters = { - seed: number[]; - x: number; - y: number; - width: number; - height: number; - params: WorldLayerParams; -}; -export declare function generateNoise(parameters: NoiseParameters): number; -export {}; diff --git a/dist/utils/perlin/index.d.ts b/dist/utils/perlin/index.d.ts index 3000cdb..cb0ff5c 100644 --- a/dist/utils/perlin/index.d.ts +++ b/dist/utils/perlin/index.d.ts @@ -1,9 +1 @@ -import type { PerlinParameters } from "./types"; -export declare class Perlin { - static generate({ x, y, seed, config }: PerlinParameters): number; - private static clamp; - private static scaledCosine; - private static smootherStep; - private static heightFalloff; - private static normalizeConfig; -} +export {}; diff --git a/dist/utils/perlin/types.d.ts b/dist/utils/perlin/types.d.ts index 248a45c..cb0ff5c 100644 --- a/dist/utils/perlin/types.d.ts +++ b/dist/utils/perlin/types.d.ts @@ -1,7 +1 @@ -import type { WorldConfig } from "../../world/types"; -export type PerlinParameters = { - seed: number[]; - config: WorldConfig; - x: number; - y: number; -}; +export {}; diff --git a/dist/utils/seed.d.ts b/dist/utils/seed.d.ts deleted file mode 100644 index fbb9a33..0000000 --- a/dist/utils/seed.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function generateSeed(size?: number): number[]; diff --git a/dist/utils/seed/index.d.ts b/dist/utils/seed/index.d.ts index 4f59f1e..cb0ff5c 100644 --- a/dist/utils/seed/index.d.ts +++ b/dist/utils/seed/index.d.ts @@ -1,3 +1 @@ -export declare class Seed { - static generate(size?: number): number[]; -} +export {}; diff --git a/dist/world-biome.d.ts b/dist/world-biome.d.ts deleted file mode 100644 index b31fee1..0000000 --- a/dist/world-biome.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { WorldBiomeParams } from './types'; -export declare class WorldBiome { - readonly lowerBound: number; - readonly upperBound: number; - readonly data: T; - constructor(params: WorldBiomeParams, data: T); -} diff --git a/dist/world-generator.d.ts b/dist/world-generator.d.ts deleted file mode 100644 index 9a4ecf0..0000000 --- a/dist/world-generator.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { WorldGenerationParams, WorldLayerParams, WorldParams } from './types'; -import { World } from './world'; -import { WorldLayer } from './world-layer'; -export declare class WorldGenerator { - readonly width: number; - readonly height: number; - private layers; - constructor(params: WorldParams); - addLayer(params?: WorldLayerParams): WorldLayer; - clearLayers(): void; - getLayers(): WorldLayer[]; - generate(params?: WorldGenerationParams): World; - private generateLayer; -} diff --git a/dist/world-layer.d.ts b/dist/world-layer.d.ts deleted file mode 100644 index b0a598a..0000000 --- a/dist/world-layer.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { WorldBiomeParams, WorldLayerParams } from './types'; -import { WorldBiome } from './world-biome'; -export declare class WorldLayer { - readonly params: WorldLayerParams; - private biomes; - constructor(params?: WorldLayerParams); - addBiome(params: WorldBiomeParams, data: T): WorldBiome; - clearBiomes(): void; - getBiomes(): WorldBiome[]; - getBiomeByHeight(height: number): WorldBiome | undefined; -} diff --git a/dist/world.d.ts b/dist/world.d.ts deleted file mode 100644 index 266d51b..0000000 --- a/dist/world.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { WorldBiomePosition } from './types'; -export declare class World { - readonly width: number; - readonly height: number; - readonly seed: number[]; - private matrix; - constructor(matrix: T[][], seed: number[]); - getMatrix(): T[][]; - each(callback: (position: WorldBiomePosition, biome: T) => boolean | void): void; - getAt(position: WorldBiomePosition): T | null; - replaceAt(position: WorldBiomePosition, data: T): void; -} diff --git a/package.json b/package.json index b1ebcff..a17840b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "gen-biome", "description": "Procedural generation of 2D maps with distinct biomes", - "version": "3.0.3", + "version": "3.0.4", "keywords": [ "map", "generation", diff --git a/src/world/biome/index.ts b/src/biome/index.ts similarity index 100% rename from src/world/biome/index.ts rename to src/biome/index.ts diff --git a/src/world/biome/types.ts b/src/biome/types.ts similarity index 100% rename from src/world/biome/types.ts rename to src/biome/types.ts diff --git a/src/generator/index.ts b/src/generator/index.ts index 8a18477..46c1828 100644 --- a/src/generator/index.ts +++ b/src/generator/index.ts @@ -2,9 +2,9 @@ import type { WorldGenerationParams } from "./types"; import { Perlin } from "../utils/perlin"; import { Seed } from "../utils/seed"; import { World } from "../world"; -import { WorldBiome } from "../world/biome"; +import { WorldBiome } from "../biome"; import type { WorldConfig } from "../world/types"; -import type { WorldBiomeConfig } from "../world/biome/types"; +import type { WorldBiomeConfig } from "../biome/types"; export class WorldGenerator { readonly config: WorldConfig; diff --git a/src/index.ts b/src/index.ts index 7bbc175..0edaf7c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,14 @@ -export * from './generator'; -export * from './generator/types'; -export * from './world'; -export * from './world/types'; -export * from './world/biome'; -export * from './world/biome/types'; -export * from './utils/perlin'; -export * from './utils/seed'; +export { WorldGenerator } from "./generator"; +export { World } from "./world"; +export { WorldBiome } from "./biome"; + +import type { WorldConfig, WorldPoint } from "./world/types"; +import type { WorldGenerationParams } from "./generator/types"; +import type { WorldBiomeConfig } from "./biome/types"; + +export type { + WorldConfig, + WorldPoint, + WorldGenerationParams, + WorldBiomeConfig, +}; diff --git a/src/utils/perlin/index.ts b/src/utils/perlin/index.ts index 6662658..b3b67d0 100644 --- a/src/utils/perlin/index.ts +++ b/src/utils/perlin/index.ts @@ -8,6 +8,9 @@ import { } from "./const"; import type { PerlinParameters } from "./types"; +/** + * @internal + */ export class Perlin { public static generate({ x, y, seed, config }: PerlinParameters): number { const { diff --git a/src/utils/perlin/types.ts b/src/utils/perlin/types.ts index 68a5480..8713915 100644 --- a/src/utils/perlin/types.ts +++ b/src/utils/perlin/types.ts @@ -1,5 +1,8 @@ import type { WorldConfig } from "../../world/types"; +/** + * @internal + */ export type PerlinParameters = { seed: number[] config: WorldConfig diff --git a/src/utils/seed/index.ts b/src/utils/seed/index.ts index 500984f..d3e9367 100644 --- a/src/utils/seed/index.ts +++ b/src/utils/seed/index.ts @@ -1,11 +1,14 @@ +/** + * @internal + */ export class Seed { public static generate(size: number = 512) { const seed: number[] = []; - + for (let i = 0; i < size; i++) { seed.push(Math.random()); } - + return seed; } -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index b8296e8..ce9da8d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "target": "es6", "esModuleInterop": true, "declaration": true, + "stripInternal": true, "strict": true }, "include": ["./src/**/*"]