Merge branch 'openfrontio:main' into custom-flag

This commit is contained in:
Aotumuri
2025-04-07 08:22:37 +09:00
committed by GitHub
16 changed files with 33 additions and 29 deletions
+1 -13
View File
@@ -11,11 +11,7 @@ import {
ServerStartGameMessageSchema,
Turn,
} from "../core/Schemas";
import {
createGameRecord,
decompressGameRecord,
generateID,
} from "../core/Util";
import { createGameRecord, decompressGameRecord } from "../core/Util";
import { LobbyConfig } from "./ClientGameRunner";
import { getPersistentIDFromCookie } from "./Main";
@@ -56,14 +52,6 @@ export class LocalServer {
gameID: this.lobbyConfig.gameStartInfo.gameID,
gameStartInfo: this.lobbyConfig.gameStartInfo,
turns: this.turns,
players: [
{
flag: this.lobbyConfig.flag,
playerID: generateID(),
clientID: this.lobbyConfig.clientID,
username: this.lobbyConfig.playerName,
},
],
}),
);
}
+9
View File
@@ -10,6 +10,7 @@ import "./components/baseComponents/Modal";
import "./components/Difficulties";
import { DifficultyDescription } from "./components/Difficulties";
import "./components/Maps";
import { FlagInput } from "./FlagInput";
import { JoinLobbyEvent } from "./Main";
import { UsernameInput } from "./UsernameInput";
@@ -334,6 +335,10 @@ export class SinglePlayerModal extends LitElement {
consolex.warn("Username input element not found");
}
const flagInput = document.querySelector("flag-input") as FlagInput;
if (!flagInput) {
consolex.warn("Flag input element not found");
}
this.dispatchEvent(
new CustomEvent("join-lobby", {
detail: {
@@ -346,6 +351,10 @@ export class SinglePlayerModal extends LitElement {
playerID: generateID(),
clientID,
username: usernameInput.getCurrentUsername(),
flag:
flagInput.getCurrentFlag() == "xx"
? ""
: flagInput.getCurrentFlag(),
},
],
config: {
+1
View File
@@ -337,6 +337,7 @@ export class Transport {
lastTurn: numTurns,
persistentID: this.lobbyConfig.persistentID,
username: this.lobbyConfig.playerName,
flag: this.lobbyConfig.flag,
}),
),
);
+2 -2
View File
@@ -205,7 +205,7 @@ export class OptionsMenu extends LitElement implements Layer {
? "Opens menu"
: "Attack"),
})}
${button({
<!-- ${button({
onClick: this.onToggleFocusLockedButtonClick,
title: "Lock Focus",
children:
@@ -213,7 +213,7 @@ export class OptionsMenu extends LitElement implements Layer {
(this.userSettings.focusLocked()
? "Focus locked"
: "Hover focus"),
})}
})} -->
</div>
</div>
`;
@@ -58,7 +58,6 @@ export class TerrainLayer implements Layer {
}
renderLayer(context: CanvasRenderingContext2D) {
console.log(this.transformHandler.scale);
if (this.transformHandler.scale < 1) {
context.imageSmoothingEnabled = true;
context.imageSmoothingQuality = "low";
+1 -1
View File
@@ -55,7 +55,7 @@ export class TerritoryLayer implements Layer {
paintPlayerBorder(player: PlayerView) {
player.borderTiles().then((playerBorderTiles) => {
playerBorderTiles.borderTiles.forEach((tile: TileRef) => {
this.paintTerritory(tile); // Immediately paint the tile instead of enqueueing
this.paintTerritory(tile, true); // Immediately paint the tile instead of enqueueing
});
});
}
+2 -4
View File
@@ -125,12 +125,9 @@ const GameConfigSchema = z.object({
const SafeString = z
.string()
// Remove common dangerous characters and patterns
// The weird \u stuff is to allow emojis
.regex(
/^[a-zA-Z0-9\s.,!?@#$%&*()-_+=\[\]{}|;:"'\/\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]|üÜ]+$/,
/^([a-zA-Z0-9\s.,!?@#$%&*()-_+=\[\]{}|;:"'\/\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]|üÜ])*$/,
)
// Reasonable max length to prevent DOS
.max(1000);
const EmojiSchema = z.string().refine(
@@ -396,6 +393,7 @@ export const ClientJoinMessageSchema = ClientBaseMessageSchema.extend({
type: z.literal("join"),
lastTurn: z.number(), // The last turn the client saw.
username: SafeString,
flag: SafeString.nullable().optional(),
});
export const ClientMessageSchema = z.union([
+1 -1
View File
@@ -268,7 +268,7 @@ export class DefaultConfig implements Config {
case UnitType.AtomBomb:
return {
cost: (p: Player) =>
p.type() == PlayerType.Human && this.infiniteGold() ? 0 : 500_000,
p.type() == PlayerType.Human && this.infiniteGold() ? 0 : 750_000,
territoryBound: false,
};
case UnitType.HydrogenBomb:
+5 -5
View File
@@ -1,4 +1,4 @@
import { GameType, UnitInfo, UnitType } from "../game/Game";
import { UnitInfo, UnitType } from "../game/Game";
import { UserSettings } from "../game/UserSettings";
import { GameConfig } from "../Schemas";
import { GameEnv, ServerConfig } from "./Config";
@@ -40,10 +40,10 @@ export class DevConfig extends DefaultConfig {
super(sc, gc, us);
}
numSpawnPhaseTurns(): number {
return this.gameConfig().gameType == GameType.Singleplayer ? 70 : 100;
// return 100
}
// numSpawnPhaseTurns(): number {
// return this.gameConfig().gameType == GameType.Singleplayer ? 70 : 100;
// // return 100
// }
unitInfo(type: UnitType): UnitInfo {
const info = super.unitInfo(type);
+2
View File
@@ -550,6 +550,8 @@ export class GameView implements GameMap {
}
focusedPlayer(): PlayerView | null {
// TODO: renable when performance issues are fixed.
return this.myPlayer();
if (userSettings.focusLocked()) return this.myPlayer();
return this._focusedPlayer;
}
+2
View File
@@ -86,6 +86,8 @@ export class UnitImpl implements Unit {
}
this._lastTile = this._tile;
this._tile = tile;
this.mg.removeUnit(this);
this.mg.addUnit(this);
this.mg.addUpdate(this.toUpdate());
}
setTroops(troops: number): void {
+3 -1
View File
@@ -25,7 +25,9 @@ export class UserSettings {
}
focusLocked() {
return this.get("settings.focusLocked", false);
return false;
// TODO: renable when performance issues are fixed.
this.get("settings.focusLocked", true);
}
toggleLeftClickOpenMenu() {
+1
View File
@@ -16,5 +16,6 @@ export class Client {
public readonly ip: string,
public readonly username: string,
public readonly ws: WebSocket,
public readonly flag: string | null,
) {}
}
+1
View File
@@ -267,6 +267,7 @@ export class GameServer {
playerID: c.playerID,
username: c.username,
clientID: c.clientID,
flag: c.flag,
})),
});
+1 -1
View File
@@ -238,7 +238,7 @@ async function schedulePublicGame(playlist: MapPlaylist) {
instantBuild: false,
disableNPCs: false,
disableNukes: false,
gameMode: Math.random() < 0.7 ? GameMode.FFA : GameMode.Team,
gameMode: Math.random() < 0.5 ? GameMode.FFA : GameMode.Team,
bots: 400,
} as GameConfig;
+1
View File
@@ -303,6 +303,7 @@ export function startWorker() {
ip,
clientMsg.username,
ws,
clientMsg.flag,
);
const wasFound = gm.addClient(