From 02898ed3fc1718214cbcec51af605588c2c745a2 Mon Sep 17 00:00:00 2001 From: neki-dev Date: Thu, 29 Feb 2024 13:47:48 +0300 Subject: [PATCH] Rebuild --- dist/generator/index.d.ts | 15 +++++++++++++ dist/generator/types.d.ts | 22 +++++++++++++++++++ dist/index.d.ts | 7 ++++-- dist/index.js | 2 +- dist/utils/perlin/index.d.ts | 2 ++ dist/utils/perlin/types.d.ts | 7 ++++++ dist/utils/seed/index.d.ts | 1 + dist/world/biome/index.d.ts | 7 ++++++ dist/world/biome/types.d.ts | 14 ++++++++++++ dist/world/index.d.ts | 12 +++++++++++ dist/world/types.d.ts | 42 ++++++++++++++++++++++++++++++++++++ package.json | 2 +- 12 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 dist/generator/index.d.ts create mode 100644 dist/generator/types.d.ts create mode 100644 dist/utils/perlin/index.d.ts create mode 100644 dist/utils/perlin/types.d.ts create mode 100644 dist/utils/seed/index.d.ts create mode 100644 dist/world/biome/index.d.ts create mode 100644 dist/world/biome/types.d.ts create mode 100644 dist/world/index.d.ts create mode 100644 dist/world/types.d.ts diff --git a/dist/generator/index.d.ts b/dist/generator/index.d.ts new file mode 100644 index 0000000..c43bf62 --- /dev/null +++ b/dist/generator/index.d.ts @@ -0,0 +1,15 @@ +import type { WorldGenerationParams } from "./types"; +import { World } from "../world"; +import { WorldBiome } from "../world/biome"; +import type { WorldConfig } from "../world/types"; +import type { WorldBiomeConfig } from "../world/biome/types"; +export declare class WorldGenerator { + readonly config: WorldConfig; + private biomes; + constructor(config: WorldConfig); + addBiome(config: WorldBiomeConfig, data: T): WorldBiome; + clearBiomes(): void; + getBiomes(): WorldBiome[]; + peakBiome(height: number): WorldBiome | null; + generate(params?: WorldGenerationParams): World; +} diff --git a/dist/generator/types.d.ts b/dist/generator/types.d.ts new file mode 100644 index 0000000..031e069 --- /dev/null +++ b/dist/generator/types.d.ts @@ -0,0 +1,22 @@ +export type WorldGenerationParams = { + /** + * Generation seed + * Default: Autogenerate + */ + seed?: number[]; + /** + * Size of seed array + * Default: 512 + */ + seedSize?: number; + /** + * Generation offset X + * Default: 0 + */ + offsetX?: number; + /** + * Generation offset Y + * Default: 0 + */ + offsetY?: number; +}; diff --git a/dist/index.d.ts b/dist/index.d.ts index 9896c83..7bbc175 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,5 +1,8 @@ -export * from './world-generator'; +export * from './generator'; +export * from './generator/types'; export * from './world'; -export * from './types'; +export * from './world/types'; +export * from './world/biome'; +export * from './world/biome/types'; export * from './utils/perlin'; export * from './utils/seed'; diff --git a/dist/index.js b/dist/index.js index c6e54a7..d907d59 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1 +1 @@ -(()=>{"use strict";var e={465:function(e,t,r){var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,i)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||o(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),i(r(771),t),i(r(535),t),i(r(309),t),i(r(650),t),i(r(718),t)},309:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},650:(e,t)=>{function r(e,t,r=[0,1]){return Math.max(r[0],Math.min(r[1],null!=e?e:t))}function o(e){return.5*(1-Math.cos(e*Math.PI))}function i(e,t,r){const o=t/2,i=Math.abs(o-e),n=o*(1-r);if(i=1&&(B++,P--),O<<=1,j*=2,j>=1&&(O++,j--)}return p&&(W>.5?W=Math.pow(W,(1.5-W)/1.1):W<.5&&(W=Math.pow(W,1.1*(1.5-W)))),W=Math.pow(W,f),g&&(W*=i(n,h,g)*i(s,a,g)),W}},718:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.generateSeed=void 0,t.generateSeed=function(e=512){const t=[];for(let r=0;r{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}}},771:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WorldGenerator=void 0;const o=r(650),i=r(718),n=r(535),s=r(481);t.WorldGenerator=class{constructor(e){this.layers=[],this.width=e.width,this.height=e.height}addLayer(e={}){const t=new s.WorldLayer(e);return this.layers.push(t),t}clearLayers(){this.layers=[]}getLayers(){return this.layers}generate(e){var t;const r=null!==(t=null==e?void 0:e.seed)&&void 0!==t?t:(0,i.generateSeed)(null==e?void 0:e.seedSize),o=[];for(const e of this.layers){const t=this.generateLayer(e,r);for(let e=0;e{Object.defineProperty(t,"__esModule",{value:!0}),t.WorldLayer=void 0;const o=r(910);t.WorldLayer=class{constructor(e={}){this.biomes=[],this.params=e}addBiome(e,t){const r=new o.WorldBiome(e,t);return this.biomes.push(r),r}clearBiomes(){this.biomes=[]}getBiomes(){return this.biomes}getBiomeByHeight(e){return this.getBiomes().find((t=>e>=t.lowerBound&&e<=t.upperBound))}}},535:(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||e.x>=this.width)throw Error(`Position [${e.x},${e.y}] is out of world bounds`);this.matrix[e.y][e.x]=t}}}},t={},r=function r(o){var i=t[o];if(void 0!==i)return i.exports;var n=t[o]={exports:{}};return e[o].call(n.exports,n,n.exports,r),n.exports}(465);module.exports=r})(); \ No newline at end of file +(()=>{"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{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=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{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||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})(); \ No newline at end of file diff --git a/dist/utils/perlin/index.d.ts b/dist/utils/perlin/index.d.ts new file mode 100644 index 0000000..61c5190 --- /dev/null +++ b/dist/utils/perlin/index.d.ts @@ -0,0 +1,2 @@ +import type { PerlinParameters } from "./types"; +export declare function generateNoise(parameters: PerlinParameters): number; diff --git a/dist/utils/perlin/types.d.ts b/dist/utils/perlin/types.d.ts new file mode 100644 index 0000000..248a45c --- /dev/null +++ b/dist/utils/perlin/types.d.ts @@ -0,0 +1,7 @@ +import type { WorldConfig } from "../../world/types"; +export type PerlinParameters = { + seed: number[]; + config: WorldConfig; + x: number; + y: number; +}; diff --git a/dist/utils/seed/index.d.ts b/dist/utils/seed/index.d.ts new file mode 100644 index 0000000..fbb9a33 --- /dev/null +++ b/dist/utils/seed/index.d.ts @@ -0,0 +1 @@ +export declare function generateSeed(size?: number): number[]; diff --git a/dist/world/biome/index.d.ts b/dist/world/biome/index.d.ts new file mode 100644 index 0000000..fdd5d34 --- /dev/null +++ b/dist/world/biome/index.d.ts @@ -0,0 +1,7 @@ +import type { WorldBiomeConfig } from "./types"; +export declare class WorldBiome { + readonly lowerBound: number; + readonly upperBound: number; + readonly data: T; + constructor(config: WorldBiomeConfig, data: T); +} diff --git a/dist/world/biome/types.d.ts b/dist/world/biome/types.d.ts new file mode 100644 index 0000000..96956ba --- /dev/null +++ b/dist/world/biome/types.d.ts @@ -0,0 +1,14 @@ +export type WorldBiomeConfig = { + /** + * Lower biome bound + * Default: 0.0 + * Min: 0.0 + */ + lowerBound?: number; + /** + * Upper biome bound + * Default: 1.0 + * Max: 1.0 + */ + upperBound?: number; +}; diff --git a/dist/world/index.d.ts b/dist/world/index.d.ts new file mode 100644 index 0000000..e102da6 --- /dev/null +++ b/dist/world/index.d.ts @@ -0,0 +1,12 @@ +import type { WorldPoint } 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: (point: WorldPoint, biome: T) => boolean | void): void; + getAt(point: WorldPoint): T | null; + replaceAt(point: WorldPoint, data: T): void; +} diff --git a/dist/world/types.d.ts b/dist/world/types.d.ts new file mode 100644 index 0000000..a592bdb --- /dev/null +++ b/dist/world/types.d.ts @@ -0,0 +1,42 @@ +export type WorldConfig = { + /** + * World width + */ + width: number; + /** + * World height + */ + height: number; + /** + * 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 WorldPoint = { + x: number; + y: number; +}; diff --git a/package.json b/package.json index 87cb642..e1ed75e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "gen-biome", "description": "Procedural generation 2D map with biomes", - "version": "3.0.0", + "version": "3.0.1", "keywords": [ "map", "generation",