Skip to content

Commit

Permalink
Removed layers
Browse files Browse the repository at this point in the history
  • Loading branch information
neki-dev committed Feb 29, 2024
1 parent 5578175 commit 642ff3a
Show file tree
Hide file tree
Showing 22 changed files with 1,853 additions and 7,653 deletions.
33 changes: 33 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// eslint-disable-next-line no-undef
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
],
rules: {
// Basic
"no-multiple-empty-lines": ["error", { max: 1, maxBOF: 0, maxEOF: 1 }],
"no-multi-spaces": "error",
"object-curly-spacing": ["error", "always"],
"array-bracket-spacing": ["error", "never"],
"computed-property-spacing": ["error", "never"],
"comma-dangle": ["error", "always-multiline"],
"eol-last": ["error", "always"],
"no-trailing-spaces": "error",
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"indent": ["error", 2],
"keyword-spacing": ["error", { before: true, after: true }],
"padded-blocks": ["error", "never"],
"comma-spacing": ["error", { "before": false, "after": true }],
// TypeScript
"@typescript-eslint/semi": "error",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off",
},
};
3 changes: 0 additions & 3 deletions .eslintrc.json

This file was deleted.

35 changes: 8 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Documentation

* [Install](https://github.com/neki-dev/gen-biome?tab=readme-ov-file#install)
* [Generator](https://github.com/neki-dev/gen-biome?tab=readme-ov-file#generator)
* [Layers](https://github.com/neki-dev/gen-biome?tab=readme-ov-file#layers)
* [Biomes](https://github.com/neki-dev/gen-biome?tab=readme-ov-file#biomes)
* [Generation](https://github.com/neki-dev/gen-biome?tab=readme-ov-file#generation)
* [World](https://github.com/neki-dev/gen-biome?tab=readme-ov-file#world)
Expand All @@ -32,21 +31,11 @@ npm i gen-biome
## Generator
#### Create world generator
```ts
const generator = new WorldGenerator<T>(params)
const generator = new WorldGenerator<T>(config)
```
* `params {`
* `config {`
* * `width` - Map width
* * `height` - Map height
* `}`

.

## Layers
#### Add layer to generator
```ts
const layer: WorldLayer = generator.addLayer(params?)
```
* `params {`
* * `frequencyChange` - Frequency of biomes change
* * * _Default: 0.3, Min: 0.0, Max: 1.0_
* * `borderSmoothness` - Smoothness of biomes borders
Expand All @@ -59,23 +48,13 @@ const layer: WorldLayer = generator.addLayer(params?)
* * * _Default: 0.0_
* `}`

#### Get generator layers
```ts
const layers: WorldLayers[] = generator.getLayers()
```
#### Clear all generator layers
```ts
generator.clearLayers()
```
.

## Biomes
#### Add biome to layer
```ts
for (const { params, data } of ...) {
const biome: WorldBiome = layer.addBiome(params, data)
const biome: WorldBiome = generator.addBiome(params, data)
}
```
* `params {`
Expand Down Expand Up @@ -108,6 +87,10 @@ const world: World = generator.generate(params?)
* * * _Default: Autogenerate_
* * `seedSize` - Size of seed array
* * * _Default: 512_
* * `offsetX` - Generation offset X
* * * _Default: 0_
* * `offsetY` - Generation offset Y
* * * _Default: 0_
* `}`
.
Expand Down Expand Up @@ -187,10 +170,8 @@ const generator = new WorldGenerator({
height: 100,
});

const layer = generator.addLayer();

for (const { params, data } of BIOMES) {
layer.addBiome(params, data);
generator.addBiome(params, data);
}

const world = generator.generate();
Expand Down
4 changes: 2 additions & 2 deletions demo/src/biomes.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { WorldBiomeParams } from '../../src';
import type { WorldBiomeConfig } from "../../src";

export type BiomeData = {
name: string
color: string
};

export const BIOMES: Array<{
params: WorldBiomeParams
params: WorldBiomeConfig
data: BiomeData
}> = [
{
Expand Down
24 changes: 14 additions & 10 deletions demo/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { WorldGenerator } from "../../src/index";
import { BiomeData, BIOMES } from "./biomes";
import { WorldGenerator } from "../../src";
import type { BiomeData } from "./biomes";
import { BIOMES } from "./biomes";
import { ui } from "./interface";

const ctx = ui.screen.getContext("2d") as CanvasRenderingContext2D;
const tileSize = 2;
let savedSeed!: number[];

function generateAndRenderWorld() {
// PREPARE
/**
* PREPARE
*/

const generator = new WorldGenerator<BiomeData>({
width: Number(ui.inputs.worldWidth?.value),
height: Number(ui.inputs.worldHeight?.value),
});

const layer = generator.addLayer({
frequencyChange: Number(ui.inputs.frequencyChange?.value),
borderSmoothness: Number(ui.inputs.borderSmoothness?.value),
heightRedistribution: Number(ui.inputs.heightRedistribution?.value),
Expand All @@ -23,18 +23,22 @@ function generateAndRenderWorld() {
});

for (const { params, data } of BIOMES) {
layer.addBiome(params, data);
generator.addBiome(params, data);
}

// GENERATE
/**
* GENERATE
*/

const world = generator.generate({
const world = generator.generate({
seed: ui.inputs.resetSeed?.checked ? undefined : savedSeed,
});

savedSeed = world.seed;

// RENDER
/**
* RENDER
*/

ui.screen.width = world.width * tileSize;
ui.screen.height = world.height * tileSize;
Expand Down
18 changes: 10 additions & 8 deletions demo/src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const input = (name: string) => document.querySelector<HTMLInputElement>(`[name=${name}]`);

export const ui = {
screen: document.getElementById('screen') as HTMLCanvasElement,
inputs: {
resetSeed: document.querySelector<HTMLInputElement>('[name=resetSeed]'),
frequencyChange: document.querySelector<HTMLInputElement>('[name=frequencyChange]'),
borderSmoothness: document.querySelector<HTMLInputElement>('[name=borderSmoothness]'),
heightRedistribution: document.querySelector<HTMLInputElement>('[name=heightRedistribution]'),
falloff: document.querySelector<HTMLInputElement>('[name=falloff]'),
heightAveraging: document.querySelector<HTMLInputElement>('[name=heightAveraging]'),
worldWidth: document.querySelector<HTMLInputElement>('[name=worldWidth]'),
worldHeight: document.querySelector<HTMLInputElement>('[name=worldHeight]'),
resetSeed: input('resetSeed'),
frequencyChange: input('frequencyChange'),
borderSmoothness: input('borderSmoothness'),
heightRedistribution: input('heightRedistribution'),
falloff: input('falloff'),
heightAveraging: input('heightAveraging'),
worldWidth: input('worldWidth'),
worldHeight: input('worldHeight'),
},
buttons: {
generate: document.getElementById('generate'),
Expand Down
Loading

0 comments on commit 642ff3a

Please sign in to comment.