mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 15:00:43 +00:00
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:
@@ -324,6 +324,8 @@ export class PlayerInfo {
|
||||
}
|
||||
|
||||
export interface Unit {
|
||||
hash(): number;
|
||||
|
||||
// Common properties.
|
||||
id(): number;
|
||||
type(): UnitType;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user