Prefer z.literal(true).optional() over z.boolean()

This commit is contained in:
Scott Anderson
2025-05-24 20:44:46 -04:00
parent c6e8f2f998
commit 9225ccee44
9 changed files with 18 additions and 30 deletions
+4 -4
View File
@@ -531,11 +531,11 @@ export class HostLobbyModal extends LitElement {
body: JSON.stringify({
gameMap: this.selectedMap,
difficulty: this.selectedDifficulty,
disableNPCs: this.disableNPCs,
disableNPCs: this.disableNPCs ? true : undefined,
bots: this.bots,
infiniteGold: this.infiniteGold,
infiniteTroops: this.infiniteTroops,
instantBuild: this.instantBuild,
infiniteGold: this.infiniteGold ? true : undefined,
infiniteTroops: this.infiniteTroops ? true : undefined,
instantBuild: this.instantBuild ? true : undefined,
gameMode: this.gameMode,
disabledUnits: this.disabledUnits,
playerTeams: this.teamCount,
+4 -4
View File
@@ -450,11 +450,11 @@ export class SinglePlayerModal extends LitElement {
gameMode: this.gameMode,
playerTeams: this.teamCount,
difficulty: this.selectedDifficulty,
disableNPCs: this.disableNPCs,
disableNPCs: this.disableNPCs ? true : undefined,
bots: this.bots,
infiniteGold: this.infiniteGold,
infiniteTroops: this.infiniteTroops,
instantBuild: this.instantBuild,
infiniteGold: this.infiniteGold ? true : undefined,
infiniteTroops: this.infiniteTroops ? true : undefined,
instantBuild: this.instantBuild ? true : undefined,
disabledUnits: this.disabledUnits
.map((u) => Object.values(UnitType).find((ut) => ut === u))
.filter((ut): ut is UnitType => ut !== undefined),
+1 -1
View File
@@ -398,7 +398,7 @@ export class Transport {
type: "allianceRequestReply",
clientID: this.lobbyConfig.clientID,
requestor: event.requestor.id(),
accept: event.accepted,
accept: event.accepted ? true : undefined,
});
}
+5 -5
View File
@@ -117,11 +117,11 @@ const GameConfigSchema = z.object({
difficulty: z.nativeEnum(Difficulty),
gameType: z.nativeEnum(GameType),
gameMode: z.nativeEnum(GameMode),
disableNPCs: z.boolean(),
disableNPCs: z.literal(true).optional(),
bots: z.number().int().min(0).max(400),
infiniteGold: z.boolean(),
infiniteTroops: z.boolean(),
instantBuild: z.boolean(),
infiniteGold: z.literal(true).optional(),
infiniteTroops: z.literal(true).optional(),
instantBuild: z.literal(true).optional(),
maxPlayers: z.number().optional(),
disabledUnits: z.array(z.nativeEnum(UnitType)).optional(),
playerTeams: z.union([z.number().optional(), z.literal(Duos)]),
@@ -227,7 +227,7 @@ export const AllianceRequestIntentSchema = BaseIntentSchema.extend({
export const AllianceRequestReplyIntentSchema = BaseIntentSchema.extend({
type: z.literal("allianceRequestReply"),
requestor: ID, // The one who made the original alliance request
accept: z.boolean(),
accept: z.literal(true).optional(),
});
export const BreakAllianceIntentSchema = BaseIntentSchema.extend({
+3 -3
View File
@@ -263,13 +263,13 @@ export class DefaultConfig implements Config {
return this._gameConfig.bots;
}
instantBuild(): boolean {
return this._gameConfig.instantBuild;
return this._gameConfig.instantBuild ?? false;
}
infiniteGold(): boolean {
return this._gameConfig.infiniteGold;
return this._gameConfig.infiniteGold ?? false;
}
infiniteTroops(): boolean {
return this._gameConfig.infiniteTroops;
return this._gameConfig.infiniteTroops ?? false;
}
tradeShipGold(dist: number): Gold {
return 10000 + 150 * Math.pow(dist, 1.1);
+1 -1
View File
@@ -87,7 +87,7 @@ export class Executor {
return new AllianceRequestReplyExecution(
intent.requestor,
playerID,
intent.accept,
intent.accept ?? false,
);
case "breakAlliance":
return new BreakAllianceExecution(playerID, intent.recipient);
-4
View File
@@ -33,10 +33,6 @@ export class GameManager {
gameMap: GameMapType.World,
gameType: GameType.Private,
difficulty: Difficulty.Medium,
disableNPCs: false,
infiniteGold: false,
infiniteTroops: false,
instantBuild: false,
gameMode: GameMode.FFA,
bots: 400,
disabledUnits: [],
-4
View File
@@ -54,11 +54,7 @@ export class MapPlaylist {
maxPlayers: config.lobbyMaxPlayers(map, mode),
gameType: GameType.Public,
difficulty: Difficulty.Medium,
infiniteGold: false,
infiniteTroops: false,
instantBuild: false,
disableNPCs: mode === GameMode.Team,
disableNukes: false,
gameMode: mode,
playerTeams: numPlayerTeams,
bots: 400,
-4
View File
@@ -41,11 +41,7 @@ export async function setup(
gameMode: GameMode.FFA,
gameType: GameType.Singleplayer,
difficulty: Difficulty.Medium,
disableNPCs: false,
bots: 0,
infiniteGold: false,
infiniteTroops: false,
instantBuild: false,
..._gameConfig,
};
const config = new TestConfig(