Skip to content

Commit

Permalink
tie up loose ends from suggestion/WIP commit
Browse files Browse the repository at this point in the history
  • Loading branch information
embix committed Dec 21, 2024
1 parent 2bffdbb commit 7e81236
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 40 deletions.
15 changes: 1 addition & 14 deletions ts/RailroadMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
34 changes: 8 additions & 26 deletions ts/Studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 ');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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
[
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 7e81236

Please sign in to comment.