fix: Ground units spawned in group are on top of each other, no heading when importing units

Units spawned via map, context menu, or unit spawn menu now include a heading property and are offset in latitude to prevent overlap. Also ensures heading is set during import/export. Minor JSX formatting improvements in UnitSpawnMenu.
This commit is contained in:
Pax1601 2025-08-04 20:03:40 +02:00
parent 89bd39cea8
commit e4af9b06d3
4 changed files with 38 additions and 22 deletions

View File

@ -1055,7 +1055,13 @@ export class Map extends L.Map {
.getUnitsManager()
.spawnUnits(
this.#spawnRequestTable.category,
Array(this.#spawnRequestTable.amount).fill(this.#spawnRequestTable.unit),
Array(this.#spawnRequestTable.amount).fill(this.#spawnRequestTable.unit).map((unit, index) => {
return {
...unit,
location: new L.LatLng(unit.location.lat + (this.#spawnRequestTable?.category === "groundunit" ? 0.00025 * index : 0.005 * index), unit.location.lng),
heading: this.#spawnHeading,
};
}),
this.#spawnRequestTable.coalition,
false,
undefined,

View File

@ -660,7 +660,13 @@ export function SpawnContextMenu(props: {}) {
.getUnitsManager()
.spawnUnits(
spawnRequestTable.category,
Array(spawnRequestTable.amount).fill(spawnRequestTable.unit),
Array(spawnRequestTable.amount).fill(spawnRequestTable.unit).map((unit, index) => {
return {
...unit,
location: new LatLng(unit.location.lat + (spawnRequestTable?.category === "groundunit" ? 0.00025 * index : 0.005 * index), unit.location.lng),
heading: unit.heading || 0,
};
}),
spawnRequestTable.coalition,
false
);

View File

@ -319,7 +319,7 @@ export function ImportExportModal(props: { open: boolean }) {
if (selectionFilter[coalition][markerCategory] !== true) continue;
let unitsToSpawn = groupData.map((unitData: UnitData) => {
return { unitType: unitData.name, location: unitData.position, liveryID: "", skill: "High" };
return { unitType: unitData.name, location: unitData.position, liveryID: "", skill: "High", heading: unitData.heading || 0 };
});
getApp().getUnitsManager().spawnUnits(category.toLocaleLowerCase(), unitsToSpawn, coalition, false);

View File

@ -451,10 +451,9 @@ export function UnitSpawnMenu(props: {
`}
>
{props.blueprint?.liveries && props.blueprint?.liveries[id].countries.length == 1 && (
<img
src={`images/countries/${country?.flagCode.toLowerCase()}.svg`}
className={`h-6`}
/>
<img src={`images/countries/${country?.flagCode.toLowerCase()}.svg`} className={`
h-6
`} />
)}
<div className="my-auto truncate">
@ -521,12 +520,9 @@ export function UnitSpawnMenu(props: {
<div className="my-auto flex flex-col gap-2">
<span>Spawn heading</span>
<div className="flex gap-1 text-sm text-gray-400">
<FaQuestionCircle className={`my-auto`} />{" "}
<div
className={`my-auto`}
>
Drag to change
</div>
<FaQuestionCircle className={`my-auto`} /> <div className={`
my-auto
`}>Drag to change</div>
</div>
</div>
@ -632,7 +628,15 @@ export function UnitSpawnMenu(props: {
.getUnitsManager()
.spawnUnits(
spawnRequestTable.category,
Array(spawnRequestTable.amount).fill(spawnRequestTable.unit),
Array(spawnRequestTable.amount)
.fill(spawnRequestTable.unit)
.map((unit, index) => {
return {
...unit,
location: new LatLng(unit.location.lat + (spawnRequestTable?.category === "groundunit" ? 0.00025 * index : 0.005 * index), unit.location.lng),
heading: unit.heading || 0,
};
}),
spawnRequestTable.coalition,
false,
props.airbase?.getName() ?? undefined
@ -912,9 +916,12 @@ export function UnitSpawnMenu(props: {
`}
>
{props.blueprint?.liveries && props.blueprint?.liveries[id].countries.length == 1 && (
<img src={`images/countries/${country?.flagCode.toLowerCase()}.svg`} className={`
<img
src={`images/countries/${country?.flagCode.toLowerCase()}.svg`}
className={`
h-6
`} />
`}
/>
)}
<div className="my-auto truncate">
@ -980,12 +987,9 @@ export function UnitSpawnMenu(props: {
<div className="my-auto flex flex-col gap-2">
<span className="text-white">Spawn heading</span>
<div className="flex gap-1 text-sm text-gray-400">
<FaQuestionCircle className={`my-auto`} />{" "}
<div
className={`my-auto`}
>
Drag to change
</div>
<FaQuestionCircle className={`my-auto`} /> <div className={`
my-auto
`}>Drag to change</div>
</div>
</div>