-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tileset.js
43 lines (43 loc) · 1.37 KB
/
Tileset.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tileset = void 0;
const EntityRegistry_1 = require("@civ-clone/core-registry/EntityRegistry");
const Tile_1 = require("./Tile");
class Tileset extends EntityRegistry_1.EntityRegistry {
static from(...tiles) {
return new this(...tiles);
}
static fromSurrounding(tile, radius = 2) {
const gen = (radius) => {
const pairs = [];
for (let x = tile.x() - radius; x <= tile.x() + radius; x++) {
for (let y = tile.y() - radius; y <= tile.y() + radius; y++) {
pairs.push([x, y]);
}
}
return pairs;
};
return this.from(...gen(radius).map(([x, y]) => tile.map().get(x, y)));
}
constructor(...tiles) {
super(Tile_1.Tile);
this.register(...tiles);
}
push(...tiles) {
this.register(...tiles);
}
shift() {
const [first] = this.entries();
this.unregister(first);
return first;
}
score(player = null, values = []) {
return this.entries().reduce((total, tile) => total + tile.score(player, values), 0);
}
yields(player = null) {
return this.entries().flatMap((tile) => tile.yields(player));
}
}
exports.Tileset = Tileset;
exports.default = Tileset;
//# sourceMappingURL=Tileset.js.map