Loadouts changes and spawn menu update

This commit is contained in:
Pax1601
2023-08-24 16:16:59 +02:00
parent b1e4dd62b0
commit eb80c39b98
298 changed files with 67845 additions and 6766 deletions

View File

@@ -312,11 +312,6 @@ export class Unit extends CustomMarker {
}
}
getLiveryID(): string {
const liveryID = this.getDatabase()?.getByName(this.getName())?.liveryID;
return liveryID? liveryID: "";
}
setAlive(newAlive: boolean) {
if (newAlive != this.#alive)
document.dispatchEvent(new CustomEvent("unitDeath", { detail: this }));

View File

@@ -170,6 +170,15 @@ export class UnitDatabase {
return loadoutsByRole;
}
/* Get the livery names for a specific unit */
getLiveryNamesByName(name: string) {
var liveries = this.blueprints[name].liveries;
if (liveries !== undefined)
return Object.values(liveries);
else
return [];
}
/* Get the loadout content from the unit name and loadout name */
getLoadoutByName(name: string, loadoutName: string) {
var loadouts = this.blueprints[name].loadouts;

View File

@@ -560,7 +560,7 @@ export class UnitsManager {
this.#showActionMessage(selectedUnits, `unit bombing point`);
}
// TODO add undo group
// TODO handle from lua
selectedUnitsCreateGroup() {
var selectedUnits = this.getSelectedUnits({ excludeHumans: true, onlyOnePerGroup: false });
var units = [];
@@ -569,7 +569,7 @@ export class UnitsManager {
var unit = selectedUnits[idx];
coalition = unit.getCoalition();
deleteUnit(unit.ID, false, true);
units.push({unitType: unit.getName(), location: unit.getPosition(), liveryID: unit.getLiveryID()});
units.push({unitType: unit.getName(), location: unit.getPosition()});
}
const category = this.getSelectedUnitsTypes()[0];
this.spawnUnits(category, units, coalition, true);
@@ -581,6 +581,7 @@ export class UnitsManager {
getInfoPopup().setText(`${this.#copiedUnits.length} units copied`);
}
// TODO handle from lua
pasteUnits() {
if (!this.#pasteDisabled && getMissionHandler().getCommandModeOptions().commandMode == GAME_MASTER) {
/* Compute the position of the center of the copied units */
@@ -607,8 +608,7 @@ export class UnitsManager {
var units = groups[groupName].map((unit: any) => {
var position = new LatLng(getMap().getMouseCoordinates().lat + unit.position.lat - avgLat, getMap().getMouseCoordinates().lng + unit.position.lng - avgLng);
getMap().addTemporaryMarker(position, unit.name, unit.coalition);
const liveryID = unit.getDatabase()?.getByName(unit.getName())?.liveryID;
return {unitType: unit.name, location: position, liveryID: liveryID? liveryID: ""};
return {unitType: unit.name, location: position, liveryID: ""};
});
this.spawnUnits(groups[groupName][0].category, units, groups[groupName][0].coalition, true);
}
@@ -644,8 +644,7 @@ export class UnitsManager {
if (Math.random() < IADSDensities[type]) {
const unitBlueprint = randomUnitBlueprint(groundUnitDatabase, {type: type, eras: activeEras, ranges: activeRanges});
if (unitBlueprint) {
const liveryID = unitBlueprint.liveryID;
this.spawnUnits("GroundUnit", [{unitType: unitBlueprint.name, location: latlng, liveryID: liveryID? liveryID: ""}], coalitionArea.getCoalition(), true);
this.spawnUnits("GroundUnit", [{unitType: unitBlueprint.name, location: latlng, liveryID: ""}], coalitionArea.getCoalition(), true);
getMap().addTemporaryMarker(latlng, unitBlueprint.name, coalitionArea.getCoalition());
}
}
@@ -690,8 +689,7 @@ export class UnitsManager {
if (groupName !== "" && groups[groupName].length > 0 && (groups[groupName].every((unit: any) => {return unit.category == "GroundUnit";}) || groups[groupName].every((unit: any) => {return unit.category == "NavyUnit";}))) {
var aliveUnits = groups[groupName].filter((unit: any) => {return unit.alive});
var units = aliveUnits.map((unit: any) => {
const liveryID = unit.getDatabase()?.getByName(unit.getName())?.liveryID;
return { unitType: unit.name, location: unit.position, liveryID: liveryID? liveryID: "" }
return { unitType: unit.name, location: unit.position, liveryID: "" }
});
getUnitsManager().spawnUnits(groups[groupName][0].category, units, groups[groupName][0].coalition, true);
}