Mid-way commit

This commit is contained in:
PeekabooSteam
2023-11-12 16:18:31 +00:00
parent b43afd4e9c
commit 9ef6efa3e0
8 changed files with 142 additions and 42 deletions

View File

@@ -16,6 +16,7 @@ import { HotgroupPanel } from "../panels/hotgrouppanel";
import { Contact, UnitData, UnitSpawnTable } from "../interfaces";
import { Dialog } from "../dialog/dialog";
import { UnitDataFileExport } from "./unitdatafileexport";
import { UnitDataFileImport } from "./unitdatafileimport";
/** The UnitsManager handles the creation, update, and control of units. Data is strictly updated by the server ONLY. This means that any interaction from the user will always and only
* result in a command to the server, executed by means of a REST PUT request. Any subsequent change in data will be reflected only when the new data is sent back by the server. This strategy allows
@@ -28,7 +29,8 @@ export class UnitsManager {
#selectionEventDisabled: boolean = false;
#slowDeleteDialog!:Dialog;
#units: { [ID: number]: Unit };
#unitDataExport!:UnitDataFileExport;
#unitDataImport!:UnitDataFileImport;
constructor() {
this.#copiedUnits = [];
@@ -986,38 +988,18 @@ export class UnitsManager {
* TODO: Extend to aircraft and helicopters
*/
exportToFile() {
const fileExport = new UnitDataFileExport("unit-import-export-dialog");
fileExport.showForm(Object.values(this.#units));
if (!this.#unitDataExport)
this.#unitDataExport = new UnitDataFileExport("unit-import-export-dialog");
this.#unitDataExport.showForm(Object.values(this.#units));
}
/** Import ground and navy units from file
* TODO: extend to support aircraft and helicopters
*/
importFromFile() {
var input = document.createElement("input");
input.type = "file";
input.addEventListener("change", (e: any) => {
var file = e.target.files[0];
if (!file) {
return;
}
var reader = new FileReader();
reader.onload = function (e: any) {
var contents = e.target.result;
var groups = JSON.parse(contents);
for (let groupName in groups) {
if (groupName !== "" && groups[groupName].length > 0 && (groups[groupName].every((unit: UnitData) => { return unit.category == "GroundUnit"; }) || groups[groupName].every((unit: any) => { return unit.category == "NavyUnit"; }))) {
var aliveUnits = groups[groupName].filter((unit: UnitData) => { return unit.alive });
var units = aliveUnits.map((unit: UnitData) => {
return { unitType: unit.name, location: unit.position, liveryID: "" }
});
getApp().getUnitsManager().spawnUnits(groups[groupName][0].category, units, groups[groupName][0].coalition, true);
}
}
};
reader.readAsText(file);
})
input.click();
if (!this.#unitDataImport)
this.#unitDataImport = new UnitDataFileImport("unit-import-export-dialog");
this.#unitDataImport.selectFile();
}
/** Spawn a new group of units