diff options
author | Jeff Heiges <jehe8729@colorado.edu> | 2025-03-11 07:21:20 +0000 |
---|---|---|
committer | Jeff Heiges <jehe8729@colorado.edu> | 2025-03-11 07:21:20 +0000 |
commit | fe66ba45312872879a39352c7a2e95de7af4fd26 (patch) | |
tree | 11c768860e79f2b9210c662b5ce5cc35416ce8cd | |
parent | d6a0e11b8026394f36401a1165c59edbf937ac4e (diff) |
Resolve Line 86:28: Do not access Object.prototype method 'hasOwnProperty' from target object no-prototype-builtins
Line 88:28: Do not access Object.prototype method 'hasOwnProperty' from target object no-prototype-builtins
Line 90:28: Do not access Object.prototype method 'hasOwnProperty' from target object no-prototype-builtins
Line 92:26: Do not access Object.prototype method 'hasOwnProperty' from target object no-prototype-builtins
Line 94:26: Do not access Object.prototype method 'hasOwnProperty' from target object no-prototype-builtins
Line 96:26: Do not access Object.prototype method 'hasOwnProperty' from target object no-prototype-builtins
-rw-r--r-- | diplomacy/web/src/gui/utils/map_data.js | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/diplomacy/web/src/gui/utils/map_data.js b/diplomacy/web/src/gui/utils/map_data.js new file mode 100644 index 0000000..ea63dd7 --- /dev/null +++ b/diplomacy/web/src/gui/utils/map_data.js @@ -0,0 +1,100 @@ +// ============================================================================== +// Copyright (C) 2019 - Philip Paquette, Steven Bocco +// +// This program is free software: you can redistribute it and/or modify it under +// the terms of the GNU Affero General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) any +// later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +// details. +// +// You should have received a copy of the GNU Affero General Public License along +// with this program. If not, see <https://www.gnu.org/licenses/>. +// ============================================================================== +import {Province} from "./province"; + +export class MapData { + constructor(mapInfo, game) { + // mapInfo: {powers: [], supply_centers: [], aliases: {alias: name}, loc_type: {loc => type}, loc_abut: {loc => [abuts]}} + // game: a NetworkGame object. + this.game = game; + this.powers = new Set(mapInfo.powers); + this.supplyCenters = new Set(mapInfo.supply_centers); + this.aliases = Object.assign({}, mapInfo.aliases); + this.provinces = {}; + for (let entry of Object.entries(mapInfo.loc_type)) { + const provinceName = entry[0]; + const provinceType = entry[1]; + this.provinces[provinceName] = new Province(provinceName, provinceType, this.supplyCenters.has(provinceName)); + } + for (let entry of Object.entries(mapInfo.loc_abut)) { + this.getProvince(entry[0]).setNeighbors(entry[1].map(name => this.getProvince(name))); + } + for (let province of Object.values(this.provinces)) { + province.setCoasts(this.provinces); + } + for (let power of Object.values(this.game.powers)) { + for (let center of power.centers) { + this.getProvince(center).setController(power.name, 'C'); + } + for (let loc of power.influence) { + this.getProvince(loc).setController(power.name, 'I'); + } + for (let unit of power.units) { + this.__add_unit(unit, power.name); + } + for (let unit of Object.keys(power.retreats)) { + this.__add_retreat(unit, power.name); + } + } + for (let entry of Object.entries(this.aliases)) { + const alias = entry[0]; + const provinceName = entry[1]; + const province = this.getProvince(provinceName); + if (province) + province.aliases.push(alias); + } + } + + __add_unit(unit, power_name) { + const splitUnit = unit.split(/ +/); + const unitType = splitUnit[0]; + const location = splitUnit[1]; + const province = this.getProvince(location); + province.setController(power_name, 'U'); + province.unit = unitType; + } + + __add_retreat(unit, power_name) { + const splitUnit = unit.split(/ +/); + const location = splitUnit[1]; + const province = this.getProvince(location); + province.retreatController = power_name; + province.retreatUnit = unit; + } + + getProvince(abbr) { + if (abbr === '') + return null; + if (abbr[0] === '_') + abbr = abbr.substr(1, 3); + if (!abbr) + return null; + if (Object.prototype.hasOwnProperty.call(this.provinces, abbr)) + return this.provinces[abbr]; + if (Object.prototype.hasOwnProperty.call(this.provinces, abbr.toUpperCase())) + return this.provinces[abbr.toUpperCase()]; + if (Object.prototype.hasOwnProperty.call(this.provinces, abbr.toLowerCase())) + return this.provinces[abbr.toLowerCase()]; + if (Object.prototype.hasOwnProperty.call(this.aliases, abbr)) + return this.provinces[this.aliases[abbr]]; + if (Object.prototype.hasOwnProperty.call(this.aliases, abbr.toUpperCase())) + return this.provinces[this.aliases[abbr.toUpperCase()]]; + if (Object.prototype.hasOwnProperty.call(this.aliases, abbr.toLowerCase())) + return this.provinces[this.aliases[abbr.toLowerCase()]]; + return null; + } +} |