Skip to content

Commit 1d46d49

Browse files
authored
Merge pull request #4 from autosysops/dev
Remember last edited ride
2 parents a784685 + 822797a commit 1d46d49

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ If you still have a RideHeight.js file in your plugin folder remove this one.
1414

1515
# Changelog
1616

17+
2.2 - The editor now remembers the last ride you edited and will show this one again if you open the window
18+
1719
2.1 - Added option to add/remove chainlift to the track
1820

1921
2.0 - Improved UI and added option to make parts invisble and change the ride type. Renamed to "Ride Editor"

RideEditor.js

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ function get_ridetype_name(ridetype) {
266266
}
267267
}
268268

269-
function update_widget_ridetype() {
269+
function reset_widget_ridetype_dropdown() {
270270
var ridetypedropdown = window.findWidget("ridetype_dropdown");
271271

272272
for (var r = 0; r <= MAX_RIDETYPES; r++) {
@@ -278,6 +278,18 @@ function update_widget_ridetype() {
278278
ridetypedropdown.selectedIndex = (r);
279279
}
280280

281+
function update_widget_ridetype(e) {
282+
update_global_ride(e);
283+
reset_widget_ridetype_dropdown();
284+
reset_widget_colourScheme();
285+
context.getParkStorage('Levis.RideEditor').set('selected_ride', e)
286+
}
287+
288+
function update_global_ride(index) {
289+
rideID = map.rides[index].id;
290+
rideType = map.rides[index].object.rideType[0];
291+
}
292+
281293
function update_widget_height(widgetname, increase) {
282294
var heightwidget = window.findWidget(widgetname);
283295
heightoffset = heightoffset + increase
@@ -291,13 +303,36 @@ function reset_widget_colourScheme() {
291303
colourdropdown.selectedIndex = 0;
292304
}
293305

306+
function get_last_selection() {
307+
var index = context.getParkStorage('Levis.RideEditor').get('selected_ride')
308+
if(index == null) {
309+
return -1
310+
}
311+
if(index > map.rides.length) {
312+
return -1
313+
}
314+
// Set the global ride id as it's stored
315+
update_global_ride(index);
316+
return index
317+
}
318+
319+
function find_rideType() {
320+
for (var r = 0; r < rideTypes.length; r++) {
321+
if (rideTypes[r].id == rideType) {
322+
return r
323+
}
324+
}
325+
326+
return -1
327+
}
328+
294329
function validate_selection() {
295330
if (rideID == -1) {
296331
ui.showError("Ride Editor Error:", "Select a ride first.")
297332
return false;
298333
}
299334

300-
if (!changeType && !changeVisibility && !changeHeight &&!changeChain) {
335+
if (!changeType && !changeVisibility && !changeHeight && !changeChain) {
301336
ui.showError("Ride Editor Error:", "Select at least one option to change.")
302337
return false;
303338
}
@@ -312,7 +347,7 @@ function inverse_boolean(boolean) {
312347
}
313348

314349
var change_ride = function () {
315-
// Iterate every tile in the
350+
// Iterate every tile in the
316351
if (rideID >= 0) {
317352
for (var y = 0; y < map.size.y; y++) {
318353
for (var x = 0; x < map.size.x; x++) {
@@ -386,12 +421,9 @@ function rides_window() {
386421
items: map.rides.map(function (ride) {
387422
return [ride.id, ride.name].join(" - ");
388423
}),
389-
selectedIndex: -1,
424+
selectedIndex: get_last_selection(),
390425
onChange: function onChange(e) {
391-
rideID = map.rides[e].id;
392-
rideType = map.rides[e].object.rideType[0];
393-
update_widget_ridetype();
394-
reset_widget_colourScheme();
426+
update_widget_ridetype(e);
395427
}
396428
});
397429
widgets.push({
@@ -452,7 +484,7 @@ function rides_window() {
452484
items: rideTypes.map(function (ridetype) {
453485
return ridetype.name;
454486
}),
455-
selectedIndex: -1,
487+
selectedIndex: find_rideType(),
456488
onChange: function onChange(e) {
457489
rideType = rideTypes[e].id;
458490
}
@@ -562,7 +594,7 @@ function rides_window() {
562594

563595
window = ui.openWindow({
564596
classification: 'Ride Editor',
565-
title: "Ride Editor 2.1 (by Levis)",
597+
title: "Ride Editor 2.2 (by Levis)",
566598
width: 300,
567599
height: 255,
568600
x: 20,

0 commit comments

Comments
 (0)