Skip to content

Commit

Permalink
Merge pull request #22 from PatPL/dev
Browse files Browse the repository at this point in the history
Web.0.9.3.2
  • Loading branch information
PatPL authored Jan 13, 2020
2 parents 4959664 + 9aa52fa commit ceed9b1
Show file tree
Hide file tree
Showing 15 changed files with 824 additions and 177 deletions.
20 changes: 15 additions & 5 deletions TS_SOURCE/js/DialogBoxes/BrowserCacheDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class BrowserCacheDialog {
let lists: string[] = [];

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

listItem.addEventListener ("click", () => {
this.FinishTransaction (Store.GetBinary (i), i.replace (/\.enl.autosave$/, ""));
// do not re-autosave this file
Autosave.Enabled = false;

this.FinishTransaction (Store.GetBinary (i), i.replace (/\.enl.autosave2$/, "").replace (/^[0-9]+-/, ""));

Autosave.Enabled = true;
});

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

let time = new Date (parseInt (tmp[0]));
listItem.title = `@${ time.toLocaleString () } | ${ tmp[1] }`;
listItem.title = `This file started being edited at ${ time.toLocaleString () } | ${ tmp[1] }`;
listItem.innerHTML = `@${ time.toLocaleString () } | ${ tmp[1] }`;
container.appendChild (listItem);
});
Expand Down Expand Up @@ -201,12 +206,17 @@ class BrowserCacheDialog {
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?")) {
ListNameDisplay.SetValue (i.replace (/\.enl$/, ""))

// Disable autosave for a list that was just opened
Autosave.Enabled = false;

MainEngineTable.Items = Serializer.DeserializeMany (Store.GetBinary (i));
MainEngineTable.Items.forEach (e => {
e.EngineList = MainEngineTable.Items;
});
MainEngineTable.RebuildTable ();

Autosave.Enabled = true;

this.DialogBoxElement.style.display = "none";
}
});
Expand Down
30 changes: 25 additions & 5 deletions TS_SOURCE/js/DialogBoxes/SettingsDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,30 @@ document.addEventListener ("DOMContentLoaded", () => {
SettingsDialog.SettingsBoxElement.querySelector ("div.fullscreen-grayout")!.addEventListener ("click", () => {
SettingsDialog.Apply ();
})

document.getElementById ("settings-remove-all-autosaves")!.addEventListener ("click", () => {
if (confirm ("Are you sure you want to permanently remove all autosaves?")) {
for (let i in localStorage) {
if (/.enl.autosave2$/.test (i)) {
localStorage.removeItem (i);
}
}

SettingsDialog.RefreshLocalStorageUsage ();
Notifier.Info ("All autosaves removed");
}
});
});

class SettingsDialog {

public static SettingsBoxElement: HTMLElement;

public static RefreshLocalStorageUsage () {
document.getElementById ("settings-localStorage-usage-display")!.innerHTML = Debug_GetLocalStorageUsage ().toString ();
document.getElementById ("settings-localStorage-autosave-usage-display")!.innerHTML = Debug_GetLocalStorageUsage (/.enl.autosave2$/).toString ();
}

public static Show () {
let inputs = this.SettingsBoxElement.querySelectorAll ("input");

Expand All @@ -36,6 +54,8 @@ class SettingsDialog {
}
});

this.RefreshLocalStorageUsage ();

FullscreenWindows["settings-box"].style.display = "flex";
}

Expand Down Expand Up @@ -87,10 +107,6 @@ const Settings: ISettings = {
return Store.GetText ("setting:prettify_config", "0") == "1";
}, set prettify_config(value: boolean) {
Store.SetText ("setting:prettify_config", value ? "1" : "0");
}, get async_sort(): boolean {
return Store.GetText ("setting:async_sort", "0") == "1";
}, set async_sort(value: boolean) {
Store.SetText ("setting:async_sort", value ? "1" : "0");
}, get hide_disabled_fields_on_sort(): boolean {
return Store.GetText ("setting:hide_disabled_fields_on_sort", "1") == "1";
}, set hide_disabled_fields_on_sort(value: boolean) {
Expand All @@ -103,6 +119,10 @@ const Settings: ISettings = {
return Store.GetText ("setting:custom_theme", btoa (JSON.stringify ([])));
}, set custom_theme(value: string) {
Store.SetText ("setting:custom_theme", value);
}, get ignore_localstorage_usage(): boolean {
return Store.GetText ("setting:ignore_localstorage_usage", "0") == "1";
}, set ignore_localstorage_usage(value: boolean) {
Store.SetText ("setting:ignore_localstorage_usage", value ? "1" : "0");
}
}

Expand All @@ -114,8 +134,8 @@ interface ISettings {
dark_theme: boolean;
show_info_panel: boolean;
prettify_config: boolean;
async_sort: boolean;
hide_disabled_fields_on_sort: boolean;
current_theme: string;
custom_theme: string;
ignore_localstorage_usage: boolean;
}
11 changes: 7 additions & 4 deletions TS_SOURCE/js/EditableField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class EditableField {
static EditedField: EditableField | null = null;
static IDCounter: number = 0;

OnSaveEdit?: () => void;
OnValueChange?: () => void;

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

this.ShowEditMode (false);

if (this.OnSaveEdit && saveChanges) {
this.OnSaveEdit ();
if (this.OnValueChange && saveChanges) {
this.OnValueChange ();
}
}

public SetValue (newValue: any) {
this.ValueOwner[this.ValueName] = newValue;
this.ApplyValueToDisplayElement ();
if (this.OnValueChange) {
this.OnValueChange ();
}
}

public RefreshDisplayElement () {
Expand Down Expand Up @@ -143,7 +146,7 @@ class EditableField {

tmp.addEventListener ("change", (e) => {
this.ValueOwner[this.ValueName] = tmp.checked;
if (this.OnSaveEdit) { this.OnSaveEdit (); }
if (this.OnValueChange) { this.OnValueChange (); }
})

output = tmp;
Expand Down
45 changes: 40 additions & 5 deletions TS_SOURCE/js/Engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,35 @@ class Engine implements ITableElement<Engine> {
return 0;
}

// Dependencies don't need to include itself
// Active: ["Active", "ID"], // "Active" is unnecessary here
// Active: ["ID"], // It'll work
// ID: [] // Can be omitted altogether (Would be ID: ["ID"])
public static readonly _ColumnSortDependencies: { [columnID: string]: string[] } = {
Active: ["ID"],
Labels: ["Polymorphism", "ID"],
EngineVariant: ["Polymorphism", "ID"],
Mass: ["Polymorphism", "ID"], // GetMass () depends on the polymorphism setting
Propulsion: ["ID"],
MinThrust: ["ID"],
PressureFed: ["ID"],
NeedsUllage: ["ID"],
TechUnlockNode: ["Polymorphism", "ID"],
EntryCost: ["Polymorphism", "ID"],
Cost: ["Polymorphism", "ID"],
AlternatorPower: ["Polymorphism", "ID"],
ThrustCurve: ["ID"],
Polymorphism: ["ID"],
FuelRatios: ["ID"],
Ignitions: ["Polymorphism", "ID"],
Visuals: ["Polymorphism", "ID"], // GetModelID () depends on the polymorphism setting
Dimensions: ["Polymorphism", "ID"], // GetWidth () & GetHeight () depend on the polymorphism setting
Gimbal: ["Polymorphism", "ID"],
TestFlight: ["Polymorphism", "ID"],
Tank: ["Polymorphism", "ID"],
};

// Make sure to add used columns to the _ColumnSortDependencies too.
public static readonly _ColumnSorts: { [columnID: string]: (a: Engine, b: Engine) => number } = {
Active: (a, b) => Engine.RegularSort (a.Active, b.Active, a.ID, b.ID),
ID: (a, b) => Engine.RegularSort (a.ID, b.ID),
Expand Down Expand Up @@ -156,7 +185,7 @@ class Engine implements ITableElement<Engine> {
Polymorphism: (a, b) => {
let output = Engine.RegularSort (a.PolyType, b.PolyType);

if (output) { return output } // Return if non 0
if (output != 0) { return output }

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

if (output) { return output } // Return if non 0
if (output != 0) { return output }
}

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

if (output) { return output } // Return if non 0
if (output != 0) { return output }

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

if (output) { return output } // Return if non 0
if (output != 0) { return output }
}

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

public ColumnSortDependencies () {
// TS doesn't allow static properties in interfaces :/
// This is a workaround, not to keep that list of functions in every single Engine instance
return Engine._ColumnSortDependencies;
}

public ColumnSorts () {
// TS doesn't allow static properties in interfaces :/
// This is a workaround, not to keep that list of functions in every single Engine instance
Expand Down
Loading

0 comments on commit ceed9b1

Please sign in to comment.