mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-26 12:34:36 +00:00
made terrain type and enum
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {EventBus} from "./EventBus";
|
||||
import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerEvent, PlayerID, PlayerInfo, Player, TerraNullius, Tile, TileEvent, Boat, MutableBoat, BoatEvent} from "./Game";
|
||||
import {TerrainMap, TerrainType, TerrainTypes} from "./TerrainMapLoader";
|
||||
import {TerrainMap, TerrainType} from "./TerrainMapLoader";
|
||||
|
||||
export function createGame(terrainMap: TerrainMap, eventBus: EventBus): Game {
|
||||
return new GameImpl(terrainMap, eventBus)
|
||||
@@ -20,10 +20,10 @@ class TileImpl implements Tile {
|
||||
private readonly _terrain: TerrainType
|
||||
) { }
|
||||
isLand(): boolean {
|
||||
return this._terrain == TerrainTypes.Land
|
||||
return this._terrain == TerrainType.Land
|
||||
}
|
||||
isWater(): boolean {
|
||||
return this._terrain == TerrainTypes.Water
|
||||
return this._terrain == TerrainType.Water
|
||||
}
|
||||
|
||||
borders(other: Player | TerraNullius): boolean {
|
||||
|
||||
@@ -23,19 +23,9 @@ export class TerrainMap {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: make terrain api better.
|
||||
export class Terrain {
|
||||
constructor(
|
||||
public readonly expansionCost: number,
|
||||
public readonly expansionTime: number,
|
||||
) { }
|
||||
}
|
||||
|
||||
export type TerrainType = typeof TerrainTypes[keyof typeof TerrainTypes];
|
||||
|
||||
export const TerrainTypes = {
|
||||
Land: new Terrain(1, 1),
|
||||
Water: new Terrain(0, 0)
|
||||
export enum TerrainType {
|
||||
Land,
|
||||
Water
|
||||
}
|
||||
|
||||
export async function loadTerrainMap(): Promise<TerrainMap> {
|
||||
@@ -44,14 +34,14 @@ export async function loadTerrainMap(): Promise<TerrainMap> {
|
||||
const image = await Jimp.read(imageUrl)
|
||||
const {width, height} = image.bitmap;
|
||||
|
||||
const terrain: TerrainType[][] = Array(width).fill(null).map(() => Array(height).fill(TerrainTypes.Water));
|
||||
const terrain: TerrainType[][] = Array(width).fill(null).map(() => Array(height).fill(TerrainType.Water));
|
||||
|
||||
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] = TerrainTypes.Land;
|
||||
terrain[x][y] = TerrainType.Land;
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user