mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-03 01:38:13 +00:00
Revert "Fix remaining errors and enable strict mode (#1628)"
This reverts commit ad2598361b.
This commit is contained in:
@@ -64,7 +64,6 @@ declare global {
|
||||
// Extend the global interfaces to include your custom events
|
||||
interface DocumentEventMap {
|
||||
"join-lobby": CustomEvent<JoinLobbyEvent>;
|
||||
"kick-player": CustomEvent;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import { Executor } from "./execution/ExecutionManager";
|
||||
import { WinCheckExecution } from "./execution/WinCheckExecution";
|
||||
import {
|
||||
AllPlayers,
|
||||
Attack,
|
||||
Cell,
|
||||
Game,
|
||||
GameUpdates,
|
||||
@@ -36,7 +35,7 @@ export async function createGameRunner(
|
||||
gameStart: GameStartInfo,
|
||||
clientID: ClientID,
|
||||
mapLoader: GameMapLoader,
|
||||
callBack: (gu: GameUpdateViewData | ErrorUpdate) => void,
|
||||
callBack: (gu: GameUpdateViewData) => void,
|
||||
): Promise<GameRunner> {
|
||||
const config = await getConfig(gameStart.config, null);
|
||||
const gameMap = await loadGameMap(gameStart.config.gameMap, mapLoader);
|
||||
@@ -232,7 +231,7 @@ export class GameRunner {
|
||||
throw new Error(`player with id ${playerID} not found`);
|
||||
}
|
||||
|
||||
const condition = (a: Attack) => a.id() === attackID;
|
||||
const condition = (a) => a.id() === attackID;
|
||||
const attack =
|
||||
player.outgoingAttacks().find(condition) ??
|
||||
player.incomingAttacks().find(condition);
|
||||
|
||||
+1
-5
@@ -215,11 +215,7 @@ export const RequiredPatternSchema = z
|
||||
new PatternDecoder(val, base64url.decode);
|
||||
return true;
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
console.error(JSON.stringify(e.message, null, 2));
|
||||
} else {
|
||||
console.error(String(e));
|
||||
}
|
||||
console.error(JSON.stringify(e.message, null, 2));
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -350,7 +350,7 @@ export class FakeHumanExecution implements Execution {
|
||||
const dist = euclDistFN(tile, 25, false);
|
||||
let tileValue = targets
|
||||
.filter((unit) => dist(this.mg, unit.tile()))
|
||||
.map((unit): number => {
|
||||
.map((unit) => {
|
||||
switch (unit.type()) {
|
||||
case UnitType.City:
|
||||
return 25_000;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Config } from "../configuration/Config";
|
||||
import { Execution, Game, Player, UnitType } from "../game/Game";
|
||||
import { GameImpl } from "../game/GameImpl";
|
||||
import { GameMap, TileRef } from "../game/GameMap";
|
||||
import { TileRef } from "../game/GameMap";
|
||||
import { calculateBoundingBox, getMode, inscribed, simpleHash } from "../Util";
|
||||
|
||||
export class PlayerExecution implements Execution {
|
||||
@@ -190,11 +190,7 @@ export class PlayerExecution implements Execution {
|
||||
}
|
||||
|
||||
const firstTile = cluster.values().next().value;
|
||||
if (!firstTile) {
|
||||
return;
|
||||
}
|
||||
|
||||
const filter = (_: GameMap, t: TileRef): boolean =>
|
||||
const filter = (_, t: TileRef): boolean =>
|
||||
this.mg?.ownerID(t) === this.player?.smallID();
|
||||
const tiles = this.mg.bfs(firstTile, filter);
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
Execution,
|
||||
Game,
|
||||
isUnit,
|
||||
MessageType,
|
||||
Player,
|
||||
Unit,
|
||||
@@ -81,9 +80,7 @@ class SAMTargetingSystem {
|
||||
[UnitType.AtomBomb, UnitType.HydrogenBomb],
|
||||
({ unit }) => {
|
||||
return (
|
||||
isUnit(unit) &&
|
||||
unit.owner() !== this.player &&
|
||||
!this.player.isFriendly(unit.owner())
|
||||
unit.owner() !== this.player && !this.player.isFriendly(unit.owner())
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -215,7 +212,6 @@ export class SAMLauncherExecution implements Execution {
|
||||
this.MIRVWarheadSearchRadius,
|
||||
UnitType.MIRVWarhead,
|
||||
({ unit }) => {
|
||||
if (!isUnit(unit)) return false;
|
||||
if (unit.owner() === this.player) return false;
|
||||
if (this.player.isFriendly(unit.owner())) return false;
|
||||
const dst = unit.targetTile();
|
||||
|
||||
@@ -31,9 +31,7 @@ export class BinaryLoaderGameMapLoader implements GameMapLoader {
|
||||
return cachedMap;
|
||||
}
|
||||
|
||||
const key = Object.keys(GameMapType).find(
|
||||
(k) => GameMapType[k as keyof typeof GameMapType] === map,
|
||||
);
|
||||
const key = Object.keys(GameMapType).find((k) => GameMapType[k] === map);
|
||||
const fileName = key?.toLowerCase();
|
||||
|
||||
const mapData = {
|
||||
|
||||
@@ -17,9 +17,7 @@ export class FetchGameMapLoader implements GameMapLoader {
|
||||
return cachedMap;
|
||||
}
|
||||
|
||||
const key = Object.keys(GameMapType).find(
|
||||
(k) => GameMapType[k as keyof typeof GameMapType] === map,
|
||||
);
|
||||
const key = Object.keys(GameMapType).find((k) => GameMapType[k] === map);
|
||||
const fileName = key?.toLowerCase();
|
||||
|
||||
if (!fileName) {
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
} from "./GameUpdates";
|
||||
import { RailNetwork } from "./RailNetwork";
|
||||
import { Stats } from "./Stats";
|
||||
import { UnitPredicate } from "./UnitGrid";
|
||||
|
||||
export type PlayerID = string;
|
||||
export type Tick = number;
|
||||
@@ -390,10 +389,9 @@ export class PlayerInfo {
|
||||
}
|
||||
}
|
||||
|
||||
export function isUnit(unit: unknown): unit is Unit {
|
||||
export function isUnit(unit: Unit | UnitParams<UnitType>): unit is Unit {
|
||||
return (
|
||||
unit &&
|
||||
typeof unit === "object" &&
|
||||
unit !== undefined &&
|
||||
"isUnit" in unit &&
|
||||
typeof unit.isUnit === "function" &&
|
||||
unit.isUnit()
|
||||
@@ -666,12 +664,12 @@ export interface Game extends GameMap {
|
||||
searchRange: number,
|
||||
type: UnitType,
|
||||
playerId: PlayerID,
|
||||
): boolean;
|
||||
);
|
||||
nearbyUnits(
|
||||
tile: TileRef,
|
||||
searchRange: number,
|
||||
types: UnitType | UnitType[],
|
||||
predicate?: UnitPredicate,
|
||||
predicate?: (value: { unit: Unit; distSquared: number }) => boolean,
|
||||
): Array<{ unit: Unit; distSquared: number }>;
|
||||
|
||||
addExecution(...exec: Execution[]): void;
|
||||
@@ -707,7 +705,7 @@ export interface Game extends GameMap {
|
||||
|
||||
addUpdate(update: GameUpdate): void;
|
||||
railNetwork(): RailNetwork;
|
||||
conquerPlayer(conqueror: Player, conquered: Player): void;
|
||||
conquerPlayer(conqueror: Player, conquered: Player);
|
||||
}
|
||||
|
||||
export interface PlayerActions {
|
||||
|
||||
@@ -40,7 +40,7 @@ import { Stats } from "./Stats";
|
||||
import { StatsImpl } from "./StatsImpl";
|
||||
import { assignTeams } from "./TeamAssignment";
|
||||
import { TerraNulliusImpl } from "./TerraNulliusImpl";
|
||||
import { UnitGrid, UnitPredicate } from "./UnitGrid";
|
||||
import { UnitGrid } from "./UnitGrid";
|
||||
|
||||
export function createGame(
|
||||
humans: PlayerInfo[],
|
||||
@@ -758,7 +758,7 @@ export class GameImpl implements Game {
|
||||
tile: TileRef,
|
||||
searchRange: number,
|
||||
types: UnitType | UnitType[],
|
||||
predicate?: UnitPredicate,
|
||||
predicate?: (value: { unit: Unit; distSquared: number }) => boolean,
|
||||
): Array<{ unit: Unit; distSquared: number }> {
|
||||
return this.unitGrid.nearbyUnits(
|
||||
tile,
|
||||
|
||||
@@ -18,7 +18,7 @@ export interface GameUpdateViewData {
|
||||
tick: number;
|
||||
updates: GameUpdates;
|
||||
packedTileUpdates: BigUint64Array;
|
||||
playerNameViewData: Record<string, NameViewData>;
|
||||
playerNameViewData: Record<number, NameViewData>;
|
||||
}
|
||||
|
||||
export interface ErrorUpdate {
|
||||
|
||||
@@ -34,7 +34,7 @@ import {
|
||||
} from "./GameUpdates";
|
||||
import { TerrainMapData } from "./TerrainMapLoader";
|
||||
import { TerraNulliusImpl } from "./TerraNulliusImpl";
|
||||
import { UnitGrid, UnitPredicate } from "./UnitGrid";
|
||||
import { UnitGrid } from "./UnitGrid";
|
||||
import { UserSettings } from "./UserSettings";
|
||||
|
||||
const userSettings: UserSettings = new UserSettings();
|
||||
@@ -476,7 +476,7 @@ export class GameView implements GameMap {
|
||||
tile: TileRef,
|
||||
searchRange: number,
|
||||
types: UnitType | UnitType[],
|
||||
predicate?: UnitPredicate,
|
||||
predicate?: (value: { unit: UnitView; distSquared: number }) => boolean,
|
||||
): Array<{ unit: UnitView; distSquared: number }> {
|
||||
return this.unitGrid.nearbyUnits(
|
||||
tile,
|
||||
|
||||
@@ -213,9 +213,9 @@ export class PlayerImpl implements Player {
|
||||
return this._units.filter((u) => ts.has(u.type()));
|
||||
}
|
||||
|
||||
private numUnitsConstructed: Partial<Record<UnitType, number>> = {};
|
||||
private numUnitsConstructed: number[] = [];
|
||||
private recordUnitConstructed(type: UnitType): void {
|
||||
if (this.numUnitsConstructed[type] !== undefined) {
|
||||
if (type in this.numUnitsConstructed) {
|
||||
this.numUnitsConstructed[type]++;
|
||||
} else {
|
||||
this.numUnitsConstructed[type] = 1;
|
||||
|
||||
@@ -2,11 +2,6 @@ import { PlayerID, Unit, UnitType } from "./Game";
|
||||
import { GameMap, TileRef } from "./GameMap";
|
||||
import { UnitView } from "./GameView";
|
||||
|
||||
export type UnitPredicate = (value: {
|
||||
unit: Unit | UnitView;
|
||||
distSquared: number;
|
||||
}) => boolean;
|
||||
|
||||
export class UnitGrid {
|
||||
private grid: Map<UnitType, Set<Unit | UnitView>>[][];
|
||||
private readonly cellSize = 100;
|
||||
@@ -135,8 +130,11 @@ export class UnitGrid {
|
||||
nearbyUnits(
|
||||
tile: TileRef,
|
||||
searchRange: number,
|
||||
types: readonly UnitType[] | UnitType,
|
||||
predicate?: UnitPredicate,
|
||||
types: UnitType | UnitType[],
|
||||
predicate?: (value: {
|
||||
unit: Unit | UnitView;
|
||||
distSquared: number;
|
||||
}) => boolean,
|
||||
): Array<{ unit: Unit | UnitView; distSquared: number }> {
|
||||
const nearby: Array<{ unit: Unit | UnitView; distSquared: number }> = [];
|
||||
const { startGridX, endGridX, startGridY, endGridY } = this.getCellsInRange(
|
||||
|
||||
@@ -124,7 +124,7 @@ export class DistanceBasedBezierCurve extends CubicBezierCurve {
|
||||
/**
|
||||
* Precompute all points spaced @p pixelSpacing apart
|
||||
*/
|
||||
computeAllPoints(pixelSpacing: number, precision: number): void {
|
||||
computeAllPoints(pixelSpacing: number, precision): void {
|
||||
this.cachedPoints = [];
|
||||
this.totalDistance = 0;
|
||||
this.currentIndex = 0;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import version from "../../../resources/version.txt";
|
||||
import { createGameRunner, GameRunner } from "../GameRunner";
|
||||
import { FetchGameMapLoader } from "../game/FetchGameMapLoader";
|
||||
import { ErrorUpdate, GameUpdateViewData } from "../game/GameUpdates";
|
||||
import { GameUpdateViewData } from "../game/GameUpdates";
|
||||
import {
|
||||
AttackAveragePositionResultMessage,
|
||||
InitializedMessage,
|
||||
@@ -17,11 +17,7 @@ const ctx: Worker = self as any;
|
||||
let gameRunner: Promise<GameRunner> | null = null;
|
||||
const mapLoader = new FetchGameMapLoader(`/maps`, version);
|
||||
|
||||
function gameUpdate(gu: GameUpdateViewData | ErrorUpdate) {
|
||||
// skip if ErrorUpdate
|
||||
if (!("updates" in gu)) {
|
||||
return;
|
||||
}
|
||||
function gameUpdate(gu: GameUpdateViewData) {
|
||||
sendMessage({
|
||||
type: "game_update",
|
||||
gameUpdate: gu,
|
||||
|
||||
+12
-5
@@ -29,7 +29,7 @@ async function nearbyUnits(
|
||||
unitPosX: number,
|
||||
rangeCheck: number,
|
||||
range: number,
|
||||
unitTypes: readonly UnitType[],
|
||||
unitTypes: UnitType[],
|
||||
) {
|
||||
const game = await setup(mapName, { infiniteGold: true, instantBuild: true });
|
||||
const grid = new UnitGrid(game.map());
|
||||
@@ -51,7 +51,7 @@ describe("Unit Grid range tests", () => {
|
||||
["plains", 0, 10, 11, false], // Exactly 1px outside
|
||||
["big_plains", 0, 198, 42, true], // Inside huge range
|
||||
["big_plains", 0, 198, 199, false], // Exactly 1px outside huge range
|
||||
] as const;
|
||||
];
|
||||
|
||||
describe("Is unit in range", () => {
|
||||
test.each(hasUnitCases)(
|
||||
@@ -77,18 +77,25 @@ describe("Unit Grid range tests", () => {
|
||||
["plains", 0, 10, 11, [UnitType.DefensePost], 0], // 1px outside
|
||||
["big_plains", 0, 198, 42, [UnitType.TradeShip], 1], // Inside huge range
|
||||
["big_plains", 0, 198, 199, [UnitType.TransportShip], 0], // 1px outside
|
||||
] as const;
|
||||
];
|
||||
|
||||
describe("Retrieve all units in range", () => {
|
||||
test.each(unitsInRangeCases)(
|
||||
"on %p map, look if unit at position %p with a range of %p is in range of %p position, returns %p",
|
||||
async (mapName, unitPosX, range, rangeCheck, units, expectedResult) => {
|
||||
async (
|
||||
mapName: string,
|
||||
unitPosX: number,
|
||||
range: number,
|
||||
rangeCheck: number,
|
||||
units: UnitType[],
|
||||
expectedResult: number,
|
||||
) => {
|
||||
const result = await nearbyUnits(
|
||||
mapName,
|
||||
unitPosX,
|
||||
rangeCheck,
|
||||
range,
|
||||
units, // remove readonly
|
||||
units,
|
||||
);
|
||||
expect(result.length).toBe(expectedResult);
|
||||
},
|
||||
|
||||
+1
-2
@@ -21,8 +21,7 @@
|
||||
"resolveJsonModule": true,
|
||||
"strictNullChecks": true,
|
||||
"useDefineForClassFields": false,
|
||||
"strictPropertyInitialization": false,
|
||||
"strict": true
|
||||
"strictPropertyInitialization": false
|
||||
},
|
||||
"include": [
|
||||
"src/**/*",
|
||||
|
||||
Reference in New Issue
Block a user