From d7dc5769a8717949da906ba1dbc7b3d44e935d45 Mon Sep 17 00:00:00 2001 From: Pax1601 Date: Sat, 9 Dec 2023 18:06:47 +0100 Subject: [PATCH] Bugfixing, switched to human name for humans --- client/public/stylesheets/panels/unitinfo.css | 12 +++++++ client/src/panels/unitinfopanel.ts | 9 ++++-- client/views/panels/unitinfo.ejs | 1 + scripts/OlympusCommand.lua | 29 ++++++++++++----- src/olympus/src/olympus.cpp | 31 +++++++++++++++++-- 5 files changed, 70 insertions(+), 12 deletions(-) diff --git a/client/public/stylesheets/panels/unitinfo.css b/client/public/stylesheets/panels/unitinfo.css index 4a4d92f6..0b925aaf 100644 --- a/client/public/stylesheets/panels/unitinfo.css +++ b/client/public/stylesheets/panels/unitinfo.css @@ -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; diff --git a/client/src/panels/unitinfopanel.ts b/client/src/panels/unitinfopanel.ts index 1193ca85..bbdeb13a 100644 --- a/client/src/panels/unitinfopanel.ts +++ b/client/src/panels/unitinfopanel.ts @@ -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) => 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; diff --git a/client/views/panels/unitinfo.ejs b/client/views/panels/unitinfo.ejs index f1daa12b..017e346e 100644 --- a/client/views/panels/unitinfo.ejs +++ b/client/views/panels/unitinfo.ejs @@ -7,6 +7,7 @@
+
diff --git a/scripts/OlympusCommand.lua b/scripts/OlympusCommand.lua index e14826b2..3306068a 100644 --- a/scripts/OlympusCommand.lua +++ b/scripts/OlympusCommand.lua @@ -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() diff --git a/src/olympus/src/olympus.cpp b/src/olympus/src/olympus.cpp index 6951684d..62f5bd7c 100644 --- a/src/olympus/src/olympus.cpp +++ b/src/olympus/src/olympus.cpp @@ -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; }