From 7517f933ca31bb8f0f44cabe1aec8b2e98809268 Mon Sep 17 00:00:00 2001 From: evanpelle Date: Thu, 22 Aug 2024 08:00:18 -0700 Subject: [PATCH] added shoreline to tiles --- src/core/Game.ts | 2 ++ src/core/GameImpl.ts | 16 +++++++---- src/core/TerrainMapLoader.ts | 38 ++++++++++++++++++++++++--- src/core/configuration/PastelTheme.ts | 10 +++++++ 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/core/Game.ts b/src/core/Game.ts index 403299dea..a8de0cfe1 100644 --- a/src/core/Game.ts +++ b/src/core/Game.ts @@ -39,7 +39,9 @@ export class PlayerInfo { export interface Tile { isLand(): boolean + isShore(): boolean isWater(): boolean + isShorelineWater(): boolean owner(): Player | TerraNullius hasOwner(): boolean isBorder(): boolean diff --git a/src/core/GameImpl.ts b/src/core/GameImpl.ts index 7a789dabb..15817f3e2 100644 --- a/src/core/GameImpl.ts +++ b/src/core/GameImpl.ts @@ -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} from "./TerrainMapLoader"; +import {Terrain, TerrainMap, TerrainType} from "./TerrainMapLoader"; export function createGame(terrainMap: TerrainMap, eventBus: EventBus): Game { return new GameImpl(terrainMap, eventBus) @@ -17,13 +17,19 @@ class TileImpl implements Tile { private readonly gs: GameImpl, public _owner: PlayerImpl | TerraNulliusImpl, private readonly _cell: Cell, - private readonly _terrain: TerrainType + private readonly _terrain: Terrain ) { } + isShore(): boolean { + return this.isLand() && this._terrain.shoreline + } + isShorelineWater(): boolean { + return this.isWater() && this._terrain.shoreline + } isLand(): boolean { - return this._terrain == TerrainType.Land + return this._terrain.type == TerrainType.Land } isWater(): boolean { - return this._terrain == TerrainType.Water + return this._terrain.type == TerrainType.Water } borders(other: Player | TerraNullius): boolean { @@ -213,7 +219,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).terrainType); + this.map[x][y] = new TileImpl(this, this._terraNullius, cell, terrainMap.terrain(cell)); } } } diff --git a/src/core/TerrainMapLoader.ts b/src/core/TerrainMapLoader.ts index 82053367e..8e156448e 100644 --- a/src/core/TerrainMapLoader.ts +++ b/src/core/TerrainMapLoader.ts @@ -29,7 +29,8 @@ export enum TerrainType { } export class Terrain { - constructor(public terrainType: TerrainType) { } + public shoreline: boolean = false + constructor(public type: TerrainType) { } } export async function loadTerrainMap(): Promise { @@ -56,6 +57,37 @@ export async function loadTerrainMap(): Promise { return new TerrainMap(terrain); } -function process(terrain: Terrain[][]) { - +function process(map: Terrain[][]) { + for (let x = 0; x < map.length; x++) { + for (let y = 0; y < map[0].length; y++) { + const terrain = map[x][y] + const ns = neighbors(x, y, map) + if (terrain.type == TerrainType.Land) { + if (ns.filter(t => t.type == TerrainType.Water).length > 0) { + terrain.shoreline = true + } + } else { + if (ns.filter(t => t.type == TerrainType.Land).length > 0) { + terrain.shoreline = true + } + } + } + } +} + +function neighbors(x: number, y: number, map: Terrain[][]): Terrain[] { + const ns: Terrain[] = [] + if (x > 0) { + ns.push(map[x - 1][y]) + } + if (x < map.length - 1) { + ns.push(map[x + 1][y]) + } + if (y > 0) { + ns.push(map[x][y - 1]) + } + if (y < map[0].length - 1) { + ns.push(map[x][y + 1]) + } + return ns } \ No newline at end of file diff --git a/src/core/configuration/PastelTheme.ts b/src/core/configuration/PastelTheme.ts index a52d52c36..3c9774e1e 100644 --- a/src/core/configuration/PastelTheme.ts +++ b/src/core/configuration/PastelTheme.ts @@ -5,7 +5,11 @@ import {Theme} from "./Config"; export const pastelTheme = new class implements Theme { private background = colord({r: 100, g: 100, b: 100}); private land = colord({r: 244, g: 243, b: 198}); + private shore = colord({r: 234, g: 343, b: 188}); + private water = colord({r: 160, g: 203, b: 231}); + private shorelineWater = colord({r: 150, g: 193, b: 221}); + private territoryColors: Colord[] = [ colord({r: 255, g: 179, b: 186}), // Vibrant Light Pink colord({r: 255, g: 223, b: 186}), // Vibrant Peach @@ -77,8 +81,14 @@ export const pastelTheme = new class implements Theme { terrainColor(tile: Tile): Colord { if (tile.isLand()) { + if (tile.isShore()) { + return this.shore + } return this.land; } else { + if (tile.isShorelineWater()) { + return this.shorelineWater + } return this.water; } }