Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/client/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export class AlternateViewEvent implements GameEvent {
constructor(public readonly alternateView: boolean) {}
}

export class ToggleShowDefensePostRangeEvent implements GameEvent {}

export class CloseViewEvent implements GameEvent {}

export class RefreshGraphicsEvent implements GameEvent {}
Expand Down
18 changes: 17 additions & 1 deletion src/client/graphics/layers/OptionsMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { GameType } from "../../../core/game/Game";
import { GameUpdateType } from "../../../core/game/GameUpdates";
import { GameView } from "../../../core/game/GameView";
import { UserSettings } from "../../../core/game/UserSettings";
import { AlternateViewEvent, RefreshGraphicsEvent } from "../../InputHandler";
import {
AlternateViewEvent,
RefreshGraphicsEvent,
ToggleShowDefensePostRangeEvent,
} from "../../InputHandler";
import { PauseGameEvent } from "../../Transport";
import { Layer } from "./Layer";

Expand Down Expand Up @@ -115,6 +119,11 @@ export class OptionsMenu extends LitElement implements Layer {
this.userSettings.toggleLeftClickOpenMenu();
}

private onToggleShowDefensePostRange() {
this.userSettings.toggleShowDefensePostRange();
this.eventBus.emit(new ToggleShowDefensePostRangeEvent());
}

init() {
console.log("init called from OptionsMenu");
this.showPauseButton =
Expand Down Expand Up @@ -214,6 +223,13 @@ export class OptionsMenu extends LitElement implements Layer {
? "Focus locked"
: "Hover focus"),
})} -->
${button({
onClick: this.onToggleShowDefensePostRange,
title: "Show Defense Post Range",
children:
"🛡️: " +
(this.userSettings.showDefensePostRange() ? "Show" : "Hide"),
})}
</div>
</div>
`;
Expand Down
72 changes: 43 additions & 29 deletions src/client/graphics/layers/TerritoryLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
import { GameUpdateType, UnitUpdate } from "../../../core/game/GameUpdates";
import { GameView, PlayerView } from "../../../core/game/GameView";
import { PseudoRandom } from "../../../core/PseudoRandom";
import { AlternateViewEvent, DragEvent } from "../../InputHandler";
import {
AlternateViewEvent,
DragEvent,
ToggleShowDefensePostRangeEvent,
} from "../../InputHandler";
import { Layer } from "./Layer";

export class TerritoryLayer implements Layer {
Expand Down Expand Up @@ -66,19 +70,22 @@ export class TerritoryLayer implements Layer {
const update = u as UnitUpdate;
if (update.unitType == UnitType.DefensePost && update.isActive) {
const tile = update.pos;
this.game
.bfs(
tile,
manhattanDistFN(tile, this.game.config().defensePostRange()),
)
.forEach((t) => {
if (
this.game.isBorder(t) &&
this.game.ownerID(t) == update.ownerID
) {
this.enqueueTile(t);
}
});
const config = this.game.config();
const defensePostRange = config.defensePostRange();
const showDefensePostRange = config
.userSettings()
.showDefensePostRange();
const distanceFN = showDefensePostRange
? euclDistFN(tile, defensePostRange)
: manhattanDistFN(tile, defensePostRange);

this.game.bfs(tile, distanceFN).forEach((t) => {
if (this.game.isBorder(t) && this.game.ownerID(t) == update.ownerID) {
this.enqueueTile(t);
} else if (showDefensePostRange) {
this.enqueueTile(t);
}
});
}
});

Expand Down Expand Up @@ -142,6 +149,14 @@ export class TerritoryLayer implements Layer {
// TODO: consider re-enabling this on mobile or low end devices for smoother dragging.
// this.lastDragTime = Date.now();
});
this.eventBus.on(ToggleShowDefensePostRangeEvent, () => {
const defensePostRange = this.game.config().defensePostRange();
this.game.units(UnitType.DefensePost).forEach((unit) => {
this.game
.bfs(unit.tile(), euclDistFN(unit.tile(), defensePostRange))
.forEach((tile) => this.enqueueTile(tile));
});
});
this.redraw();
}

Expand Down Expand Up @@ -247,18 +262,16 @@ export class TerritoryLayer implements Layer {
this.clearCell(new Cell(this.game.x(tile), this.game.y(tile)));
return;
}

const owner = this.game.owner(tile) as PlayerView;
const defensePostRange = this.game.config().defensePostRange();
const tileIsInDefensePostRange =
this.game
.nearbyUnits(tile, defensePostRange, UnitType.DefensePost)
.filter((u) => u.unit.owner() == owner).length > 0;
if (this.game.isBorder(tile)) {
const playerIsFocused = owner && this.game.focusedPlayer() == owner;
if (
this.game
.nearbyUnits(
tile,
this.game.config().defensePostRange(),
UnitType.DefensePost,
)
.filter((u) => u.unit.owner() == owner).length > 0
) {
if (tileIsInDefensePostRange) {
const useDefendedBorderColor = playerIsFocused
? this.theme.focusedDefendedBorderColor()
: this.theme.defendedBorderColor(owner);
Expand All @@ -280,12 +293,13 @@ export class TerritoryLayer implements Layer {
);
}
} else {
this.paintCell(
this.game.x(tile),
this.game.y(tile),
this.theme.territoryColor(owner),
150,
);
const color =
tileIsInDefensePostRange &&
this.game.config().userSettings().showDefensePostRange()
? this.theme.defendedTerritoryColor(owner)
: this.theme.territoryColor(owner);

this.paintCell(this.game.x(tile), this.game.y(tile), color, 150);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/configuration/Colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const orange = colord({ h: 25, s: 95, l: 53 });
export const green = colord({ h: 128, s: 49, l: 50 });
export const botColor: Colord = colord({ r: 210, g: 206, b: 200 }); // Muted Beige Gray

export const defendedTerritoryDarkenPercent: number = 0.075;

export const territoryColors: Colord[] = [
colord({ r: 230, g: 100, b: 100 }), // Bright Red
colord({ r: 100, g: 180, b: 230 }), // Sky Blue
Expand Down
1 change: 1 addition & 0 deletions src/core/configuration/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export interface Config {
export interface Theme {
teamColor(team: Team): Colord;
territoryColor(playerInfo: PlayerView): Colord;
defendedTerritoryColor(playerInfo: PlayerView): Colord;
specialBuildingColor(playerInfo: PlayerView): Colord;
borderColor(playerInfo: PlayerView): Colord;
defendedBorderColor(playerInfo: PlayerView): Colord;
Expand Down
4 changes: 4 additions & 0 deletions src/core/configuration/PastelTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
blue,
botColor,
botColors,
defendedTerritoryDarkenPercent,
green,
humanColors,
orange,
Expand Down Expand Up @@ -75,6 +76,9 @@ export const pastelTheme = new (class implements Theme {
}
return territoryColors[simpleHash(player.id()) % territoryColors.length];
}
defendedTerritoryColor(player: PlayerView): Colord {
return this.territoryColor(player).darken(defendedTerritoryDarkenPercent);
}

textColor(player: PlayerView): string {
return player.info().playerType == PlayerType.Human ? "#000000" : "#4D4D4D";
Expand Down
4 changes: 4 additions & 0 deletions src/core/configuration/PastelThemeDark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
blue,
botColor,
botColors,
defendedTerritoryDarkenPercent,
green,
humanColors,
orange,
Expand Down Expand Up @@ -75,6 +76,9 @@ export const pastelThemeDark = new (class implements Theme {
}
return territoryColors[simpleHash(player.id()) % territoryColors.length];
}
defendedTerritoryColor(player: PlayerView): Colord {
return this.territoryColor(player).darken(defendedTerritoryDarkenPercent);
}

textColor(player: PlayerView): string {
return player.info().playerType == PlayerType.Human ? "#ffffff" : "#e6e6e6";
Expand Down
8 changes: 8 additions & 0 deletions src/core/game/UserSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export class UserSettings {
this.get("settings.focusLocked", true);
}

showDefensePostRange() {
return this.get("settings.showDefensePostRange", false);
}

toggleLeftClickOpenMenu() {
this.set("settings.leftClickOpensMenu", !this.leftClickOpensMenu());
}
Expand All @@ -50,4 +54,8 @@ export class UserSettings {
document.documentElement.classList.remove("dark");
}
}

toggleShowDefensePostRange() {
this.set("settings.showDefensePostRange", !this.showDefensePostRange());
}
}