From 7e81236e0f0c287f3b2625e4ec48427da90323eb Mon Sep 17 00:00:00 2001 From: Michel Bretschneider Date: Sat, 21 Dec 2024 18:08:42 +0100 Subject: [PATCH] tie up loose ends from suggestion/WIP commit --- ts/RailroadMap.ts | 15 +-------------- ts/Studio.ts | 34 ++++++++-------------------------- 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/ts/RailroadMap.ts b/ts/RailroadMap.ts index 0cd4124..8efe044 100644 --- a/ts/RailroadMap.ts +++ b/ts/RailroadMap.ts @@ -115,9 +115,6 @@ const DEFAULT_LAYER_VISIBILITY: MapLayerVisibility = { turntables: true, }; -// this is just a guess and could be determined with binary search given enough old savegames -const ROTATION_FIX_SAVE_GAME_VERSION = 231117; - /** * The RailroadMap class is used to create a visual representation of a Railroad * object on a web page and provide tools for interacting with it. It can render @@ -433,19 +430,9 @@ export class RailroadMap { return this.layerVisibility[layer]; } - toggleLegacyRotate(): boolean { - this.legacyRotate = !this.legacyRotate; - this.refresh(); - return this.legacyRotate; - } - isInverted(): boolean { return this.inverted; } - isLegacyRotationSaveGame(): boolean { - const currentVersion = Number(this.railroad.saveGame.version); - return currentVersion < ROTATION_FIX_SAVE_GAME_VERSION; - } private parallelToolTracksFlag = false; toggleParallelTool(): boolean { @@ -682,7 +669,7 @@ export class RailroadMap { private createLayers(): MapLayers { const group = this.svg.group() - .rotate(this.legacyRotate ? 180 : 0) + .rotate(this.inverted ? 180 : 0) .font('family', 'sans-serif') .font('size', 500); // The z-order of these groups is the order they are created diff --git a/ts/Studio.ts b/ts/Studio.ts index 5518592..a25279c 100644 --- a/ts/Studio.ts +++ b/ts/Studio.ts @@ -56,6 +56,7 @@ import {VegetationUtil} from './VegetationUtil'; const OLDEST_TESTED_SAVE_GAME_VERSION = 1; const NEWEST_TESTED_SAVE_GAME_VERSION = 231117; +const INVERT_BEFORE_SAVE_GAME_VERSION = 231117; /** * Web UI for editing a Railroad object. @@ -95,7 +96,8 @@ export class Studio { this.floatHeader(true); }); content.replaceChildren(mapDiv); - this.map = new RailroadMap(this, mapDiv); + const useLegacyRotation = this.isLegacyRotationSaveGame(); + this.map = new RailroadMap(this, mapDiv, useLegacyRotation); // Layers dropdown const txtLayers = document.createTextNode(' Layers '); @@ -455,25 +457,6 @@ export class Studio { return btnAction; })); - // Rotate 180 Button for legacy version maps - const btnLegacyRotate = document.createElement('button'); - btnLegacyRotate.textContent = 'Legacy Rotation 180°'; - if (this.map.isInLegacyOrientationMode()) { - btnLegacyRotate.classList.add('active', 'btn-danger'); - } else { - btnLegacyRotate.classList.add('btn', 'btn-secondary'); - } - btnLegacyRotate.addEventListener('click', () => { - const legacyRotateEnabled = this.map.toggleLegacyRotate(); - if (legacyRotateEnabled) { - btnLegacyRotate.classList.add('active', 'btn-danger'); - btnLegacyRotate.classList.remove('btn-secondary'); - } else { - btnLegacyRotate.classList.remove('active', 'btn-danger'); - btnLegacyRotate.classList.add('btn-secondary'); - } - }); - // Rerail frame tool const btnRerail = document.createElement('button'); const imgRerail = bootstrapIcon('bi-train-front', 'Rerail Frame Tool'); @@ -717,12 +700,6 @@ export class Studio { grpLayers, btnDelete, ); - if (this.map.isLegacyRotationSaveGame()) { - // show rotate button only for legacy maps - [ - btnLegacyRotate, - ].forEach((e) => mapButtons.insertBefore(e, btnDelete)); - } if (hasFrames) { // Enable tools that work on frames [ @@ -1734,4 +1711,9 @@ export class Studio { tr.appendChild(td); } } + + isLegacyRotationSaveGame(): boolean { + const currentVersion = Number(this.railroad.saveGame.version); + return currentVersion < INVERT_BEFORE_SAVE_GAME_VERSION; + } }