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 df84d0c..65e1206 100644 --- a/ts/industries.ts +++ b/ts/industries.ts @@ -89,7 +89,7 @@ export const IndustryNames = [ /** * Lookup table for converting legacy industry types to names. */ -const legacyIndustryNames: Record = { +export const legacyIndustryNames: Record = { [IndustryType.coal_mine]: 'coalmine', [IndustryType.coaling_tower]: 'coaltower', [IndustryType.engine_house_brown]: 'enginehouse_princess',