mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-18 09:14:09 +00:00
eqeqeq
This commit is contained in:
@@ -72,12 +72,12 @@ export function joinLobby(
|
||||
let terrainLoad: Promise<TerrainMapData> | null = null;
|
||||
|
||||
const onmessage = (message: ServerMessage) => {
|
||||
if (message.type == "prestart") {
|
||||
if (message.type === "prestart") {
|
||||
consolex.log(`lobby: game prestarting: ${JSON.stringify(message)}`);
|
||||
terrainLoad = loadTerrainMap(message.gameMap);
|
||||
onPrestart();
|
||||
}
|
||||
if (message.type == "start") {
|
||||
if (message.type === "start") {
|
||||
// Trigger prestart for singleplayer games
|
||||
onPrestart();
|
||||
consolex.log(`lobby: game started: ${JSON.stringify(message)}`);
|
||||
@@ -160,7 +160,7 @@ export async function createClientGame(
|
||||
}
|
||||
|
||||
export class ClientGameRunner {
|
||||
private myPlayer: PlayerView;
|
||||
private myPlayer: PlayerView | null = null;
|
||||
private isActive = false;
|
||||
|
||||
private turnsSeen = 0;
|
||||
@@ -193,7 +193,7 @@ export class ClientGameRunner {
|
||||
},
|
||||
];
|
||||
let winner: ClientID | Team | null = null;
|
||||
if (update.winnerType == "player") {
|
||||
if (update.winnerType === "player") {
|
||||
winner = this.gameView
|
||||
.playerBySmallID(update.winner as number)
|
||||
.clientID();
|
||||
@@ -272,7 +272,7 @@ export class ClientGameRunner {
|
||||
};
|
||||
const onmessage = (message: ServerMessage) => {
|
||||
this.lastMessageTime = Date.now();
|
||||
if (message.type == "start") {
|
||||
if (message.type === "start") {
|
||||
this.hasJoined = true;
|
||||
consolex.log("starting game!");
|
||||
for (const turn of message.turns) {
|
||||
@@ -291,7 +291,7 @@ export class ClientGameRunner {
|
||||
this.turnsSeen++;
|
||||
}
|
||||
}
|
||||
if (message.type == "desync") {
|
||||
if (message.type === "desync") {
|
||||
if (typeof this.lobby.gameStartInfo === "undefined") {
|
||||
throw new Error("missing gameStartInfo");
|
||||
}
|
||||
@@ -304,12 +304,12 @@ export class ClientGameRunner {
|
||||
"You are desynced from other players. What you see might differ from other players.",
|
||||
);
|
||||
}
|
||||
if (message.type == "turn") {
|
||||
if (message.type === "turn") {
|
||||
if (!this.hasJoined) {
|
||||
this.transport.joinGame(0);
|
||||
return;
|
||||
}
|
||||
if (this.turnsSeen != message.turn.turnNumber) {
|
||||
if (this.turnsSeen !== message.turn.turnNumber) {
|
||||
consolex.error(
|
||||
`got wrong turn have turns ${this.turnsSeen}, received turn ${message.turn.turnNumber}`,
|
||||
);
|
||||
@@ -356,13 +356,14 @@ export class ClientGameRunner {
|
||||
if (this.gameView.inSpawnPhase()) {
|
||||
return;
|
||||
}
|
||||
if (this.myPlayer == null) {
|
||||
if (this.myPlayer === null) {
|
||||
const myPlayer = this.gameView.playerByClientID(this.lobby.clientID);
|
||||
if (myPlayer === null) return;
|
||||
this.myPlayer = myPlayer;
|
||||
}
|
||||
this.myPlayer.actions(tile).then((actions) => {
|
||||
console.log(`got actions: ${JSON.stringify(actions)}`);
|
||||
if (this.myPlayer === null) return;
|
||||
if (actions.canAttack) {
|
||||
this.eventBus.emit(
|
||||
new SendAttackIntentEvent(
|
||||
|
||||
@@ -26,7 +26,7 @@ export class FlagInput extends LitElement {
|
||||
}
|
||||
|
||||
private setFlag(flag: string) {
|
||||
if (flag == "xx") {
|
||||
if (flag === "xx") {
|
||||
flag = "";
|
||||
}
|
||||
this.flag = flag;
|
||||
|
||||
@@ -178,7 +178,7 @@ export class HostLobbyModal extends LitElement {
|
||||
/>
|
||||
<div class="option-card-title">
|
||||
<span>${translateText("host_modal.bots")}</span>${
|
||||
this.bots == 0
|
||||
this.bots === 0
|
||||
? translateText("host_modal.bots_disabled")
|
||||
: this.bots
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ export class InputHandler {
|
||||
this.onContextMenu(e);
|
||||
});
|
||||
window.addEventListener("mousemove", (e) => {
|
||||
if (e.movementX == 0 && e.movementY == 0) {
|
||||
if (e.movementX === 0 && e.movementY === 0) {
|
||||
return;
|
||||
}
|
||||
this.eventBus.emit(new MouseMoveEvent(e.clientX, e.clientY));
|
||||
@@ -307,7 +307,7 @@ export class InputHandler {
|
||||
Math.abs(event.x - this.lastPointerDownX) +
|
||||
Math.abs(event.y - this.lastPointerDownY);
|
||||
if (dist < 10) {
|
||||
if (event.pointerType == "touch") {
|
||||
if (event.pointerType === "touch") {
|
||||
this.eventBus.emit(new ContextMenuEvent(event.clientX, event.clientY));
|
||||
event.preventDefault();
|
||||
return;
|
||||
|
||||
@@ -71,13 +71,13 @@ export class LocalServer {
|
||||
const clientMsg: ClientMessage = ClientMessageSchema.parse(
|
||||
JSON.parse(message),
|
||||
);
|
||||
if (clientMsg.type == "intent") {
|
||||
if (clientMsg.type === "intent") {
|
||||
if (this.lobbyConfig.gameRecord) {
|
||||
// If we are replaying a game, we don't want to process intents
|
||||
return;
|
||||
}
|
||||
if (this.paused) {
|
||||
if (clientMsg.intent.type == "troop_ratio") {
|
||||
if (clientMsg.intent.type === "troop_ratio") {
|
||||
// Store troop change events because otherwise they are
|
||||
// not registered when game is paused.
|
||||
this.intents.push(clientMsg.intent);
|
||||
@@ -86,7 +86,7 @@ export class LocalServer {
|
||||
}
|
||||
this.intents.push(clientMsg.intent);
|
||||
}
|
||||
if (clientMsg.type == "hash") {
|
||||
if (clientMsg.type === "hash") {
|
||||
if (!this.lobbyConfig.gameRecord) {
|
||||
// If we are playing a singleplayer then store hash.
|
||||
this.turns[clientMsg.turnNumber].hash = clientMsg.hash;
|
||||
@@ -100,7 +100,7 @@ export class LocalServer {
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (archivedHash != clientMsg.hash) {
|
||||
if (archivedHash !== clientMsg.hash) {
|
||||
console.error(
|
||||
`desync detected on turn ${clientMsg.turnNumber}, client hash: ${clientMsg.hash}, server hash: ${archivedHash}`,
|
||||
);
|
||||
@@ -118,7 +118,7 @@ export class LocalServer {
|
||||
);
|
||||
}
|
||||
}
|
||||
if (clientMsg.type == "winner") {
|
||||
if (clientMsg.type === "winner") {
|
||||
this.winner = clientMsg;
|
||||
this.allPlayersStats = clientMsg.allPlayersStats;
|
||||
}
|
||||
|
||||
+6
-6
@@ -40,7 +40,7 @@ export interface JoinLobbyEvent {
|
||||
}
|
||||
|
||||
class Client {
|
||||
private gameStop: (() => void) | null;
|
||||
private gameStop: (() => void) | null = null;
|
||||
|
||||
private usernameInput: UsernameInput | null = null;
|
||||
private flagInput: FlagInput | null = null;
|
||||
@@ -93,7 +93,7 @@ class Client {
|
||||
|
||||
window.addEventListener("beforeunload", () => {
|
||||
consolex.log("Browser is closing");
|
||||
if (this.gameStop != null) {
|
||||
if (this.gameStop !== null) {
|
||||
this.gameStop();
|
||||
}
|
||||
});
|
||||
@@ -186,7 +186,7 @@ class Client {
|
||||
private async handleJoinLobby(event: CustomEvent) {
|
||||
const lobby = event.detail as JoinLobbyEvent;
|
||||
consolex.log(`joining lobby ${lobby.gameID}`);
|
||||
if (this.gameStop != null) {
|
||||
if (this.gameStop !== null) {
|
||||
consolex.log("joining lobby, stopping existing game");
|
||||
this.gameStop();
|
||||
}
|
||||
@@ -197,7 +197,7 @@ class Client {
|
||||
gameID: lobby.gameID,
|
||||
serverConfig: config,
|
||||
flag:
|
||||
this.flagInput === null || this.flagInput.getCurrentFlag() == "xx"
|
||||
this.flagInput === null || this.flagInput.getCurrentFlag() === "xx"
|
||||
? ""
|
||||
: this.flagInput.getCurrentFlag(),
|
||||
playerName: this.usernameInput?.getCurrentUsername() ?? "",
|
||||
@@ -220,7 +220,7 @@ class Client {
|
||||
(ad as HTMLElement).style.display = "none";
|
||||
});
|
||||
|
||||
if (event.detail.gameConfig?.gameType != GameType.Singleplayer) {
|
||||
if (event.detail.gameConfig?.gameType !== GameType.Singleplayer) {
|
||||
window.history.pushState({}, "", `/join/${lobby.gameID}`);
|
||||
sessionStorage.setItem("inLobby", "true");
|
||||
}
|
||||
@@ -229,7 +229,7 @@ class Client {
|
||||
}
|
||||
|
||||
private async handleLeaveLobby(/* event: CustomEvent */) {
|
||||
if (this.gameStop == null) {
|
||||
if (this.gameStop === null) {
|
||||
return;
|
||||
}
|
||||
consolex.log("leaving lobby, cancelling game");
|
||||
|
||||
@@ -123,7 +123,7 @@ export class PublicLobby extends LitElement {
|
||||
)}
|
||||
</div>
|
||||
<div class="text-md font-medium text-blue-100">
|
||||
${lobby.gameConfig.gameMode == GameMode.Team
|
||||
${lobby.gameConfig.gameMode === GameMode.Team
|
||||
? translateText("game_mode.teams")
|
||||
: translateText("game_mode.ffa")}
|
||||
</div>
|
||||
@@ -160,7 +160,7 @@ export class PublicLobby extends LitElement {
|
||||
this.isButtonDebounced = false;
|
||||
}, this.debounceDelay);
|
||||
|
||||
if (this.currLobby == null) {
|
||||
if (this.currLobby === null) {
|
||||
this.isLobbyHighlighted = true;
|
||||
this.currLobby = lobby;
|
||||
this.dispatchEvent(
|
||||
|
||||
@@ -155,7 +155,7 @@ export class SinglePlayerModal extends LitElement {
|
||||
/>
|
||||
<div class="option-card-title">
|
||||
<span>${translateText("single_modal.bots")}</span>${this
|
||||
.bots == 0
|
||||
.bots === 0
|
||||
? translateText("single_modal.bots_disabled")
|
||||
: this.bots}
|
||||
</div>
|
||||
@@ -352,7 +352,7 @@ export class SinglePlayerModal extends LitElement {
|
||||
clientID,
|
||||
username: usernameInput.getCurrentUsername(),
|
||||
flag:
|
||||
flagInput.getCurrentFlag() == "xx"
|
||||
flagInput.getCurrentFlag() === "xx"
|
||||
? ""
|
||||
: flagInput.getCurrentFlag(),
|
||||
},
|
||||
|
||||
+10
-10
@@ -148,7 +148,7 @@ export class MoveWarshipIntentEvent implements GameEvent {
|
||||
}
|
||||
|
||||
export class Transport {
|
||||
private socket: WebSocket | null;
|
||||
private socket: WebSocket | null = null;
|
||||
|
||||
private localServer: LocalServer;
|
||||
|
||||
@@ -166,8 +166,8 @@ export class Transport {
|
||||
// If gameRecord is not null, we are replaying an archived game.
|
||||
// For multiplayer games, GameConfig is not known until game starts.
|
||||
this.isLocal =
|
||||
lobbyConfig.gameRecord != null ||
|
||||
lobbyConfig.gameStartInfo?.config.gameType == GameType.Singleplayer;
|
||||
typeof lobbyConfig.gameRecord !== "undefined" ||
|
||||
lobbyConfig.gameStartInfo?.config.gameType === GameType.Singleplayer;
|
||||
|
||||
this.eventBus.on(SendAllianceRequestIntentEvent, (e) =>
|
||||
this.onSendAllianceRequest(e),
|
||||
@@ -217,9 +217,9 @@ export class Transport {
|
||||
|
||||
private startPing() {
|
||||
if (this.isLocal || this.pingInterval) return;
|
||||
if (this.pingInterval == null) {
|
||||
if (this.pingInterval === null) {
|
||||
this.pingInterval = window.setInterval(() => {
|
||||
if (this.socket != null && this.socket.readyState === WebSocket.OPEN) {
|
||||
if (this.socket !== null && this.socket.readyState === WebSocket.OPEN) {
|
||||
this.sendMsg(
|
||||
JSON.stringify(
|
||||
ClientPingMessageSchema.parse({
|
||||
@@ -307,7 +307,7 @@ export class Transport {
|
||||
console.log(
|
||||
`WebSocket closed. Code: ${event.code}, Reason: ${event.reason}`,
|
||||
);
|
||||
if (event.code != 1000) {
|
||||
if (event.code !== 1000) {
|
||||
console.log(`reconnecting`);
|
||||
this.reconnect();
|
||||
}
|
||||
@@ -439,7 +439,7 @@ export class Transport {
|
||||
type: "emoji",
|
||||
clientID: this.lobbyConfig.clientID,
|
||||
recipient:
|
||||
event.recipient == AllPlayers ? AllPlayers : event.recipient.id(),
|
||||
event.recipient === AllPlayers ? AllPlayers : event.recipient.id(),
|
||||
emoji: event.emoji,
|
||||
});
|
||||
}
|
||||
@@ -587,8 +587,8 @@ export class Transport {
|
||||
} else {
|
||||
if (this.socket === null) return;
|
||||
if (
|
||||
this.socket.readyState == WebSocket.CLOSED ||
|
||||
this.socket.readyState == WebSocket.CLOSED
|
||||
this.socket.readyState === WebSocket.CLOSED ||
|
||||
this.socket.readyState === WebSocket.CLOSED
|
||||
) {
|
||||
console.warn("socket not ready, closing and trying later");
|
||||
this.socket.close();
|
||||
@@ -602,7 +602,7 @@ export class Transport {
|
||||
}
|
||||
|
||||
private killExistingSocket(): void {
|
||||
if (this.socket == null) {
|
||||
if (this.socket === null) {
|
||||
return;
|
||||
}
|
||||
// Remove all event listeners
|
||||
|
||||
@@ -232,7 +232,7 @@ export class TransformHandler {
|
||||
}
|
||||
|
||||
private clearTarget() {
|
||||
if (this.intervalID != null) {
|
||||
if (this.intervalID !== null) {
|
||||
clearInterval(this.intervalID);
|
||||
this.intervalID = null;
|
||||
}
|
||||
|
||||
@@ -292,11 +292,11 @@ export class BuildMenu extends LitElement implements Layer {
|
||||
private _hidden = true;
|
||||
|
||||
private canBuild(item: BuildItemDisplay): boolean {
|
||||
if (this.game?.myPlayer() == null || this.playerActions == null) {
|
||||
if (this.game?.myPlayer() === null || this.playerActions === null) {
|
||||
return false;
|
||||
}
|
||||
const unit = this.playerActions.buildableUnits.filter(
|
||||
(u) => u.type == item.unitType,
|
||||
(u) => u.type === item.unitType,
|
||||
);
|
||||
if (!unit) {
|
||||
return false;
|
||||
@@ -306,7 +306,7 @@ export class BuildMenu extends LitElement implements Layer {
|
||||
|
||||
private cost(item: BuildItemDisplay): number {
|
||||
for (const bu of this.playerActions?.buildableUnits ?? []) {
|
||||
if (bu.type == item.unitType) {
|
||||
if (bu.type === item.unitType) {
|
||||
return bu.cost;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ export class ControlPanel extends LitElement implements Layer {
|
||||
newAttackRatio = 1;
|
||||
}
|
||||
|
||||
if (newAttackRatio == 0.11 && this.attackRatio == 0.01) {
|
||||
if (newAttackRatio === 0.11 && this.attackRatio === 0.01) {
|
||||
// If we're changing the ratio from 1%, then set it to 10% instead of 11% to keep a consistency
|
||||
newAttackRatio = 0.1;
|
||||
}
|
||||
@@ -92,13 +92,13 @@ export class ControlPanel extends LitElement implements Layer {
|
||||
}
|
||||
|
||||
const player = this.game.myPlayer();
|
||||
if (player == null || !player.isAlive()) {
|
||||
if (player === null || !player.isAlive()) {
|
||||
this.setVisibile(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const popIncreaseRate = player.population() - this._population;
|
||||
if (this.game.ticks() % 5 == 0) {
|
||||
if (this.game.ticks() % 5 === 0) {
|
||||
this._popRateIsIncreasing =
|
||||
popIncreaseRate >= this._lastPopulationIncreaseRate;
|
||||
this._lastPopulationIncreaseRate = popIncreaseRate;
|
||||
|
||||
@@ -127,7 +127,7 @@ export class EmojiTable extends LitElement {
|
||||
|
||||
this.showTable((emoji) => {
|
||||
const recipient =
|
||||
targetPlayer == this.game.myPlayer()
|
||||
targetPlayer === this.game.myPlayer()
|
||||
? AllPlayers
|
||||
: (targetPlayer as PlayerView);
|
||||
this.eventBus.emit(new SendEmojiIntentEvent(recipient, emoji));
|
||||
|
||||
@@ -132,16 +132,16 @@ export class EventsDisplay extends LitElement implements Layer {
|
||||
// Update attacks
|
||||
this.incomingAttacks = myPlayer.incomingAttacks().filter((a) => {
|
||||
const t = (this.game.playerBySmallID(a.attackerID) as PlayerView).type();
|
||||
return t != PlayerType.Bot;
|
||||
return t !== PlayerType.Bot;
|
||||
});
|
||||
|
||||
this.outgoingAttacks = myPlayer
|
||||
.outgoingAttacks()
|
||||
.filter((a) => a.targetID != 0);
|
||||
.filter((a) => a.targetID !== 0);
|
||||
|
||||
this.outgoingLandAttacks = myPlayer
|
||||
.outgoingAttacks()
|
||||
.filter((a) => a.targetID == 0);
|
||||
.filter((a) => a.targetID === 0);
|
||||
|
||||
this.outgoingBoats = myPlayer
|
||||
.units()
|
||||
@@ -152,7 +152,7 @@ export class EventsDisplay extends LitElement implements Layer {
|
||||
|
||||
private addEvent(event: Event) {
|
||||
this.events = [...this.events, event];
|
||||
if (this._hidden == true) {
|
||||
if (this._hidden === true) {
|
||||
this.newEvents++;
|
||||
}
|
||||
this.requestUpdate();
|
||||
@@ -174,7 +174,7 @@ export class EventsDisplay extends LitElement implements Layer {
|
||||
onDisplayMessageEvent(event: DisplayMessageUpdate) {
|
||||
const myPlayer = this.game.playerByClientID(this.clientID);
|
||||
if (
|
||||
event.playerID != null &&
|
||||
event.playerID !== null &&
|
||||
(!myPlayer || myPlayer.smallID() !== event.playerID)
|
||||
) {
|
||||
return;
|
||||
@@ -353,14 +353,14 @@ export class EventsDisplay extends LitElement implements Layer {
|
||||
if (!myPlayer) return;
|
||||
|
||||
const recipient =
|
||||
update.emoji.recipientID == AllPlayers
|
||||
update.emoji.recipientID === AllPlayers
|
||||
? AllPlayers
|
||||
: this.game.playerBySmallID(update.emoji.recipientID);
|
||||
const sender = this.game.playerBySmallID(
|
||||
update.emoji.senderID,
|
||||
) as PlayerView;
|
||||
|
||||
if (recipient == myPlayer) {
|
||||
if (recipient === myPlayer) {
|
||||
this.addEvent({
|
||||
description: `${sender.displayName()}:${update.emoji.message}`,
|
||||
unsafeDescription: true,
|
||||
@@ -545,7 +545,7 @@ export class EventsDisplay extends LitElement implements Layer {
|
||||
this.events.sort((a, b) => {
|
||||
const aPrior = a.priority ?? 100000;
|
||||
const bPrior = b.priority ?? 100000;
|
||||
if (aPrior == bPrior) {
|
||||
if (aPrior === bPrior) {
|
||||
return a.createdAt - b.createdAt;
|
||||
}
|
||||
return bPrior - aPrior;
|
||||
|
||||
@@ -27,9 +27,9 @@ export class GoToUnitEvent implements GameEvent {
|
||||
|
||||
@customElement("leader-board")
|
||||
export class Leaderboard extends LitElement implements Layer {
|
||||
public game: GameView;
|
||||
public clientID: ClientID;
|
||||
public eventBus: EventBus;
|
||||
public game: GameView | null = null;
|
||||
public clientID: ClientID | null = null;
|
||||
public eventBus: EventBus | null = null;
|
||||
|
||||
players: Entry[] = [];
|
||||
|
||||
@@ -41,6 +41,7 @@ export class Leaderboard extends LitElement implements Layer {
|
||||
init() {}
|
||||
|
||||
tick() {
|
||||
if (this.game === null) throw new Error("Not initialized");
|
||||
if (!this._shownOnInit && !this.game.inSpawnPhase()) {
|
||||
this._shownOnInit = true;
|
||||
this.showLeaderboard();
|
||||
@@ -50,18 +51,19 @@ export class Leaderboard extends LitElement implements Layer {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.game.ticks() % 10 == 0) {
|
||||
if (this.game.ticks() % 10 === 0) {
|
||||
this.updateLeaderboard();
|
||||
}
|
||||
}
|
||||
|
||||
private updateLeaderboard() {
|
||||
if (this.clientID == null) {
|
||||
if (this.game === null) throw new Error("Not initialized");
|
||||
if (this.clientID === null) {
|
||||
return;
|
||||
}
|
||||
const myPlayer = this.game
|
||||
.playerViews()
|
||||
.find((p) => p.clientID() == this.clientID);
|
||||
const myPlayer =
|
||||
this.game.playerViews().find((p) => p.clientID() === this.clientID) ??
|
||||
null;
|
||||
|
||||
const sorted = this.game
|
||||
.playerViews()
|
||||
@@ -85,16 +87,19 @@ export class Leaderboard extends LitElement implements Layer {
|
||||
),
|
||||
gold: renderNumber(player.gold()),
|
||||
troops: renderNumber(troops),
|
||||
isMyPlayer: player == myPlayer,
|
||||
isMyPlayer: player === myPlayer,
|
||||
player: player,
|
||||
};
|
||||
});
|
||||
|
||||
if (myPlayer != null && this.players.find((p) => p.isMyPlayer) == null) {
|
||||
if (
|
||||
myPlayer !== null &&
|
||||
this.players.find((p) => p.isMyPlayer) === undefined
|
||||
) {
|
||||
let place = 0;
|
||||
for (const p of sorted) {
|
||||
place++;
|
||||
if (p == myPlayer) {
|
||||
if (p === myPlayer) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -121,6 +126,7 @@ export class Leaderboard extends LitElement implements Layer {
|
||||
}
|
||||
|
||||
private handleRowClickPlayer(player: PlayerView) {
|
||||
if (this.eventBus === null) return;
|
||||
this.eventBus.emit(new GoToPlayerEvent(player));
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ export class NameLayer implements Layer {
|
||||
}
|
||||
|
||||
public tick() {
|
||||
if (this.game.ticks() % 10 != 0) {
|
||||
if (this.game.ticks() % 10 !== 0) {
|
||||
return;
|
||||
}
|
||||
const sorted = this.game
|
||||
@@ -218,7 +218,7 @@ export class NameLayer implements Layer {
|
||||
|
||||
renderPlayerInfo(render: RenderInfo) {
|
||||
if (!render.player.nameLocation() || !render.player.isAlive()) {
|
||||
this.renders = this.renders.filter((r) => r != render);
|
||||
this.renders = this.renders.filter((r) => r !== render);
|
||||
render.element.remove();
|
||||
return;
|
||||
}
|
||||
@@ -311,7 +311,7 @@ export class NameLayer implements Layer {
|
||||
|
||||
// Alliance icon
|
||||
const existingAlliance = iconsDiv.querySelector('[data-icon="alliance"]');
|
||||
if (myPlayer != null && myPlayer.isAlliedWith(render.player)) {
|
||||
if (myPlayer !== null && myPlayer.isAlliedWith(render.player)) {
|
||||
if (!existingAlliance) {
|
||||
iconsDiv.appendChild(
|
||||
this.createIconElement(
|
||||
@@ -328,7 +328,7 @@ export class NameLayer implements Layer {
|
||||
// Alliance request icon
|
||||
const data = '[data-icon="alliance-request"]';
|
||||
const existingRequestAlliance = iconsDiv.querySelector(data);
|
||||
if (myPlayer != null && render.player.isRequestingAllianceWith(myPlayer)) {
|
||||
if (myPlayer !== null && render.player.isRequestingAllianceWith(myPlayer)) {
|
||||
if (!existingRequestAlliance) {
|
||||
iconsDiv.appendChild(
|
||||
this.createIconElement(
|
||||
@@ -345,7 +345,7 @@ export class NameLayer implements Layer {
|
||||
// Target icon
|
||||
const existingTarget = iconsDiv.querySelector('[data-icon="target"]');
|
||||
if (
|
||||
myPlayer != null &&
|
||||
myPlayer !== null &&
|
||||
new Set(myPlayer.transitiveTargets()).has(render.player)
|
||||
) {
|
||||
if (!existingTarget) {
|
||||
@@ -368,8 +368,8 @@ export class NameLayer implements Layer {
|
||||
.outgoingEmojis()
|
||||
.filter(
|
||||
(emoji) =>
|
||||
emoji.recipientID == AllPlayers ||
|
||||
emoji.recipientID == myPlayer?.smallID(),
|
||||
emoji.recipientID === AllPlayers ||
|
||||
emoji.recipientID === myPlayer?.smallID(),
|
||||
);
|
||||
|
||||
if (this.game.config().userSettings()?.emojis() && emojis.length > 0) {
|
||||
@@ -407,8 +407,8 @@ export class NameLayer implements Layer {
|
||||
}
|
||||
|
||||
const nukesSentByOtherPlayer = this.game.units().filter((unit) => {
|
||||
const isSendingNuke = render.player.id() == unit.owner().id();
|
||||
const notMyPlayer = !myPlayer || unit.owner().id() != myPlayer.id();
|
||||
const isSendingNuke = render.player.id() === unit.owner().id();
|
||||
const notMyPlayer = !myPlayer || unit.owner().id() !== myPlayer.id();
|
||||
return (
|
||||
nukeTypes.includes(unit.type()) &&
|
||||
isSendingNuke &&
|
||||
@@ -420,23 +420,23 @@ export class NameLayer implements Layer {
|
||||
const detonationDst = unit.detonationDst();
|
||||
if (typeof detonationDst === "undefined") return false;
|
||||
const targetId = this.game.owner(detonationDst).id();
|
||||
return myPlayer && targetId == myPlayer.id();
|
||||
return myPlayer && targetId === myPlayer.id();
|
||||
});
|
||||
const existingNuke = iconsDiv.querySelector(
|
||||
'[data-icon="nuke"]',
|
||||
) as HTMLImageElement;
|
||||
|
||||
if (existingNuke) {
|
||||
if (nukesSentByOtherPlayer.length == 0) {
|
||||
if (nukesSentByOtherPlayer.length === 0) {
|
||||
existingNuke.remove();
|
||||
} else if (
|
||||
isMyPlayerTarget &&
|
||||
existingNuke.src != this.nukeRedIconImage.src
|
||||
existingNuke.src !== this.nukeRedIconImage.src
|
||||
) {
|
||||
existingNuke.src = this.nukeRedIconImage.src;
|
||||
} else if (
|
||||
!isMyPlayerTarget &&
|
||||
existingNuke.src != this.nukeWhiteIconImage.src
|
||||
existingNuke.src !== this.nukeWhiteIconImage.src
|
||||
) {
|
||||
existingNuke.src = this.nukeWhiteIconImage.src;
|
||||
}
|
||||
@@ -456,7 +456,7 @@ export class NameLayer implements Layer {
|
||||
}
|
||||
|
||||
// Position element with scale
|
||||
if (render.location && render.location != oldLocation) {
|
||||
if (render.location && render.location !== oldLocation) {
|
||||
const scale = Math.min(baseSize * 0.25, 3);
|
||||
render.element.style.transform = `translate(${render.location.x}px, ${render.location.y}px) translate(-50%, -50%) scale(${scale})`;
|
||||
}
|
||||
@@ -482,11 +482,11 @@ export class NameLayer implements Layer {
|
||||
}
|
||||
|
||||
private getPlayer(): PlayerView | null {
|
||||
if (this.myPlayer != null) {
|
||||
if (this.myPlayer !== null) {
|
||||
return this.myPlayer;
|
||||
}
|
||||
this.myPlayer =
|
||||
this.game.playerViews().find((p) => p.clientID() == this.clientID) ??
|
||||
this.game.playerViews().find((p) => p.clientID() === this.clientID) ??
|
||||
null;
|
||||
return this.myPlayer;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ export class OptionsMenu extends LitElement implements Layer {
|
||||
init() {
|
||||
console.log("init called from OptionsMenu");
|
||||
this.showPauseButton =
|
||||
this.game.config().gameConfig().gameType == GameType.Singleplayer;
|
||||
this.game.config().gameConfig().gameType === GameType.Singleplayer;
|
||||
this.isVisible = true;
|
||||
this.requestUpdate();
|
||||
}
|
||||
@@ -130,7 +130,7 @@ export class OptionsMenu extends LitElement implements Layer {
|
||||
}
|
||||
if (this.game.inSpawnPhase()) {
|
||||
this.timer = 0;
|
||||
} else if (!this.hasWinner && this.game.ticks() % 10 == 0) {
|
||||
} else if (!this.hasWinner && this.game.ticks() % 10 === 0) {
|
||||
this.timer++;
|
||||
}
|
||||
this.isVisible = true;
|
||||
|
||||
@@ -167,7 +167,7 @@ export class PlayerInfoOverlay extends LitElement implements Layer {
|
||||
.map((a) => a.troops)
|
||||
.reduce((a, b) => a + b, 0);
|
||||
|
||||
if (player.type() == PlayerType.FakeHuman && myPlayer != null) {
|
||||
if (player.type() === PlayerType.FakeHuman && myPlayer !== null) {
|
||||
const relation =
|
||||
this.playerProfile?.relations[myPlayer.smallID()] ?? Relation.Neutral;
|
||||
const relationClass = this.getRelationClass(relation);
|
||||
@@ -240,7 +240,7 @@ export class PlayerInfoOverlay extends LitElement implements Layer {
|
||||
|
||||
private renderUnitInfo(unit: UnitView) {
|
||||
const isAlly =
|
||||
(unit.owner() == this.myPlayer() ||
|
||||
(unit.owner() === this.myPlayer() ||
|
||||
this.myPlayer()?.isFriendly(unit.owner())) ??
|
||||
false;
|
||||
|
||||
@@ -278,8 +278,8 @@ export class PlayerInfoOverlay extends LitElement implements Layer {
|
||||
<div
|
||||
class="bg-opacity-60 bg-gray-900 rounded-lg shadow-lg backdrop-blur-sm transition-all duration-300 text-white text-lg md:text-base ${containerClasses}"
|
||||
>
|
||||
${this.player != null ? this.renderPlayerInfo(this.player) : ""}
|
||||
${this.unit != null ? this.renderUnitInfo(this.unit) : ""}
|
||||
${this.player !== null ? this.renderPlayerInfo(this.player) : ""}
|
||||
${this.unit !== null ? this.renderUnitInfo(this.unit) : ""}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -121,7 +121,7 @@ export class PlayerPanel extends LitElement implements Layer {
|
||||
private handleEmojiClick(e: Event, myPlayer: PlayerView, other: PlayerView) {
|
||||
e.stopPropagation();
|
||||
this.emojiTable.showTable((emoji: string) => {
|
||||
if (myPlayer == other) {
|
||||
if (myPlayer === other) {
|
||||
this.eventBus.emit(new SendEmojiIntentEvent(AllPlayers, emoji));
|
||||
} else {
|
||||
this.eventBus.emit(new SendEmojiIntentEvent(other, emoji));
|
||||
@@ -164,7 +164,7 @@ export class PlayerPanel extends LitElement implements Layer {
|
||||
return 0;
|
||||
}
|
||||
for (const nukeType in nukes) {
|
||||
if (nukeType != UnitType.MIRVWarhead) {
|
||||
if (nukeType !== UnitType.MIRVWarhead) {
|
||||
sum += nukes[nukeType];
|
||||
}
|
||||
}
|
||||
@@ -176,7 +176,7 @@ export class PlayerPanel extends LitElement implements Layer {
|
||||
return html``;
|
||||
}
|
||||
const myPlayer = this.g.myPlayer();
|
||||
if (myPlayer == null) return;
|
||||
if (myPlayer === null) return;
|
||||
if (this.tile === null) return;
|
||||
let other = this.g.owner(this.tile);
|
||||
if (!other.isPlayer()) {
|
||||
@@ -188,7 +188,7 @@ export class PlayerPanel extends LitElement implements Layer {
|
||||
const canSendAllianceRequest =
|
||||
this.actions?.interaction?.canSendAllianceRequest;
|
||||
const canSendEmoji =
|
||||
other == myPlayer
|
||||
other === myPlayer
|
||||
? this.actions?.canSendEmojiAllPlayers
|
||||
: this.actions?.interaction?.canSendEmoji;
|
||||
const canBreakAlliance = this.actions?.interaction?.canBreakAlliance;
|
||||
@@ -350,7 +350,7 @@ export class PlayerPanel extends LitElement implements Layer {
|
||||
</button>`
|
||||
: ""}
|
||||
</div>
|
||||
${canEmbargo && other != myPlayer
|
||||
${canEmbargo && other !== myPlayer
|
||||
? html`<button
|
||||
@click=${(e) => this.handleEmbargoClick(e, myPlayer, other)}
|
||||
class="w-100 h-10 flex items-center justify-center
|
||||
@@ -360,7 +360,7 @@ export class PlayerPanel extends LitElement implements Layer {
|
||||
Stop trading
|
||||
</button>`
|
||||
: ""}
|
||||
${!canEmbargo && other != myPlayer
|
||||
${!canEmbargo && other !== myPlayer
|
||||
? html`<button
|
||||
@click=${(e) =>
|
||||
this.handleStopEmbargoClick(e, myPlayer, other)}
|
||||
|
||||
@@ -108,7 +108,7 @@ export class RadialMenu implements Layer {
|
||||
e.x,
|
||||
e.y,
|
||||
);
|
||||
if (clickedCell == null) {
|
||||
if (clickedCell === null) {
|
||||
return;
|
||||
}
|
||||
if (!this.g.isValidCoord(clickedCell.x, clickedCell.y)) {
|
||||
@@ -116,7 +116,7 @@ export class RadialMenu implements Layer {
|
||||
}
|
||||
const tile = this.g.ref(clickedCell.x, clickedCell.y);
|
||||
const p = this.g.playerByClientID(this.clientID);
|
||||
if (p == null) {
|
||||
if (p === null) {
|
||||
return;
|
||||
}
|
||||
this.buildMenu.showMenu(tile);
|
||||
@@ -323,8 +323,8 @@ export class RadialMenu implements Layer {
|
||||
|
||||
const myPlayer = this.g
|
||||
.playerViews()
|
||||
.find((p) => p.clientID() == this.clientID);
|
||||
if (!myPlayer) {
|
||||
.find((p) => p.clientID() === this.clientID);
|
||||
if (myPlayer === undefined) {
|
||||
consolex.warn("my player not found");
|
||||
return;
|
||||
}
|
||||
@@ -428,7 +428,7 @@ export class RadialMenu implements Layer {
|
||||
this.eventBus.emit(new SendSpawnIntentEvent(this.clickedCell));
|
||||
} else {
|
||||
const myPlayer = this.g.myPlayer();
|
||||
if (myPlayer != null && this.g.owner(clicked) != myPlayer) {
|
||||
if (myPlayer !== null && this.g.owner(clicked) !== myPlayer) {
|
||||
this.eventBus.emit(
|
||||
new SendAttackIntentEvent(
|
||||
this.g.owner(clicked).id(),
|
||||
|
||||
@@ -21,19 +21,19 @@ export class SpawnTimer implements Layer {
|
||||
this.ratio = this.game.ticks() / this.game.config().numSpawnPhaseTurns();
|
||||
return;
|
||||
}
|
||||
if (this.game.config().gameConfig().gameMode != GameMode.Team) {
|
||||
if (this.game.config().gameConfig().gameMode !== GameMode.Team) {
|
||||
this.ratio = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
const numBlueTiles = this.game
|
||||
.players()
|
||||
.filter((p) => p.team() == Team.Blue)
|
||||
.filter((p) => p.team() === Team.Blue)
|
||||
.reduce((acc, p) => acc + p.numTilesOwned(), 0);
|
||||
|
||||
const numRedTiles = this.game
|
||||
.players()
|
||||
.filter((p) => p.team() == Team.Red)
|
||||
.filter((p) => p.team() === Team.Red)
|
||||
.reduce((acc, p) => acc + p.numTilesOwned(), 0);
|
||||
|
||||
this.ratio = numBlueTiles / (numBlueTiles + numRedTiles);
|
||||
@@ -46,7 +46,7 @@ export class SpawnTimer implements Layer {
|
||||
}
|
||||
|
||||
renderLayer(context: CanvasRenderingContext2D) {
|
||||
if (this.ratio == 0) {
|
||||
if (this.ratio === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ export class StructureLayer implements Layer {
|
||||
)) {
|
||||
this.paintCell(
|
||||
new Cell(this.game.x(tile), this.game.y(tile)),
|
||||
unit.type() == UnitType.Construction
|
||||
unit.type() === UnitType.Construction
|
||||
? underConstructionColor
|
||||
: this.theme.territoryColor(unit.owner()),
|
||||
130,
|
||||
@@ -227,13 +227,13 @@ export class StructureLayer implements Layer {
|
||||
const config = this.unitConfigs[unitType];
|
||||
let icon: ImageData | undefined;
|
||||
|
||||
if (unitType == UnitType.SAMLauncher && unit.isCooldown()) {
|
||||
if (unitType === UnitType.SAMLauncher && unit.isCooldown()) {
|
||||
icon = this.unitIcons.get("reloadingSam");
|
||||
} else {
|
||||
icon = this.unitIcons.get(iconType);
|
||||
}
|
||||
|
||||
if (unitType == UnitType.MissileSilo && unit.isCooldown()) {
|
||||
if (unitType === UnitType.MissileSilo && unit.isCooldown()) {
|
||||
icon = this.unitIcons.get("reloadingSilo");
|
||||
} else {
|
||||
icon = this.unitIcons.get(iconType);
|
||||
@@ -253,15 +253,15 @@ export class StructureLayer implements Layer {
|
||||
if (!unit.isActive()) return;
|
||||
|
||||
let borderColor = this.theme.borderColor(unit.owner());
|
||||
if (unitType == UnitType.SAMLauncher && unit.isCooldown()) {
|
||||
if (unitType === UnitType.SAMLauncher && unit.isCooldown()) {
|
||||
borderColor = reloadingColor;
|
||||
} else if (unit.type() == UnitType.Construction) {
|
||||
} else if (unit.type() === UnitType.Construction) {
|
||||
borderColor = underConstructionColor;
|
||||
}
|
||||
|
||||
if (unitType == UnitType.MissileSilo && unit.isCooldown()) {
|
||||
if (unitType === UnitType.MissileSilo && unit.isCooldown()) {
|
||||
borderColor = reloadingColor;
|
||||
} else if (unit.type() == UnitType.Construction) {
|
||||
} else if (unit.type() === UnitType.Construction) {
|
||||
borderColor = underConstructionColor;
|
||||
}
|
||||
|
||||
@@ -282,7 +282,7 @@ export class StructureLayer implements Layer {
|
||||
unit: UnitView,
|
||||
) {
|
||||
let color = this.theme.borderColor(unit.owner());
|
||||
if (unit.type() == UnitType.Construction) {
|
||||
if (unit.type() === UnitType.Construction) {
|
||||
color = underConstructionColor;
|
||||
}
|
||||
for (let y = 0; y < height; y++) {
|
||||
|
||||
@@ -65,7 +65,7 @@ export class TerritoryLayer implements Layer {
|
||||
const updates = this.game.updatesSinceLastTick();
|
||||
const unitUpdates = updates !== null ? updates[GameUpdateType.Unit] : [];
|
||||
unitUpdates.forEach((update) => {
|
||||
if (update.unitType == UnitType.DefensePost && update.isActive) {
|
||||
if (update.unitType === UnitType.DefensePost && update.isActive) {
|
||||
const tile = update.pos;
|
||||
this.game
|
||||
.bfs(
|
||||
@@ -75,7 +75,7 @@ export class TerritoryLayer implements Layer {
|
||||
.forEach((t) => {
|
||||
if (
|
||||
this.game.isBorder(t) &&
|
||||
this.game.ownerID(t) == update.ownerID
|
||||
this.game.ownerID(t) === update.ownerID
|
||||
) {
|
||||
this.enqueueTile(t);
|
||||
}
|
||||
@@ -97,7 +97,7 @@ export class TerritoryLayer implements Layer {
|
||||
if (!this.game.inSpawnPhase()) {
|
||||
return;
|
||||
}
|
||||
if (this.game.ticks() % 5 == 0) {
|
||||
if (this.game.ticks() % 5 === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ export class TerritoryLayer implements Layer {
|
||||
);
|
||||
const humans = this.game
|
||||
.playerViews()
|
||||
.filter((p) => p.type() == PlayerType.Human);
|
||||
.filter((p) => p.type() === PlayerType.Human);
|
||||
|
||||
for (const human of humans) {
|
||||
const center = human.nameLocation();
|
||||
@@ -221,7 +221,7 @@ export class TerritoryLayer implements Layer {
|
||||
|
||||
renderTerritory() {
|
||||
let numToRender = Math.floor(this.tileToRenderQueue.size() / 10);
|
||||
if (numToRender == 0 || this.game.inSpawnPhase()) {
|
||||
if (numToRender === 0 || this.game.inSpawnPhase()) {
|
||||
numToRender = this.tileToRenderQueue.size();
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ export class TerritoryLayer implements Layer {
|
||||
}
|
||||
const owner = this.game.owner(tile) as PlayerView;
|
||||
if (this.game.isBorder(tile)) {
|
||||
const playerIsFocused = owner && this.game.focusedPlayer() == owner;
|
||||
const playerIsFocused = owner && this.game.focusedPlayer() === owner;
|
||||
if (
|
||||
this.game
|
||||
.nearbyUnits(
|
||||
@@ -262,7 +262,7 @@ export class TerritoryLayer implements Layer {
|
||||
this.game.config().defensePostRange(),
|
||||
UnitType.DefensePost,
|
||||
)
|
||||
.filter((u) => u.unit.owner() == owner).length > 0
|
||||
.filter((u) => u.unit.owner() === owner).length > 0
|
||||
) {
|
||||
const useDefendedBorderColor = playerIsFocused
|
||||
? this.theme.focusedDefendedBorderColor()
|
||||
|
||||
@@ -30,7 +30,7 @@ export class TopBar extends LitElement implements Layer {
|
||||
const player = this.game?.myPlayer();
|
||||
if (player === null) return;
|
||||
const popIncreaseRate = player.population() - this._population;
|
||||
if (this.game.ticks() % 5 == 0) {
|
||||
if (this.game.ticks() % 5 === 0) {
|
||||
this._popRateIsIncreasing =
|
||||
popIncreaseRate >= this._lastPopulationIncreaseRate;
|
||||
this._lastPopulationIncreaseRate = popIncreaseRate;
|
||||
|
||||
@@ -64,7 +64,7 @@ export class UnitLayer implements Layer {
|
||||
}
|
||||
|
||||
tick() {
|
||||
if (this.myPlayer == null) {
|
||||
if (this.myPlayer === null) {
|
||||
this.myPlayer = this.game.playerByClientID(this.clientID);
|
||||
}
|
||||
const updates = this.game.updatesSinceLastTick();
|
||||
@@ -96,7 +96,7 @@ export class UnitLayer implements Layer {
|
||||
const clickRef = this.game.ref(cell.x, cell.y);
|
||||
|
||||
// Make sure we have the current player
|
||||
if (this.myPlayer == null) {
|
||||
if (this.myPlayer === null) {
|
||||
this.myPlayer = this.game.playerByClientID(this.clientID);
|
||||
}
|
||||
|
||||
@@ -215,10 +215,10 @@ export class UnitLayer implements Layer {
|
||||
}
|
||||
|
||||
private relationship(unit: UnitView): Relationship {
|
||||
if (this.myPlayer == null) {
|
||||
if (this.myPlayer === null) {
|
||||
return Relationship.Enemy;
|
||||
}
|
||||
if (this.myPlayer == unit.owner()) {
|
||||
if (this.myPlayer === unit.owner()) {
|
||||
return Relationship.Self;
|
||||
}
|
||||
if (this.myPlayer.isFriendly(unit.owner())) {
|
||||
@@ -279,9 +279,9 @@ export class UnitLayer implements Layer {
|
||||
if (unit.warshipTargetId()) {
|
||||
const targetOwner = this.game
|
||||
.units()
|
||||
.find((u) => u.id() == unit.warshipTargetId())
|
||||
.find((u) => u.id() === unit.warshipTargetId())
|
||||
?.owner();
|
||||
if (targetOwner == this.myPlayer) {
|
||||
if (targetOwner === this.myPlayer) {
|
||||
outerColor = colord({ r: 200, b: 0, g: 0 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user