diff --git a/package-lock.json b/package-lock.json index bc471ad..6492cdb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -522,9 +522,9 @@ } }, "node_modules/@types/estree": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", - "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", + "integrity": "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==", "dev": true, "license": "MIT" }, diff --git a/ts/Studio.ts b/ts/Studio.ts index c73a427..adb2a28 100644 --- a/ts/Studio.ts +++ b/ts/Studio.ts @@ -51,7 +51,6 @@ import { getIndustryName, industryInputLabels, industryOutputLabels, - isIndustryName, } from './industries'; import {VegetationUtil} from './VegetationUtil'; @@ -1498,13 +1497,16 @@ export class Studio { if (typeof industry.type === 'number') { const setIndustryType = (type: IndustryType) => industry.type = type; td.replaceChildren(editIndustryType(this, industry.type, setIndustryType)); - } else if (isIndustryName(industry.type)) { - const setIndustryName = (name: IndustryName) => industry.type = name; - td.replaceChildren(editIndustryName(this, industry.type, setIndustryName)); } else { - const setIndustryName = (name: GvasString) => industry.type = name; - td.replaceChildren(editString(this, industry.type, setIndustryName)); - td.classList.add('table-warning'); + const industryName = getIndustryName(industry); + if (industryName !== null) { + const setIndustryName = (name: IndustryName) => industry.type = name; + td.replaceChildren(editIndustryName(this, industryName, setIndustryName)); + } else { + const setIndustryName = (name: GvasString) => industry.type = name; + td.replaceChildren(editString(this, industry.type, setIndustryName)); + td.classList.add('table-warning'); + } } tr.appendChild(td); // Inputs diff --git a/ts/StudioEditor.ts b/ts/StudioEditor.ts index 535d0f6..518bf09 100644 --- a/ts/StudioEditor.ts +++ b/ts/StudioEditor.ts @@ -1,5 +1,5 @@ import {GvasString, GvasText, gvasToString} from './Gvas'; -import {IndustryName, IndustryNames, IndustryType, industryNames, isIndustryName} from './industries'; +import {IndustryName, IndustryType, industryNames, isIndustryName, legacyIndustryNames} from './industries'; import {Permission, permissionEqual, permissionLabels, permissionToString} from './Permission'; import {Quaternion} from './Quaternion'; import {Quadruplet} from './Railroad'; @@ -457,9 +457,11 @@ export function editIndustryType( type: IndustryType, saveValue: (value: IndustryType) => void, ): Node { - const options: {[key: string]: string} = {}; - for (const key of IndustryNames) { - options[key] = isIndustryName(key) ? industryNames[key] : key; + const options: {[key: number]: string} = {}; + for (const [key, value] of Object.entries(legacyIndustryNames)) { + const type: IndustryType = Number(key); + const name = value; + options[type] = isIndustryName(name) ? industryNames[name] : name; } const save = (value: string) => saveValue(Number(value) as IndustryType); return editDropdown(studio, String(type), options, save); diff --git a/ts/industries.ts b/ts/industries.ts index e6bdaca..65e1206 100644 --- a/ts/industries.ts +++ b/ts/industries.ts @@ -56,15 +56,20 @@ export const IndustryNames = [ 'engineshed_style4', 'firewooddepot', 'freightdepot', + 'GoldDredge', + 'GoldMine', + 'GoldSmelter', 'ironoremine', 'ironworks', 'logcamp', 'MeatPackingPlant', 'oilfield', + 'RailExpressAgency', 'Refinery', 'Sandhouse', 'sawmill', 'smelter', + 'StampMill', 'telegraphoffice', 'watertower_1870_style1', 'watertower_1870_style2', @@ -79,11 +84,6 @@ export const IndustryNames = [ 'WaterWell', 'WheatFarm', 'Woodrick', - 'GoldDredge', - 'GoldMine', - 'StampMill', - 'GoldSmelter', - 'RailExpressAgency', ] as const satisfies readonly string[]; /** @@ -121,6 +121,18 @@ export const legacyIndustryNames: Record = { [IndustryType.wood_rick]: 'Woodrick', }; +/** + * Lookup table for legacy industry names. + */ +const legacyIndustryMap: Record = { + 'enginehouse_alpine_blue': 'enginehouse_alpine', + 'enginehouse_aspen_gold': 'enginehouse_aspen', + 'enginehouse_barn_red': 'enginehouse_barn', + 'enginehouse_princes_mineral_brown': 'enginehouse_princess', + 'SandHouse': 'Sandhouse', + 'Waterwell': 'WaterWell', +}; + export const isIndustryName = (name: IndustryType | GvasString): name is IndustryName => !!name && (typeof name === 'string') && IndustryNames.includes(name); @@ -129,6 +141,9 @@ export type IndustryName = typeof IndustryNames[number]; export function getIndustryName(industry: Industry): IndustryName | null { if (typeof industry.type === 'number') return legacyIndustryNames[industry.type]; if (isIndustryName(industry.type)) return industry.type; + if (industry.type === null) return null; + if (industry.type in legacyIndustryMap) return legacyIndustryMap[industry.type]; + console.warn(`Unrecognized industry type ${industry.type}`); return null; }