Skip to content

Commit ceed9b1

Browse files
authored
Merge pull request #22 from PatPL/dev
Web.0.9.3.2
2 parents 4959664 + 9aa52fa commit ceed9b1

File tree

15 files changed

+824
-177
lines changed

15 files changed

+824
-177
lines changed

TS_SOURCE/js/DialogBoxes/BrowserCacheDialog.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class BrowserCacheDialog {
8080
let lists: string[] = [];
8181

8282
for (let i in localStorage) {
83-
if (/^(.)+\.enl.autosave$/.test (i)) {
83+
if (/^(.)+\.enl.autosave2$/.test (i)) {
8484
lists.push (i);
8585
}
8686
}
@@ -92,11 +92,16 @@ class BrowserCacheDialog {
9292
listItem.classList.add ("option-button");
9393

9494
listItem.addEventListener ("click", () => {
95-
this.FinishTransaction (Store.GetBinary (i), i.replace (/\.enl.autosave$/, ""));
95+
// do not re-autosave this file
96+
Autosave.Enabled = false;
97+
98+
this.FinishTransaction (Store.GetBinary (i), i.replace (/\.enl.autosave2$/, "").replace (/^[0-9]+-/, ""));
99+
100+
Autosave.Enabled = true;
96101
});
97102

98-
// [timestamp]-[name].enl.autosave
99-
let tmp = i.replace (/\.enl.autosave$/, "").split ("-");
103+
// [timestamp]-[name].enl.autosave2
104+
let tmp = i.replace (/\.enl.autosave2$/, "").split ("-");
100105
for (let i = 2; i < tmp.length; ++i) {
101106
// .split (limit) skips the rest of the string once it hits the limit
102107
// It needs to be reappended
@@ -105,7 +110,7 @@ class BrowserCacheDialog {
105110
tmp.length = 2;
106111

107112
let time = new Date (parseInt (tmp[0]));
108-
listItem.title = `@${ time.toLocaleString () } | ${ tmp[1] }`;
113+
listItem.title = `This file started being edited at ${ time.toLocaleString () } | ${ tmp[1] }`;
109114
listItem.innerHTML = `@${ time.toLocaleString () } | ${ tmp[1] }`;
110115
container.appendChild (listItem);
111116
});
@@ -201,12 +206,17 @@ class BrowserCacheDialog {
201206
if (MainEngineTable.Items.length == 0 || confirm ("All unsaved changes to this list will be lost.\n\nAre you sure you want to open a list from cache?")) {
202207
ListNameDisplay.SetValue (i.replace (/\.enl$/, ""))
203208

209+
// Disable autosave for a list that was just opened
210+
Autosave.Enabled = false;
211+
204212
MainEngineTable.Items = Serializer.DeserializeMany (Store.GetBinary (i));
205213
MainEngineTable.Items.forEach (e => {
206214
e.EngineList = MainEngineTable.Items;
207215
});
208216
MainEngineTable.RebuildTable ();
209217

218+
Autosave.Enabled = true;
219+
210220
this.DialogBoxElement.style.display = "none";
211221
}
212222
});

TS_SOURCE/js/DialogBoxes/SettingsDialog.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,30 @@ document.addEventListener ("DOMContentLoaded", () => {
66
SettingsDialog.SettingsBoxElement.querySelector ("div.fullscreen-grayout")!.addEventListener ("click", () => {
77
SettingsDialog.Apply ();
88
})
9+
10+
document.getElementById ("settings-remove-all-autosaves")!.addEventListener ("click", () => {
11+
if (confirm ("Are you sure you want to permanently remove all autosaves?")) {
12+
for (let i in localStorage) {
13+
if (/.enl.autosave2$/.test (i)) {
14+
localStorage.removeItem (i);
15+
}
16+
}
17+
18+
SettingsDialog.RefreshLocalStorageUsage ();
19+
Notifier.Info ("All autosaves removed");
20+
}
21+
});
922
});
1023

1124
class SettingsDialog {
1225

1326
public static SettingsBoxElement: HTMLElement;
1427

28+
public static RefreshLocalStorageUsage () {
29+
document.getElementById ("settings-localStorage-usage-display")!.innerHTML = Debug_GetLocalStorageUsage ().toString ();
30+
document.getElementById ("settings-localStorage-autosave-usage-display")!.innerHTML = Debug_GetLocalStorageUsage (/.enl.autosave2$/).toString ();
31+
}
32+
1533
public static Show () {
1634
let inputs = this.SettingsBoxElement.querySelectorAll ("input");
1735

@@ -36,6 +54,8 @@ class SettingsDialog {
3654
}
3755
});
3856

57+
this.RefreshLocalStorageUsage ();
58+
3959
FullscreenWindows["settings-box"].style.display = "flex";
4060
}
4161

@@ -87,10 +107,6 @@ const Settings: ISettings = {
87107
return Store.GetText ("setting:prettify_config", "0") == "1";
88108
}, set prettify_config(value: boolean) {
89109
Store.SetText ("setting:prettify_config", value ? "1" : "0");
90-
}, get async_sort(): boolean {
91-
return Store.GetText ("setting:async_sort", "0") == "1";
92-
}, set async_sort(value: boolean) {
93-
Store.SetText ("setting:async_sort", value ? "1" : "0");
94110
}, get hide_disabled_fields_on_sort(): boolean {
95111
return Store.GetText ("setting:hide_disabled_fields_on_sort", "1") == "1";
96112
}, set hide_disabled_fields_on_sort(value: boolean) {
@@ -103,6 +119,10 @@ const Settings: ISettings = {
103119
return Store.GetText ("setting:custom_theme", btoa (JSON.stringify ([])));
104120
}, set custom_theme(value: string) {
105121
Store.SetText ("setting:custom_theme", value);
122+
}, get ignore_localstorage_usage(): boolean {
123+
return Store.GetText ("setting:ignore_localstorage_usage", "0") == "1";
124+
}, set ignore_localstorage_usage(value: boolean) {
125+
Store.SetText ("setting:ignore_localstorage_usage", value ? "1" : "0");
106126
}
107127
}
108128

@@ -114,8 +134,8 @@ interface ISettings {
114134
dark_theme: boolean;
115135
show_info_panel: boolean;
116136
prettify_config: boolean;
117-
async_sort: boolean;
118137
hide_disabled_fields_on_sort: boolean;
119138
current_theme: string;
120139
custom_theme: string;
140+
ignore_localstorage_usage: boolean;
121141
}

TS_SOURCE/js/EditableField.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class EditableField {
1212
static EditedField: EditableField | null = null;
1313
static IDCounter: number = 0;
1414

15-
OnSaveEdit?: () => void;
15+
OnValueChange?: () => void;
1616

1717
constructor (valueOwner: { [id: string]: any }, valueName: string, container: HTMLElement) {
1818
this.FieldID = EditableField.IDCounter++;
@@ -91,14 +91,17 @@ class EditableField {
9191

9292
this.ShowEditMode (false);
9393

94-
if (this.OnSaveEdit && saveChanges) {
95-
this.OnSaveEdit ();
94+
if (this.OnValueChange && saveChanges) {
95+
this.OnValueChange ();
9696
}
9797
}
9898

9999
public SetValue (newValue: any) {
100100
this.ValueOwner[this.ValueName] = newValue;
101101
this.ApplyValueToDisplayElement ();
102+
if (this.OnValueChange) {
103+
this.OnValueChange ();
104+
}
102105
}
103106

104107
public RefreshDisplayElement () {
@@ -143,7 +146,7 @@ class EditableField {
143146

144147
tmp.addEventListener ("change", (e) => {
145148
this.ValueOwner[this.ValueName] = tmp.checked;
146-
if (this.OnSaveEdit) { this.OnSaveEdit (); }
149+
if (this.OnValueChange) { this.OnValueChange (); }
147150
})
148151

149152
output = tmp;

TS_SOURCE/js/Engine/Engine.ts

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,35 @@ class Engine implements ITableElement<Engine> {
120120
return 0;
121121
}
122122

123+
// Dependencies don't need to include itself
124+
// Active: ["Active", "ID"], // "Active" is unnecessary here
125+
// Active: ["ID"], // It'll work
126+
// ID: [] // Can be omitted altogether (Would be ID: ["ID"])
127+
public static readonly _ColumnSortDependencies: { [columnID: string]: string[] } = {
128+
Active: ["ID"],
129+
Labels: ["Polymorphism", "ID"],
130+
EngineVariant: ["Polymorphism", "ID"],
131+
Mass: ["Polymorphism", "ID"], // GetMass () depends on the polymorphism setting
132+
Propulsion: ["ID"],
133+
MinThrust: ["ID"],
134+
PressureFed: ["ID"],
135+
NeedsUllage: ["ID"],
136+
TechUnlockNode: ["Polymorphism", "ID"],
137+
EntryCost: ["Polymorphism", "ID"],
138+
Cost: ["Polymorphism", "ID"],
139+
AlternatorPower: ["Polymorphism", "ID"],
140+
ThrustCurve: ["ID"],
141+
Polymorphism: ["ID"],
142+
FuelRatios: ["ID"],
143+
Ignitions: ["Polymorphism", "ID"],
144+
Visuals: ["Polymorphism", "ID"], // GetModelID () depends on the polymorphism setting
145+
Dimensions: ["Polymorphism", "ID"], // GetWidth () & GetHeight () depend on the polymorphism setting
146+
Gimbal: ["Polymorphism", "ID"],
147+
TestFlight: ["Polymorphism", "ID"],
148+
Tank: ["Polymorphism", "ID"],
149+
};
150+
151+
// Make sure to add used columns to the _ColumnSortDependencies too.
123152
public static readonly _ColumnSorts: { [columnID: string]: (a: Engine, b: Engine) => number } = {
124153
Active: (a, b) => Engine.RegularSort (a.Active, b.Active, a.ID, b.ID),
125154
ID: (a, b) => Engine.RegularSort (a.ID, b.ID),
@@ -156,7 +185,7 @@ class Engine implements ITableElement<Engine> {
156185
Polymorphism: (a, b) => {
157186
let output = Engine.RegularSort (a.PolyType, b.PolyType);
158187

159-
if (output) { return output } // Return if non 0
188+
if (output != 0) { return output }
160189

161190
// Both have the same PolyType value
162191
if (
@@ -165,21 +194,21 @@ class Engine implements ITableElement<Engine> {
165194
) {
166195
output = Engine.RegularSort (a.MasterEngineName, b.MasterEngineName);
167196

168-
if (output) { return output } // Return if non 0
197+
if (output != 0) { return output }
169198
}
170199

171-
// a & b have the same gimbal, sort by ID, as a last resort
200+
// a & b have the same polymorphism, sort by ID, as a last resort
172201
return Engine.RegularSort (a.ID, b.ID);
173202
}, FuelRatios: (a, b) => {
174203
let output = Engine.RegularSort (a.FuelRatioItems.length, b.FuelRatioItems.length);
175204

176-
if (output) { return output } // Return if non 0
205+
if (output != 0) { return output }
177206

178207
// At this point both a & b have the same propellant count
179208
for (let i = 0; i < a.FuelRatioItems.length; ++i) {
180209
output = Engine.RegularSort (a.FuelRatioItems[i][0], b.FuelRatioItems[i][0]);
181210

182-
if (output) { return output } // Return if non 0
211+
if (output != 0) { return output }
183212
}
184213

185214
// a & b have the same propellants, sort by ID, as a last resort
@@ -276,6 +305,12 @@ class Engine implements ITableElement<Engine> {
276305
}, // first by enabled, then by volume
277306
}
278307

308+
public ColumnSortDependencies () {
309+
// TS doesn't allow static properties in interfaces :/
310+
// This is a workaround, not to keep that list of functions in every single Engine instance
311+
return Engine._ColumnSortDependencies;
312+
}
313+
279314
public ColumnSorts () {
280315
// TS doesn't allow static properties in interfaces :/
281316
// This is a workaround, not to keep that list of functions in every single Engine instance

0 commit comments

Comments
 (0)