mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Bugfixing, switched to human name for humans
This commit is contained in:
parent
b0ee653bff
commit
d7dc5769a8
@ -56,6 +56,18 @@
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#unit-group {
|
||||
border-radius: var(--border-radius-md);
|
||||
margin-top: auto;
|
||||
padding: 6px 16px;
|
||||
background-color: var(--secondary-light-grey);
|
||||
}
|
||||
|
||||
#unit-group::after {
|
||||
content: attr(data-group-name);
|
||||
display: block;
|
||||
}
|
||||
|
||||
#unit-control {
|
||||
color: var(--secondary-lighter-grey);
|
||||
font-weight: bold;
|
||||
|
||||
@ -12,6 +12,7 @@ export class UnitInfoPanel extends Panel {
|
||||
#silhouette: HTMLImageElement;
|
||||
#unitControl: HTMLElement;
|
||||
#unitLabel: HTMLElement;
|
||||
#unitGroup: HTMLElement;
|
||||
#unitName: HTMLElement;
|
||||
|
||||
constructor(ID: string) {
|
||||
@ -24,6 +25,7 @@ export class UnitInfoPanel extends Panel {
|
||||
this.#silhouette = (this.getElement().querySelector("#loadout-silhouette")) as HTMLImageElement;
|
||||
this.#unitControl = (this.getElement().querySelector("#unit-control")) as HTMLElement;
|
||||
this.#unitLabel = (this.getElement().querySelector("#unit-label")) as HTMLElement;
|
||||
this.#unitGroup = (this.getElement().querySelector("#unit-group")) as HTMLElement;
|
||||
this.#unitName = (this.getElement().querySelector("#unit-name")) as HTMLElement;
|
||||
|
||||
document.addEventListener("unitsSelection", (e: CustomEvent<Unit[]>) => this.#onUnitsSelection(e.detail));
|
||||
@ -39,6 +41,7 @@ export class UnitInfoPanel extends Panel {
|
||||
|
||||
/* Set the unit info */
|
||||
this.#unitLabel.innerText = aircraftDatabase.getByName(unit.getName())?.label || unit.getName();
|
||||
this.#unitGroup.dataset.groupName = unit.getGroup()?.getName() ?? "No group";
|
||||
this.#unitName.innerText = unit.getUnitName();
|
||||
if (unit.getHuman())
|
||||
this.#unitControl.innerText = "Human";
|
||||
@ -51,8 +54,10 @@ export class UnitInfoPanel extends Panel {
|
||||
this.#currentTask.dataset.currentTask = unit.getTask() !== "" ? unit.getTask() : "No task";
|
||||
this.#currentTask.dataset.coalition = unit.getCoalition();
|
||||
|
||||
this.#silhouette.src = `/images/units/${unit.getDatabase()?.getByName(unit.getName())?.filename}`;
|
||||
this.#silhouette.classList.toggle("hide", unit.getDatabase()?.getByName(unit.getName())?.filename == undefined || unit.getDatabase()?.getByName(unit.getName())?.filename == '');
|
||||
const filename = unit.getDatabase()?.getByName(unit.getName())?.filename;
|
||||
if (filename)
|
||||
this.#silhouette.src = `/images/units/${filename}`;
|
||||
this.#silhouette.classList.toggle("hide", filename == undefined || filename == '');
|
||||
|
||||
/* Add the loadout elements */
|
||||
const items = this.#loadoutContainer.querySelector("#loadout-items") as HTMLElement;
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
<div id="unit-label"></div>
|
||||
<div id="unit-control"></div>
|
||||
</div>
|
||||
<div id="unit-group" class="pill" data-group-name=""></div>
|
||||
<div id="current-task" class="pill highlight-coalition" data-coalition="blue" data-current-task=""></div>
|
||||
</div>
|
||||
|
||||
|
||||
@ -960,6 +960,10 @@ function Olympus.setOnOff(groupName, onOff)
|
||||
end
|
||||
end
|
||||
|
||||
function getUnitDescription(unit)
|
||||
return unit:getDescr()
|
||||
end
|
||||
|
||||
-- This function is periodically called to collect the data of all the existing units in the mission to be transmitted to the olympus.dll
|
||||
function Olympus.setUnitsData(arg, time)
|
||||
-- Units data
|
||||
@ -990,8 +994,9 @@ function Olympus.setUnitsData(arg, time)
|
||||
table["category"] = Olympus.modsList[unit:getDesc().typeName]
|
||||
end
|
||||
else
|
||||
if Olympus.modsList ~= nil and Olympus.modsList[unit:getDesc().typeName] ~= nil then
|
||||
table["category"] = Olympus.modsList[unit:getDesc().typeName]
|
||||
local status, description = pcall(getUnitDescription, unit)
|
||||
if status and Olympus.modsList ~= nil and Olympus.modsList[description.typeName] ~= nil then
|
||||
table["category"] = Olympus.modsList[description.typeName]
|
||||
else
|
||||
units[ID] = {isAlive = false}
|
||||
Olympus.units[ID] = nil
|
||||
@ -1019,12 +1024,16 @@ function Olympus.setUnitsData(arg, time)
|
||||
table["heading"] = heading
|
||||
|
||||
-- Track angles are wrong because of weird reference systems, approximate it using latitude and longitude differences
|
||||
if Olympus.unitsData["units"] ~= nil and Olympus.unitsData["units"][ID] ~= nil and Olympus.unitsData["units"][ID]["position"] ~= nil and Olympus.unitsData["units"][ID]["position"]["lat"] ~= nil and Olympus.unitsData["units"][ID]["position"]["lng"] ~= nil then
|
||||
local latDifference = lat - Olympus.unitsData["units"][ID]["position"]["lat"]
|
||||
local lngDifference = lng - Olympus.unitsData["units"][ID]["position"]["lng"]
|
||||
table["track"] = math.atan2(lngDifference * math.cos(lat / 57.29577), latDifference)
|
||||
if (table["horizontalVelocity"] > 1) then
|
||||
if Olympus.unitsData["units"] ~= nil and Olympus.unitsData["units"][ID] ~= nil and Olympus.unitsData["units"][ID]["position"] ~= nil and Olympus.unitsData["units"][ID]["position"]["lat"] ~= nil and Olympus.unitsData["units"][ID]["position"]["lng"] ~= nil then
|
||||
local latDifference = lat - Olympus.unitsData["units"][ID]["position"]["lat"]
|
||||
local lngDifference = lng - Olympus.unitsData["units"][ID]["position"]["lng"]
|
||||
table["track"] = math.atan2(lngDifference * math.cos(lat / 57.29577), latDifference)
|
||||
else
|
||||
table["track"] = math.atan2(velocity.z, velocity.x)
|
||||
end
|
||||
else
|
||||
table["track"] = math.atan2(velocity.z, velocity.x)
|
||||
table["track"] = table["heading"]
|
||||
end
|
||||
|
||||
table["isAlive"] = unit:isExist() and unit:isActive() and unit:getLife() >= 1
|
||||
@ -1060,7 +1069,11 @@ function Olympus.setUnitsData(arg, time)
|
||||
end
|
||||
|
||||
table["country"] = unit:getCountry()
|
||||
table["unitName"] = unit:getName()
|
||||
if unit:getPlayerName() ~= nil then
|
||||
table["unitName"] = unit:getPlayerName()
|
||||
else
|
||||
table["unitName"] = unit:getName()
|
||||
end
|
||||
table["groupName"] = group:getName()
|
||||
table["isHuman"] = (unit:getPlayerName() ~= nil)
|
||||
table["hasTask"] = controller:hasTask()
|
||||
|
||||
@ -20,8 +20,35 @@ f_coreMissionData coreMissionData = nullptr;
|
||||
|
||||
string modPath;
|
||||
|
||||
//Returns the last Win32 error, in string format. Returns an empty string if there is no error.
|
||||
std::string GetLastErrorAsString()
|
||||
{
|
||||
//Get the error message ID, if any.
|
||||
DWORD errorMessageID = ::GetLastError();
|
||||
if (errorMessageID == 0) {
|
||||
return std::string(); //No error message has been recorded
|
||||
}
|
||||
|
||||
LPSTR messageBuffer = nullptr;
|
||||
|
||||
//Ask Win32 to give us the string version of that message ID.
|
||||
//The parameters we pass in, tell Win32 to create the buffer that holds the message for us (because we don't yet know how long the message string will be).
|
||||
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
|
||||
|
||||
//Copy the error message into a std::string.
|
||||
std::string message(messageBuffer, size);
|
||||
|
||||
//Free the Win32's string's buffer.
|
||||
LocalFree(messageBuffer);
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
static int onSimulationStart(lua_State* L)
|
||||
{
|
||||
LogInfo(L, "Trying to load core.dll from " + modPath);
|
||||
SetDllDirectoryA(modPath.c_str());
|
||||
log("onSimulationStart callback called successfully");
|
||||
|
||||
string dllLocation = modPath + "\\core.dll";
|
||||
@ -85,7 +112,7 @@ static int onSimulationStart(lua_State* L)
|
||||
return 0;
|
||||
|
||||
error:
|
||||
LogError(L, "Error while loading module, see Olympus.log in temporary folder for additional details.");
|
||||
LogError(L, "Error while loading module: " + GetLastErrorAsString());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -132,7 +159,7 @@ static int onSimulationStop(lua_State* L)
|
||||
return 0;
|
||||
|
||||
error:
|
||||
LogError(L, "Error while unloading module, see Olympus.log in temporary folder for additional details.");
|
||||
LogError(L, "Error while unloading module: " + GetLastErrorAsString());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user