Added spawn from airbase code

The spawn from airbase code has been added. A couple of fixes to the UnitDataTable.
This commit is contained in:
Pax1601
2023-03-21 21:22:29 +01:00
parent 2d47b93445
commit 2212162239
10 changed files with 107 additions and 138 deletions

View File

@@ -1,103 +1,57 @@
export class UnitDataTable {
#element;
#tableId = "unit-data-table";
constructor() {
const table = document.getElementById( this.#tableId );
if ( table instanceof HTMLElement ) {
this.#element = table;
} else {
return;
}
import { getUnitsManager } from "..";
import { Panel } from "../panels/panel";
import { Unit } from "./unit";
export class UnitDataTable extends Panel {
constructor(id: string) {
super(id);
this.hide();
}
update() {
var units = getUnitsManager().getUnits();
getElement() {
return this.#element;
}
const unitsArray = Object.values(units).sort((a: Unit, b: Unit) => {
const aVal = a.getBaseData().unitName?.toLowerCase();
const bVal = b.getBaseData().unitName?.toLowerCase();
hide() {
this.getElement()?.closest( ".ol-dialog" )?.classList.add( "hide" );
}
show() {
this.getElement()?.closest( ".ol-dialog" )?.classList.remove( "hide" );
}
toggle() {
this.getElement()?.closest( ".ol-dialog" )?.classList.toggle( "hide" );
}
update( units:object ) {
const unitsArray = Object.values( units ).sort( ( a, b ) => {
const aVal = a.baseData.unitName.toLowerCase();
const bVal = b.baseData.unitName.toLowerCase();
if ( aVal > bVal ) {
if (aVal > bVal) {
return 1;
} else if ( bVal > aVal ) {
} else if (bVal > aVal) {
return -1;
} else {
return 0;
}
});
function addRow(parentEl: HTMLElement, columns: string[]) {
const rowDiv = document.createElement("div");
function addRow( parentEl:HTMLElement, columns:string[] ) {
for (const item of columns) {
const rowDiv = document.createElement( "div" );
for ( const item of columns ) {
const div = document.createElement( "div" );
const div = document.createElement("div");
div.innerText = item;
rowDiv.appendChild( div );
rowDiv.appendChild(div);
}
parentEl.appendChild( rowDiv );
parentEl.appendChild(rowDiv);
}
const el = <HTMLElement> this.getElement().querySelector("#unit-list");
const el = this.getElement();
if ( el ) {
if (el) {
el.innerHTML = "";
addRow( el, [ "Callsign", "Name", "Category", "AI/Human" ] )
addRow(el, ["Callsign", "Name", "Category", "AI/Human"])
for ( const unit of unitsArray ) {
const dataset = [ unit.baseData.unitName, unit.baseData.name, unit.baseData.category, ( unit.baseData.AI ) ? "AI" : "Human" ];
if ( this.getElement() ) {
}
addRow( el, dataset );
for (const unit of unitsArray) {
const dataset = [unit.getBaseData().unitName, unit.getBaseData().name, unit.getBaseData().category, (unit.getBaseData().AI) ? "AI" : "Human"];
addRow(el, dataset);
}
}
}
}