mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-20 05:49:56 +00:00
Enable strictNullChecks, eqeqeq (#436)
## Description: Improve type safety and runtime correctness by: 1. Enabling TypeScript's [strictNullChecks](https://www.typescriptlang.org/tsconfig/#strictNullChecks) compiler option. 2. Replacing all loose equality operators (`==` and `!=`) with strict equality operators (`===` and `!==`). 3. Cleaning up of type declarations, null handling logic, and equality expressions throughout the project. Currently, the code allows implicit assumptions that `null` and `undefined` are interchangeable, and relies on type-coercing equality checks that can introduce subtle bugs. These practices make it difficult to reason about when values may be absent and hinder the effectiveness of static analysis. Migrating to strict null checks and enforcing strict equality comparisons will clarify intent, reduce bugs, and make the codebase safer and easier to maintain. Fixes #466 ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors --------- Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> Co-authored-by: evanpelle <openfrontio@gmail.com>
This commit is contained in:
co-authored by
Scott Anderson
evanpelle
parent
369483b4ac
commit
70745faac4
+11
-14
@@ -199,21 +199,26 @@ export function createGameRecord(
|
||||
const record: GameRecord = {
|
||||
id: id,
|
||||
gameStartInfo: gameStart,
|
||||
players,
|
||||
startTimestampMS: start,
|
||||
endTimestampMS: end,
|
||||
durationSeconds: Math.floor((end - start) / 1000),
|
||||
date: new Date().toISOString().split("T")[0],
|
||||
num_turns: 0,
|
||||
turns: [],
|
||||
allPlayersStats,
|
||||
version: "v0.0.1",
|
||||
winner,
|
||||
winnerType,
|
||||
};
|
||||
|
||||
for (const turn of turns) {
|
||||
if (turn.intents.length != 0 || turn.hash != undefined) {
|
||||
if (turn.intents.length !== 0 || turn.hash !== undefined) {
|
||||
record.turns.push(turn);
|
||||
for (const intent of turn.intents) {
|
||||
if (intent.type == "spawn") {
|
||||
if (intent.type === "spawn") {
|
||||
for (const playerRecord of players) {
|
||||
if (playerRecord.clientID == intent.clientID) {
|
||||
if (playerRecord.clientID === intent.clientID) {
|
||||
playerRecord.username = intent.name;
|
||||
}
|
||||
}
|
||||
@@ -221,24 +226,17 @@ export function createGameRecord(
|
||||
}
|
||||
}
|
||||
}
|
||||
record.players = players;
|
||||
record.durationSeconds = Math.floor(
|
||||
(record.endTimestampMS - record.startTimestampMS) / 1000,
|
||||
);
|
||||
record.num_turns = turns.length;
|
||||
record.winner = winner;
|
||||
record.winnerType = winnerType;
|
||||
return record;
|
||||
}
|
||||
|
||||
export function decompressGameRecord(gameRecord: GameRecord) {
|
||||
const turns = [];
|
||||
const turns: Turn[] = [];
|
||||
let lastTurnNum = -1;
|
||||
for (const turn of gameRecord.turns) {
|
||||
while (lastTurnNum < turn.turnNumber - 1) {
|
||||
lastTurnNum++;
|
||||
turns.push({
|
||||
gameID: gameRecord.id,
|
||||
turnNumber: lastTurnNum,
|
||||
intents: [],
|
||||
});
|
||||
@@ -249,7 +247,6 @@ export function decompressGameRecord(gameRecord: GameRecord) {
|
||||
const turnLength = turns.length;
|
||||
for (let i = turnLength; i < gameRecord.num_turns; i++) {
|
||||
turns.push({
|
||||
gameID: gameRecord.id,
|
||||
turnNumber: i,
|
||||
intents: [],
|
||||
});
|
||||
@@ -296,7 +293,7 @@ export function createRandomName(
|
||||
name: string,
|
||||
playerType: string,
|
||||
): string | null {
|
||||
let randomName = null;
|
||||
let randomName: string | null = null;
|
||||
if (playerType === "HUMAN") {
|
||||
const hash = simpleHash(name);
|
||||
const prefixIndex = hash % BOT_NAME_PREFIXES.length;
|
||||
@@ -322,4 +319,4 @@ export const emojiTable: string[][] = [
|
||||
["💰", "⚓", "⛵", "🏡", "🛡️"],
|
||||
];
|
||||
// 2d to 1d array
|
||||
export const flattenedEmojiTable: string[] = [].concat(...emojiTable);
|
||||
export const flattenedEmojiTable: string[] = emojiTable.flat();
|
||||
|
||||
Reference in New Issue
Block a user