Skip to content

Commit

Permalink
Added each of building positions
Browse files Browse the repository at this point in the history
  • Loading branch information
neki-dev committed Sep 13, 2023
1 parent a135a33 commit e40e38d
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 5 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ const nodeEnd = path.getNodeEnd(): Node
const length = path.getLength(): number
```
#### Each path positions
```ts
path.each(callback: (position: Position) => void)
```
#### Get path buildings
```ts
const buildings = path.getBuildings(): Building[]
Expand Down Expand Up @@ -176,6 +181,11 @@ const width: number = building.width
const height: number = building.height
```
#### Each building positions
```ts
building.each(callback: (position: Position) => void)
```
.
## Example
Expand Down
1 change: 1 addition & 0 deletions dist/building.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export declare class Building {
readonly width: number;
readonly height: number;
constructor(vertices: Position[]);
each(callback: (position: Position) => void): void;
}
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gen-city",
"description": "Procedural generation city",
"version": "1.0.1",
"version": "1.1.0",
"keywords": [
"map",
"generation",
Expand Down
11 changes: 11 additions & 0 deletions src/building.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,15 @@ export class Building {
this.width = Math.max(...xs) - this.position.x + 1;
this.height = Math.max(...ys) - this.position.y + 1;
}

public each(callback: (position: Position) => void) {
for (let x = 0; x < this.width; x++) {
for (let y = 0; y < this.height; y++) {
callback({
x: this.position.x + x,
y: this.position.y + y,
});
}
}
}
}
2 changes: 1 addition & 1 deletion src/city.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class City {
y: Math.round(this.height / 2),
},
startDirections: [0, 90, 180, 270],
streetMinLength: 0,
streetMinLength: 10,
buildingMinSize: 3,
buildingMaxSize: 6,
buildingMinSpace: 1,
Expand Down

0 comments on commit e40e38d

Please sign in to comment.