Add hash to Unit interface (#811)

## Description:

- Add `hash()` to the `Unit` interface to avoid casts with `as`.

## 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>
This commit is contained in:
Scott Anderson
2025-05-19 14:02:50 -04:00
committed by GitHub
parent fa1ed7c653
commit 090ef8046c
2 changed files with 3 additions and 1 deletions
+2
View File
@@ -324,6 +324,8 @@ export class PlayerInfo {
}
export interface Unit {
hash(): number;
// Common properties.
id(): number;
type(): UnitType;
+1 -1
View File
@@ -925,7 +925,7 @@ export class PlayerImpl implements Player {
hash(): number {
return (
simpleHash(this.id()) * (this.population() + this.numTilesOwned()) +
this._units.reduce((acc, unit) => acc + (unit as UnitImpl).hash(), 0)
this._units.reduce((acc, unit) => acc + unit.hash(), 0)
);
}
toString(): string {