Skip to content

Commit

Permalink
Editor legacy industry support
Browse files Browse the repository at this point in the history
  • Loading branch information
scottanderson committed Sep 18, 2024
1 parent cc20540 commit 3ac64bc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
16 changes: 9 additions & 7 deletions ts/Studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import {
getIndustryName,
industryInputLabels,
industryOutputLabels,
isIndustryName,
} from './industries';
import {VegetationUtil} from './VegetationUtil';

Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions ts/StudioEditor.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ts/industries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const IndustryNames = [
/**
* Lookup table for converting legacy industry types to names.
*/
const legacyIndustryNames: Record<IndustryType, IndustryName> = {
export const legacyIndustryNames: Record<IndustryType, IndustryName> = {
[IndustryType.coal_mine]: 'coalmine',
[IndustryType.coaling_tower]: 'coaltower',
[IndustryType.engine_house_brown]: 'enginehouse_princess',
Expand Down

0 comments on commit 3ac64bc

Please sign in to comment.