diff --git a/src/core/GameImpl.ts b/src/core/GameImpl.ts index a8f497fad..7a789dabb 100644 --- a/src/core/GameImpl.ts +++ b/src/core/GameImpl.ts @@ -213,7 +213,7 @@ export class GameImpl implements MutableGame { this.map[x] = new Array(this._height); for (let y = 0; y < this._height; y++) { let cell = new Cell(x, y); - this.map[x][y] = new TileImpl(this, this._terraNullius, cell, terrainMap.terrain(cell)); + this.map[x][y] = new TileImpl(this, this._terraNullius, cell, terrainMap.terrain(cell).terrainType); } } } diff --git a/src/core/TerrainMapLoader.ts b/src/core/TerrainMapLoader.ts index 3543982be..82053367e 100644 --- a/src/core/TerrainMapLoader.ts +++ b/src/core/TerrainMapLoader.ts @@ -8,9 +8,9 @@ declare const Jimp: JimpType & JimpConstructors; export class TerrainMap { - constructor(public readonly tiles: TerrainType[][]) { } + constructor(public readonly tiles: Terrain[][]) { } - terrain(cell: Cell): TerrainType { + terrain(cell: Cell): Terrain { return this.tiles[cell.x][cell.y] } @@ -28,22 +28,34 @@ export enum TerrainType { Water } +export class Terrain { + constructor(public terrainType: TerrainType) { } +} + export async function loadTerrainMap(): Promise { const imageModule = await import(`../../resources/maps/World.png`); const imageUrl = imageModule.default; const image = await Jimp.read(imageUrl) const {width, height} = image.bitmap; - const terrain: TerrainType[][] = Array(width).fill(null).map(() => Array(height).fill(TerrainType.Water)); + const terrain: Terrain[][] = Array(width).fill(null).map(() => Array(height).fill(null)); image.scan(0, 0, width, height, function (x: number, y: number, idx: number) { const t: TerrainTile = new TerrainTile() const red = this.bitmap.data[idx + 0]; if (red > 100) { - terrain[x][y] = TerrainType.Land; + terrain[x][y] = new Terrain(TerrainType.Land) + } else { + terrain[x][y] = new Terrain(TerrainType.Water); } }) + process(terrain) + return new TerrainMap(terrain); +} + +function process(terrain: Terrain[][]) { + } \ No newline at end of file