Database fixes

This commit is contained in:
Pax1601
2023-10-11 15:20:24 +02:00
parent a29eb3d343
commit 4cdf82cb14
9 changed files with 32247 additions and 32186 deletions

View File

@@ -40,8 +40,8 @@ export class AirUnitEditor extends UnitEditor {
addStringInput(this.contentDiv2, "Name", blueprint.name, "text", (value: string) => { blueprint.name = value; }, true);
addStringInput(this.contentDiv2, "Label", blueprint.label, "text", (value: string) => { blueprint.label = value; });
addStringInput(this.contentDiv2, "Short label", blueprint.shortLabel, "text", (value: string) => { blueprint.shortLabel = value; });
addDropdownInput(this.contentDiv2, "Coalition", blueprint.coalition, ["", "blue", "red"],);
addDropdownInput(this.contentDiv2, "Era", blueprint.era, ["WW2", "Early Cold War", "Mid Cold War", "Late Cold War", "Modern"]);
addDropdownInput(this.contentDiv2, "Coalition", blueprint.coalition, ["", "blue", "red"], (value: string) => {blueprint.coalition = value; });
addDropdownInput(this.contentDiv2, "Era", blueprint.era, ["WW2", "Early Cold War", "Mid Cold War", "Late Cold War", "Modern"], (value: string) => {blueprint.era = value; });
addStringInput(this.contentDiv2, "Filename", blueprint.filename ?? "", "text", (value: string) => { blueprint.filename = value; });
addStringInput(this.contentDiv2, "Cost", String(blueprint.cost) ?? "", "number", (value: string) => { blueprint.cost = parseFloat(value); });
addStringInput(this.contentDiv2, "Rufels from", String(blueprint.refuelsFrom) ?? "", "text", (value: string) => { blueprint.refuelsFrom = value; });
@@ -73,7 +73,8 @@ export class AirUnitEditor extends UnitEditor {
label: "",
shortLabel: "",
era: "",
loadouts: []
loadouts: [],
enabled: true
}
this.show();
this.setBlueprint(this.database.blueprints[key]);
@@ -91,7 +92,8 @@ export class AirUnitEditor extends UnitEditor {
code: "",
fuel: 1,
items: [],
roles: []
roles: [],
enabled: true
})
this.setBlueprint(this.blueprint);
}

View File

@@ -30,8 +30,8 @@ export class GroundUnitEditor extends UnitEditor {
addStringInput(this.contentDiv2, "Label", blueprint.label, "text", (value: string) => {blueprint.label = value; });
addStringInput(this.contentDiv2, "Short label", blueprint.shortLabel, "text", (value: string) => {blueprint.shortLabel = value; });
addStringInput(this.contentDiv2, "Type", blueprint.type?? "", "text", (value: string) => {blueprint.type = value; });
addDropdownInput(this.contentDiv2, "Coalition", blueprint.coalition, ["", "blue", "red"],);
addDropdownInput(this.contentDiv2, "Era", blueprint.era, ["WW2", "Early Cold War", "Mid Cold War", "Late Cold War", "Modern"]);
addDropdownInput(this.contentDiv2, "Coalition", blueprint.coalition, ["", "blue", "red"], (value: string) => {blueprint.coalition = value; });
addDropdownInput(this.contentDiv2, "Era", blueprint.era, ["WW2", "Early Cold War", "Mid Cold War", "Late Cold War", "Modern"], (value: string) => {blueprint.era = value; });
//addStringInput(this.contentDiv2, "Filename", blueprint.filename?? "", "text", (value: string) => {blueprint.filename = value; });
addStringInput(this.contentDiv2, "Cost", String(blueprint.cost)?? "", "number", (value: string) => {blueprint.cost = parseFloat(value); });
addStringInput(this.contentDiv2, "Acquisition range [m]", String(blueprint.acquisitionRange)?? "", "number", (value: string) => {blueprint.acquisitionRange = parseFloat(value); });
@@ -54,7 +54,8 @@ export class GroundUnitEditor extends UnitEditor {
coalition: "",
label: "",
shortLabel: "",
era: ""
era: "",
enabled: true
}
this.show();
this.setBlueprint(this.database.blueprints[key]);

View File

@@ -30,8 +30,8 @@ export class NavyUnitEditor extends UnitEditor {
addStringInput(this.contentDiv2, "Label", blueprint.label, "text", (value: string) => {blueprint.label = value; });
addStringInput(this.contentDiv2, "Short label", blueprint.shortLabel, "text", (value: string) => {blueprint.shortLabel = value; });
addStringInput(this.contentDiv2, "Type", blueprint.type?? "", "text", (value: string) => {blueprint.type = value; });
addDropdownInput(this.contentDiv2, "Coalition", blueprint.coalition, ["", "blue", "red"],);
addDropdownInput(this.contentDiv2, "Era", blueprint.era, ["WW2", "Early Cold War", "Mid Cold War", "Late Cold War", "Modern"]);
addDropdownInput(this.contentDiv2, "Coalition", blueprint.coalition, ["", "blue", "red"], (value: string) => {blueprint.coalition = value; });
addDropdownInput(this.contentDiv2, "Era", blueprint.era, ["WW2", "Early Cold War", "Mid Cold War", "Late Cold War", "Modern"], (value: string) => {blueprint.era = value; });
//addStringInput(this.contentDiv2, "Filename", blueprint.filename?? "", "text", (value: string) => {blueprint.filename = value; });
addStringInput(this.contentDiv2, "Cost", String(blueprint.cost)?? "", "number", (value: string) => {blueprint.cost = parseFloat(value); });
addStringInput(this.contentDiv2, "Barrel height [m]", String(blueprint.barrelHeight)?? "", "number", (value: string) => {blueprint.barrelHeight = parseFloat(value); });
@@ -50,7 +50,8 @@ export class NavyUnitEditor extends UnitEditor {
coalition: "",
label: "",
shortLabel: "",
era: ""
era: "",
enabled: true
}
this.show();
this.setBlueprint(this.database.blueprints[key]);

View File

@@ -45,7 +45,7 @@ export abstract class UnitEditor {
* @param database The database that the editor will operate on
*/
setDatabase(database: UnitDatabase) {
this.database = JSON.parse(JSON.stringify(database));
this.database = JSON.parse(JSON.stringify({blueprints: database.getBlueprints(true)}));
}
/** Show the editor

View File

@@ -38,7 +38,7 @@ export function addStringInput(div: HTMLElement, key: string, value: string, typ
* @param value The initial value of the input
* @param options The dropdown options
*/
export function addDropdownInput(div: HTMLElement, key: string, value: string, options: string[]) {
export function addDropdownInput(div: HTMLElement, key: string, value: string, options: string[], callback: CallableFunction) {
var row = document.createElement("div");
var dt = document.createElement("dt");
var dd = document.createElement("dd");
@@ -51,6 +51,7 @@ export function addDropdownInput(div: HTMLElement, key: string, value: string, o
select.appendChild(el);
});
select.value = value;
select.onchange = () => callback(select.value);
dd.appendChild(select);
row.appendChild(dt);
row.appendChild(dd);
@@ -164,6 +165,15 @@ export function addBlueprintsScroll(div: HTMLElement, database: {blueprints: {[k
text.onclick = () => callback(key);
rowDiv.appendChild(text);
let checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.checked = blueprints[key].enabled;
checkbox.onclick = () => {
console.log(checkbox.checked);
blueprints[key].enabled = checkbox.checked;
}
rowDiv.appendChild(checkbox);
/* This button allows to remove an element from the list. It requires a refresh. */
var button = document.createElement("button");
button.innerText = "X";
@@ -199,7 +209,16 @@ export function addLoadoutsScroll(div: HTMLElement, loadouts: LoadoutBlueprint[]
/* The "Empty loadout" can not be removed */
if (loadout.name !== "Empty loadout") {
/* This button allows to remove an element from the list. It requires a refresh. */
let checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.checked = loadout.enabled;
checkbox.onclick = () => {
console.log(checkbox.checked);
loadout.enabled = checkbox.checked;
}
rowDiv.appendChild(checkbox);
/* This button allows to remove an element from the list. It requires a refresh. */
var button = document.createElement("button");
button.innerText = "X";
button.onclick = () => {