Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve original frame GvasText #33

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ts/Railroad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export interface Railroad {

export interface Frame {
location: Vector;
name: GvasString;
number: GvasString;
name: GvasText;
number: GvasText;
rotation: Rotator;
type: GvasString;
state: FrameState;
Expand Down
8 changes: 4 additions & 4 deletions ts/RailroadMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {localToWorld} from './HasLocationRotation';
import {catmullRomMinRadius, catmullRomToBezier} from './util-catmullrom';
import {rect} from './util-path';
import {GizmoDirection, gizmoDirection} from './Gizmo';
import {unknownProperty} from './util';
import {textToString, unknownProperty} from './util';

enum MapToolMode {
pan_zoom,
Expand Down Expand Up @@ -782,8 +782,8 @@ export class RailroadMap {
// Tooltip
const tooltipText = [
definition.name,
frame.name,
frame.number,
textToString(frame.name),
textToString(frame.number),
cargoText(frame)]
.filter(Boolean)
.map(gvasToString)
Expand All @@ -795,7 +795,7 @@ export class RailroadMap {
const frameText = frame.number;
if (frameText) {
const text = g
.text(gvasToString(frameText))
.text(gvasToString(textToString(frameText)))
.attr('transform', `rotate(180) translate(${dx} 90)`)
.addClass('frame-text');
if (definition.engine) {
Expand Down
15 changes: 8 additions & 7 deletions ts/Studio.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createFilter} from './Filter';
import {calculateSteepestGrade} from './Grade';
import {GvasString, gvasToString} from './Gvas';
import {GvasString, GvasText, gvasToString} from './Gvas';
import {IndustryType, industryProductInputLabels, industryProductOutputLabels} from './IndustryType';
import {createPager} from './Pager';
import {Frame, NumericFrameState, Railroad, SplineType, Quadruplet} from './Railroad';
Expand Down Expand Up @@ -42,6 +42,7 @@ import {clamp} from './math';
import {toggleDarkMode} from './themes';
import {catmullRomToHermite} from './util-catmullrom';
import {Quaternion} from './Quaternion';
import {textToString} from './util';

const OLDEST_TESTED_SAVE_GAME_VERSION = 1;
const NEWEST_TESTED_SAVE_GAME_VERSION = 230403;
Expand Down Expand Up @@ -239,8 +240,8 @@ export class Studio {
const imgFrame = document.createElement('i');
const text =
(isFrameType(frame.type) ? frameDefinitions[frame.type].name + ' ' : '') +
(frame.number ? '#' + gvasToString(frame.number) + ' ' : '') +
(frame.name ? gvasToString(frame.name) : '');
(frame.number ? '#' + gvasToString(textToString(frame.number)) + ' ' : '') +
(frame.name ? gvasToString(textToString(frame.name)) : '');
const txtFrame = document.createTextNode(` ${text} `);
imgFrame.classList.add('bi', 'bi-geo');
btnFrame.classList.add('dropdown-item', 'text-nowrap');
Expand Down Expand Up @@ -922,13 +923,13 @@ export class Studio {
tr.appendChild(td);
// Name
td = document.createElement('td');
const setFrameName = (name: GvasString) => frame.name = name;
td.appendChild(editString(this, frame.name, setFrameName));
const setFrameName = (name: GvasText) => frame.name = name;
td.appendChild(editText(this, frame.name, setFrameName));
tr.appendChild(td);
// Number
td = document.createElement('td');
const setFrameNumber = (frameNo: GvasString) => frame.number = frameNo;
td.appendChild(editString(this, frame.number, setFrameNumber));
const setFrameNumber = (frameNo: GvasText) => frame.number = frameNo;
td.appendChild(editText(this, frame.number, setFrameNumber));
tr.appendChild(td);
// State table
td = document.createElement('td');
Expand Down
5 changes: 2 additions & 3 deletions ts/exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {Railroad} from './Railroad';
import {Rotator} from './Rotator';
import {Transform} from './Transform';
import {Vector} from './Vector';
import {stringToText} from './util';

const exportKeys = [
'AnimateTimeOfDay',
Expand Down Expand Up @@ -216,10 +215,10 @@ export function railroadToGvas(railroad: Railroad): Gvas {
vectorArrays[propertyName] = railroad.frames.map((f) => f.location);
break;
case 'framenamearray':
textArrays[propertyName] = railroad.frames.map((f) => stringToText(f.name));
textArrays[propertyName] = railroad.frames.map((f) => f.name);
break;
case 'framenumberarray':
textArrays[propertyName] = railroad.frames.map((f) => stringToText(f.number));
textArrays[propertyName] = railroad.frames.map((f) => f.number);
break;
case 'framerotationarray':
rotatorArrays[propertyName] = railroad.frames.map((f) => f.rotation);
Expand Down
9 changes: 3 additions & 6 deletions ts/importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
Vegeation,
Watertower,
} from './Railroad';
import {textToString} from './util';

/**
* Converts a Gvas object, which represents the contents of a GVAS file, into a
Expand All @@ -33,9 +32,7 @@ import {textToString} from './util';
* as the player, industries, and splines.
*
* The function also makes use of several helper functions, such as optionalMap,
* which is used to retrieve a property from the Gvas object if it exists, and
* textToString, which is used to convert a GvasText object (a special type of
* string used in GVAS files) into a regular string.
* which is used to retrieve a property from the Gvas object if it exists.
* @param {Gvas} gvas
* @return {Railroad}
*/
Expand Down Expand Up @@ -143,8 +140,8 @@ export function gvasToRailroad(gvas: Gvas): Railroad {
for (let i = 0; i < frameLocation.length; i++) {
const frame: Frame = {
location: frameLocation[i],
name: textToString(frameName[i]),
number: textToString(frameNumber[i]),
name: frameName[i],
number: frameNumber[i],
rotation: frameRotation[i],
type: frameType[i],
state: {
Expand Down