From 65e8eb4faa6da6403c925bf06479a8d90be9016d Mon Sep 17 00:00:00 2001 From: Merl Date: Fri, 18 Dec 2020 22:41:41 +0100 Subject: [PATCH 1/7] Updated source to current version and moved in src/ folder --- SatNav_system_2_0_0.lua | 58 - SatNav_unit_2_0_0.lua | 619 --------- .../slots/screen.lua | 0 src/system/inputText.lua | 53 + src/unit/start.lua | 1155 +++++++++++++++++ src/unit/tick_loadwp.lua | 62 + 6 files changed, 1270 insertions(+), 677 deletions(-) delete mode 100644 SatNav_system_2_0_0.lua delete mode 100644 SatNav_unit_2_0_0.lua rename SatNav_screen_2_0_0.lua => src/slots/screen.lua (100%) create mode 100644 src/system/inputText.lua create mode 100644 src/unit/start.lua create mode 100644 src/unit/tick_loadwp.lua diff --git a/SatNav_system_2_0_0.lua b/SatNav_system_2_0_0.lua deleted file mode 100644 index a4143df..0000000 --- a/SatNav_system_2_0_0.lua +++ /dev/null @@ -1,58 +0,0 @@ -function loadLocationTable () - -locationTable = {{}} -locationTable[1] = {"Alioth Market 1", "::pos{0,2,30.3314,101.3106,122.9764}"} -locationTable[#locationTable+1] = {"Alioth Market 2", "::pos{0,2,24.4469,88.0409,238.3019}"} -locationTable[#locationTable+1] = {"Alioth Market 3", "::pos{0,2,34.9734,87.3012,176.2188}"} -locationTable[#locationTable+1] = {"Alioth Market 4", "::pos{0,2,28.3352,99.5187,165.9078}"} -locationTable[#locationTable+1] = {"Alioth Market 5", "::pos{0,2,33.3939,87.3299,277.1366}"} -locationTable[#locationTable+1] = {"Alioth Market 6", "::pos{0,2,36.0044,101.3503,220.0897}"} -locationTable[#locationTable+1] = {"Alioth Market 7", "::pos{0,2,22.5024,98.1449,232.5154}"} -locationTable[#locationTable+1] = {"Alioth Market 8", "::pos{0,2,21.2154,93.9616,251.0768}"} -locationTable[#locationTable+1] = {"Alioth Market 9", "::pos{0,2,28.7133,85.6389,260.7636}"} -locationTable[#locationTable+1] = {"Alioth Market 10", "::pos{0,2,35.9865,91.8393,190.1616}"} -locationTable[#locationTable+1] = {"Alioth Market 11", "::pos{0,2,-1.0735,178.5062,69.9428}"} -locationTable[#locationTable+1] = {"Alioth Market 12", "::pos{0,2,22.7112,-92.3078,166.8481}"} -locationTable[#locationTable+1] = {"Alioth Market 13", "::pos{0,2,-23.3768,-10.5455,178.8458}"} -locationTable[#locationTable+1] = {"Alioth Market 14", "::pos{0,2,-73.4716,101.3697,89.5661}"} -locationTable[#locationTable+1] = {"Alioth Market 15", "::pos{0,2,61.7831,27.8517,54.9186}"} -locationTable[#locationTable+1] = {"Alioth Market 16", "::pos{0,2,23.4406,114.4179,211.1991}"} -locationTable[#locationTable+1] = {"Alioth Market 17", "::pos{0,2,37.8637,64.1825,151.5507}"} -locationTable[#locationTable+1] = {"Alioth Market 18", "::pos{0,2,49.9360,-170.7565,62.1982}"} -locationTable[#locationTable+1] = {"Alioth Market 19", "::pos{0,2,-32.7357,76.3764,209.0805}"} -locationTable[#locationTable+1] = {"Alioth Market 20", "::pos{0,2,-35.1535,-95.1230,301.0724}"} - -locationTable[#locationTable+1] = {"Madis Market 1", "::pos{0,1,2.6476,176.8761,813.0974}"} -locationTable[#locationTable+1] = {"Madis Market 2", "::pos{0,1,10.3552,8.5146,816.2210}"} -locationTable[#locationTable+1] = {"Madis Market 3", "::pos{0,1,-0.2107,82.0779,809.5571}"} -locationTable[#locationTable+1] = {"Madis Market 4", "::pos{0,1,-80.6046,44.9385,822.6188}"} -locationTable[#locationTable+1] = {"Madis Market 5", "::pos{0,1,81.0827,5.3022,823.1976}"} -locationTable[#locationTable+1] = {"Madis Market 6", "::pos{0,1,13.9814,-91.6163,811.0679}"} - -locationTable[#locationTable+1] = {"Thades M1: Market", "::pos{0,30,-2.9797,-117.7645,203.7519}"} -locationTable[#locationTable+1] = {"Feli: Market", "::pos{0,5,0.9348,178.6658,18417.2812}"} - -locationTable[#locationTable+1] = {"Symeon Market 1", "::pos{0,110,3.1400,-174.0223,267.1084}"} -locationTable[#locationTable+1] = {"Symeon Market 2", "::pos{0,110,-0.9862,88.3038,197.0626}"} -locationTable[#locationTable+1] = {"Symeon Market 3", "::pos{0,110,18.1117,11.1108,180.8022}"} -locationTable[#locationTable+1] = {"Symeon Market 4", "::pos{0,110,-26.9701,103.3741,186.2557}"} -locationTable[#locationTable+1] = {"Symeon Market 5", "::pos{0,110,83.1653,108.7807,142.5796}"} -locationTable[#locationTable+1] = {"Symeon Market 6", "::pos{0,110,-79.3167,95.3975,138.5268}"} - -locationTable[#locationTable+1] = {"TMV Troghelm", "::pos{0,0,2416521.6598,1415126.8118,59323.7340}"} -locationTable[#locationTable+1] = {"TMV Alioth Factory", "::pos{0,2,22.8158,111.1414,103.5685}"} -locationTable[#locationTable+1] = {"TMV Feli Outpost", "::pos{0,5,23.6988,-77.8811,18480.5176}"} -locationTable[#locationTable+1] = {"TMV Thandes M1 Outpost", "::pos{0,30,-22.3548,-168.7352,288.1909}"} -locationTable[#locationTable+1] = {"TMV Madis Outpost", "::pos{0,1,-43.0914,75.0728,749.6641}"} -locationTable[#locationTable+1] = {"TMV Symoen Outpost", "::pos{0,110,-5.3046,32.6900,108.4144}"} - - - - - - - - - -end - diff --git a/SatNav_unit_2_0_0.lua b/SatNav_unit_2_0_0.lua deleted file mode 100644 index 2409dec..0000000 --- a/SatNav_unit_2_0_0.lua +++ /dev/null @@ -1,619 +0,0 @@ ---[[ - SatNav version 2.0.0 - Created By TrogLaByte - - Discord: Trog#5105 - InGame: TrogLaByte - - GNU Public License 3.0. Use whatever you want, be so kind to leave credit. - - Thanks to Dorien Grey for his SVG and onscreen button code. -]] ------------------------------------------------ --- requirements ------------------------------------------------ - -function initiateRequiredLibaries() - json = require('dkjson') - vec3 = require('cpml.vec3') - utils = require('cpml.utils') - planetRef = require('cpml.planetref') - referenceTableSource = require('cpml.atlas') - clamp = utils.clamp -end -if pcall(initiateRequiredLibaries) then - system.print("Libaries loaded successfully") - else - system.print("Libaries failed to load: check that the following libraries exist:") - system.print(" /DualUniverse/Game/data/lua/dkjson") - system.print(" /DualUniverse/Game/data/lua/cpml/vec3") - system.print(" /DualUniverse/Game/data/lua/cpml/utils") - system.print(" /DualUniverse/Game/data/lua/cpml/planetref") - system.print(" /DualUniverse/Game/data/lua/cpml/atlas") - system.print("") - system.print("planetref.lua and atlas.lua can be obtained from the following GitLab url:") - system.print("https://gitlab.com/JayleBreak/dualuniverse/-/tree/master/DUflightfiles/autoconf/custom") - unit.exit() -end ------------------------------------------------ --- Global Variables ------------------------------------------------ - -local UpdateInterval = 1 --export: Interval in seconds between updates of the calculations and (if anything changed) redrawing to the screen(s). You need to restart the script after changing this value. -local BackgroundColor = "#1e1e1e" -local PlanetBackgroundColor = "#34b1eb" --export Set the background color of the screens. YOU NEED TO LEAVE THE QUOTATION MARKS. -local LocationBackgroundColor = "#6e3de3" --export Set the background color of the screens. YOU NEED TO LEAVE THE QUOTATION MARKS. -local clickAreas = {} -local locList={} -local lastPlanetSelected = "Alioth" -local pageLines=12 -local displayPlanetList={} -local displayLocationList={} -local CurrentLocationPage = 1 -local CurrentPlanetPage = 1 - ------------------------------------------------ --- initiate slots to know names ------------------------------------------------ - -function InitiateSlots() - for slot_name, slot in pairs(unit) do - if type(slot) == "table" and type(slot.export) == "table" and - slot.getElementClass then - --system.print(slot.getElementClass()) - if slot.getElementClass():lower():find("coreunit") then - core = slot - --system.print("found core") - end - if slot.getElementClass():lower():find("screenunit") then - screen = slot - --system.print("found screen") - end - if slot.getElementClass():lower():find("databankunit") then - myDatabank = slot - --system.print("found databank") - end - end - end -end -InitiateSlots() ------------------------------------------------ --- set up galaxy data and functions for planets and locations ------------------------------------------------ - -galaxyReference = planetRef(referenceTableSource) -helios = galaxyReference[0] -- PlanetaryReference.PlanetarySystem instance -planetList={} -jdecode = json.decode -jencode = json.encode - -function getBodyId(planetName) - for i=1,200 do - if helios[tonumber(i)] ~= nil then - if string.lower(helios[tonumber(i)].name) ==string.lower(planetName) then - return i - end - end - end - return 0 -end - -function buildPlanetList() - for i=1,200 do - if helios[tonumber(i)] ~= nil then - planetList[#planetList+1]=helios[tonumber(i)].name - end - end - planetList[#planetList+1]="Space" - table.sort(planetList) -end - -function buildPlanetLocList(planetName) - local savedLocation = myDatabank.getStringValue("SavedLocations") - local planet={} - locList={} - if planetName ~= "Space" then - table.insert(locList, planetName) -- add planet name into the list as a default - end - if savedLocation ~= nil and savedLocations ~= "" then - local result = jdecode(savedLocation) - if result ~= nil then - --system.print("Loc Planet: "..planetName) - for k, v in pairs(result) do - --system.print("Planet: "..v["planetname"]) - if string.lower(v["planetname"]) == string.lower(planetName) or - string.find(string.lower(v["planetname"]),string.lower(planetName)) - then - local location = v["position"] - local bodyId = getBodyId(v["planetname"]) - planet = helios[tonumber(bodyId)] - - worldCoords = planet:convertToMapPosition(vec3(location["x"],location["y"],location["z"])) - - --system.print(string.format([["%s" @ ::pos{%d,%d,%f,%f,%f}]], - -- v["name"], - -- worldCoords.systemId, - -- worldCoords.bodyId, - -- worldCoords.latitude*constants.rad2deg, - -- worldCoords.longitude*constants.rad2deg, - -- worldCoords.altitude)) - table.insert(locList, v["name"]) - else if v["planetname"] == "" and planetName == "Space" then -- a space location - local location = v["position"] - -- system.print(string.format([["%s" @ ::pos{%d,%d,%f,%f,%f}]], - -- v["name"], - -- 0, - -- 0, - -- location["x"], - -- location["y"], - -- location["z"])) - table.insert(locList, v["name"]) - end - end - end - end - end - table.sort(locList) -end - -function printLocMapPos(locationName) - local savedLocation = myDatabank.getStringValue("SavedLocations") - local planet={} - if savedLocation ~= nil and savedLocations ~= "" then - --system.print(savedLocation) - local result = jdecode(savedLocation) - if result ~= nil then - for k, v in pairs(result) do - if string.lower(v["name"]) == string.lower(locationName) then - local location = v["position"] - local bodyId = getBodyId(v["planetname"]) - planet = helios[tonumber(bodyId)] - if planet ~= nil then - worldCoords = planet:convertToMapPosition(vec3(location["x"],location["y"],location["z"])) - - system.print(string.format([["%s" @ ::pos{%d,%d,%f,%f,%f}]], - v["name"], - worldCoords.systemId, - worldCoords.bodyId, - worldCoords.latitude*constants.rad2deg, - worldCoords.longitude*constants.rad2deg, - worldCoords.altitude)) - return locationName - else - system.print(string.format([["%s" @ ::pos{%d,%d,%f,%f,%f}]], - v["name"], - 0, - bodyId, - location["x"], - location["y"], - location["z"])) - return locationName - end - break - end - end - end - end - return "" -end - -function clearSavedLocations() - myDatabank.setStringValue("SavedLocations","[]") - system.print("Databank cleared") -end - -function isDuplicateLocation(locName, savedLocations) - for i=1,#savedLocations do - if savedLocations and savedLocations[i].name ~= nil then - if savedLocations[i].name == locName then - return locName - end - end - end - return "" -end - -function loadPointsOfInterest() - local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)' - local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' .. - num .. ',' .. num .. '}' - local savedLocation = {} - local j=0 - loadLocationTable() - savedLocation = jdecode(myDatabank.getStringValue("SavedLocations")) - - for i = 1, #locationTable do - local newLoc={} - local planet={} - if isDuplicateLocation(locationTable[i][1],savedLocation) == "" then - newLoc["name"]=locationTable[i][1] - local newLocPos = locationTable[i][2] - --system.print("Name: "..locationTable[i][1].." "..newLocPos) - local systemId, bodyId, latitude, longitude, altitude = - string.match(locationTable[i][2], posPattern) - --system.print("BodyId: ".. bodyId) - if tonumber(bodyId) > 0 then - planet = helios[tonumber(bodyId)] - local worldCoords = planet:convertToWorldCoordinates(newLocPos) - newLoc["position"]=worldCoords - newLoc["gravity"]=unit.getClosestPlanetInfluence() - newLoc["atmosphere"]=unit.getAtmosphereDensity() - newLoc["planetname"]=planet.name - else -- it is a space location - newLoc["position"]=vec3(tonumber(latitude), tonumber(longitude), tonumber(altitude)) - newLoc["gravity"]=0 - newLoc["atmosphere"]=0 - newLoc["planetname"]="" - end - - if savedLocation == nil then - savedLocation = {} - savedLocation[1]=newLoc - j = 1 - else - j = j + 1 - savedLocation[#savedLocation+1]=newLoc - end - else - system.print("Duplicate entry for location ignored: "..locationTable[i][1]) - end - end - myDatabank.setStringValue("SavedLocations",jencode(savedLocation)) - system.print(j .. " Saved Locations loaded") -end - -buildPlanetList() -buildPlanetLocList(lastPlanetSelected) -local planetCount=#planetList - ------------------------------------------------ --- Code for on screen buttons ------------------------------------------------ - -function DrawSVG(output) screen.setSVG(output) end - -function AddClickArea(newEntry) table.insert(clickAreas, newEntry) end - -function RemoveFromClickAreas(candidate) - for k, v in pairs(clickAreas) do - if v.id == candidate then - clickAreas[k] = nil - break - end - end -end - -function UpdateClickArea(candidate, newEntry) - --system.print("Candidate: "..candidate.." x1"..newEntry.x1) - for k, v in pairs(clickAreas) do - if v.id == candidate then - clickAreas[k] = newEntry - --system.print("Click Area: "..candidate.." x1"..clickAreas[k].x1) - break - end - end -end - -function DisableClickArea(candidate) - for k, v in pairs(clickAreas) do - if v.id == candidate then - UpdateClickArea(candidate, { - id = candidate, - x1 = -1, - x2 = -1, - y1 = -1, - y2 = -1 - }) - break - end - end -end - -function InitiateClickAreas() - clickAreas = {} - - AddClickArea({id = "LoadSavedLocations", x1 = 300, x2 = 800, y1 = 900, y2 = 1000}) - AddClickArea({id = "ClearSavedLocations", x1 = 1200, x2 = 1700, y1 = 900, y2 = 1000}) - AddClickArea({id = "PlanetPageDown", x1 = -1, x2 = -1, y1 = -1, y2 = -1}) - AddClickArea({id = "PlanetPageUp", x1 = -1, x2 = -1, y1 = -1, y2 = -1}) - AddClickArea({id = "LocationPageDown", x1 = -1, x2 = -1, y1 = -1, y2 = -1}) - AddClickArea({id = "LocationPageUp", x1 = -1, x2 = -1, y1 = -1, y2 = -1}) - - for i = 1, pageLines do - AddClickArea({id = string.format("PList%d",i), x1 = 90, x2 = 800, y1 = (180 + i * 55), y2 = (235 + i * 55)}) - AddClickArea({id = string.format("LList%d",i), x1 = 1090, x2 = 1500, y1 = (180 + i * 55), y2 = (235 + i * 55)}) - end -end - -function FlushClickAreas() clickAreas = {} end - -function clearLocDispList() - for i=1,pageLines do - displayLocationList[i] = "" - end -end - -function CheckClick(x, y, HitTarget) - HitTarget = HitTarget or "" - if HitTarget == "" then - for k, v in pairs(clickAreas) do - if v and x >= v.x1 and x <= v.x2 and y >= v.y1 and y <= v.y2 then - HitTarget = v.id - break - end - end - end - - --system.print("Target Hit = "..HitTarget) - - if HitTarget == "PlanetPageDown" then - CurrentPlanetPage = CurrentPlanetPage+1 - DrawPlanetList() - elseif HitTarget == "PlanetPageUp" then - CurrentPlanetPage = math.max(CurrentPlanetPage-1,0) - DrawPlanetList() - elseif HitTarget == "LocationPageDown" then - CurrentLocationPage = CurrentLocationPage+1 - DrawPlanetList() - elseif HitTarget == "LocationPageUp" then - CurrentLocationPage = math.max(CurrentLocationPage-1,0) - DrawPlanetList() - elseif HitTarget == "LoadSavedLocations" then - --system.print("LoadSavedLocations") - loadPointsOfInterest() - if displayPlanetList[1] ~= "" then - lastPlanetSelected = displayPlanetList[1] - buildPlanetLocList(lastPlanetSelected) - clearLocDispList() - selected = "" - CurrentLocationPage=1 - CurrentPlanetPage=1 - DrawPlanetList() - end - elseif HitTarget == "ClearSavedLocations" then - --system.print("ClearSavedLocations") - clearSavedLocations() - if displayPlanetList[1] ~= "" then - lastPlanetSelected = displayPlanetList[1] - buildPlanetLocList(lastPlanetSelected) - clearLocDispList() - selected = "" - CurrentLocationPage=1 - CurrentPlanetPage=1 - DrawPlanetList() - end - else - for i = 1,pageLines do - if HitTarget == string.format("PList%s",i) then - --system.print("PHitTarget: "..HitTarget) - if displayPlanetList[i] ~= "" then - lastPlanetSelected = displayPlanetList[i] - buildPlanetLocList(lastPlanetSelected) - clearLocDispList() - selected = "" - DrawPlanetList() - end - end - if HitTarget == string.format("LList%s",i) then - if displayLocationList[i] ~= "" then - selected = displayLocationList[i] - if printLocMapPos(selected) == "" then - system.print("Location: "..selected.." sent to Hud") - else - myDatabank.setStringValue("SPBAutopilotTargetName",selected) - end - end - end - end - end -end - ------------------------------------------------ --- Code for building screen content and displaying it ------------------------------------------------ - -local svgBootstrap = [[ - ]] - -function DrawPlanetList() - local healthyColor = "#00aa00" - local brokenColor = "#aa0000" - local damagedColor = "#aaaa00" - local integrityColor = "#aaaaaa" - local healthyTextColor = "white" - local brokenTextColor = "#ff4444" - local damagedTextColor = "#ffff44" - local integrityTextColor = "white" - - - local screenOutput = "" - - -- Draw Header - screenOutput = screenOutput .. svgBootstrap - - -- Draw main background - screenOutput = screenOutput .. - [[]] - screenOutput = screenOutput .. - [[Sat Nav]] - screenOutput = screenOutput .. - [[]] - screenOutput = screenOutput .. - [[]] - screenOutput = screenOutput .. - [[Planets]] - - - local i = 0 - for j = 1 + (CurrentPlanetPage - 1) * pageLines, pageLines + - (CurrentPlanetPage - 1) * pageLines, 1 do - i = i + 1 - if j < #planetList and j>0 then - if lastPlanetSelected == planetList[j] then - screenOutput = screenOutput .. [[]] .. - string.format("%s", planetList[j]) .. [[]] - else - screenOutput = screenOutput .. [[]] .. - string.format("%s", planetList[j]) .. [[]] - end - displayPlanetList[i]=planetList[j] - else - displayPlanetList[i]="" - end - end - - if planetCount > 12 then - screenOutput = screenOutput .. - [[Page ]] .. - CurrentPlanetPage .. " of " .. - math.ceil(planetCount / 12) .. - [[]] - - if CurrentPlanetPage < math.ceil(planetCount / 12) then - screenOutput = screenOutput .. [[ - - - ]] - UpdateClickArea("PlanetPageDown", { - id = "PlanetPageDown", - x1 = 70, - x2 = 270, - y1 = 1050, - y2 = 1105 - }) - else - DisableClickArea("PlanetPageDown") - end - - if planetCount > 1 and CurrentPlanetPage > 1 then - screenOutput = screenOutput .. [[ - - - ]] - UpdateClickArea("PlanetPageUp", { - id = "PlanetPageUp", - x1 = 280, - x2 = 480, - y1 = 1050, - y2 = 1105 - }) - else - DisableClickArea("PlanetPageUp") - end - end - -- Start of Location List - screenOutput = screenOutput .. - [[]] - screenOutput = screenOutput .. - [[]] - screenOutput = screenOutput .. - [[]].. lastPlanetSelected ..[[ Locations]] - - - local i = 0 - for j = 1 + (CurrentLocationPage - 1) * pageLines, pageLines + - (CurrentLocationPage - 1) * pageLines, 1 do - --system.print("locList: "..locList[j]) - i = i + 1 - if j <= #locList and j>0 then - screenOutput = screenOutput .. [[]] .. - string.format("%s", locList[j]) .. [[]] - displayLocationList[i]=locList[j] - else - displayLocationList[i]="" - end - end - - if #locList > 12 then - screenOutput = screenOutput .. - [[Page ]] .. - CurrentLocationPage .. " of " .. - math.ceil(#locList / 12) .. - [[]] - - if CurrentLocationPage < math.ceil(#locList / 12) then - screenOutput = screenOutput .. [[ - - - ]] - UpdateClickArea("LocationPageDown", { - id = "LocationPageDown", - x1 = 1070, - x2 = 1270, - y1 = 1050, - y2 = 1105 - }) - else - DisableClickArea("LocationPageDown") - end - - if #locList > 1 and CurrentLocationPage > 1 then - screenOutput = screenOutput .. [[ - - - ]] - UpdateClickArea("LocationPageUp", { - id = "LocationPageUp", - x1 = 1280, - x2 = 1480, - y1 = 1050, - y2 = 1105 - }) - else - DisableClickArea("LocationPageUp") - end - end - - screenOutput = screenOutput .. - [[]] .. - [[Load Saved Locations]] - - screenOutput = screenOutput .. - [[]] .. - [[Clear Saved Locations]] - - screenOutput = screenOutput .. [[]] - - DrawSVG(screenOutput) - - forceRedraw = false -end - ------------------------------------------------ --- Execute ------------------------------------------------ - -unit.hide() -InitiateClickAreas() -DrawPlanetList() - diff --git a/SatNav_screen_2_0_0.lua b/src/slots/screen.lua similarity index 100% rename from SatNav_screen_2_0_0.lua rename to src/slots/screen.lua diff --git a/src/system/inputText.lua b/src/system/inputText.lua new file mode 100644 index 0000000..4e0aacc --- /dev/null +++ b/src/system/inputText.lua @@ -0,0 +1,53 @@ +if string.sub(text,1,2) == "u " then + local newLocName = string.sub(text,3,string.len(text)) + updateLocationName(newLocName) + if displayPlanetList[1] ~= "" then + lastPlanetSelected = displayPlanetList[1] + lastLocationSelected = "" + buildPlanetLocList(lastPlanetSelected) + clearLocDispList() + selected = "" + CurrentLocationPage=1 + CurrentPlanetPage=1 + DrawPlanetList() + end +elseif text == "d SatNav" then + deleteLocationName(lastLocationSelected) + if displayPlanetList[1] ~= "" then + lastPlanetSelected = displayPlanetList[1] + lastLocationSelected = "" + buildPlanetLocList(lastPlanetSelected) + clearLocDispList() + selected = "" + CurrentLocationPage=1 + CurrentPlanetPage=1 + DrawPlanetList() + end +elseif text == "c SatNav" then + system.print("ClearSatNavLocations") + CheckClick(0, 0, "ClearSatNavLocations") +elseif text == "c Hud" then + if HUD == "Dimencia" then + system.print("ClearHudLocations") + CheckClick(0, 0, "ClearHudLocations") + else + system.print("ClearHudLocations not available in standalone mode") + end +elseif text == "l SatNav" then + system.print("LoadSatNavLocations") + CheckClick(0, 0, "LoadSatNavLocations") +elseif text == "l Hud" then + if HUD == "Dimencia" then + system.print("LoadHudLocations") + CheckClick(0, 0, "LoadHudLocations") + else + system.print("LoadHudLocations not available in standalone mode") + end +elseif text == "x SatNav" then + if dupSatnavDB then + system.print("DuplicateSatNavDB") + duplicateSatnavDB() + else + system.print("Please link an empty databank to the programming board") + end +end \ No newline at end of file diff --git a/src/unit/start.lua b/src/unit/start.lua new file mode 100644 index 0000000..a5c9ce7 --- /dev/null +++ b/src/unit/start.lua @@ -0,0 +1,1155 @@ +--[[ + SatNav version 2_1_2 + Created By TrogLaByte + + Discord: Trog#5105 + InGame: TrogLaByte + + GNU Public License 3.0. Use whatever you want, be so kind to leave credit. + + Thanks to Dorien Grey for his SVG and onscreen button code. +]] +----------------------------------------------- +-- requirements +----------------------------------------------- + +function initiateRequiredLibaries() + --json = require('dkjson') + vec3 = require('cpml.vec3') + utils = require('cpml.utils') + planetRef = require('cpml.planetref') + referenceTableSource = require('cpml.atlas') + clamp = utils.clamp +end +if pcall(initiateRequiredLibaries) then + system.print("Libaries loaded successfully") + else + system.print("Libaries failed to load: check that the following libraries exist:") + system.print("( is the directory in to which you installed DU)") + system.print(" /DualUniverse/Game/data/lua/dkjson") + system.print(" /DualUniverse/Game/data/lua/cpml/vec3") + system.print(" /DualUniverse/Game/data/lua/cpml/utils") + system.print(" /DualUniverse/Game/data/lua/cpml/planetref") + system.print(" /DualUniverse/Game/data/lua/cpml/atlas") + system.print("") + system.print("planetref.lua and atlas.lua can be obtained from the following GitLab url:") + system.print("https://gitlab.com/JayleBreak/dualuniverse/-/tree/master/DUflightfiles/autoconf/custom") + unit.exit() +end +----------------------------------------------- +-- Global Variables +----------------------------------------------- + +local version = "2_1_2" + +local UpdateInterval = 1 +local defaultNewLocName = "SatNav Location" --export: default name used for new locations +--[[Original colours are 34b1eb, 6e3de3 and 1e1e1e]] +local PlanetPanelColour = "99eeff" --export: Hex code for colour of planet panel and buttons (you need to include the quotes) +local LocPanelColour = "aa99ff" --export: Hex code for colour of locations panel and buttons (you need to include the quotes) +local FontPanelColour = "000000" --export: Hex code for font colour of planet/locations panel (you need to include the quotes) +local LineHighlightColour = "ccffff"--export: Hex code for colour of highlighted lines in planet/location panel (you need to include the quotes) + +local BackgroundColor = "#1e1e1e" +local PlanetBackgroundColor = "#" .. PlanetPanelColour +local LocationBackgroundColor = "#" .. LocPanelColour +local MainFontColor = "#" .. FontPanelColour +local HighlightColor = "#" .. LineHighlightColour + +local lastPlanetSelected = "Alioth" --export: The default start planet for displaying locations + +local clickAreas = {} +local locList={} +pageLines=12 +displayPlanetList={} +displayLocationList={} +CurrentLocationPage = 1 +CurrentPlanetPage = 1 +myDatabank={} +dbHud={} + +if db1 then db1Keys = db1.getKeys() end +if db2 then db2Keys = db2.getKeys() end + +--if db1Keys then system.print("DB1 Keys: "..string.sub(db1Keys,1,50)) end +--if db2Keys then system.print("DB2 Keys: "..string.sub(db2Keys,1,50)) end + +if db1 and (db1Keys==nil or db1Keys == "" or string.match(db1Keys, "lastNewLoc")) then + myDatabank = db1 + system.print("SatNav Databank Identified") +elseif db2 and (db2Keys==nil or db2Keys == "" or string.match(db2Keys, "lastNewLoc")) then + myDatabank = db2 + system.print("SatNav Databank Identified") +else + system.print("SatNav databank not found... application will stop") + if db1Keys then system.print("DB1 Keys: "..string.sub(db1Keys,1,50)) end + if db2Keys then system.print("DB2 Keys: "..string.sub(db2Keys,1,50)) end + unit.exit() + unit.deactivate() +end + +if myDatabank==db1 and db2 and string.match(db2Keys, "AutopilotTargetIndex") then + dbHud = db2 + system.print("Dimencia Hud Identified") + HUD = "Dimencia" +elseif myDatabank==db2 and db1 and string.match(db1Keys, "AutopilotTargetIndex") then + dbHud = db1 + system.print("Dimencia Hud Identified") + HUD = "Dimencia" +else + system.print("No Dimencia Hud Identified - will run in Stand Alone mode") + HUD = "unknown" +end + +--unit.exit() +----------------------------------------------- +-- set up galaxy data and functions for planets and locations +----------------------------------------------- + +galaxyReference = planetRef(referenceTableSource) +helios = galaxyReference[0] -- PlanetaryReference.PlanetarySystem instance +planetList={} +planetDistList={} +locDistList={} + +function getBodyId(planetName) + for i=1,200 do + if helios[tonumber(i)] ~= nil then + if string.lower(helios[tonumber(i)].name) ==string.lower(planetName) then + return i + end + end + end + return 0 +end + +function buildPlanetList() + local planet={} + local currentLoc = vec3(core.getConstructWorldPos()) + local shipMass = core.getConstructMass() + for i=1,200 do + if helios[tonumber(i)] ~= nil then + planet = helios[tonumber(i)] + planetList[#planetList+1] = planet.name + local planetDistance = planet:getDistance(currentLoc) + planetDistList[planet.name] = formatDistance(planetDistance) .. + string.format(" [%.0f wc]", ((planetDistance/200000)*(shipMass/1000)/4000)) + end + end + planetList[#planetList+1]="Space" + table.sort(planetList) +end + +function formatDistance(distance) + if distance < 200000 then + return string.format("%.0f km",distance/1000) + elseif distance < 4000000 then + return string.format("%.2f su",distance/200000) + else + return string.format("%.0f su",distance/200000) + end +end + +-- json parser + +-- Extracts values from a JSON string with pattern matching +-- This is faster than using dkjson when only a few fields are needed + +-- Use this only with trusted data sources! Limitations: +-- * Character escapes are not supported +-- * Field nesting is ignored + +local find, gsub = string.find, string.gsub + +---@param json string +---@param key string +---@param init number|nil +---@return string|nil, number|nil, number|nil +local function extractStringJsonValue (json, key, init) + local pattern = [["]] .. key .. [["%s*:%s*"([^"]*)"]] + local startIndex, endIndex, valueStr = find(json, pattern, init) + return valueStr, startIndex, endIndex +end + +---@param json string +---@param key string +---@param init number|nil +---@return number|nil, number|nil, number|nil +local function extractNumberJsonValue (json, key, init) + local pattern = [["]] .. key .. [["%s*:%s*(-?[0-9.e-]+)]] + local startIndex, endIndex, valueStr = find(json, pattern, init) + return tonumber(valueStr), startIndex, endIndex +end + +---@param json string +---@param key string +---@param init number|nil +---@return boolean|nil, number|nil, number|nil +local function extractBooleanJsonValue (json, key, init) + local pattern = [["]] .. key .. [["%s*:%s*([truefals]+)]] + local startIndex, endIndex, valueStr = find(json, pattern, init) + + if valueStr == "true" then + return true, startIndex, endIndex + elseif valueStr == "false" then + return false, startIndex, endIndex + else + return nil + end +end + +---@param extractJsonValue function +---@param json string +---@param key string +---@param stopAfterIndex number|nil +---@param stopAfterValue any|nil +---@return any[] +local function extractAllJsonValues (extractJsonValue, json, key, stopAfterIndex, stopAfterValue) + local values = {} + local valuesLen = 0 + + local jsonPos = 1 + local value, valueStartIndex, valueEndIndex -- luacheck: ignore valueStartIndex -- unused + + repeat + value, valueStartIndex, valueEndIndex = extractJsonValue(json, key, jsonPos) + + if value ~= nil then + valuesLen = valuesLen + 1 + values[valuesLen] = value + + jsonPos = valueEndIndex + 1 + end + + if value == stopAfterValue then break end + if valuesLen == stopAfterIndex then break end + until value == nil + + return values +end + +---@param json string +---@param key string +---@param stopAfterIndex number|nil +---@param stopAfterValue string|nil +---@return string[] +local function extractAllStringJsonValues (json, key, stopAfterIndex, stopAfterValue) + return extractAllJsonValues(extractStringJsonValue, json, key, stopAfterIndex, stopAfterValue) +end + +---@param json string +---@param key string +---@param stopAfterIndex number|nil +---@param stopAfterValue number|nil +---@return number[] +local function extractAllNumberJsonValues (json, key, stopAfterIndex, stopAfterValue) + return extractAllJsonValues(extractNumberJsonValue, json, key, stopAfterIndex, stopAfterValue) +end + +---@param json string +---@param key string +---@param stopAfterIndex number|nil +---@param stopAfterValue boolean|nil +---@return boolean[] +local function extractAllBooleanJsonValues (json, key, stopAfterIndex, stopAfterValue) + return extractAllJsonValues(extractBooleanJsonValue, json, key, stopAfterIndex, stopAfterValue) +end + +-- end json Parser + + +function buildPlanetLocList(planetName) + local savedLocation = myDatabank.getStringValue("SavedLocations") + local atmosphere={} + local gravity={} + local planetname = {} + local posX = {} + local posY = {} + local posZ = {} + local name = {} + + atmosphere = extractAllNumberJsonValues(savedLocation,"atmosphere") + gravity = extractAllNumberJsonValues(savedLocation,"gravity") + planetname = extractAllStringJsonValues(savedLocation,"planetname") + posX = extractAllNumberJsonValues(savedLocation,"x") + posY = extractAllNumberJsonValues(savedLocation,"y") + posZ = extractAllNumberJsonValues(savedLocation,"z") + name = extractAllStringJsonValues(savedLocation,"name") + + local currentLoc = vec3(core.getConstructWorldPos()) + local shipMass = core.getConstructMass() + local planet={} + locList={} + if planetName ~= "Space" then + table.insert(locList, planetName) -- add planet name into the list as a default + locDistList[planetName] = planetDistList[planetName] + end + if #name > 0 then + for i=1,#name do + if string.lower(planetname[i]) == string.lower(planetName) or + string.find(string.lower(planetname[i]),string.lower(planetName)) + then + table.insert(locList, name[i]) + elseif planetname[i] == "" and planetName == "Space" then -- a space location + table.insert(locList, name[i]) + end + local locDistance = (currentLoc - vec3(posX[i],posY[i],posZ[i])):len() + if planetName == "Space" then + locDistList[name[i]] = formatDistance(locDistance) .. + string.format(" [%.0f wc]", ((locDistance/200000)*(shipMass/1000)/4000)) + else + locDistList[name[i]] = formatDistance(locDistance) + end + end + end + table.sort(locList) +end + +function printLocMapPos(locationName) + local savedLocation = myDatabank.getStringValue("SavedLocations") + local wayPoint="" + local atmosphere={} + local gravity={} + local planetname = {} + local posX = {} + local posY = {} + local posZ = {} + local name = {} + atmosphere = extractAllNumberJsonValues(savedLocation,"atmosphere") + gravity = extractAllNumberJsonValues(savedLocation,"gravity") + planetname = extractAllStringJsonValues(savedLocation,"planetname") + posX = extractAllNumberJsonValues(savedLocation,"x") + posY = extractAllNumberJsonValues(savedLocation,"y") + posZ = extractAllNumberJsonValues(savedLocation,"z") + name = extractAllStringJsonValues(savedLocation,"name") + local planet={} + if #name > 0 then + for i = 1, #name do + if string.lower(name[i]) == string.lower(locationName) then + local bodyId = getBodyId(planetname[i]) + planet = helios[tonumber(bodyId)] + if planet ~= nil then + worldCoords = planet:convertToMapPosition(vec3(posX[i],posY[i],posZ[i])) + wayPoint=string.format([[::pos{%d,%d,%f,%f,%f}]], + worldCoords.systemId, + worldCoords.bodyId, + worldCoords.latitude*constants.rad2deg, + worldCoords.longitude*constants.rad2deg, + worldCoords.altitude) + system.print(name[i].." @ "..wayPoint) + system.setWaypoint(wayPoint) + return locationName, + planetname[i], + atmosphere[i], + gravity[i], + posX[i], + posY[i], + posZ[i] + else + wayPoint=string.format([[::pos{%d,%d,%f,%f,%f}]], + 0, + bodyId, + posX[i],posY[i],posZ[i]) + system.print(name[i].." @ "..wayPoint) + system.setWaypoint(wayPoint) + return locationName, + planetname[i], + atmosphere[i], + gravity[i], + posX[i], + posY[i], + posZ[i] + end + break + end + end + end + return "" +end + +function clearSavedLocations() + myDatabank.setStringValue("SavedLocations","[]") + system.print("Satnav Databank cleared") +end + +function isDuplicateLocation(locName, locNameList) + for i=1,#locNameList do + if locNameList[i] == locName then + return locName + end + end + return "" +end + +function saveSavedLocations (name, planetname, atmosphere, gravity, posX, posY, posZ) + local newSavedLocations = "[" + for i = 1, #name do + if name[i]~="" then + newSavedLocations = newSavedLocations.. + "{"..[["name":"]]..name[i].. + [[","planetname":"]]..planetname[i]..[["]].. + [[,"atmosphere":]]..atmosphere[i].. + [[,"gravity":]]..gravity[i].. + [[,"position":{"x":]]..posX[i].. + [[,"y":]]..posY[i].. + [[,"z":]]..posZ[i]..[[}}]] + end + if i+1<#name then + newSavedLocations= newSavedLocations.."," + end + end + newSavedLocations= newSavedLocations.."]" + --system.print(newSavedLocations) + myDatabank.setStringValue("SavedLocations",newSavedLocations) + system.print("Satnav Databank Updated") +end + +function updateLocationName(newLocName) + if newLocName ~= nil and newLocName ~= "" and + lastLocationSelected ~= nil and lastLocationSelected ~= "" then + system.print("Updating location name for: "..lastLocationSelected.." to: "..newLocName) + else + system.print("Invalid update request") + return + end + local savedLocation = {} + local oldLocFound = false + savedLocation = myDatabank.getStringValue("SavedLocations") + local atmosphere={} + local gravity={} + local planetname = {} + local posX = {} + local posY = {} + local posZ = {} + local name = {} + atmosphere = extractAllNumberJsonValues(savedLocation,"atmosphere") + gravity = extractAllNumberJsonValues(savedLocation,"gravity") + planetname = extractAllStringJsonValues(savedLocation,"planetname") + posX = extractAllNumberJsonValues(savedLocation,"x") + posY = extractAllNumberJsonValues(savedLocation,"y") + posZ = extractAllNumberJsonValues(savedLocation,"z") + name = extractAllStringJsonValues(savedLocation,"name") + for i = 1, #name do + if name[i] == lastLocationSelected then + --system.print("Found: "..lastLocationSelected) + name[i] = newLocName + oldLocFound = true + break + end + end + + if oldLocFound then + saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ) + else + system.print("Old Location Name Not Found") + end +end + +function deleteLocationName(delLocName) + if delLocName ~= nil and delLocName ~= "" then + system.print("Deleting location name: "..delLocName) + else + system.print("Invalid update request") + return + end + local savedLocation = {} + local oldLocFound = false + savedLocation = myDatabank.getStringValue("SavedLocations") + local atmosphere={} + local gravity={} + local planetname = {} + local posX = {} + local posY = {} + local posZ = {} + local name = {} + atmosphere = extractAllNumberJsonValues(savedLocation,"atmosphere") + gravity = extractAllNumberJsonValues(savedLocation,"gravity") + planetname = extractAllStringJsonValues(savedLocation,"planetname") + posX = extractAllNumberJsonValues(savedLocation,"x") + posY = extractAllNumberJsonValues(savedLocation,"y") + posZ = extractAllNumberJsonValues(savedLocation,"z") + name = extractAllStringJsonValues(savedLocation,"name") + for i = 1, #name do + if name[i] == delLocName then + --system.print("Found: "..delLocName) + name[i] = "" + oldLocFound = true + break + end + end + + if oldLocFound then + saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ) + else + system.print("Location Name Not Found") + end +end + +function loadPointsOfInterest() + -- get existing locations from SatNav Databank + local savedLocation = myDatabank.getStringValue("SavedLocations") + local atmosphere={} + local gravity={} + local planetname = {} + local posX = {} + local posY = {} + local posZ = {} + local name = {} + + atmosphere = extractAllNumberJsonValues(savedLocation,"atmosphere") + gravity = extractAllNumberJsonValues(savedLocation,"gravity") + planetname = extractAllStringJsonValues(savedLocation,"planetname") + posX = extractAllNumberJsonValues(savedLocation,"x") + posY = extractAllNumberJsonValues(savedLocation,"y") + posZ = extractAllNumberJsonValues(savedLocation,"z") + name = extractAllStringJsonValues(savedLocation,"name") + + + local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)' + local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' .. + num .. ',' .. num .. '}' + local j=0 + loadLocationTable() + + for i = 1, #locationTable do + local newRef = #name + 1 + if isDuplicateLocation(locationTable[i][1],name) == "" then + name[newRef]=locationTable[i][1] + local newLocPos = locationTable[i][2] + --system.print("Name: "..locationTable[i][1].." "..newLocPos) + local systemId, bodyId, latitude, longitude, altitude = + string.match(locationTable[i][2], posPattern) + --system.print("BodyId: ".. bodyId) + if tonumber(bodyId) > 0 then + local planet = helios[tonumber(bodyId)] + local worldCoords = planet:convertToWorldCoordinates(newLocPos) + posX[newRef]=worldCoords["x"] + posY[newRef]=worldCoords["y"] + posZ[newRef]=worldCoords["z"] + gravity[newRef]=core.g() + atmosphere[newRef]=unit.getAtmosphereDensity() + planetname[newRef]=planet.name + else -- it is a space location + posX[newRef]=latitude + posY[newRef]=longitude + posZ[newRef]=altitude + gravity[newRef]=0 + atmosphere[newRef]=0 + planetname[newRef]="" + end + else + system.print("Duplicate entry for location ignored: "..locationTable[i][1]) + end + end + saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ) + --system.print("Default SatNav locations loaded") +end + +function loadHudLocations() + -- get existing locations from SatNav Databank + local savedLocation = myDatabank.getStringValue("SavedLocations") + local atmosphere={} + local gravity={} + local planetname = {} + local posX = {} + local posY = {} + local posZ = {} + local name = {} + + atmosphere = extractAllNumberJsonValues(savedLocation,"atmosphere") + gravity = extractAllNumberJsonValues(savedLocation,"gravity") + planetname = extractAllStringJsonValues(savedLocation,"planetname") + posX = extractAllNumberJsonValues(savedLocation,"x") + posY = extractAllNumberJsonValues(savedLocation,"y") + posZ = extractAllNumberJsonValues(savedLocation,"z") + name = extractAllStringJsonValues(savedLocation,"name") + + local hudLocation = dbHud.getStringValue("SavedLocations") + local hudatmosphere={} + local hudgravity={} + local hudplanetname = {} + local hudposX = {} + local hudposY = {} + local hudposZ = {} + local hudname = {} + + hudatmosphere = extractAllNumberJsonValues(hudLocation,"atmosphere") + hudgravity = extractAllNumberJsonValues(hudLocation,"gravity") + hudplanetname = extractAllStringJsonValues(hudLocation,"planetname") + hudposX = extractAllNumberJsonValues(hudLocation,"x") + hudposY = extractAllNumberJsonValues(hudLocation,"y") + hudposZ = extractAllNumberJsonValues(hudLocation,"z") + hudname = extractAllStringJsonValues(hudLocation,"name") + + + for i = 1, #hudname do + local newRef = #name + 1 + system.print("HudName: "..hudname[i]) + if isDuplicateLocation(hudname[i],name) == "" and + hudname[i] ~= "SatNav Location" then + name[newRef]=hudname[i] + posX[newRef]=hudposX[i] + posY[newRef]=hudposY[i] + posZ[newRef]=hudposZ[i] + gravity[newRef]=hudgravity[i] + atmosphere[newRef]=hudatmosphere[i] + planetname[newRef]=hudplanetname[i] + else + system.print("Duplicate entry for location ignored: "..hudname[i]) + end + end + saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ) + --system.print("Default SatNav locations loaded") +end + + +function newLocation () + local location = system.getWaypointFromPlayerPos() + local newLocId = myDatabank.getIntValue("lastNewLoc") + 1 + myDatabank.setIntValue("lastNewLoc",newLocId) + + local newLocName = defaultNewLocName.." ("..newLocId..")" + + local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)' + local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' .. + num .. ',' .. num .. '}' + + local savedLocation = {} + savedLocation = myDatabank.getStringValue("SavedLocations") + local atmosphere={} + local gravity={} + local planetname = {} + local posX = {} + local posY = {} + local posZ = {} + local name = {} + atmosphere = extractAllNumberJsonValues(savedLocation,"atmosphere") + gravity = extractAllNumberJsonValues(savedLocation,"gravity") + planetname = extractAllStringJsonValues(savedLocation,"planetname") + posX = extractAllNumberJsonValues(savedLocation,"x") + posY = extractAllNumberJsonValues(savedLocation,"y") + posZ = extractAllNumberJsonValues(savedLocation,"z") + name = extractAllStringJsonValues(savedLocation,"name") + + local systemId, bodyId, latitude, longitude, altitude = + string.match(location, posPattern) + local worldPos = unit.getMasterPlayerRelativePosition() + local body = helios:closestBody(worldPos) + --system.print(json.encode(body)) + --system.print("Distance="..((vec3(worldPos)-vec3(body.center)):len())/(1000)) + --system.print("Calc="..((body.radius+body.center):len())/(1000)) + + newlocAlt = ((vec3(worldPos)-vec3(body.center)):len())/(1000) +-- system.print("New Loc Alt:"..newlocAlt) +-- system.print("Radius:"..(((body.radius)/1000) + 200)) + if newlocAlt < (((body.radius)/1000) + 200) then + local bodyId = getBodyId(body.name) + --system.print("BodyId: ".. bodyId) + local planet = helios[tonumber(bodyId)] -- PlanetaryReference.BodyParameters instance + --system.print("Planet BodyId: ".. planet.bodyId) + local worldCoords = planet:convertToWorldCoordinates(location) + newRef = #name + 1 + name[newRef]=newLocName + posX[newRef]=worldCoords["x"] + posY[newRef]=worldCoords["y"] + posZ[newRef]=worldCoords["z"] + gravity[newRef]=core.g() + atmosphere[newRef]=unit.getAtmosphereDensity() + planetname[newRef]=body.name + else + newRef = #name + 1 + name[newRef]=newLocName + posX[newRef]=latitude + posY[newRef]=longitude + posZ[newRef]=altitude + gravity[newRef]=core.g() + atmosphere[newRef]=unit.getAtmosphereDensity() + planetname[newRef]="Space" + + end + saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ) + system.print("New location: "..newLocName.." added to SatNav databank") + printLocMapPos(newLocName) +end + +function copySelectedToHud (locName) + + local locName, locplanetname, locatmosphere, locgravity, locX, locY, locZ = + printLocMapPos(locName) + if HUD == "Dimencia" then + savedLocation = dbHud.getStringValue("SavedLocations") + --system.print("savedLocation="..savedLocation) + local atmosphere={} + local gravity={} + local planetname = {} + local posX = {} + local posY = {} + local posZ = {} + local name = {} + atmosphere = extractAllNumberJsonValues(savedLocation,"atmosphere") + gravity = extractAllNumberJsonValues(savedLocation,"gravity") + planetname = extractAllStringJsonValues(savedLocation,"planetname") + posX = extractAllNumberJsonValues(savedLocation,"x") + posY = extractAllNumberJsonValues(savedLocation,"y") + posZ = extractAllNumberJsonValues(savedLocation,"z") + name = extractAllStringJsonValues(savedLocation,"name") + local newSavedLocations = "[" + for i = 1, #name do + if name[i] ~= "SatNav Location" then + newSavedLocations = newSavedLocations.. + "{"..[["name":"]]..name[i].. + [[","planetname":"]]..planetname[i]..[["]].. + [[,"atmosphere":]]..atmosphere[i].. + [[,"gravity":]]..gravity[i].. + [[,"position":{"x":]]..posX[i].. + [[,"y":]]..posY[i].. + [[,"z":]]..posZ[i]..[[}},]] + end + end + if locplanetname ~= "" then + newSavedLocations = newSavedLocations.. + "{"..[["name":"]].."SatNav Location".. + [[","planetname":"]]..locplanetname..[["]].. + [[,"atmosphere":]]..locatmosphere.. + [[,"gravity":]]..locgravity.. + [[,"position":{"x":]]..locX.. + [[,"y":]]..locY.. + [[,"z":]]..locZ..[[}}]] + end + newSavedLocations= newSavedLocations.."]" + dbHud.setStringValue("SavedLocations",newSavedLocations) + dbHud.setStringValue("SPBAutopilotTargetName","SatNav Location") + end +end + +function clearHudLocations() + if HUD == "Dimencia" then + dbHud.setStringValue("SavedLocations","[]") + dbHud.setStringValue("SPBAutopilotTargetName","") + system.print("Dimencia HUD Saved Locations Cleared") + end +end + +function duplicateSatnavDB() + local satnavLocation = myDatabank.getStringValue("SavedLocations") + local lastNewLoc = myDatabank.getIntValue("lastNewLoc") + if dupSatnavDB then + dupSatnavDB.clear() + dupSatnavDB.setStringValue("SavedLocations",satnavLocation) + dupSatnavDB.setIntValue("lastNewLoc",lastNewLoc) + system.print("SatNav Databank Duplicated Successfully") + else + system.print("No space databank linked, duplication aborted") + end +end + +buildPlanetList() +buildPlanetLocList(lastPlanetSelected) +local planetCount=#planetList + +----------------------------------------------- +-- Code for on screen buttons +----------------------------------------------- + +function DrawSVG(output) screen.setSVG(output) end + +function AddClickArea(newEntry) table.insert(clickAreas, newEntry) end + +function RemoveFromClickAreas(candidate) + for k, v in pairs(clickAreas) do + if v.id == candidate then + clickAreas[k] = nil + break + end + end +end + +function UpdateClickArea(candidate, newEntry) + --system.print("Candidate: "..candidate.." x1"..newEntry.x1) + for k, v in pairs(clickAreas) do + if v.id == candidate then + clickAreas[k] = newEntry + --system.print("Click Area: "..candidate.." x1"..clickAreas[k].x1) + break + end + end +end + +function DisableClickArea(candidate) + for k, v in pairs(clickAreas) do + if v.id == candidate then + UpdateClickArea(candidate, { + id = candidate, + x1 = -1, + x2 = -1, + y1 = -1, + y2 = -1 + }) + break + end + end +end + +function InitiateClickAreas() + clickAreas = {} + + AddClickArea({id = "LoadSatNavLocations", x1 = -1, x2 = -1, y1 = -1, y2 = -1}) + AddClickArea({id = "LoadHudLocations", x1 = -1, x2 = -1, y1 = -1, y2 = -1}) + AddClickArea({id = "NewLocation", x1 = 700, x2 = 1100, y1 = 900, y2 = 1000}) + AddClickArea({id = "ClearHudLocations", x1 = -1, x2 = -1, y1 = -1, y2 = -1}) + AddClickArea({id = "PlanetPageDown", x1 = -1, x2 = -1, y1 = -1, y2 = -1}) + AddClickArea({id = "PlanetPageUp", x1 = -1, x2 = -1, y1 = -1, y2 = -1}) + AddClickArea({id = "LocationPageDown", x1 = -1, x2 = -1, y1 = -1, y2 = -1}) + AddClickArea({id = "LocationPageUp", x1 = -1, x2 = -1, y1 = -1, y2 = -1}) + + for i = 1, pageLines do + AddClickArea({id = string.format("PList%d",i), x1 = 90, x2 = 800, y1 = (170 + i * 55), y2 = (225 + i * 55)}) + AddClickArea({id = string.format("LList%d",i), x1 = 1090, x2 = 1500, y1 = (170 + i * 55), y2 = (225 + i * 55)}) + end +end + +function FlushClickAreas() clickAreas = {} end + +function clearLocDispList() + for i=1,pageLines do + displayLocationList[i] = "" + end +end + +function CheckClick(x, y, HitTarget) + HitTarget = HitTarget or "" + if HitTarget == "" then + for k, v in pairs(clickAreas) do + if v and x >= v.x1 and x <= v.x2 and y >= v.y1 and y <= v.y2 then + HitTarget = v.id + break + end + end + end + + --system.print("Target Hit = "..HitTarget) + + if HitTarget == "PlanetPageDown" then + CurrentPlanetPage = CurrentPlanetPage+1 + DrawPlanetList() + elseif HitTarget == "PlanetPageUp" then + CurrentPlanetPage = math.max(CurrentPlanetPage-1,0) + DrawPlanetList() + elseif HitTarget == "LocationPageDown" then + CurrentLocationPage = CurrentLocationPage+1 + DrawPlanetList() + elseif HitTarget == "LocationPageUp" then + CurrentLocationPage = math.max(CurrentLocationPage-1,0) + DrawPlanetList() + elseif HitTarget == "LoadSatNavLocations" then + loadPointsOfInterest() + if displayPlanetList[1] ~= "" then + lastPlanetSelected = displayPlanetList[1] + lastLocationSelected = "" + buildPlanetLocList(lastPlanetSelected) + clearLocDispList() + selected = "" + CurrentLocationPage=1 + CurrentPlanetPage=1 + DrawPlanetList() + end + elseif HitTarget == "LoadHudLocations" then + loadHudLocations() + if displayPlanetList[1] ~= "" then + lastPlanetSelected = displayPlanetList[1] + lastLocationSelected = "" + buildPlanetLocList(lastPlanetSelected) + clearLocDispList() + selected = "" + CurrentLocationPage=1 + CurrentPlanetPage=1 + DrawPlanetList() + end + elseif HitTarget == "ClearSatNavLocations" then + system.print("ClearSavedLocations") + clearSavedLocations() + system.print("defaul="..displayPlanetList[1]) + if displayPlanetList[1] ~= "" then + lastPlanetSelected = displayPlanetList[1] + lastLocationSelected = "" + buildPlanetLocList(lastPlanetSelected) + clearLocDispList() + selected = "" + CurrentLocationPage=1 + CurrentPlanetPage=1 + DrawPlanetList() + end + elseif HitTarget == "ClearHudLocations" then + --system.print("ClearSavedLocations") + clearHudLocations() + elseif HitTarget == "NewLocation" then + system.print("NewLocation") + newLocation() + if displayPlanetList[1] ~= "" then + lastPlanetSelected = displayPlanetList[1] + lastLocationSelected = "" + buildPlanetLocList(lastPlanetSelected) + clearLocDispList() + selected = "" + CurrentLocationPage=1 + CurrentPlanetPage=1 + DrawPlanetList() + end + else + for i = 1,pageLines do + if HitTarget == string.format("PList%s",i) then + --system.print("PHitTarget: "..HitTarget) + if displayPlanetList[i] ~= "" then + lastPlanetSelected = displayPlanetList[i] + buildPlanetLocList(lastPlanetSelected) + clearLocDispList() + selected = "" + DrawPlanetList() + end + end + if HitTarget == string.format("LList%s",i) then + if displayLocationList[i] ~= "" then + selected = displayLocationList[i] + if HUD == "Dimencia" then + copySelectedToHud(selected) + end + lastLocationSelected = selected + selected = "" + DrawPlanetList() + end + end + end + end +end + +----------------------------------------------- +-- Code for building screen content and displaying it +----------------------------------------------- + +local svgBootstrap = [[ + ]] + +function DrawPlanetList() + + local screenOutput = "" + + -- Draw Header + screenOutput = screenOutput .. svgBootstrap + + -- Draw main background + screenOutput = screenOutput .. + [[]] + screenOutput = screenOutput .. + [[(Version: ]]..version..[[)]] + screenOutput = screenOutput .. + [[Sat Nav]] + if HUD == "Dimencia" then + screenOutput = screenOutput .. + [[(Dimencia HUD enabled)]] + else + screenOutput = screenOutput .. + [[(Standalone mode enabled)]] + end + screenOutput = screenOutput .. + [[]] + screenOutput = screenOutput .. + [[]] + screenOutput = screenOutput .. + [[Planets]] + + + local i = 0 + for j = 1 + (CurrentPlanetPage - 1) * pageLines, pageLines + + (CurrentPlanetPage - 1) * pageLines, 1 do + i = i + 1 + if j < #planetList and j>0 then + local planetName = planetList[j] + if lastPlanetSelected == planetList[j] then + screenOutput = screenOutput .. + [[]] + end + screenOutput = screenOutput .. [[]] .. planetName .. + [[]] + if planetName ~= "Space" then + screenOutput = screenOutput .. [[]] .. planetDistList[planetName] .. + [[]] + end + displayPlanetList[i]=planetList[j] + else + displayPlanetList[i]="" + end + end + + if planetCount > 12 then + screenOutput = screenOutput .. + [[Page ]] .. + CurrentPlanetPage .. " of " .. + math.ceil(planetCount / 12) .. + [[]] + + if CurrentPlanetPage < math.ceil(planetCount / 12) then + screenOutput = screenOutput .. [[ + + + ]] + UpdateClickArea("PlanetPageDown", { + id = "PlanetPageDown", + x1 = 70, + x2 = 270, + y1 = 1050, + y2 = 1105 + }) + else + DisableClickArea("PlanetPageDown") + end + + if planetCount > 1 and CurrentPlanetPage > 1 then + screenOutput = screenOutput .. [[ + + + ]] + UpdateClickArea("PlanetPageUp", { + id = "PlanetPageUp", + x1 = 280, + x2 = 480, + y1 = 1050, + y2 = 1105 + }) + else + DisableClickArea("PlanetPageUp") + end + end + -- Start of Location List + screenOutput = screenOutput .. + [[]] + screenOutput = screenOutput .. + [[]] + screenOutput = screenOutput .. + [[]].. lastPlanetSelected ..[[ Locations]] + + + local i = 0 + for j = 1 + (CurrentLocationPage - 1) * pageLines, pageLines + + (CurrentLocationPage - 1) * pageLines, 1 do + + i = i + 1 + if j <= #locList and j>0 then + if lastLocationSelected == locList[j] then + screenOutput = screenOutput .. + [[]] + end + screenOutput = screenOutput .. [[]] .. locList[j] .. + [[]] + displayLocationList[i]=locList[j] + screenOutput = screenOutput .. [[]] .. locDistList[locList[j]] .. + [[]] + else + displayLocationList[i]="" + end + end + + if #locList > 12 then + screenOutput = screenOutput .. + [[Page ]] .. + CurrentLocationPage .. " of " .. + math.ceil(#locList / 12) .. + [[]] + + if CurrentLocationPage < math.ceil(#locList / 12) then + screenOutput = screenOutput .. [[ + + + ]] + UpdateClickArea("LocationPageDown", { + id = "LocationPageDown", + x1 = 1070, + x2 = 1270, + y1 = 1050, + y2 = 1105 + }) + else + DisableClickArea("LocationPageDown") + end + + if #locList > 1 and CurrentLocationPage > 1 then + screenOutput = screenOutput .. [[ + + + ]] + UpdateClickArea("LocationPageUp", { + id = "LocationPageUp", + x1 = 1280, + x2 = 1480, + y1 = 1050, + y2 = 1105 + }) + else + DisableClickArea("LocationPageUp") + end + end + +-- screenOutput = screenOutput .. +-- [[]] .. +-- [[Load SatNav DB]] + + screenOutput = screenOutput .. + [[]] .. + [[Save Current Location]] + +-- screenOutput = screenOutput .. +-- [[]] .. +-- [[Clear HUD Locs]] + + + screenOutput = screenOutput .. [[]] + + DrawSVG(screenOutput) + + forceRedraw = false +end + +----------------------------------------------- +-- Execute +----------------------------------------------- + +unit.hide() +InitiateClickAreas() +DrawPlanetList() +system.print("Running") +unit.setTimer("loadwp",1) diff --git a/src/unit/tick_loadwp.lua b/src/unit/tick_loadwp.lua new file mode 100644 index 0000000..22ec73c --- /dev/null +++ b/src/unit/tick_loadwp.lua @@ -0,0 +1,62 @@ +function loadLocationTable () + locationTable = {{}} + locationTable[1] = {"Alioth Market 1", "::pos{0,2,30.3314,101.3106,122.9764}"} + locationTable[#locationTable+1] = {"Alioth Market 2", "::pos{0,2,24.4469,88.0409,238.3019}"} + locationTable[#locationTable+1] = {"Alioth Market 3", "::pos{0,2,34.9734,87.3012,176.2188}"} + locationTable[#locationTable+1] = {"Alioth Market 4", "::pos{0,2,28.3352,99.5187,165.9078}"} + locationTable[#locationTable+1] = {"Alioth Market 5", "::pos{0,2,33.3939,87.3299,277.1366}"} + locationTable[#locationTable+1] = {"Alioth Market 6", "::pos{0,2,36.0044,101.3503,220.0897}"} + locationTable[#locationTable+1] = {"Alioth Market 7", "::pos{0,2,22.5024,98.1449,232.5154}"} + locationTable[#locationTable+1] = {"Alioth Market 8", "::pos{0,2,21.2154,93.9616,251.0768}"} + locationTable[#locationTable+1] = {"Alioth Market 9", "::pos{0,2,28.7133,85.6389,260.7636}"} + locationTable[#locationTable+1] = {"Alioth Market 10", "::pos{0,2,35.9865,91.8393,190.1616}"} + locationTable[#locationTable+1] = {"Alioth Market 11", "::pos{0,2,-1.0735,178.5062,69.9428}"} + locationTable[#locationTable+1] = {"Alioth Market 12", "::pos{0,2,22.7112,-92.3078,166.8481}"} + locationTable[#locationTable+1] = {"Alioth Market 13", "::pos{0,2,-23.3768,-10.5455,178.8458}"} + locationTable[#locationTable+1] = {"Alioth Market 14", "::pos{0,2,-73.4716,101.3697,89.5661}"} + locationTable[#locationTable+1] = {"Alioth Market 15", "::pos{0,2,61.7831,27.8517,54.9186}"} + locationTable[#locationTable+1] = {"Alioth Market 16", "::pos{0,2,23.4406,114.4179,211.1991}"} + locationTable[#locationTable+1] = {"Alioth Market 17", "::pos{0,2,37.8637,64.1825,151.5507}"} + locationTable[#locationTable+1] = {"Alioth Market 18", "::pos{0,2,49.9360,-170.7565,62.1982}"} + locationTable[#locationTable+1] = {"Alioth Market 19", "::pos{0,2,-32.7357,76.3764,209.0805}"} + locationTable[#locationTable+1] = {"Alioth Market 20", "::pos{0,2,-35.1535,-95.1230,301.0724}"} + + locationTable[#locationTable+1] = {"Madis Market 1", "::pos{0,1,2.6476,176.8761,813.0974}"} + locationTable[#locationTable+1] = {"Madis Market 2", "::pos{0,1,10.3552,8.5146,816.2210}"} + locationTable[#locationTable+1] = {"Madis Market 3", "::pos{0,1,-0.2107,82.0779,809.5571}"} + locationTable[#locationTable+1] = {"Madis Market 4", "::pos{0,1,-80.6046,44.9385,822.6188}"} + locationTable[#locationTable+1] = {"Madis Market 5", "::pos{0,1,81.0827,5.3022,823.1976}"} + locationTable[#locationTable+1] = {"Madis Market 6", "::pos{0,1,13.9814,-91.6163,811.0679}"} + + locationTable[#locationTable+1] = {"Thades M1: Market", "::pos{0,30,-2.9797,-117.7645,203.7519}"} + locationTable[#locationTable+1] = {"Feli: Market", "::pos{0,5,0.9348,178.6658,18417.2812}"} + locationTable[#locationTable+1] = {"Feli: Market 3", "::pos{0,5,-0.7500,-17.3248,18473.4238}"} + + locationTable[#locationTable+1] = {"Symeon Market 1", "::pos{0,110,3.1400,-174.0223,267.1084}"} + locationTable[#locationTable+1] = {"Symeon Market 2", "::pos{0,110,-0.9862,88.3038,197.0626}"} + locationTable[#locationTable+1] = {"Symeon Market 3", "::pos{0,110,18.1117,11.1108,180.8022}"} + locationTable[#locationTable+1] = {"Symeon Market 4", "::pos{0,110,-26.9701,103.3741,186.2557}"} + locationTable[#locationTable+1] = {"Symeon Market 5", "::pos{0,110,83.1653,108.7807,142.5796}"} + locationTable[#locationTable+1] = {"Symeon Market 6", "::pos{0,110,-79.3167,95.3975,138.5268}"} + + locationTable[#locationTable+1] = {"TMV Troghelm", "::pos{0,0,2416521.6598,1415126.8118,59323.7340}"} + locationTable[#locationTable+1] = {"TMV Alioth Factory", "::pos{0,2,22.8158,111.1414,103.5685}"} + locationTable[#locationTable+1] = {"TMV Feli Outpost", "::pos{0,5,23.6988,-77.8811,18480.5176}"} + locationTable[#locationTable+1] = {"TMV Thandes M1 Outpost", "::pos{0,30,-22.3548,-168.7352,288.1909}"} + locationTable[#locationTable+1] = {"TMV Madis Outpost", "::pos{0,1,-43.0914,75.0728,749.6641}"} + locationTable[#locationTable+1] = {"TMV Symoen Outpost", "::pos{0,110,-5.3046,32.6900,108.4144}"} + locationTable[#locationTable+1] = {"TMV Jago Outpost", "::pos{0,9,61.3760,-33.7830,10.7593}"} +end + +unit.stopTimer("loadwp") +loadLocationTable() +lastNewLoc = myDatabank.getIntValue("lastNewLoc") +--system.print("lastNewLoc"..lastNewLoc) +if lastNewLoc == nil or lastNewLoc==0 then + --this is th first time satnav has run on this databank + system.print("Initialising SatNav Databank") + CheckClick(0, 0, "LoadSatNavLocations") + lastNewLoc =1 + myDatabank.setIntValue("lastNewLoc",lastNewLoc) + system.print("Completed SatNav Databank") +end \ No newline at end of file From 35c4c8a84cf325f19b6059fc854663ff8aa90774 Mon Sep 17 00:00:00 2001 From: Merl Date: Sat, 19 Dec 2020 00:25:23 +0100 Subject: [PATCH 2/7] removed old versions and renamed current to SatNav_PB_Paste.json --- SatNav_PB_Paste_2_0_0 | 1 - SatNav_PB_Paste_2_0_1 | 1 - SatNav_PB_Paste_2_0_2 | 1 - SatNav_PB_Paste_2_1_0 | 1 - SatNav_PB_Paste_2_1_1 | 1 - SatNav_PB_Paste_2_1_2 | 1 - 6 files changed, 6 deletions(-) delete mode 100644 SatNav_PB_Paste_2_0_0 delete mode 100644 SatNav_PB_Paste_2_0_1 delete mode 100644 SatNav_PB_Paste_2_0_2 delete mode 100644 SatNav_PB_Paste_2_1_0 delete mode 100644 SatNav_PB_Paste_2_1_1 delete mode 100644 SatNav_PB_Paste_2_1_2 diff --git a/SatNav_PB_Paste_2_0_0 b/SatNav_PB_Paste_2_0_0 deleted file mode 100644 index 3e75230..0000000 --- a/SatNav_PB_Paste_2_0_0 +++ /dev/null @@ -1 +0,0 @@ -{"slots":{"0":{"name":"slot1","type":{"events":[],"methods":[]}},"1":{"name":"slot2","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"1"},"key":"0"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"3"},"key":"1"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"4"},"key":"2"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"5"},"key":"3"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"6"},"key":"4"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"7"},"key":"5"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"8"},"key":"6"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"9"},"key":"7"},{"code":"--[[\n SatNav version 2\n Created By TrogLaByte\n\n Discord: Trog#5105\n InGame: TrogLaByte\n \n GNU Public License 3.0. Use whatever you want, be so kind to leave credit.\n\n Thanks to Dorien Grey for his SVG and onscreen button code.\n]] \n-----------------------------------------------\n-- requirements\n-----------------------------------------------\n\nfunction initiateRequiredLibaries()\n json = require('dkjson')\n vec3 = require('cpml.vec3')\n utils = require('cpml.utils')\n planetRef = require('cpml.planetref')\n referenceTableSource = require('cpml.atlas')\n clamp = utils.clamp\nend\nif pcall(initiateRequiredLibaries) then\n system.print(\"Libaries loaded successfully\")\n else\n system.print(\"Libaries failed to load: check that the following libraries exist:\")\n system.print(\" /DualUniverse/Game/data/lua/dkjson\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/vec3\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/utils\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/planetref\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/atlas\")\n system.print(\"\")\n system.print(\"planetref.lua and atlas.lua can be obtained from the following GitLab url:\")\n system.print(\"https://gitlab.com/JayleBreak/dualuniverse/-/tree/master/DUflightfiles/autoconf/custom\")\n unit.exit()\nend\n-----------------------------------------------\n-- Global Variables\n-----------------------------------------------\n\nlocal UpdateInterval = 1 --export: Interval in seconds between updates of the calculations and (if anything changed) redrawing to the screen(s). You need to restart the script after changing this value.\nlocal BackgroundColor = \"#1e1e1e\"\nlocal PlanetBackgroundColor = \"#34b1eb\" --export Set the background color of the screens. YOU NEED TO LEAVE THE QUOTATION MARKS.\nlocal LocationBackgroundColor = \"#6e3de3\" --export Set the background color of the screens. YOU NEED TO LEAVE THE QUOTATION MARKS.\nlocal clickAreas = {}\nlocal locList={}\nlocal lastPlanetSelected = \"Alioth\"\nlocal pageLines=12\nlocal displayPlanetList={}\nlocal displayLocationList={}\nlocal CurrentLocationPage = 1\nlocal CurrentPlanetPage = 1\n\n-----------------------------------------------\n-- initiate slots to know names\n-----------------------------------------------\n\nfunction InitiateSlots()\n for slot_name, slot in pairs(unit) do\n if type(slot) == \"table\" and type(slot.export) == \"table\" and\n slot.getElementClass then\n --system.print(slot.getElementClass())\n if slot.getElementClass():lower():find(\"coreunit\") then\n core = slot\n --system.print(\"found core\")\n end\n if slot.getElementClass():lower():find(\"screenunit\") then\n screen = slot\n --system.print(\"found screen\")\n end\n if slot.getElementClass():lower():find(\"databankunit\") then\n myDatabank = slot\n --system.print(\"found databank\")\n end\n end\n end\nend\nInitiateSlots()\n-----------------------------------------------\n-- set up galaxy data and functions for planets and locations\n-----------------------------------------------\n\ngalaxyReference = planetRef(referenceTableSource)\nhelios = galaxyReference[0] -- PlanetaryReference.PlanetarySystem instance\nplanetList={}\njdecode = json.decode\njencode = json.encode\n\nfunction getBodyId(planetName)\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n if string.lower(helios[tonumber(i)].name) ==string.lower(planetName) then\n return i\n end\n end\n end\n return 0\nend\n\nfunction buildPlanetList()\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n planetList[#planetList+1]=helios[tonumber(i)].name\n end\n end\n planetList[#planetList+1]=\"Space\"\n table.sort(planetList)\nend\n\nfunction buildPlanetLocList(planetName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\") \n local planet={}\n locList={}\n if planetName ~= \"Space\" then\n table.insert(locList, planetName) -- add planet name into the list as a default\n end\n if savedLocation ~= nil and savedLocations ~= \"\" then \n local result = jdecode(savedLocation)\n if result ~= nil then\n --system.print(\"Loc Planet: \"..planetName)\n for k, v in pairs(result) do\n --system.print(\"Planet: \"..v[\"planetname\"])\n if string.lower(v[\"planetname\"]) == string.lower(planetName) or\n string.find(string.lower(v[\"planetname\"]),string.lower(planetName))\n then\n local location = v[\"position\"]\n local bodyId = getBodyId(v[\"planetname\"])\n planet = helios[tonumber(bodyId)] \n\n worldCoords = planet:convertToMapPosition(vec3(location[\"x\"],location[\"y\"],location[\"z\"]))\n\n --system.print(string.format([[\"%s\" @ ::pos{%d,%d,%f,%f,%f}]],\n -- v[\"name\"],\n -- worldCoords.systemId,\n -- worldCoords.bodyId,\n -- worldCoords.latitude*constants.rad2deg,\n -- worldCoords.longitude*constants.rad2deg,\n -- worldCoords.altitude))\n table.insert(locList, v[\"name\"])\n else if v[\"planetname\"] == \"\" and planetName == \"Space\" then -- a space location\n local location = v[\"position\"]\n -- system.print(string.format([[\"%s\" @ ::pos{%d,%d,%f,%f,%f}]],\n -- v[\"name\"],\n -- 0,\n -- 0,\n -- location[\"x\"],\n -- location[\"y\"],\n -- location[\"z\"]))\n table.insert(locList, v[\"name\"])\n end\n end\n end\n end\n end\n table.sort(locList)\nend\n\nfunction printLocMapPos(locationName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\") \n local planet={}\n if savedLocation ~= nil and savedLocations ~= \"\" then \n --system.print(savedLocation)\n local result = jdecode(savedLocation)\n if result ~= nil then\n for k, v in pairs(result) do\n if string.lower(v[\"name\"]) == string.lower(locationName) then\n local location = v[\"position\"]\n local bodyId = getBodyId(v[\"planetname\"])\n planet = helios[tonumber(bodyId)] \n if planet ~= nil then\n worldCoords = planet:convertToMapPosition(vec3(location[\"x\"],location[\"y\"],location[\"z\"]))\n\n system.print(string.format([[\"%s\" @ ::pos{%d,%d,%f,%f,%f}]],\n v[\"name\"],\n worldCoords.systemId,\n worldCoords.bodyId,\n worldCoords.latitude*constants.rad2deg,\n worldCoords.longitude*constants.rad2deg,\n worldCoords.altitude))\n return locationName\n else\n system.print(string.format([[\"%s\" @ ::pos{%d,%d,%f,%f,%f}]],\n v[\"name\"],\n 0,\n bodyId,\n location[\"x\"],\n location[\"y\"],\n location[\"z\"]))\n return locationName\n end\n break\n end\n end \n end\n end\n return \"\"\nend\n\nfunction clearSavedLocations()\n myDatabank.setStringValue(\"SavedLocations\",\"[]\")\n system.print(\"Databank cleared\")\nend\n\nfunction isDuplicateLocation(locName, savedLocations)\n for i=1,#savedLocations do\n if savedLocations and savedLocations[i].name ~= nil then\n if savedLocations[i].name == locName then\n return locName\n end\n end\n end\n return \"\"\nend\n\nfunction loadPointsOfInterest()\n local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)'\n local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' ..\n num .. ',' .. num .. '}'\n local savedLocation = {}\n local j=0\n loadLocationTable()\n savedLocation = jdecode(myDatabank.getStringValue(\"SavedLocations\"))\n \n for i = 1, #locationTable do\n local newLoc={}\n local planet={}\n if isDuplicateLocation(locationTable[i][1],savedLocation) == \"\" then\n newLoc[\"name\"]=locationTable[i][1]\n local newLocPos = locationTable[i][2]\n --system.print(\"Name: \"..locationTable[i][1]..\" \"..newLocPos)\n local systemId, bodyId, latitude, longitude, altitude =\n string.match(locationTable[i][2], posPattern)\n --system.print(\"BodyId: \".. bodyId)\n if tonumber(bodyId) > 0 then\n planet = helios[tonumber(bodyId)] \n local worldCoords = planet:convertToWorldCoordinates(newLocPos)\n newLoc[\"position\"]=worldCoords\n newLoc[\"gravity\"]=unit.getClosestPlanetInfluence()\n newLoc[\"atmosphere\"]=unit.getAtmosphereDensity()\n newLoc[\"planetname\"]=planet.name\n else -- it is a space location\n newLoc[\"position\"]=vec3(tonumber(latitude), tonumber(longitude), tonumber(altitude))\n newLoc[\"gravity\"]=0\n newLoc[\"atmosphere\"]=0\n newLoc[\"planetname\"]=\"\"\n end\n \n if savedLocation == nil then\n savedLocation = {}\n savedLocation[1]=newLoc\n j = 1\n else\n j = j + 1\n savedLocation[#savedLocation+1]=newLoc\n end\n else\n system.print(\"Duplicate entry for location ignored: \"..locationTable[i][1])\n end\n end\n myDatabank.setStringValue(\"SavedLocations\",jencode(savedLocation))\n system.print(j .. \" Saved Locations loaded\")\nend\n\nbuildPlanetList()\nbuildPlanetLocList(lastPlanetSelected)\nlocal planetCount=#planetList\n\n-----------------------------------------------\n-- Code for on screen buttons\n-----------------------------------------------\n\nfunction DrawSVG(output) screen.setSVG(output) end\n\nfunction AddClickArea(newEntry) table.insert(clickAreas, newEntry) end\n\nfunction RemoveFromClickAreas(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = nil\n break\n end\n end\nend\n\nfunction UpdateClickArea(candidate, newEntry)\n --system.print(\"Candidate: \"..candidate..\" x1\"..newEntry.x1)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = newEntry\n --system.print(\"Click Area: \"..candidate..\" x1\"..clickAreas[k].x1)\n break\n end\n end\nend\n\nfunction DisableClickArea(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n UpdateClickArea(candidate, {\n id = candidate,\n x1 = -1,\n x2 = -1,\n y1 = -1,\n y2 = -1\n })\n break\n end\n end\nend\n\nfunction InitiateClickAreas()\n clickAreas = {}\n \n AddClickArea({id = \"LoadSavedLocations\", x1 = 300, x2 = 800, y1 = 900, y2 = 1000})\n AddClickArea({id = \"ClearSavedLocations\", x1 = 1200, x2 = 1700, y1 = 900, y2 = 1000})\n AddClickArea({id = \"PlanetPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"PlanetPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n \n for i = 1, pageLines do\n AddClickArea({id = string.format(\"PList%d\",i), x1 = 90, x2 = 800, y1 = (180 + i * 55), y2 = (235 + i * 55)})\n AddClickArea({id = string.format(\"LList%d\",i), x1 = 1090, x2 = 1500, y1 = (180 + i * 55), y2 = (235 + i * 55)})\n end\nend\n\nfunction FlushClickAreas() clickAreas = {} end\n\nfunction clearLocDispList()\n for i=1,pageLines do\n displayLocationList[i] = \"\"\n end\nend\n\nfunction CheckClick(x, y, HitTarget)\n HitTarget = HitTarget or \"\"\n if HitTarget == \"\" then\n for k, v in pairs(clickAreas) do\n if v and x >= v.x1 and x <= v.x2 and y >= v.y1 and y <= v.y2 then\n HitTarget = v.id\n break\n end\n end\n end\n \n --system.print(\"Target Hit = \"..HitTarget)\n \n if HitTarget == \"PlanetPageDown\" then\n CurrentPlanetPage = CurrentPlanetPage+1\n DrawPlanetList()\n elseif HitTarget == \"PlanetPageUp\" then\n CurrentPlanetPage = math.max(CurrentPlanetPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LocationPageDown\" then\n CurrentLocationPage = CurrentLocationPage+1\n DrawPlanetList()\n elseif HitTarget == \"LocationPageUp\" then\n CurrentLocationPage = math.max(CurrentLocationPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LoadSavedLocations\" then\n --system.print(\"LoadSavedLocations\")\n loadPointsOfInterest()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n elseif HitTarget == \"ClearSavedLocations\" then\n --system.print(\"ClearSavedLocations\")\n clearSavedLocations()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n else\n for i = 1,pageLines do\n if HitTarget == string.format(\"PList%s\",i) then\n --system.print(\"PHitTarget: \"..HitTarget)\n if displayPlanetList[i] ~= \"\" then\n lastPlanetSelected = displayPlanetList[i]\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n DrawPlanetList()\n end\n end\n if HitTarget == string.format(\"LList%s\",i) then\n if displayLocationList[i] ~= \"\" then\n selected = displayLocationList[i]\n if printLocMapPos(selected) == \"\" then\n system.print(\"Location: \"..selected..\" sent to Hud\")\n else\n myDatabank.setStringValue(\"SPBAutopilotTargetName\",selected)\n end\n end\n end\n end\n end\nend\n\n-----------------------------------------------\n-- Code for building screen content and displaying it\n-----------------------------------------------\n\nlocal svgBootstrap = [[\n ]]\n\nfunction DrawPlanetList()\n local healthyColor = \"#00aa00\"\n local brokenColor = \"#aa0000\"\n local damagedColor = \"#aaaa00\"\n local integrityColor = \"#aaaaaa\"\n local healthyTextColor = \"white\"\n local brokenTextColor = \"#ff4444\"\n local damagedTextColor = \"#ffff44\"\n local integrityTextColor = \"white\"\n \n\n local screenOutput = \"\"\n\n -- Draw Header\n screenOutput = screenOutput .. svgBootstrap\n \n -- Draw main background\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[Sat Nav]]\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[Planets]]\n \n\n local i = 0\n for j = 1 + (CurrentPlanetPage - 1) * pageLines, pageLines +\n (CurrentPlanetPage - 1) * pageLines, 1 do\n i = i + 1\n if j < #planetList and j>0 then\n if lastPlanetSelected == planetList[j] then\n screenOutput = screenOutput .. [[]] ..\n string.format(\"%s\", planetList[j]) .. [[]]\n else\n screenOutput = screenOutput .. [[]] ..\n string.format(\"%s\", planetList[j]) .. [[]]\n end\n displayPlanetList[i]=planetList[j]\n else\n displayPlanetList[i]=\"\"\n end\n end\n \n if planetCount > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentPlanetPage .. \" of \" ..\n math.ceil(planetCount / 12) ..\n [[]]\n\n if CurrentPlanetPage < math.ceil(planetCount / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageDown\", {\n id = \"PlanetPageDown\",\n x1 = 70,\n x2 = 270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageDown\")\n end\n\n if planetCount > 1 and CurrentPlanetPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageUp\", {\n id = \"PlanetPageUp\",\n x1 = 280,\n x2 = 480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageUp\")\n end\n end\n -- Start of Location List\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[]].. lastPlanetSelected ..[[ Locations]]\n \n\n local i = 0\n for j = 1 + (CurrentLocationPage - 1) * pageLines, pageLines +\n (CurrentLocationPage - 1) * pageLines, 1 do\n --system.print(\"locList: \"..locList[j])\n i = i + 1\n if j <= #locList and j>0 then\n screenOutput = screenOutput .. [[]] ..\n string.format(\"%s\", locList[j]) .. [[]]\n displayLocationList[i]=locList[j]\n else\n displayLocationList[i]=\"\"\n end\n end\n \n if #locList > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentLocationPage .. \" of \" ..\n math.ceil(#locList / 12) ..\n [[]]\n\n if CurrentLocationPage < math.ceil(#locList / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageDown\", {\n id = \"LocationPageDown\",\n x1 = 1070,\n x2 = 1270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageDown\")\n end\n\n if #locList > 1 and CurrentLocationPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageUp\", {\n id = \"LocationPageUp\",\n x1 = 1280,\n x2 = 1480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageUp\")\n end\n end\n \n screenOutput = screenOutput ..\n [[]] ..\n [[Load Saved Locations]]\n \n screenOutput = screenOutput ..\n [[]] ..\n [[Clear Saved Locations]]\n\n screenOutput = screenOutput .. [[]]\n\n DrawSVG(screenOutput)\n\n forceRedraw = false\nend\n\n-----------------------------------------------\n-- Execute\n-----------------------------------------------\n\nunit.hide()\nInitiateClickAreas()\nDrawPlanetList()\n","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"8"},{"code":"function loadLocationTable ()\n\nlocationTable = {{}}\nlocationTable[1] = {\"Alioth Market 1\", \"::pos{0,2,30.3314,101.3106,122.9764}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 2\", \"::pos{0,2,24.4469,88.0409,238.3019}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 3\", \"::pos{0,2,34.9734,87.3012,176.2188}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 4\", \"::pos{0,2,28.3352,99.5187,165.9078}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 5\", \"::pos{0,2,33.3939,87.3299,277.1366}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 6\", \"::pos{0,2,36.0044,101.3503,220.0897}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 7\", \"::pos{0,2,22.5024,98.1449,232.5154}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 8\", \"::pos{0,2,21.2154,93.9616,251.0768}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 9\", \"::pos{0,2,28.7133,85.6389,260.7636}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 10\", \"::pos{0,2,35.9865,91.8393,190.1616}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 11\", \"::pos{0,2,-1.0735,178.5062,69.9428}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 12\", \"::pos{0,2,22.7112,-92.3078,166.8481}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 13\", \"::pos{0,2,-23.3768,-10.5455,178.8458}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 14\", \"::pos{0,2,-73.4716,101.3697,89.5661}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 15\", \"::pos{0,2,61.7831,27.8517,54.9186}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 16\", \"::pos{0,2,23.4406,114.4179,211.1991}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 17\", \"::pos{0,2,37.8637,64.1825,151.5507}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 18\", \"::pos{0,2,49.9360,-170.7565,62.1982}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 19\", \"::pos{0,2,-32.7357,76.3764,209.0805}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 20\", \"::pos{0,2,-35.1535,-95.1230,301.0724}\"}\n\nlocationTable[#locationTable+1] = {\"Madis Market 1\", \"::pos{0,1,2.6476,176.8761,813.0974}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 2\", \"::pos{0,1,10.3552,8.5146,816.2210}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 3\", \"::pos{0,1,-0.2107,82.0779,809.5571}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 4\", \"::pos{0,1,-80.6046,44.9385,822.6188}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 5\", \"::pos{0,1,81.0827,5.3022,823.1976}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 6\", \"::pos{0,1,13.9814,-91.6163,811.0679}\"}\n\nlocationTable[#locationTable+1] = {\"Thades M1: Market\", \"::pos{0,30,-2.9797,-117.7645,203.7519}\"}\nlocationTable[#locationTable+1] = {\"Feli: Market\", \"::pos{0,5,0.9348,178.6658,18417.2812}\"}\n\nlocationTable[#locationTable+1] = {\"Symeon Market 1\", \"::pos{0,110,3.1400,-174.0223,267.1084}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 2\", \"::pos{0,110,-0.9862,88.3038,197.0626}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 3\", \"::pos{0,110,18.1117,11.1108,180.8022}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 4\", \"::pos{0,110,-26.9701,103.3741,186.2557}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 5\", \"::pos{0,110,83.1653,108.7807,142.5796}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 6\", \"::pos{0,110,-79.3167,95.3975,138.5268}\"}\n\nlocationTable[#locationTable+1] = {\"TMV Troghelm\", \"::pos{0,0,2416521.6598,1415126.8118,59323.7340}\"}\nlocationTable[#locationTable+1] = {\"TMV Alioth Factory\", \"::pos{0,2,22.8158,111.1414,103.5685}\"}\nlocationTable[#locationTable+1] = {\"TMV Feli Outpost\", \"::pos{0,5,23.6988,-77.8811,18480.5176}\"}\nlocationTable[#locationTable+1] = {\"TMV Thandes M1 Outpost\", \"::pos{0,30,-22.3548,-168.7352,288.1909}\"}\nlocationTable[#locationTable+1] = {\"TMV Madis Outpost\", \"::pos{0,1,-43.0914,75.0728,749.6641}\"}\nlocationTable[#locationTable+1] = {\"TMV Symoen Outpost\", \"::pos{0,110,-5.3046,32.6900,108.4144}\"}\n\n\n\n\n\n\n\n \n\nend\n\n","filter":{"args":[],"signature":"start()","slotKey":"-2"},"key":"9"}],"methods":[],"events":[]} diff --git a/SatNav_PB_Paste_2_0_1 b/SatNav_PB_Paste_2_0_1 deleted file mode 100644 index 414170a..0000000 --- a/SatNav_PB_Paste_2_0_1 +++ /dev/null @@ -1 +0,0 @@ -{"slots":{"0":{"name":"slot1","type":{"events":[],"methods":[]}},"1":{"name":"slot2","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"1"},"key":"0"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"3"},"key":"1"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"4"},"key":"2"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"5"},"key":"3"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"6"},"key":"4"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"7"},"key":"5"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"8"},"key":"6"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"9"},"key":"7"},{"code":"--[[\n SatNav version 2\n Created By TrogLaByte\n\n Discord: Trog#5105\n InGame: TrogLaByte\n \n GNU Public License 3.0. Use whatever you want, be so kind to leave credit.\n\n Thanks to Dorien Grey for his SVG and onscreen button code.\n]] \n-----------------------------------------------\n-- requirements\n-----------------------------------------------\n\nfunction initiateRequiredLibaries()\n json = require('dkjson')\n vec3 = require('cpml.vec3')\n utils = require('cpml.utils')\n planetRef = require('cpml.planetref')\n referenceTableSource = require('cpml.atlas')\n clamp = utils.clamp\nend\nif pcall(initiateRequiredLibaries) then\n system.print(\"Libaries loaded successfully\")\n else\n system.print(\"Libaries failed to load: check that the following libraries exist:\")\n system.print(\" /DualUniverse/Game/data/lua/dkjson\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/vec3\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/utils\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/planetref\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/atlas\")\n system.print(\"\")\n system.print(\"planetref.lua and atlas.lua can be obtained from the following GitLab url:\")\n system.print(\"https://gitlab.com/JayleBreak/dualuniverse/-/tree/master/DUflightfiles/autoconf/custom\")\n unit.exit()\nend\n-----------------------------------------------\n-- Global Variables\n-----------------------------------------------\n\nlocal UpdateInterval = 1 --export: Interval in seconds between updates of the calculations and (if anything changed) redrawing to the screen(s). You need to restart the script after changing this value.\nlocal BackgroundColor = \"#1e1e1e\"\nlocal PlanetBackgroundColor = \"#34b1eb\" --export Set the background color of the screens. YOU NEED TO LEAVE THE QUOTATION MARKS.\nlocal LocationBackgroundColor = \"#6e3de3\" --export Set the background color of the screens. YOU NEED TO LEAVE THE QUOTATION MARKS.\nlocal clickAreas = {}\nlocal locList={}\nlocal lastPlanetSelected = \"Alioth\"\nlocal pageLines=12\nlocal displayPlanetList={}\nlocal displayLocationList={}\nlocal CurrentLocationPage = 1\nlocal CurrentPlanetPage = 1\nlocal HUD = \"unknown\"\n\n-----------------------------------------------\n-- initiate slots to know names\n-----------------------------------------------\n\nfunction InitiateSlots()\n for slot_name, slot in pairs(unit) do\n if type(slot) == \"table\" and type(slot.export) == \"table\" and\n slot.getElementClass then\n --system.print(slot.getElementClass())\n if slot.getElementClass():lower():find(\"coreunit\") then\n core = slot\n --system.print(\"found core\")\n end\n if slot.getElementClass():lower():find(\"screenunit\") then\n screen = slot\n --system.print(\"found screen\")\n end\n if slot.getElementClass():lower():find(\"databankunit\") then\n myDatabank = slot\n --system.print(\"found databank\")\n if myDatabank.getStringValue(\"AutopilotTargetIndex\")~= nil then\n HUD = \"Dimencia\"\n else\n HUD = \"unknown\"\n end\n end\n end\n end\nend\nInitiateSlots()\n\n-----------------------------------------------\n-- set up galaxy data and functions for planets and locations\n-----------------------------------------------\n\ngalaxyReference = planetRef(referenceTableSource)\nhelios = galaxyReference[0] -- PlanetaryReference.PlanetarySystem instance\nplanetList={}\nplanetDistList={}\nlocDistList={}\njdecode = json.decode\njencode = json.encode\n\nfunction getBodyId(planetName)\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n if string.lower(helios[tonumber(i)].name) ==string.lower(planetName) then\n return i\n end\n end\n end\n return 0\nend\n\nfunction buildPlanetList()\n local planet={}\n local currentLoc = vec3(core.getConstructWorldPos())\n local shipMass = core.getConstructMass()\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n planet = helios[tonumber(i)]\n planetList[#planetList+1] = planet.name\n local planetDistance = planet:getDistance(currentLoc)\n planetDistList[planet.name] = formatDistance(planetDistance) .. \n string.format(\" [%.0f wc]\", ((planetDistance/200000)*(shipMass/1000)/4000))\n end\n end\n planetList[#planetList+1]=\"Space\"\n table.sort(planetList)\nend\n\nfunction formatDistance(distance)\n if distance < 200000 then\n return string.format(\"%.0f km\",distance/1000)\n elseif distance < 4000000 then\n return string.format(\"%.2f su\",distance/200000)\n else\n return string.format(\"%.0f su\",distance/200000)\n end\nend\n\n\nfunction buildPlanetLocList(planetName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local currentLoc = vec3(core.getConstructWorldPos())\n local shipMass = core.getConstructMass()\n local planet={}\n locList={}\n if planetName ~= \"Space\" then\n table.insert(locList, planetName) -- add planet name into the list as a default\n locDistList[planetName] = planetDistList[planetName]\n end\n if savedLocation ~= nil and savedLocations ~= \"\" then \n local result = jdecode(savedLocation)\n if result ~= nil then\n for k, v in pairs(result) do\n local location = v[\"position\"]\n if string.lower(v[\"planetname\"]) == string.lower(planetName) or\n string.find(string.lower(v[\"planetname\"]),string.lower(planetName))\n then\n table.insert(locList, v[\"name\"])\n elseif v[\"planetname\"] == \"\" and planetName == \"Space\" then -- a space location\n table.insert(locList, v[\"name\"])\n end\n local locDistance = (currentLoc - vec3(location[\"x\"],location[\"y\"],location[\"z\"])):len()\n if planetName == \"Space\" then\n locDistList[v[\"name\"]] = formatDistance(locDistance) ..\n string.format(\" [%.0f wc]\", ((locDistance/200000)*(shipMass/1000)/4000))\n else\n locDistList[v[\"name\"]] = formatDistance(locDistance)\n end\n\n\n end\n end\n end\n table.sort(locList)\nend\n\nfunction printLocMapPos(locationName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\") \n local planet={}\n if savedLocation ~= nil and savedLocations ~= \"\" then \n --system.print(savedLocation)\n local result = jdecode(savedLocation)\n if result ~= nil then\n for k, v in pairs(result) do\n if string.lower(v[\"name\"]) == string.lower(locationName) then\n local location = v[\"position\"]\n local bodyId = getBodyId(v[\"planetname\"])\n planet = helios[tonumber(bodyId)] \n if planet ~= nil then\n worldCoords = planet:convertToMapPosition(vec3(location[\"x\"],location[\"y\"],location[\"z\"]))\n\n system.print(string.format([[\"%s\" @ ::pos{%d,%d,%f,%f,%f}]],\n v[\"name\"],\n worldCoords.systemId,\n worldCoords.bodyId,\n worldCoords.latitude*constants.rad2deg,\n worldCoords.longitude*constants.rad2deg,\n worldCoords.altitude))\n return locationName\n else\n system.print(string.format([[\"%s\" @ ::pos{%d,%d,%f,%f,%f}]],\n v[\"name\"],\n 0,\n bodyId,\n location[\"x\"],\n location[\"y\"],\n location[\"z\"]))\n return locationName\n end\n break\n end\n end \n end\n end\n return \"\"\nend\n\nfunction clearSavedLocations()\n myDatabank.setStringValue(\"SavedLocations\",\"[]\")\n system.print(\"Databank cleared\")\nend\n\nfunction isDuplicateLocation(locName, savedLocations)\n for i=1,#savedLocations do\n if savedLocations and savedLocations[i].name ~= nil then\n if savedLocations[i].name == locName then\n return locName\n end\n end\n end\n return \"\"\nend\n\nfunction loadPointsOfInterest()\n local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)'\n local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' ..\n num .. ',' .. num .. '}'\n local savedLocation = {}\n local j=0\n loadLocationTable()\n savedLocation = jdecode(myDatabank.getStringValue(\"SavedLocations\"))\n \n for i = 1, #locationTable do\n local newLoc={}\n local planet={}\n if isDuplicateLocation(locationTable[i][1],savedLocation) == \"\" then\n newLoc[\"name\"]=locationTable[i][1]\n local newLocPos = locationTable[i][2]\n --system.print(\"Name: \"..locationTable[i][1]..\" \"..newLocPos)\n local systemId, bodyId, latitude, longitude, altitude =\n string.match(locationTable[i][2], posPattern)\n --system.print(\"BodyId: \".. bodyId)\n if tonumber(bodyId) > 0 then\n planet = helios[tonumber(bodyId)] \n local worldCoords = planet:convertToWorldCoordinates(newLocPos)\n newLoc[\"position\"]=worldCoords\n newLoc[\"gravity\"]=unit.getClosestPlanetInfluence()\n newLoc[\"atmosphere\"]=unit.getAtmosphereDensity()\n newLoc[\"planetname\"]=planet.name\n else -- it is a space location\n newLoc[\"position\"]=vec3(tonumber(latitude), tonumber(longitude), tonumber(altitude))\n newLoc[\"gravity\"]=0\n newLoc[\"atmosphere\"]=0\n newLoc[\"planetname\"]=\"\"\n end\n \n if savedLocation == nil then\n savedLocation = {}\n savedLocation[1]=newLoc\n j = 1\n else\n j = j + 1\n savedLocation[#savedLocation+1]=newLoc\n end\n else\n system.print(\"Duplicate entry for location ignored: \"..locationTable[i][1])\n end\n end\n myDatabank.setStringValue(\"SavedLocations\",jencode(savedLocation))\n system.print(j .. \" Saved Locations loaded\")\nend\n\nbuildPlanetList()\nbuildPlanetLocList(lastPlanetSelected)\nlocal planetCount=#planetList\n\n-----------------------------------------------\n-- Code for on screen buttons\n-----------------------------------------------\n\nfunction DrawSVG(output) screen.setSVG(output) end\n\nfunction AddClickArea(newEntry) table.insert(clickAreas, newEntry) end\n\nfunction RemoveFromClickAreas(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = nil\n break\n end\n end\nend\n\nfunction UpdateClickArea(candidate, newEntry)\n --system.print(\"Candidate: \"..candidate..\" x1\"..newEntry.x1)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = newEntry\n --system.print(\"Click Area: \"..candidate..\" x1\"..clickAreas[k].x1)\n break\n end\n end\nend\n\nfunction DisableClickArea(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n UpdateClickArea(candidate, {\n id = candidate,\n x1 = -1,\n x2 = -1,\n y1 = -1,\n y2 = -1\n })\n break\n end\n end\nend\n\nfunction InitiateClickAreas()\n clickAreas = {}\n \n AddClickArea({id = \"LoadSavedLocations\", x1 = 300, x2 = 800, y1 = 900, y2 = 1000})\n AddClickArea({id = \"ClearSavedLocations\", x1 = 1200, x2 = 1700, y1 = 900, y2 = 1000})\n AddClickArea({id = \"PlanetPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"PlanetPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n \n for i = 1, pageLines do\n AddClickArea({id = string.format(\"PList%d\",i), x1 = 90, x2 = 800, y1 = (180 + i * 55), y2 = (235 + i * 55)})\n AddClickArea({id = string.format(\"LList%d\",i), x1 = 1090, x2 = 1500, y1 = (180 + i * 55), y2 = (235 + i * 55)})\n end\nend\n\nfunction FlushClickAreas() clickAreas = {} end\n\nfunction clearLocDispList()\n for i=1,pageLines do\n displayLocationList[i] = \"\"\n end\nend\n\nfunction CheckClick(x, y, HitTarget)\n HitTarget = HitTarget or \"\"\n if HitTarget == \"\" then\n for k, v in pairs(clickAreas) do\n if v and x >= v.x1 and x <= v.x2 and y >= v.y1 and y <= v.y2 then\n HitTarget = v.id\n break\n end\n end\n end\n \n --system.print(\"Target Hit = \"..HitTarget)\n \n if HitTarget == \"PlanetPageDown\" then\n CurrentPlanetPage = CurrentPlanetPage+1\n DrawPlanetList()\n elseif HitTarget == \"PlanetPageUp\" then\n CurrentPlanetPage = math.max(CurrentPlanetPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LocationPageDown\" then\n CurrentLocationPage = CurrentLocationPage+1\n DrawPlanetList()\n elseif HitTarget == \"LocationPageUp\" then\n CurrentLocationPage = math.max(CurrentLocationPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LoadSavedLocations\" then\n --system.print(\"LoadSavedLocations\")\n loadPointsOfInterest()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n elseif HitTarget == \"ClearSavedLocations\" then\n --system.print(\"ClearSavedLocations\")\n clearSavedLocations()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n else\n for i = 1,pageLines do\n if HitTarget == string.format(\"PList%s\",i) then\n --system.print(\"PHitTarget: \"..HitTarget)\n if displayPlanetList[i] ~= \"\" then\n lastPlanetSelected = displayPlanetList[i]\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n DrawPlanetList()\n end\n end\n if HitTarget == string.format(\"LList%s\",i) then\n if displayLocationList[i] ~= \"\" then\n selected = displayLocationList[i]\n if printLocMapPos(selected) == \"\" then\n system.print(\"Location: \"..selected..\" sent to Hud\")\n myDatabank.setStringValue(\"SPBAutopilotTargetName\",selected)\n else\n myDatabank.setStringValue(\"SPBAutopilotTargetName\",selected)\n end\n end\n end\n end\n end\nend\n\n-----------------------------------------------\n-- Code for building screen content and displaying it\n-----------------------------------------------\n\nlocal svgBootstrap = [[\n ]]\n\nfunction DrawPlanetList()\n local healthyColor = \"#00aa00\"\n local brokenColor = \"#aa0000\"\n local damagedColor = \"#aaaa00\"\n local integrityColor = \"#aaaaaa\"\n local healthyTextColor = \"white\"\n local brokenTextColor = \"#ff4444\"\n local damagedTextColor = \"#ffff44\"\n local integrityTextColor = \"white\"\n \n\n local screenOutput = \"\"\n\n -- Draw Header\n screenOutput = screenOutput .. svgBootstrap\n \n -- Draw main background\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[Sat Nav]]\n if HUD == \"Dimencia\" then\n screenOutput = screenOutput ..\n [[(Dimencia HUD enabled)]]\n else \n screenOutput = screenOutput ..\n [[(Standalone mode enabled)]]\n end\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[Planets]]\n \n\n local i = 0\n for j = 1 + (CurrentPlanetPage - 1) * pageLines, pageLines +\n (CurrentPlanetPage - 1) * pageLines, 1 do\n i = i + 1\n if j < #planetList and j>0 then\n local planetName = planetList[j]\n if lastPlanetSelected == planetList[j] then\n screenOutput = screenOutput .. [[]] .. planetName .. \n [[]]\n else\n screenOutput = screenOutput .. [[]] .. planetName .. \n [[]]\n end\n if planetName ~= \"Space\" then\n screenOutput = screenOutput .. [[]] .. planetDistList[planetName] .. \n [[]] \n end\n displayPlanetList[i]=planetList[j]\n else\n displayPlanetList[i]=\"\"\n end\n end\n \n if planetCount > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentPlanetPage .. \" of \" ..\n math.ceil(planetCount / 12) ..\n [[]]\n\n if CurrentPlanetPage < math.ceil(planetCount / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageDown\", {\n id = \"PlanetPageDown\",\n x1 = 70,\n x2 = 270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageDown\")\n end\n\n if planetCount > 1 and CurrentPlanetPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageUp\", {\n id = \"PlanetPageUp\",\n x1 = 280,\n x2 = 480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageUp\")\n end\n end\n -- Start of Location List\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[]].. lastPlanetSelected ..[[ Locations]]\n \n\n local i = 0\n for j = 1 + (CurrentLocationPage - 1) * pageLines, pageLines +\n (CurrentLocationPage - 1) * pageLines, 1 do\n \n i = i + 1\n if j <= #locList and j>0 then\n screenOutput = screenOutput .. [[]] ..\n string.format(\"%s\", locList[j]) .. [[]]\n displayLocationList[i]=locList[j]\n --system.print(\"locList: \"..locList[j])\n --system.print(\"locDistList: \"..locDistList[locList[j]])\n screenOutput = screenOutput .. [[]] .. locDistList[locList[j]] .. \n [[]] \n else\n displayLocationList[i]=\"\"\n end\n end\n \n if #locList > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentLocationPage .. \" of \" ..\n math.ceil(#locList / 12) ..\n [[]]\n\n if CurrentLocationPage < math.ceil(#locList / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageDown\", {\n id = \"LocationPageDown\",\n x1 = 1070,\n x2 = 1270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageDown\")\n end\n\n if #locList > 1 and CurrentLocationPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageUp\", {\n id = \"LocationPageUp\",\n x1 = 1280,\n x2 = 1480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageUp\")\n end\n end\n \n screenOutput = screenOutput ..\n [[]] ..\n [[Load Saved Locations]]\n \n screenOutput = screenOutput ..\n [[]] ..\n [[Clear Saved Locations]]\n\n screenOutput = screenOutput .. [[]]\n\n DrawSVG(screenOutput)\n\n forceRedraw = false\nend\n\n-----------------------------------------------\n-- Execute\n-----------------------------------------------\n\nunit.hide()\nInitiateClickAreas()\nDrawPlanetList()\nunit.setTimer(\"refresh\",15.0)\n","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"8"},{"code":"function loadLocationTable ()\n\nlocationTable = {{}}\nlocationTable[1] = {\"Alioth Market 1\", \"::pos{0,2,30.3314,101.3106,122.9764}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 2\", \"::pos{0,2,24.4469,88.0409,238.3019}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 3\", \"::pos{0,2,34.9734,87.3012,176.2188}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 4\", \"::pos{0,2,28.3352,99.5187,165.9078}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 5\", \"::pos{0,2,33.3939,87.3299,277.1366}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 6\", \"::pos{0,2,36.0044,101.3503,220.0897}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 7\", \"::pos{0,2,22.5024,98.1449,232.5154}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 8\", \"::pos{0,2,21.2154,93.9616,251.0768}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 9\", \"::pos{0,2,28.7133,85.6389,260.7636}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 10\", \"::pos{0,2,35.9865,91.8393,190.1616}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 11\", \"::pos{0,2,-1.0735,178.5062,69.9428}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 12\", \"::pos{0,2,22.7112,-92.3078,166.8481}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 13\", \"::pos{0,2,-23.3768,-10.5455,178.8458}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 14\", \"::pos{0,2,-73.4716,101.3697,89.5661}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 15\", \"::pos{0,2,61.7831,27.8517,54.9186}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 16\", \"::pos{0,2,23.4406,114.4179,211.1991}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 17\", \"::pos{0,2,37.8637,64.1825,151.5507}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 18\", \"::pos{0,2,49.9360,-170.7565,62.1982}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 19\", \"::pos{0,2,-32.7357,76.3764,209.0805}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 20\", \"::pos{0,2,-35.1535,-95.1230,301.0724}\"}\n\nlocationTable[#locationTable+1] = {\"Madis Market 1\", \"::pos{0,1,2.6476,176.8761,813.0974}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 2\", \"::pos{0,1,10.3552,8.5146,816.2210}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 3\", \"::pos{0,1,-0.2107,82.0779,809.5571}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 4\", \"::pos{0,1,-80.6046,44.9385,822.6188}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 5\", \"::pos{0,1,81.0827,5.3022,823.1976}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 6\", \"::pos{0,1,13.9814,-91.6163,811.0679}\"}\n\nlocationTable[#locationTable+1] = {\"Thades M1: Market\", \"::pos{0,30,-2.9797,-117.7645,203.7519}\"}\nlocationTable[#locationTable+1] = {\"Feli: Market\", \"::pos{0,5,0.9348,178.6658,18417.2812}\"}\n\nlocationTable[#locationTable+1] = {\"Symeon Market 1\", \"::pos{0,110,3.1400,-174.0223,267.1084}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 2\", \"::pos{0,110,-0.9862,88.3038,197.0626}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 3\", \"::pos{0,110,18.1117,11.1108,180.8022}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 4\", \"::pos{0,110,-26.9701,103.3741,186.2557}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 5\", \"::pos{0,110,83.1653,108.7807,142.5796}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 6\", \"::pos{0,110,-79.3167,95.3975,138.5268}\"}\n\nlocationTable[#locationTable+1] = {\"TMV Troghelm\", \"::pos{0,0,2416521.6598,1415126.8118,59323.7340}\"}\nlocationTable[#locationTable+1] = {\"TMV Alioth Factory\", \"::pos{0,2,22.8158,111.1414,103.5685}\"}\nlocationTable[#locationTable+1] = {\"TMV Feli Outpost\", \"::pos{0,5,23.6988,-77.8811,18480.5176}\"}\nlocationTable[#locationTable+1] = {\"TMV Thandes M1 Outpost\", \"::pos{0,30,-22.3548,-168.7352,288.1909}\"}\nlocationTable[#locationTable+1] = {\"TMV Madis Outpost\", \"::pos{0,1,-43.0914,75.0728,749.6641}\"}\nlocationTable[#locationTable+1] = {\"TMV Symoen Outpost\", \"::pos{0,110,-5.3046,32.6900,108.4144}\"}\n\n\n\n\n\n\n\n \n\nend\n\n","filter":{"args":[],"signature":"start()","slotKey":"-2"},"key":"9"}],"methods":[],"events":[]} diff --git a/SatNav_PB_Paste_2_0_2 b/SatNav_PB_Paste_2_0_2 deleted file mode 100644 index caf17f4..0000000 --- a/SatNav_PB_Paste_2_0_2 +++ /dev/null @@ -1 +0,0 @@ -{"slots":{"0":{"name":"slot1","type":{"events":[],"methods":[]}},"1":{"name":"slot2","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"1"},"key":"0"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"3"},"key":"1"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"4"},"key":"2"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"5"},"key":"3"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"6"},"key":"4"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"7"},"key":"5"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"8"},"key":"6"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"9"},"key":"7"},{"code":"--[[\n SatNav version 2_0_2\n Created By TrogLaByte\n\n Discord: Trog#5105\n InGame: TrogLaByte\n \n GNU Public License 3.0. Use whatever you want, be so kind to leave credit.\n\n Thanks to Dorien Grey for his SVG and onscreen button code.\n]] \n-----------------------------------------------\n-- requirements\n-----------------------------------------------\n\nfunction initiateRequiredLibaries()\n json = require('dkjson')\n vec3 = require('cpml.vec3')\n utils = require('cpml.utils')\n planetRef = require('cpml.planetref')\n referenceTableSource = require('cpml.atlas')\n clamp = utils.clamp\nend\nif pcall(initiateRequiredLibaries) then\n system.print(\"Libaries loaded successfully\")\n else\n system.print(\"Libaries failed to load: check that the following libraries exist:\")\n system.print(\" /DualUniverse/Game/data/lua/dkjson\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/vec3\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/utils\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/planetref\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/atlas\")\n system.print(\"\")\n system.print(\"planetref.lua and atlas.lua can be obtained from the following GitLab url:\")\n system.print(\"https://gitlab.com/JayleBreak/dualuniverse/-/tree/master/DUflightfiles/autoconf/custom\")\n unit.exit()\nend\n-----------------------------------------------\n-- Global Variables\n-----------------------------------------------\n\nlocal UpdateInterval = 1 --export: Interval in seconds between updates of the calculations and (if anything changed) redrawing to the screen(s). You need to restart the script after changing this value.\nlocal BackgroundColor = \"#1e1e1e\"\nlocal PlanetBackgroundColor = \"#34b1eb\" --export Set the background color of the screens. YOU NEED TO LEAVE THE QUOTATION MARKS.\nlocal LocationBackgroundColor = \"#6e3de3\" --export Set the background color of the screens. YOU NEED TO LEAVE THE QUOTATION MARKS.\nlocal clickAreas = {}\nlocal locList={}\nlocal lastPlanetSelected = \"Alioth\"\nlocal pageLines=12\nlocal displayPlanetList={}\nlocal displayLocationList={}\nlocal CurrentLocationPage = 1\nlocal CurrentPlanetPage = 1\nlocal HUD = \"unknown\"\n\n-----------------------------------------------\n-- initiate slots to know names\n-----------------------------------------------\n\nfunction InitiateSlots()\n for slot_name, slot in pairs(unit) do\n if type(slot) == \"table\" and type(slot.export) == \"table\" and\n slot.getElementClass then\n --system.print(slot.getElementClass())\n if slot.getElementClass():lower():find(\"coreunit\") then\n core = slot\n --system.print(\"found core\")\n end\n if slot.getElementClass():lower():find(\"screenunit\") then\n screen = slot\n --system.print(\"found screen\")\n end\n if slot.getElementClass():lower():find(\"databankunit\") then\n myDatabank = slot\n --system.print(\"found databank\")\n if myDatabank.getStringValue(\"AutopilotTargetIndex\")~= nil then\n HUD = \"Dimencia\"\n else\n HUD = \"unknown\"\n end\n end\n end\n end\nend\nInitiateSlots()\n\n-----------------------------------------------\n-- set up galaxy data and functions for planets and locations\n-----------------------------------------------\n\ngalaxyReference = planetRef(referenceTableSource)\nhelios = galaxyReference[0] -- PlanetaryReference.PlanetarySystem instance\nplanetList={}\nplanetDistList={}\nlocDistList={}\njdecode = json.decode\njencode = json.encode\n\nfunction getBodyId(planetName)\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n if string.lower(helios[tonumber(i)].name) ==string.lower(planetName) then\n return i\n end\n end\n end\n return 0\nend\n\nfunction buildPlanetList()\n local planet={}\n local currentLoc = vec3(core.getConstructWorldPos())\n local shipMass = core.getConstructMass()\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n planet = helios[tonumber(i)]\n planetList[#planetList+1] = planet.name\n local planetDistance = planet:getDistance(currentLoc)\n planetDistList[planet.name] = formatDistance(planetDistance) .. \n string.format(\" [%.0f wc]\", ((planetDistance/200000)*(shipMass/1000)/4000))\n end\n end\n planetList[#planetList+1]=\"Space\"\n table.sort(planetList)\nend\n\nfunction formatDistance(distance)\n if distance < 200000 then\n return string.format(\"%.0f km\",distance/1000)\n elseif distance < 4000000 then\n return string.format(\"%.2f su\",distance/200000)\n else\n return string.format(\"%.0f su\",distance/200000)\n end\nend\n\n\nfunction buildPlanetLocList(planetName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local currentLoc = vec3(core.getConstructWorldPos())\n local shipMass = core.getConstructMass()\n local planet={}\n locList={}\n if planetName ~= \"Space\" then\n table.insert(locList, planetName) -- add planet name into the list as a default\n locDistList[planetName] = planetDistList[planetName]\n end\n if savedLocation ~= nil and savedLocations ~= \"\" then \n local result = jdecode(savedLocation)\n if result ~= nil then\n for k, v in pairs(result) do\n local location = v[\"position\"]\n if string.lower(v[\"planetname\"]) == string.lower(planetName) or\n string.find(string.lower(v[\"planetname\"]),string.lower(planetName))\n then\n table.insert(locList, v[\"name\"])\n elseif v[\"planetname\"] == \"\" and planetName == \"Space\" then -- a space location\n table.insert(locList, v[\"name\"])\n end\n local locDistance = (currentLoc - vec3(location[\"x\"],location[\"y\"],location[\"z\"])):len()\n if planetName == \"Space\" then\n locDistList[v[\"name\"]] = formatDistance(locDistance) ..\n string.format(\" [%.0f wc]\", ((locDistance/200000)*(shipMass/1000)/4000))\n else\n locDistList[v[\"name\"]] = formatDistance(locDistance)\n end\n\n\n end\n end\n end\n table.sort(locList)\nend\n\nfunction printLocMapPos(locationName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\") \n local planet={}\n if savedLocation ~= nil and savedLocations ~= \"\" then \n --system.print(savedLocation)\n local result = jdecode(savedLocation)\n if result ~= nil then\n for k, v in pairs(result) do\n if string.lower(v[\"name\"]) == string.lower(locationName) then\n local location = v[\"position\"]\n local bodyId = getBodyId(v[\"planetname\"])\n planet = helios[tonumber(bodyId)] \n if planet ~= nil then\n worldCoords = planet:convertToMapPosition(vec3(location[\"x\"],location[\"y\"],location[\"z\"]))\n\n system.print(string.format([[\"%s\" @ ::pos{%d,%d,%f,%f,%f}]],\n v[\"name\"],\n worldCoords.systemId,\n worldCoords.bodyId,\n worldCoords.latitude*constants.rad2deg,\n worldCoords.longitude*constants.rad2deg,\n worldCoords.altitude))\n return locationName\n else\n system.print(string.format([[\"%s\" @ ::pos{%d,%d,%f,%f,%f}]],\n v[\"name\"],\n 0,\n bodyId,\n location[\"x\"],\n location[\"y\"],\n location[\"z\"]))\n return locationName\n end\n break\n end\n end \n end\n end\n return \"\"\nend\n\nfunction clearSavedLocations()\n myDatabank.setStringValue(\"SavedLocations\",\"[]\")\n system.print(\"Databank cleared\")\nend\n\nfunction isDuplicateLocation(locName, savedLocations)\n for i=1,#savedLocations do\n if savedLocations and savedLocations[i].name ~= nil then\n if savedLocations[i].name == locName then\n return locName\n end\n end\n end\n return \"\"\nend\n\nfunction loadPointsOfInterest()\n local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)'\n local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' ..\n num .. ',' .. num .. '}'\n local savedLocation = {}\n local j=0\n loadLocationTable()\n savedLocation = jdecode(myDatabank.getStringValue(\"SavedLocations\"))\n \n for i = 1, #locationTable do\n local newLoc={}\n local planet={}\n if isDuplicateLocation(locationTable[i][1],savedLocation) == \"\" then\n newLoc[\"name\"]=locationTable[i][1]\n local newLocPos = locationTable[i][2]\n --system.print(\"Name: \"..locationTable[i][1]..\" \"..newLocPos)\n local systemId, bodyId, latitude, longitude, altitude =\n string.match(locationTable[i][2], posPattern)\n --system.print(\"BodyId: \".. bodyId)\n if tonumber(bodyId) > 0 then\n planet = helios[tonumber(bodyId)] \n local worldCoords = planet:convertToWorldCoordinates(newLocPos)\n newLoc[\"position\"]=worldCoords\n newLoc[\"gravity\"]=unit.getClosestPlanetInfluence()\n newLoc[\"atmosphere\"]=unit.getAtmosphereDensity()\n newLoc[\"planetname\"]=planet.name\n else -- it is a space location\n newLoc[\"position\"]=vec3(tonumber(latitude), tonumber(longitude), tonumber(altitude))\n newLoc[\"gravity\"]=0\n newLoc[\"atmosphere\"]=0\n newLoc[\"planetname\"]=\"\"\n end\n \n if savedLocation == nil then\n savedLocation = {}\n savedLocation[1]=newLoc\n j = 1\n else\n j = j + 1\n savedLocation[#savedLocation+1]=newLoc\n end\n else\n system.print(\"Duplicate entry for location ignored: \"..locationTable[i][1])\n end\n end\n myDatabank.setStringValue(\"SavedLocations\",jencode(savedLocation))\n system.print(j .. \" Saved Locations loaded\")\nend\n\nbuildPlanetList()\nbuildPlanetLocList(lastPlanetSelected)\nlocal planetCount=#planetList\n\n-----------------------------------------------\n-- Code for on screen buttons\n-----------------------------------------------\n\nfunction DrawSVG(output) screen.setSVG(output) end\n\nfunction AddClickArea(newEntry) table.insert(clickAreas, newEntry) end\n\nfunction RemoveFromClickAreas(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = nil\n break\n end\n end\nend\n\nfunction UpdateClickArea(candidate, newEntry)\n --system.print(\"Candidate: \"..candidate..\" x1\"..newEntry.x1)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = newEntry\n --system.print(\"Click Area: \"..candidate..\" x1\"..clickAreas[k].x1)\n break\n end\n end\nend\n\nfunction DisableClickArea(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n UpdateClickArea(candidate, {\n id = candidate,\n x1 = -1,\n x2 = -1,\n y1 = -1,\n y2 = -1\n })\n break\n end\n end\nend\n\nfunction InitiateClickAreas()\n clickAreas = {}\n \n AddClickArea({id = \"LoadSavedLocations\", x1 = 300, x2 = 800, y1 = 900, y2 = 1000})\n AddClickArea({id = \"ClearSavedLocations\", x1 = 1200, x2 = 1700, y1 = 900, y2 = 1000})\n AddClickArea({id = \"PlanetPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"PlanetPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n \n for i = 1, pageLines do\n AddClickArea({id = string.format(\"PList%d\",i), x1 = 90, x2 = 800, y1 = (180 + i * 55), y2 = (235 + i * 55)})\n AddClickArea({id = string.format(\"LList%d\",i), x1 = 1090, x2 = 1500, y1 = (180 + i * 55), y2 = (235 + i * 55)})\n end\nend\n\nfunction FlushClickAreas() clickAreas = {} end\n\nfunction clearLocDispList()\n for i=1,pageLines do\n displayLocationList[i] = \"\"\n end\nend\n\nfunction CheckClick(x, y, HitTarget)\n HitTarget = HitTarget or \"\"\n if HitTarget == \"\" then\n for k, v in pairs(clickAreas) do\n if v and x >= v.x1 and x <= v.x2 and y >= v.y1 and y <= v.y2 then\n HitTarget = v.id\n break\n end\n end\n end\n \n --system.print(\"Target Hit = \"..HitTarget)\n \n if HitTarget == \"PlanetPageDown\" then\n CurrentPlanetPage = CurrentPlanetPage+1\n DrawPlanetList()\n elseif HitTarget == \"PlanetPageUp\" then\n CurrentPlanetPage = math.max(CurrentPlanetPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LocationPageDown\" then\n CurrentLocationPage = CurrentLocationPage+1\n DrawPlanetList()\n elseif HitTarget == \"LocationPageUp\" then\n CurrentLocationPage = math.max(CurrentLocationPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LoadSavedLocations\" then\n --system.print(\"LoadSavedLocations\")\n loadPointsOfInterest()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n elseif HitTarget == \"ClearSavedLocations\" then\n --system.print(\"ClearSavedLocations\")\n clearSavedLocations()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n else\n for i = 1,pageLines do\n if HitTarget == string.format(\"PList%s\",i) then\n --system.print(\"PHitTarget: \"..HitTarget)\n if displayPlanetList[i] ~= \"\" then\n lastPlanetSelected = displayPlanetList[i]\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n DrawPlanetList()\n end\n end\n if HitTarget == string.format(\"LList%s\",i) then\n if displayLocationList[i] ~= \"\" then\n selected = displayLocationList[i]\n if printLocMapPos(selected) == \"\" then\n system.print(\"Location: \"..selected..\" sent to Hud\")\n myDatabank.setStringValue(\"SPBAutopilotTargetName\",selected)\n else\n myDatabank.setStringValue(\"SPBAutopilotTargetName\",selected)\n end\n end\n end\n end\n end\nend\n\n-----------------------------------------------\n-- Code for building screen content and displaying it\n-----------------------------------------------\n\nlocal svgBootstrap = [[\n ]]\n\nfunction DrawPlanetList()\n local healthyColor = \"#00aa00\"\n local brokenColor = \"#aa0000\"\n local damagedColor = \"#aaaa00\"\n local integrityColor = \"#aaaaaa\"\n local healthyTextColor = \"white\"\n local brokenTextColor = \"#ff4444\"\n local damagedTextColor = \"#ffff44\"\n local integrityTextColor = \"white\"\n \n\n local screenOutput = \"\"\n\n -- Draw Header\n screenOutput = screenOutput .. svgBootstrap\n \n -- Draw main background\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[Sat Nav]]\n if HUD == \"Dimencia\" then\n screenOutput = screenOutput ..\n [[(Dimencia HUD enabled)]]\n else \n screenOutput = screenOutput ..\n [[(Standalone mode enabled)]]\n end\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[Planets]]\n \n\n local i = 0\n for j = 1 + (CurrentPlanetPage - 1) * pageLines, pageLines +\n (CurrentPlanetPage - 1) * pageLines, 1 do\n i = i + 1\n if j < #planetList and j>0 then\n local planetName = planetList[j]\n if lastPlanetSelected == planetList[j] then\n screenOutput = screenOutput .. [[]] .. planetName .. \n [[]]\n else\n screenOutput = screenOutput .. [[]] .. planetName .. \n [[]]\n end\n if planetName ~= \"Space\" then\n screenOutput = screenOutput .. [[]] .. planetDistList[planetName] .. \n [[]] \n end\n displayPlanetList[i]=planetList[j]\n else\n displayPlanetList[i]=\"\"\n end\n end\n \n if planetCount > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentPlanetPage .. \" of \" ..\n math.ceil(planetCount / 12) ..\n [[]]\n\n if CurrentPlanetPage < math.ceil(planetCount / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageDown\", {\n id = \"PlanetPageDown\",\n x1 = 70,\n x2 = 270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageDown\")\n end\n\n if planetCount > 1 and CurrentPlanetPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageUp\", {\n id = \"PlanetPageUp\",\n x1 = 280,\n x2 = 480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageUp\")\n end\n end\n -- Start of Location List\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[]].. lastPlanetSelected ..[[ Locations]]\n \n\n local i = 0\n for j = 1 + (CurrentLocationPage - 1) * pageLines, pageLines +\n (CurrentLocationPage - 1) * pageLines, 1 do\n \n i = i + 1\n if j <= #locList and j>0 then\n screenOutput = screenOutput .. [[]] ..\n string.format(\"%s\", locList[j]) .. [[]]\n displayLocationList[i]=locList[j]\n --system.print(\"locList: \"..locList[j])\n --system.print(\"locDistList: \"..locDistList[locList[j]])\n screenOutput = screenOutput .. [[]] .. locDistList[locList[j]] .. \n [[]] \n else\n displayLocationList[i]=\"\"\n end\n end\n \n if #locList > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentLocationPage .. \" of \" ..\n math.ceil(#locList / 12) ..\n [[]]\n\n if CurrentLocationPage < math.ceil(#locList / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageDown\", {\n id = \"LocationPageDown\",\n x1 = 1070,\n x2 = 1270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageDown\")\n end\n\n if #locList > 1 and CurrentLocationPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageUp\", {\n id = \"LocationPageUp\",\n x1 = 1280,\n x2 = 1480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageUp\")\n end\n end\n \n screenOutput = screenOutput ..\n [[]] ..\n [[Load Saved Locations]]\n \n screenOutput = screenOutput ..\n [[]] ..\n [[Clear Saved Locations]]\n\n screenOutput = screenOutput .. [[]]\n\n DrawSVG(screenOutput)\n\n forceRedraw = false\nend\n\n-----------------------------------------------\n-- Execute\n-----------------------------------------------\n\nunit.hide()\nInitiateClickAreas()\nDrawPlanetList()\nsystem.print(\"Running\")\nunit.setTimer(\"loadwp\",1)\n--unit.setTimer(\"refresh\",15.0)\n","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"8"},{"code":"function loadLocationTable ()\n\nlocationTable = {{}}\nlocationTable[1] = {\"Alioth Market 1\", \"::pos{0,2,30.3314,101.3106,122.9764}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 2\", \"::pos{0,2,24.4469,88.0409,238.3019}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 3\", \"::pos{0,2,34.9734,87.3012,176.2188}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 4\", \"::pos{0,2,28.3352,99.5187,165.9078}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 5\", \"::pos{0,2,33.3939,87.3299,277.1366}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 6\", \"::pos{0,2,36.0044,101.3503,220.0897}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 7\", \"::pos{0,2,22.5024,98.1449,232.5154}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 8\", \"::pos{0,2,21.2154,93.9616,251.0768}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 9\", \"::pos{0,2,28.7133,85.6389,260.7636}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 10\", \"::pos{0,2,35.9865,91.8393,190.1616}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 11\", \"::pos{0,2,-1.0735,178.5062,69.9428}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 12\", \"::pos{0,2,22.7112,-92.3078,166.8481}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 13\", \"::pos{0,2,-23.3768,-10.5455,178.8458}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 14\", \"::pos{0,2,-73.4716,101.3697,89.5661}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 15\", \"::pos{0,2,61.7831,27.8517,54.9186}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 16\", \"::pos{0,2,23.4406,114.4179,211.1991}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 17\", \"::pos{0,2,37.8637,64.1825,151.5507}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 18\", \"::pos{0,2,49.9360,-170.7565,62.1982}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 19\", \"::pos{0,2,-32.7357,76.3764,209.0805}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 20\", \"::pos{0,2,-35.1535,-95.1230,301.0724}\"} \n \nlocationTable[#locationTable+1] = {\"Madis Market 1\", \"::pos{0,1,2.6476,176.8761,813.0974}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 2\", \"::pos{0,1,10.3552,8.5146,816.2210}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 3\", \"::pos{0,1,-0.2107,82.0779,809.5571}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 4\", \"::pos{0,1,-80.6046,44.9385,822.6188}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 5\", \"::pos{0,1,81.0827,5.3022,823.1976}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 6\", \"::pos{0,1,13.9814,-91.6163,811.0679}\"}\n\nlocationTable[#locationTable+1] = {\"Thades M1: Market\", \"::pos{0,30,-2.9797,-117.7645,203.7519}\"}\nlocationTable[#locationTable+1] = {\"Feli: Market\", \"::pos{0,5,0.9348,178.6658,18417.2812}\"}\n\nlocationTable[#locationTable+1] = {\"Symeon Market 1\", \"::pos{0,110,3.1400,-174.0223,267.1084}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 2\", \"::pos{0,110,-0.9862,88.3038,197.0626}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 3\", \"::pos{0,110,18.1117,11.1108,180.8022}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 4\", \"::pos{0,110,-26.9701,103.3741,186.2557}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 5\", \"::pos{0,110,83.1653,108.7807,142.5796}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 6\", \"::pos{0,110,-79.3167,95.3975,138.5268}\"}\n\nlocationTable[#locationTable+1] = {\"TMV Troghelm\", \"::pos{0,0,2416521.6598,1415126.8118,59323.7340}\"}\nlocationTable[#locationTable+1] = {\"TMV Alioth Factory\", \"::pos{0,2,22.8158,111.1414,103.5685}\"}\nlocationTable[#locationTable+1] = {\"TMV Feli Outpost\", \"::pos{0,5,23.6988,-77.8811,18480.5176}\"}\nlocationTable[#locationTable+1] = {\"TMV Thandes M1 Outpost\", \"::pos{0,30,-22.3548,-168.7352,288.1909}\"}\nlocationTable[#locationTable+1] = {\"TMV Madis Outpost\", \"::pos{0,1,-43.0914,75.0728,749.6641}\"}\nlocationTable[#locationTable+1] = {\"TMV Symoen Outpost\", \"::pos{0,110,-5.3046,32.6900,108.4144}\"}\nlocationTable[#locationTable+1] = {\"TMV Jago Outpost\", \"::pos{0,9,61.3760,-33.7830,10.7593}\"}\n\nend\n\nunit.stopTimer(\"loadwp\")\nloadLocationTable()\n\n\n","filter":{"args":[{"value":"loadwp"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"9"}],"methods":[],"events":[]} diff --git a/SatNav_PB_Paste_2_1_0 b/SatNav_PB_Paste_2_1_0 deleted file mode 100644 index af13287..0000000 --- a/SatNav_PB_Paste_2_1_0 +++ /dev/null @@ -1 +0,0 @@ -{"slots":{"0":{"name":"core","type":{"events":[],"methods":[]}},"1":{"name":"screen","type":{"events":[],"methods":[]}},"2":{"name":"satnavDB","type":{"events":[],"methods":[]}},"3":{"name":"dbHud","type":{"events":[],"methods":[]}},"4":{"name":"dupSatnavDB","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"1"},"key":"0"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"5"},"key":"1"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"6"},"key":"2"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"7"},"key":"3"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"8"},"key":"4"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"9"},"key":"5"},{"code":"--[[\n SatNav version 2_1_0\n Created By TrogLaByte\n\n Discord: Trog#5105\n InGame: TrogLaByte\n \n GNU Public License 3.0. Use whatever you want, be so kind to leave credit.\n\n Thanks to Dorien Grey for his SVG and onscreen button code.\n]] \n-----------------------------------------------\n-- requirements\n-----------------------------------------------\n\nfunction initiateRequiredLibaries()\n vec3 = require('cpml.vec3')\n utils = require('cpml.utils')\n planetRef = require('cpml.planetref')\n referenceTableSource = require('cpml.atlas')\n clamp = utils.clamp\nend\nif pcall(initiateRequiredLibaries) then\n system.print(\"Libaries loaded successfully\")\n else\n system.print(\"Libaries failed to load: check that the following libraries exist:\")\n system.print(\" /DualUniverse/Game/data/lua/dkjson\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/vec3\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/utils\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/planetref\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/atlas\")\n system.print(\"\")\n system.print(\"planetref.lua and atlas.lua can be obtained from the following GitLab url:\")\n system.print(\"https://gitlab.com/JayleBreak/dualuniverse/-/tree/master/DUflightfiles/autoconf/custom\")\n unit.exit()\nend\n-----------------------------------------------\n-- Global Variables\n-----------------------------------------------\n\nlocal version = \"2_1_0\"\n\nlocal UpdateInterval = 1 \nlocal defaultNewLocName = \"SatNav Location\" --export: default name used for new locations\nlocal BackgroundColor = \"#1e1e1e\" --export: Set the background color of the screens. YOU NEED TO LEAVE THE QUOTATION MARKS.\nlocal PlanetBackgroundColor = \"#34b1eb\" --export: Set the background color of the screens. YOU NEED TO LEAVE THE QUOTATION MARKS.\nlocal LocationBackgroundColor = \"#6e3de3\" --export: Set the background color of the screens. YOU NEED TO LEAVE THE QUOTATION MARKS.\nlocal lastPlanetSelected = \"Alioth\" --export: The default start planet for displaying locations\n\nlocal clickAreas = {}\nlocal locList={}\npageLines=12\ndisplayPlanetList={}\ndisplayLocationList={}\nCurrentLocationPage = 1\nCurrentPlanetPage = 1\nif dbHud and dbHud.getIntValue(\"AutopilotTargetIndex\")>0 then\n system.print(\"Dimencia Hud Identified\")\n HUD = \"Dimencia\"\nelse\n system.print(\"No Dimencia Hud Identified\")\n HUD = \"unknown\"\nend\n\nmyDatabank = satnavDB\n\n-----------------------------------------------\n-- set up galaxy data and functions for planets and locations\n-----------------------------------------------\n\ngalaxyReference = planetRef(referenceTableSource)\nhelios = galaxyReference[0] -- PlanetaryReference.PlanetarySystem instance\nplanetList={}\nplanetDistList={}\nlocDistList={}\n\nfunction getBodyId(planetName)\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n if string.lower(helios[tonumber(i)].name) ==string.lower(planetName) then\n return i\n end\n end\n end\n return 0\nend\n\nfunction buildPlanetList()\n local planet={}\n local currentLoc = vec3(core.getConstructWorldPos())\n local shipMass = core.getConstructMass()\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n planet = helios[tonumber(i)]\n planetList[#planetList+1] = planet.name\n local planetDistance = planet:getDistance(currentLoc)\n planetDistList[planet.name] = formatDistance(planetDistance) .. \n string.format(\" [%.0f wc]\", ((planetDistance/200000)*(shipMass/1000)/4000))\n end\n end\n planetList[#planetList+1]=\"Space\"\n table.sort(planetList)\nend\n\nfunction formatDistance(distance)\n if distance < 200000 then\n return string.format(\"%.0f km\",distance/1000)\n elseif distance < 4000000 then\n return string.format(\"%.2f su\",distance/200000)\n else\n return string.format(\"%.0f su\",distance/200000)\n end\nend\n\n-- json parser\n\n-- Extracts values from a JSON string with pattern matching\n-- This is faster than using dkjson when only a few fields are needed\n\n-- Use this only with trusted data sources! Limitations:\n-- * Character escapes are not supported\n-- * Field nesting is ignored\n\nlocal find, gsub = string.find, string.gsub\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return string|nil, number|nil, number|nil\nlocal function extractStringJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*\"([^\"]*)\"]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n return valueStr, startIndex, endIndex\nend\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return number|nil, number|nil, number|nil\nlocal function extractNumberJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*(-?[0-9.e-]+)]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n return tonumber(valueStr), startIndex, endIndex\nend\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return boolean|nil, number|nil, number|nil\nlocal function extractBooleanJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*([truefals]+)]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n\n if valueStr == \"true\" then\n return true, startIndex, endIndex\n elseif valueStr == \"false\" then\n return false, startIndex, endIndex\n else\n return nil\n end\nend\n\n---@param extractJsonValue function\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue any|nil\n---@return any[]\nlocal function extractAllJsonValues (extractJsonValue, json, key, stopAfterIndex, stopAfterValue)\n local values = {}\n local valuesLen = 0\n\n local jsonPos = 1\n local value, valueStartIndex, valueEndIndex -- luacheck: ignore valueStartIndex -- unused\n\n repeat\n value, valueStartIndex, valueEndIndex = extractJsonValue(json, key, jsonPos)\n\n if value ~= nil then\n valuesLen = valuesLen + 1\n values[valuesLen] = value\n\n jsonPos = valueEndIndex + 1\n end\n\n if value == stopAfterValue then break end\n if valuesLen == stopAfterIndex then break end\n until value == nil\n\n return values\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue string|nil\n---@return string[]\nlocal function extractAllStringJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractStringJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue number|nil\n---@return number[]\nlocal function extractAllNumberJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractNumberJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue boolean|nil\n---@return boolean[]\nlocal function extractAllBooleanJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractBooleanJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n-- end json Parser\n\n\nfunction buildPlanetLocList(planetName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n \n local currentLoc = vec3(core.getConstructWorldPos())\n local shipMass = core.getConstructMass()\n local planet={}\n locList={}\n if planetName ~= \"Space\" then\n table.insert(locList, planetName) -- add planet name into the list as a default\n locDistList[planetName] = planetDistList[planetName]\n end\n if #name > 0 then \n for i=1,#name do\n if string.lower(planetname[i]) == string.lower(planetName) or\n string.find(string.lower(planetname[i]),string.lower(planetName))\n then\n table.insert(locList, name[i])\n elseif planetname[i] == \"\" and planetName == \"Space\" then -- a space location\n table.insert(locList, name[i])\n end\n local locDistance = (currentLoc - vec3(posX[i],posY[i],posZ[i])):len()\n if planetName == \"Space\" then\n locDistList[name[i]] = formatDistance(locDistance) ..\n string.format(\" [%.0f wc]\", ((locDistance/200000)*(shipMass/1000)/4000))\n else\n locDistList[name[i]] = formatDistance(locDistance)\n end\n end\n end\n table.sort(locList)\nend\n\nfunction printLocMapPos(locationName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local wayPoint=\"\"\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n local planet={}\n if #name > 0 then \n for i = 1, #name do\n if string.lower(name[i]) == string.lower(locationName) then\n local bodyId = getBodyId(planetname[i])\n planet = helios[tonumber(bodyId)] \n if planet ~= nil then\n worldCoords = planet:convertToMapPosition(vec3(posX[i],posY[i],posZ[i]))\n wayPoint=string.format([[::pos{%d,%d,%f,%f,%f}]],\n worldCoords.systemId,\n worldCoords.bodyId,\n worldCoords.latitude*constants.rad2deg,\n worldCoords.longitude*constants.rad2deg,\n worldCoords.altitude)\n system.print(name[i]..\" @ \"..wayPoint)\n system.setWaypoint(wayPoint)\n return locationName,\n planetname[i],\n atmosphere[i],\n gravity[i],\n posX[i],\n posY[i],\n posZ[i]\n else\n wayPoint=string.format([[::pos{%d,%d,%f,%f,%f}]],\n 0,\n bodyId,\n posX[i],posY[i],posZ[i])\n system.print(name[i]..\" @ \"..wayPoint)\n system.setWaypoint(wayPoint)\n return locationName,\n planetname[i],\n atmosphere[i],\n gravity[i],\n posX[i],\n posY[i],\n posZ[i]\n end\n break\n end \n end\n end\n return \"\"\nend\n\nfunction clearSavedLocations()\n myDatabank.setStringValue(\"SavedLocations\",\"[]\")\n system.print(\"Satnav Databank cleared\")\nend\n\nfunction isDuplicateLocation(locName, locNameList)\n for i=1,#locNameList do\n if locNameList[i] == locName then\n return locName\n end\n end\n return \"\"\nend\n\nfunction saveSavedLocations (name, planetname, atmosphere, gravity, posX, posY, posZ)\n local newSavedLocations = \"[\"\n for i = 1, #name do\n if name[i]~=\"\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..name[i]..\n [[\",\"planetname\":\"]]..planetname[i]..[[\"]]..\n [[,\"atmosphere\":]]..atmosphere[i]..\n [[,\"gravity\":]]..gravity[i]..\n [[,\"position\":{\"x\":]]..posX[i]..\n [[,\"y\":]]..posY[i]..\n [[,\"z\":]]..posZ[i]..[[}}]]\n end\n if i+1<#name then\n newSavedLocations= newSavedLocations..\",\"\n end\n end\n newSavedLocations= newSavedLocations..\"]\" \n --system.print(newSavedLocations)\n myDatabank.setStringValue(\"SavedLocations\",newSavedLocations)\n system.print(\"Satnav Databank Updated\")\nend\n\nfunction updateLocationName(newLocName)\n if newLocName ~= nil and newLocName ~= \"\" and \n lastLocationSelected ~= nil and lastLocationSelected ~= \"\" then\n system.print(\"Updating location name for: \"..lastLocationSelected..\" to: \"..newLocName)\n else\n system.print(\"Invalid update request\")\n return\n end\n local savedLocation = {}\n local oldLocFound = false\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n for i = 1, #name do\n if name[i] == lastLocationSelected then\n --system.print(\"Found: \"..lastLocationSelected)\n name[i] = newLocName\n oldLocFound = true\n break\n end\n end\n \n if oldLocFound then \n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n else\n system.print(\"Old Location Name Not Found\")\n end\nend\n\nfunction deleteLocationName(delLocName)\n if delLocName ~= nil and delLocName ~= \"\" then\n system.print(\"Deleting location name: \"..delLocName)\n else\n system.print(\"Invalid update request\")\n return\n end\n local savedLocation = {}\n local oldLocFound = false\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n for i = 1, #name do\n if name[i] == delLocName then\n --system.print(\"Found: \"..delLocName)\n name[i] = \"\"\n oldLocFound = true\n break\n end\n end\n \n if oldLocFound then \n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n else\n system.print(\"Location Name Not Found\")\n end\nend\n\nfunction loadPointsOfInterest()\n -- get existing locations from SatNav Databank\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n\n\n local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)'\n local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' ..\n num .. ',' .. num .. '}'\n local j=0\n loadLocationTable()\n \n for i = 1, #locationTable do\n local newRef = #name + 1\n if isDuplicateLocation(locationTable[i][1],name) == \"\" then\n name[newRef]=locationTable[i][1]\n local newLocPos = locationTable[i][2]\n --system.print(\"Name: \"..locationTable[i][1]..\" \"..newLocPos)\n local systemId, bodyId, latitude, longitude, altitude =\n string.match(locationTable[i][2], posPattern)\n --system.print(\"BodyId: \".. bodyId)\n if tonumber(bodyId) > 0 then\n local planet = helios[tonumber(bodyId)] \n local worldCoords = planet:convertToWorldCoordinates(newLocPos)\n posX[newRef]=worldCoords[\"x\"]\n posY[newRef]=worldCoords[\"y\"]\n posZ[newRef]=worldCoords[\"z\"]\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=planet.name\n else -- it is a space location\n posX[newRef]=latitude\n posY[newRef]=longitude\n posZ[newRef]=altitude\n gravity[newRef]=0\n atmosphere[newRef]=0\n planetname[newRef]=\"\"\n end \n else\n system.print(\"Duplicate entry for location ignored: \"..locationTable[i][1])\n end\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n --system.print(\"Default SatNav locations loaded\")\nend\n\nfunction loadHudLocations()\n -- get existing locations from SatNav Databank\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n\n local hudLocation = dbHud.getStringValue(\"SavedLocations\")\n local hudatmosphere={}\n local hudgravity={}\n local hudplanetname = {}\n local hudposX\t = {}\n local hudposY\t = {}\n local hudposZ\t = {}\n local hudname\t = {}\n\n hudatmosphere = extractAllNumberJsonValues(hudLocation,\"atmosphere\")\n hudgravity = extractAllNumberJsonValues(hudLocation,\"gravity\")\n hudplanetname = extractAllStringJsonValues(hudLocation,\"planetname\")\n hudposX\t = extractAllNumberJsonValues(hudLocation,\"x\")\n hudposY\t = extractAllNumberJsonValues(hudLocation,\"y\")\n hudposZ\t = extractAllNumberJsonValues(hudLocation,\"z\")\n hudname\t = extractAllStringJsonValues(hudLocation,\"name\")\n\n\n for i = 1, #hudname do\n local newRef = #name + 1\n system.print(\"HudName: \"..hudname[i])\n if isDuplicateLocation(hudname[i],name) == \"\" and\n hudname[i] ~= \"SatNav Location\" then\n name[newRef]=hudname[i]\n posX[newRef]=hudposX[i]\n posY[newRef]=hudposY[i]\n posZ[newRef]=hudposZ[i]\n gravity[newRef]=hudgravity[i]\n atmosphere[newRef]=hudatmosphere[i]\n planetname[newRef]=hudplanetname[i] \n else\n system.print(\"Duplicate entry for location ignored: \"..hudname[i])\n end\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n --system.print(\"Default SatNav locations loaded\")\nend\n\n\nfunction newLocation ()\n local location = system.getWaypointFromPlayerPos()\n local newLocId = satnavDB.getIntValue(\"lastNewLoc\") + 1\n satnavDB.setIntValue(\"lastNewLoc\",newLocId)\n \n local newLocName = defaultNewLocName..\" (\"..newLocId..\")\"\n \n local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)'\n local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' ..\n num .. ',' .. num .. '}'\n \n local savedLocation = {}\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n \n local systemId, bodyId, latitude, longitude, altitude =\n string.match(location, posPattern)\n local worldPos = unit.getMasterPlayerRelativePosition()\n local body = helios:closestBody(worldPos)\n local bodyId = getBodyId(body.name)\n --system.print(\"BodyId: \".. bodyId)\n if tonumber(bodyId) > 0 then\n local planet = helios[tonumber(bodyId)] -- PlanetaryReference.BodyParameters instance\n --system.print(\"Planet BodyId: \".. planet.bodyId)\n local worldCoords = planet:convertToWorldCoordinates(location)\n newRef = #name + 1\n name[newRef]=newLocName\n posX[newRef]=worldCoords[\"x\"]\n posY[newRef]=worldCoords[\"y\"]\n posZ[newRef]=worldCoords[\"z\"]\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=body.name\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n system.print(\"New location: \"..newLocName..\" added to SatNav databank\")\nend\n\nfunction copySelectedToHud (locName)\n \n local locName, locplanetname, locatmosphere, locgravity, locX, locY, locZ = \n printLocMapPos(locName)\n if HUD == \"Dimencia\" then\n savedLocation = dbHud.getStringValue(\"SavedLocations\")\n --system.print(\"savedLocation=\"..savedLocation)\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n local newSavedLocations = \"[\"\n for i = 1, #name do\n if name[i] ~= \"SatNav Location\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..name[i]..\n [[\",\"planetname\":\"]]..planetname[i]..[[\"]]..\n [[,\"atmosphere\":]]..atmosphere[i]..\n [[,\"gravity\":]]..gravity[i]..\n [[,\"position\":{\"x\":]]..posX[i]..\n [[,\"y\":]]..posY[i]..\n [[,\"z\":]]..posZ[i]..[[}},]]\n end\n end\n if locplanetname ~= \"\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..\"SatNav Location\"..\n [[\",\"planetname\":\"]]..locplanetname..[[\"]]..\n [[,\"atmosphere\":]]..locatmosphere..\n [[,\"gravity\":]]..locgravity..\n [[,\"position\":{\"x\":]]..locX..\n [[,\"y\":]]..locY..\n [[,\"z\":]]..locZ..[[}}]]\n end\n newSavedLocations= newSavedLocations..\"]\" \n dbHud.setStringValue(\"SavedLocations\",newSavedLocations)\n dbHud.setStringValue(\"SPBAutopilotTargetName\",\"SatNav Location\")\n end\nend\n\nfunction clearHudLocations()\n if HUD == \"Dimencia\" then\n dbHud.setStringValue(\"SavedLocations\",\"[]\")\n dbHud.setStringValue(\"SPBAutopilotTargetName\",\"\")\n system.print(\"Dimencia HUD Saved Locations Cleared\")\n end\nend\n\nfunction duplicateSatnavDB()\n local satnavLocation = myDatabank.getStringValue(\"SavedLocations\")\n local lastNewLoc = myDatabank.getIntValue(\"lastNewLoc\")\n dupSatnavDB.clear()\n dupSatnavDB.setStringValue(\"SavedLocations\",satnavLocation)\n dupSatnavDB.setIntValue(\"lastNewLoc\",lastNewLoc)\n system.print(\"SatNav Databank Duplicated Successfully\")\nend\n\nbuildPlanetList()\nbuildPlanetLocList(lastPlanetSelected)\nlocal planetCount=#planetList\n\n-----------------------------------------------\n-- Code for on screen buttons\n-----------------------------------------------\n\nfunction DrawSVG(output) screen.setSVG(output) end\n\nfunction AddClickArea(newEntry) table.insert(clickAreas, newEntry) end\n\nfunction RemoveFromClickAreas(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = nil\n break\n end\n end\nend\n\nfunction UpdateClickArea(candidate, newEntry)\n --system.print(\"Candidate: \"..candidate..\" x1\"..newEntry.x1)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = newEntry\n --system.print(\"Click Area: \"..candidate..\" x1\"..clickAreas[k].x1)\n break\n end\n end\nend\n\nfunction DisableClickArea(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n UpdateClickArea(candidate, {\n id = candidate,\n x1 = -1,\n x2 = -1,\n y1 = -1,\n y2 = -1\n })\n break\n end\n end\nend\n\nfunction InitiateClickAreas()\n clickAreas = {}\n \n AddClickArea({id = \"LoadSatNavLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LoadHudLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"NewLocation\", x1 = 700, x2 = 1100, y1 = 900, y2 = 1000})\n AddClickArea({id = \"ClearHudLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"PlanetPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"PlanetPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n \n for i = 1, pageLines do\n AddClickArea({id = string.format(\"PList%d\",i), x1 = 90, x2 = 800, y1 = (170 + i * 55), y2 = (225 + i * 55)})\n AddClickArea({id = string.format(\"LList%d\",i), x1 = 1090, x2 = 1500, y1 = (170 + i * 55), y2 = (225 + i * 55)})\n end\nend\n\nfunction FlushClickAreas() clickAreas = {} end\n\nfunction clearLocDispList()\n for i=1,pageLines do\n displayLocationList[i] = \"\"\n end\nend\n\nfunction CheckClick(x, y, HitTarget)\n HitTarget = HitTarget or \"\"\n if HitTarget == \"\" then\n for k, v in pairs(clickAreas) do\n if v and x >= v.x1 and x <= v.x2 and y >= v.y1 and y <= v.y2 then\n HitTarget = v.id\n break\n end\n end\n end\n \n --system.print(\"Target Hit = \"..HitTarget)\n \n if HitTarget == \"PlanetPageDown\" then\n CurrentPlanetPage = CurrentPlanetPage+1\n DrawPlanetList()\n elseif HitTarget == \"PlanetPageUp\" then\n CurrentPlanetPage = math.max(CurrentPlanetPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LocationPageDown\" then\n CurrentLocationPage = CurrentLocationPage+1\n DrawPlanetList()\n elseif HitTarget == \"LocationPageUp\" then\n CurrentLocationPage = math.max(CurrentLocationPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LoadSatNavLocations\" then\n loadPointsOfInterest()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n elseif HitTarget == \"LoadHudLocations\" then\n loadHudLocations()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end \n elseif HitTarget == \"ClearSatNavLocations\" then\n system.print(\"ClearSavedLocations\")\n clearSavedLocations()\n system.print(\"defaul=\"..displayPlanetList[1])\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n elseif HitTarget == \"ClearHudLocations\" then\n --system.print(\"ClearSavedLocations\")\n clearHudLocations()\n elseif HitTarget == \"NewLocation\" then\n system.print(\"NewLocation\")\n newLocation()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n else\n for i = 1,pageLines do\n if HitTarget == string.format(\"PList%s\",i) then\n --system.print(\"PHitTarget: \"..HitTarget)\n if displayPlanetList[i] ~= \"\" then\n lastPlanetSelected = displayPlanetList[i]\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n DrawPlanetList()\n end\n end\n if HitTarget == string.format(\"LList%s\",i) then\n if displayLocationList[i] ~= \"\" then\n selected = displayLocationList[i]\n if HUD == \"Dimencia\" then\n copySelectedToHud(selected)\n end\n lastLocationSelected = selected\n selected = \"\"\n DrawPlanetList()\n end\n end\n end\n end\nend\n\n-----------------------------------------------\n-- Code for building screen content and displaying it\n-----------------------------------------------\n\nlocal svgBootstrap = [[\n ]]\n\nfunction DrawPlanetList()\n local healthyColor = \"#00aa00\"\n local brokenColor = \"#aa0000\"\n local damagedColor = \"#aaaa00\"\n local integrityColor = \"#aaaaaa\"\n local healthyTextColor = \"white\"\n local brokenTextColor = \"#ff4444\"\n local damagedTextColor = \"#ffff44\"\n local integrityTextColor = \"white\"\n \n\n local screenOutput = \"\"\n\n -- Draw Header\n screenOutput = screenOutput .. svgBootstrap\n \n -- Draw main background\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[(Version: ]]..version..[[)]]\n screenOutput = screenOutput ..\n [[Sat Nav]]\n if HUD == \"Dimencia\" then\n screenOutput = screenOutput ..\n [[(Dimencia HUD enabled)]]\n else \n screenOutput = screenOutput ..\n [[(Standalone mode enabled)]]\n end\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[Planets]]\n \n\n local i = 0\n for j = 1 + (CurrentPlanetPage - 1) * pageLines, pageLines +\n (CurrentPlanetPage - 1) * pageLines, 1 do\n i = i + 1\n if j < #planetList and j>0 then\n local planetName = planetList[j]\n if lastPlanetSelected == planetList[j] then\n screenOutput = screenOutput .. [[]] .. planetName .. \n [[]]\n else\n screenOutput = screenOutput .. [[]] .. planetName .. \n [[]]\n end\n if planetName ~= \"Space\" then\n screenOutput = screenOutput .. [[]] .. planetDistList[planetName] .. \n [[]] \n end\n displayPlanetList[i]=planetList[j]\n else\n displayPlanetList[i]=\"\"\n end\n end\n \n if planetCount > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentPlanetPage .. \" of \" ..\n math.ceil(planetCount / 12) ..\n [[]]\n\n if CurrentPlanetPage < math.ceil(planetCount / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageDown\", {\n id = \"PlanetPageDown\",\n x1 = 70,\n x2 = 270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageDown\")\n end\n\n if planetCount > 1 and CurrentPlanetPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageUp\", {\n id = \"PlanetPageUp\",\n x1 = 280,\n x2 = 480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageUp\")\n end\n end\n -- Start of Location List\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[]].. lastPlanetSelected ..[[ Locations]]\n \n\n local i = 0\n for j = 1 + (CurrentLocationPage - 1) * pageLines, pageLines +\n (CurrentLocationPage - 1) * pageLines, 1 do\n \n i = i + 1\n if j <= #locList and j>0 then\n if lastLocationSelected == locList[j] then\n screenOutput = screenOutput .. [[]] .. locList[j] .. \n [[]]\n else\n screenOutput = screenOutput .. [[]] .. locList[j] .. \n [[]]\n end\n displayLocationList[i]=locList[j]\n screenOutput = screenOutput .. [[]] .. locDistList[locList[j]] .. \n [[]] \n else\n displayLocationList[i]=\"\"\n end\n end\n \n if #locList > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentLocationPage .. \" of \" ..\n math.ceil(#locList / 12) ..\n [[]]\n\n if CurrentLocationPage < math.ceil(#locList / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageDown\", {\n id = \"LocationPageDown\",\n x1 = 1070,\n x2 = 1270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageDown\")\n end\n\n if #locList > 1 and CurrentLocationPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageUp\", {\n id = \"LocationPageUp\",\n x1 = 1280,\n x2 = 1480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageUp\")\n end\n end\n \n-- screenOutput = screenOutput ..\n-- [[]] ..\n-- [[Load SatNav DB]]\n \n screenOutput = screenOutput ..\n [[]] ..\n [[Save Current Location]]\n\n-- screenOutput = screenOutput ..\n-- [[]] ..\n-- [[Clear HUD Locs]]\n\n\n screenOutput = screenOutput .. [[]]\n\n DrawSVG(screenOutput)\n\n forceRedraw = false\nend\n\n-----------------------------------------------\n-- Execute\n-----------------------------------------------\n\nunit.hide()\nInitiateClickAreas()\nDrawPlanetList()\nsystem.print(\"Running\")\nunit.setTimer(\"loadwp\",1)\n\n\n","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"6"},{"code":"function loadLocationTable ()\n\nlocationTable = {{}}\nlocationTable[1] = {\"Alioth Market 1\", \"::pos{0,2,30.3314,101.3106,122.9764}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 2\", \"::pos{0,2,24.4469,88.0409,238.3019}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 3\", \"::pos{0,2,34.9734,87.3012,176.2188}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 4\", \"::pos{0,2,28.3352,99.5187,165.9078}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 5\", \"::pos{0,2,33.3939,87.3299,277.1366}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 6\", \"::pos{0,2,36.0044,101.3503,220.0897}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 7\", \"::pos{0,2,22.5024,98.1449,232.5154}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 8\", \"::pos{0,2,21.2154,93.9616,251.0768}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 9\", \"::pos{0,2,28.7133,85.6389,260.7636}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 10\", \"::pos{0,2,35.9865,91.8393,190.1616}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 11\", \"::pos{0,2,-1.0735,178.5062,69.9428}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 12\", \"::pos{0,2,22.7112,-92.3078,166.8481}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 13\", \"::pos{0,2,-23.3768,-10.5455,178.8458}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 14\", \"::pos{0,2,-73.4716,101.3697,89.5661}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 15\", \"::pos{0,2,61.7831,27.8517,54.9186}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 16\", \"::pos{0,2,23.4406,114.4179,211.1991}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 17\", \"::pos{0,2,37.8637,64.1825,151.5507}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 18\", \"::pos{0,2,49.9360,-170.7565,62.1982}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 19\", \"::pos{0,2,-32.7357,76.3764,209.0805}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 20\", \"::pos{0,2,-35.1535,-95.1230,301.0724}\"} \n \nlocationTable[#locationTable+1] = {\"Madis Market 1\", \"::pos{0,1,2.6476,176.8761,813.0974}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 2\", \"::pos{0,1,10.3552,8.5146,816.2210}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 3\", \"::pos{0,1,-0.2107,82.0779,809.5571}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 4\", \"::pos{0,1,-80.6046,44.9385,822.6188}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 5\", \"::pos{0,1,81.0827,5.3022,823.1976}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 6\", \"::pos{0,1,13.9814,-91.6163,811.0679}\"}\n\nlocationTable[#locationTable+1] = {\"Thades M1: Market\", \"::pos{0,30,-2.9797,-117.7645,203.7519}\"}\nlocationTable[#locationTable+1] = {\"Feli: Market\", \"::pos{0,5,0.9348,178.6658,18417.2812}\"}\n\nlocationTable[#locationTable+1] = {\"Symeon Market 1\", \"::pos{0,110,3.1400,-174.0223,267.1084}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 2\", \"::pos{0,110,-0.9862,88.3038,197.0626}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 3\", \"::pos{0,110,18.1117,11.1108,180.8022}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 4\", \"::pos{0,110,-26.9701,103.3741,186.2557}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 5\", \"::pos{0,110,83.1653,108.7807,142.5796}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 6\", \"::pos{0,110,-79.3167,95.3975,138.5268}\"}\n\nlocationTable[#locationTable+1] = {\"TMV Troghelm\", \"::pos{0,0,2416521.6598,1415126.8118,59323.7340}\"}\nlocationTable[#locationTable+1] = {\"TMV Alioth Factory\", \"::pos{0,2,22.8158,111.1414,103.5685}\"}\nlocationTable[#locationTable+1] = {\"TMV Feli Outpost\", \"::pos{0,5,23.6988,-77.8811,18480.5176}\"}\nlocationTable[#locationTable+1] = {\"TMV Thandes M1 Outpost\", \"::pos{0,30,-22.3548,-168.7352,288.1909}\"}\nlocationTable[#locationTable+1] = {\"TMV Madis Outpost\", \"::pos{0,1,-43.0914,75.0728,749.6641}\"}\nlocationTable[#locationTable+1] = {\"TMV Symoen Outpost\", \"::pos{0,110,-5.3046,32.6900,108.4144}\"}\nlocationTable[#locationTable+1] = {\"TMV Jago Outpost\", \"::pos{0,9,61.3760,-33.7830,10.7593}\"}\n\nend\n\nunit.stopTimer(\"loadwp\")\nloadLocationTable()\nlastNewLoc = satnavDB.getIntValue(\"lastNewLoc\")\n--system.print(\"lastNewLoc\"..lastNewLoc)\nif lastNewLoc == nil or lastNewLoc==0 then\n --this is th first time satnav has run on this databank\n system.print(\"Initialising SatNav Databank\")\n CheckClick(0, 0, \"LoadSatNavLocations\")\n lastNewLoc =1\n satnavDB.setIntValue(\"lastNewLoc\",lastNewLoc)\n system.print(\"Completed SatNav Databank\")\nend\n\n\n","filter":{"args":[{"value":"loadwp"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"7"},{"code":"\nif string.sub(text,1,2) == \"u \" then\n local newLocName = string.sub(text,3,string.len(text))\n updateLocationName(newLocName)\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\nelseif text == \"d SatNav\" then\n deleteLocationName(lastLocationSelected)\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\nelseif text == \"c SatNav\" then\n system.print(\"ClearSatNavLocations\")\n CheckClick(0, 0, \"ClearSatNavLocations\")\nelseif text == \"c Hud\" then\n if HUD == \"Dimencia\" then\n system.print(\"ClearHudLocations\")\n CheckClick(0, 0, \"ClearHudLocations\")\n else\n system.print(\"ClearHudLocations not available in standalone mode\")\n end\nelseif text == \"l SatNav\" then\n system.print(\"LoadSatNavLocations\")\n CheckClick(0, 0, \"LoadSatNavLocations\")\nelseif text == \"l Hud\" then\n if HUD == \"Dimencia\" then\n system.print(\"LoadHudLocations\")\n CheckClick(0, 0, \"LoadHudLocations\")\n else\n system.print(\"LoadHudLocations not available in standalone mode\")\n end\nelseif text == \"x SatNav\" then\n if dupSatnavDB then\n system.print(\"DuplicateSatNavDB\")\n duplicateSatnavDB()\n else\n system.print(\"Please link an empty databank to the programming board\")\n end\nend","filter":{"args":[{"variable":"*"}],"signature":"inputText(text)","slotKey":"-2"},"key":"8"}],"methods":[],"events":[]} diff --git a/SatNav_PB_Paste_2_1_1 b/SatNav_PB_Paste_2_1_1 deleted file mode 100644 index 7144077..0000000 --- a/SatNav_PB_Paste_2_1_1 +++ /dev/null @@ -1 +0,0 @@ -{"slots":{"0":{"name":"core","type":{"events":[],"methods":[]}},"1":{"name":"screen","type":{"events":[],"methods":[]}},"2":{"name":"db1","type":{"events":[],"methods":[]}},"3":{"name":"db2","type":{"events":[],"methods":[]}},"4":{"name":"dupSatnavDB","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"1"},"key":"0"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"5"},"key":"1"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"6"},"key":"2"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"7"},"key":"3"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"8"},"key":"4"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"9"},"key":"5"},{"code":"--[[\n SatNav version 2_1_0\n Created By TrogLaByte\n\n Discord: Trog#5105\n InGame: TrogLaByte\n \n GNU Public License 3.0. Use whatever you want, be so kind to leave credit.\n\n Thanks to Dorien Grey for his SVG and onscreen button code.\n]] \n-----------------------------------------------\n-- requirements\n-----------------------------------------------\n\nfunction initiateRequiredLibaries()\n json = require('dkjson')\n vec3 = require('cpml.vec3')\n utils = require('cpml.utils')\n planetRef = require('cpml.planetref')\n referenceTableSource = require('cpml.atlas')\n clamp = utils.clamp\nend\nif pcall(initiateRequiredLibaries) then\n system.print(\"Libaries loaded successfully\")\n else\n system.print(\"Libaries failed to load: check that the following libraries exist:\")\n system.print(\"( is the directory in to which you installed DU)\")\n system.print(\" /DualUniverse/Game/data/lua/dkjson\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/vec3\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/utils\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/planetref\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/atlas\")\n system.print(\"\")\n system.print(\"planetref.lua and atlas.lua can be obtained from the following GitLab url:\")\n system.print(\"https://gitlab.com/JayleBreak/dualuniverse/-/tree/master/DUflightfiles/autoconf/custom\")\n unit.exit()\nend\n-----------------------------------------------\n-- Global Variables\n-----------------------------------------------\n\nlocal version = \"2_1_1\"\n\nlocal UpdateInterval = 1 \nlocal defaultNewLocName = \"SatNav Location\" --export: default name used for new locations\nlocal BackgroundColor = \"#1e1e1e\" -- Set the background color of the screens. YOU NEED TO LEAVE THE QUOTATION MARKS.\nlocal PlanetBackgroundColor = \"#34b1eb\" -- Set the background color of the screens. YOU NEED TO LEAVE THE QUOTATION MARKS.\nlocal LocationBackgroundColor = \"#6e3de3\" --Set the background color of the screens. YOU NEED TO LEAVE THE QUOTATION MARKS.\nlocal lastPlanetSelected = \"Alioth\" --export: The default start planet for displaying locations\n\nlocal clickAreas = {}\nlocal locList={}\npageLines=12\ndisplayPlanetList={}\ndisplayLocationList={}\nCurrentLocationPage = 1\nCurrentPlanetPage = 1\nmyDatabank={}\ndbHud={}\n\nif db1 then db1Keys = db1.getKeys() end\nif db2 then db2Keys = db2.getKeys() end\n\n--if db1Keys then system.print(\"DB1 Keys: \"..string.sub(db1Keys,1,50)) end\n--if db2Keys then system.print(\"DB2 Keys: \"..string.sub(db2Keys,1,50)) end\n\nif db1 and (db1key == nil or db1Keys == \"\" or string.match(db1Keys, \"lastNewLoc\")) then\n myDatabank = db1\n system.print(\"SatNav Databank Identified\")\nelseif db2 and (db2key == nil or db2Keys == \"\" or string.match(db2Keys, \"lastNewLoc\")) then\n myDatabank = db2\n system.print(\"SatNav Databank Identified\")\nelse \n system.print(\"SatNav databank not found... application wiil stop\")\n unit.exit()\n unit.deactivate()\nend\n\nif myDatabank==db1 and db2 and string.match(db2Keys, \"AutopilotTargetIndex\") then\n dbHud = db2\n system.print(\"Dimencia Hud Identified\")\n HUD = \"Dimencia\"\nelseif myDatabank==db2 and db1 and string.match(db1Keys, \"AutopilotTargetIndex\") then\n dbHud = db1\n system.print(\"Dimencia Hud Identified\")\n HUD = \"Dimencia\"\nelse \n system.print(\"No Dimencia Hud Identified - will run in Stand Alone mode\")\n HUD = \"unknown\"\nend\n\n--unit.exit()\n-----------------------------------------------\n-- set up galaxy data and functions for planets and locations\n-----------------------------------------------\n\ngalaxyReference = planetRef(referenceTableSource)\nhelios = galaxyReference[0] -- PlanetaryReference.PlanetarySystem instance\nplanetList={}\nplanetDistList={}\nlocDistList={}\n\nfunction getBodyId(planetName)\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n if string.lower(helios[tonumber(i)].name) ==string.lower(planetName) then\n return i\n end\n end\n end\n return 0\nend\n\nfunction buildPlanetList()\n local planet={}\n local currentLoc = vec3(core.getConstructWorldPos())\n local shipMass = core.getConstructMass()\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n planet = helios[tonumber(i)]\n planetList[#planetList+1] = planet.name\n local planetDistance = planet:getDistance(currentLoc)\n planetDistList[planet.name] = formatDistance(planetDistance) .. \n string.format(\" [%.0f wc]\", ((planetDistance/200000)*(shipMass/1000)/4000))\n end\n end\n planetList[#planetList+1]=\"Space\"\n table.sort(planetList)\nend\n\nfunction formatDistance(distance)\n if distance < 200000 then\n return string.format(\"%.0f km\",distance/1000)\n elseif distance < 4000000 then\n return string.format(\"%.2f su\",distance/200000)\n else\n return string.format(\"%.0f su\",distance/200000)\n end\nend\n\n-- json parser\n\n-- Extracts values from a JSON string with pattern matching\n-- This is faster than using dkjson when only a few fields are needed\n\n-- Use this only with trusted data sources! Limitations:\n-- * Character escapes are not supported\n-- * Field nesting is ignored\n\nlocal find, gsub = string.find, string.gsub\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return string|nil, number|nil, number|nil\nlocal function extractStringJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*\"([^\"]*)\"]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n return valueStr, startIndex, endIndex\nend\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return number|nil, number|nil, number|nil\nlocal function extractNumberJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*(-?[0-9.e-]+)]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n return tonumber(valueStr), startIndex, endIndex\nend\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return boolean|nil, number|nil, number|nil\nlocal function extractBooleanJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*([truefals]+)]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n\n if valueStr == \"true\" then\n return true, startIndex, endIndex\n elseif valueStr == \"false\" then\n return false, startIndex, endIndex\n else\n return nil\n end\nend\n\n---@param extractJsonValue function\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue any|nil\n---@return any[]\nlocal function extractAllJsonValues (extractJsonValue, json, key, stopAfterIndex, stopAfterValue)\n local values = {}\n local valuesLen = 0\n\n local jsonPos = 1\n local value, valueStartIndex, valueEndIndex -- luacheck: ignore valueStartIndex -- unused\n\n repeat\n value, valueStartIndex, valueEndIndex = extractJsonValue(json, key, jsonPos)\n\n if value ~= nil then\n valuesLen = valuesLen + 1\n values[valuesLen] = value\n\n jsonPos = valueEndIndex + 1\n end\n\n if value == stopAfterValue then break end\n if valuesLen == stopAfterIndex then break end\n until value == nil\n\n return values\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue string|nil\n---@return string[]\nlocal function extractAllStringJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractStringJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue number|nil\n---@return number[]\nlocal function extractAllNumberJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractNumberJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue boolean|nil\n---@return boolean[]\nlocal function extractAllBooleanJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractBooleanJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n-- end json Parser\n\n\nfunction buildPlanetLocList(planetName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n \n local currentLoc = vec3(core.getConstructWorldPos())\n local shipMass = core.getConstructMass()\n local planet={}\n locList={}\n if planetName ~= \"Space\" then\n table.insert(locList, planetName) -- add planet name into the list as a default\n locDistList[planetName] = planetDistList[planetName]\n end\n if #name > 0 then \n for i=1,#name do\n if string.lower(planetname[i]) == string.lower(planetName) or\n string.find(string.lower(planetname[i]),string.lower(planetName))\n then\n table.insert(locList, name[i])\n elseif planetname[i] == \"\" and planetName == \"Space\" then -- a space location\n table.insert(locList, name[i])\n end\n local locDistance = (currentLoc - vec3(posX[i],posY[i],posZ[i])):len()\n if planetName == \"Space\" then\n locDistList[name[i]] = formatDistance(locDistance) ..\n string.format(\" [%.0f wc]\", ((locDistance/200000)*(shipMass/1000)/4000))\n else\n locDistList[name[i]] = formatDistance(locDistance)\n end\n end\n end\n table.sort(locList)\nend\n\nfunction printLocMapPos(locationName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local wayPoint=\"\"\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n local planet={}\n if #name > 0 then \n for i = 1, #name do\n if string.lower(name[i]) == string.lower(locationName) then\n local bodyId = getBodyId(planetname[i])\n planet = helios[tonumber(bodyId)] \n if planet ~= nil then\n worldCoords = planet:convertToMapPosition(vec3(posX[i],posY[i],posZ[i]))\n wayPoint=string.format([[::pos{%d,%d,%f,%f,%f}]],\n worldCoords.systemId,\n worldCoords.bodyId,\n worldCoords.latitude*constants.rad2deg,\n worldCoords.longitude*constants.rad2deg,\n worldCoords.altitude)\n system.print(name[i]..\" @ \"..wayPoint)\n system.setWaypoint(wayPoint)\n return locationName,\n planetname[i],\n atmosphere[i],\n gravity[i],\n posX[i],\n posY[i],\n posZ[i]\n else\n wayPoint=string.format([[::pos{%d,%d,%f,%f,%f}]],\n 0,\n bodyId,\n posX[i],posY[i],posZ[i])\n system.print(name[i]..\" @ \"..wayPoint)\n system.setWaypoint(wayPoint)\n return locationName,\n planetname[i],\n atmosphere[i],\n gravity[i],\n posX[i],\n posY[i],\n posZ[i]\n end\n break\n end \n end\n end\n return \"\"\nend\n\nfunction clearSavedLocations()\n myDatabank.setStringValue(\"SavedLocations\",\"[]\")\n system.print(\"Satnav Databank cleared\")\nend\n\nfunction isDuplicateLocation(locName, locNameList)\n for i=1,#locNameList do\n if locNameList[i] == locName then\n return locName\n end\n end\n return \"\"\nend\n\nfunction saveSavedLocations (name, planetname, atmosphere, gravity, posX, posY, posZ)\n local newSavedLocations = \"[\"\n for i = 1, #name do\n if name[i]~=\"\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..name[i]..\n [[\",\"planetname\":\"]]..planetname[i]..[[\"]]..\n [[,\"atmosphere\":]]..atmosphere[i]..\n [[,\"gravity\":]]..gravity[i]..\n [[,\"position\":{\"x\":]]..posX[i]..\n [[,\"y\":]]..posY[i]..\n [[,\"z\":]]..posZ[i]..[[}}]]\n end\n if i+1<#name then\n newSavedLocations= newSavedLocations..\",\"\n end\n end\n newSavedLocations= newSavedLocations..\"]\" \n --system.print(newSavedLocations)\n myDatabank.setStringValue(\"SavedLocations\",newSavedLocations)\n system.print(\"Satnav Databank Updated\")\nend\n\nfunction updateLocationName(newLocName)\n if newLocName ~= nil and newLocName ~= \"\" and \n lastLocationSelected ~= nil and lastLocationSelected ~= \"\" then\n system.print(\"Updating location name for: \"..lastLocationSelected..\" to: \"..newLocName)\n else\n system.print(\"Invalid update request\")\n return\n end\n local savedLocation = {}\n local oldLocFound = false\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n for i = 1, #name do\n if name[i] == lastLocationSelected then\n --system.print(\"Found: \"..lastLocationSelected)\n name[i] = newLocName\n oldLocFound = true\n break\n end\n end\n \n if oldLocFound then \n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n else\n system.print(\"Old Location Name Not Found\")\n end\nend\n\nfunction deleteLocationName(delLocName)\n if delLocName ~= nil and delLocName ~= \"\" then\n system.print(\"Deleting location name: \"..delLocName)\n else\n system.print(\"Invalid update request\")\n return\n end\n local savedLocation = {}\n local oldLocFound = false\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n for i = 1, #name do\n if name[i] == delLocName then\n --system.print(\"Found: \"..delLocName)\n name[i] = \"\"\n oldLocFound = true\n break\n end\n end\n \n if oldLocFound then \n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n else\n system.print(\"Location Name Not Found\")\n end\nend\n\nfunction loadPointsOfInterest()\n -- get existing locations from SatNav Databank\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n\n\n local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)'\n local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' ..\n num .. ',' .. num .. '}'\n local j=0\n loadLocationTable()\n \n for i = 1, #locationTable do\n local newRef = #name + 1\n if isDuplicateLocation(locationTable[i][1],name) == \"\" then\n name[newRef]=locationTable[i][1]\n local newLocPos = locationTable[i][2]\n --system.print(\"Name: \"..locationTable[i][1]..\" \"..newLocPos)\n local systemId, bodyId, latitude, longitude, altitude =\n string.match(locationTable[i][2], posPattern)\n --system.print(\"BodyId: \".. bodyId)\n if tonumber(bodyId) > 0 then\n local planet = helios[tonumber(bodyId)] \n local worldCoords = planet:convertToWorldCoordinates(newLocPos)\n posX[newRef]=worldCoords[\"x\"]\n posY[newRef]=worldCoords[\"y\"]\n posZ[newRef]=worldCoords[\"z\"]\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=planet.name\n else -- it is a space location\n posX[newRef]=latitude\n posY[newRef]=longitude\n posZ[newRef]=altitude\n gravity[newRef]=0\n atmosphere[newRef]=0\n planetname[newRef]=\"\"\n end \n else\n system.print(\"Duplicate entry for location ignored: \"..locationTable[i][1])\n end\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n --system.print(\"Default SatNav locations loaded\")\nend\n\nfunction loadHudLocations()\n -- get existing locations from SatNav Databank\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n\n local hudLocation = dbHud.getStringValue(\"SavedLocations\")\n local hudatmosphere={}\n local hudgravity={}\n local hudplanetname = {}\n local hudposX\t = {}\n local hudposY\t = {}\n local hudposZ\t = {}\n local hudname\t = {}\n\n hudatmosphere = extractAllNumberJsonValues(hudLocation,\"atmosphere\")\n hudgravity = extractAllNumberJsonValues(hudLocation,\"gravity\")\n hudplanetname = extractAllStringJsonValues(hudLocation,\"planetname\")\n hudposX\t = extractAllNumberJsonValues(hudLocation,\"x\")\n hudposY\t = extractAllNumberJsonValues(hudLocation,\"y\")\n hudposZ\t = extractAllNumberJsonValues(hudLocation,\"z\")\n hudname\t = extractAllStringJsonValues(hudLocation,\"name\")\n\n\n for i = 1, #hudname do\n local newRef = #name + 1\n system.print(\"HudName: \"..hudname[i])\n if isDuplicateLocation(hudname[i],name) == \"\" and\n hudname[i] ~= \"SatNav Location\" then\n name[newRef]=hudname[i]\n posX[newRef]=hudposX[i]\n posY[newRef]=hudposY[i]\n posZ[newRef]=hudposZ[i]\n gravity[newRef]=hudgravity[i]\n atmosphere[newRef]=hudatmosphere[i]\n planetname[newRef]=hudplanetname[i] \n else\n system.print(\"Duplicate entry for location ignored: \"..hudname[i])\n end\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n --system.print(\"Default SatNav locations loaded\")\nend\n\n\nfunction newLocation ()\n local location = system.getWaypointFromPlayerPos()\n local newLocId = myDatabank.getIntValue(\"lastNewLoc\") + 1\n myDatabank.setIntValue(\"lastNewLoc\",newLocId)\n \n local newLocName = defaultNewLocName..\" (\"..newLocId..\")\"\n \n local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)'\n local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' ..\n num .. ',' .. num .. '}'\n \n local savedLocation = {}\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n \n local systemId, bodyId, latitude, longitude, altitude =\n string.match(location, posPattern)\n local worldPos = unit.getMasterPlayerRelativePosition()\n local body = helios:closestBody(worldPos)\n --system.print(json.encode(body))\n --system.print(\"Distance=\"..((vec3(worldPos)-vec3(body.center)):len())/(1000))\n --system.print(\"Calc=\"..((body.radius+body.center):len())/(1000))\n\n newlocAlt = ((vec3(worldPos)-vec3(body.center)):len())/(1000)\n-- system.print(\"New Loc Alt:\"..newlocAlt)\n-- system.print(\"Radius:\"..(((body.radius)/1000) + 200))\n if newlocAlt < (((body.radius)/1000) + 200) then\n local bodyId = getBodyId(body.name)\n --system.print(\"BodyId: \".. bodyId)\n local planet = helios[tonumber(bodyId)] -- PlanetaryReference.BodyParameters instance\n --system.print(\"Planet BodyId: \".. planet.bodyId)\n local worldCoords = planet:convertToWorldCoordinates(location)\n newRef = #name + 1\n name[newRef]=newLocName\n posX[newRef]=worldCoords[\"x\"]\n posY[newRef]=worldCoords[\"y\"]\n posZ[newRef]=worldCoords[\"z\"]\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=body.name\n else\n newRef = #name + 1\n name[newRef]=newLocName\n posX[newRef]=latitude\n posY[newRef]=longitude\n posZ[newRef]=altitude\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=\"Space\"\n\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n system.print(\"New location: \"..newLocName..\" added to SatNav databank\")\n printLocMapPos(newLocName)\nend\n\nfunction copySelectedToHud (locName)\n \n local locName, locplanetname, locatmosphere, locgravity, locX, locY, locZ = \n printLocMapPos(locName)\n if HUD == \"Dimencia\" then\n savedLocation = dbHud.getStringValue(\"SavedLocations\")\n --system.print(\"savedLocation=\"..savedLocation)\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n local newSavedLocations = \"[\"\n for i = 1, #name do\n if name[i] ~= \"SatNav Location\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..name[i]..\n [[\",\"planetname\":\"]]..planetname[i]..[[\"]]..\n [[,\"atmosphere\":]]..atmosphere[i]..\n [[,\"gravity\":]]..gravity[i]..\n [[,\"position\":{\"x\":]]..posX[i]..\n [[,\"y\":]]..posY[i]..\n [[,\"z\":]]..posZ[i]..[[}},]]\n end\n end\n if locplanetname ~= \"\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..\"SatNav Location\"..\n [[\",\"planetname\":\"]]..locplanetname..[[\"]]..\n [[,\"atmosphere\":]]..locatmosphere..\n [[,\"gravity\":]]..locgravity..\n [[,\"position\":{\"x\":]]..locX..\n [[,\"y\":]]..locY..\n [[,\"z\":]]..locZ..[[}}]]\n end\n newSavedLocations= newSavedLocations..\"]\" \n system.print(newSavedLocations)\n dbHud.setStringValue(\"SavedLocations\",newSavedLocations)\n dbHud.setStringValue(\"SPBAutopilotTargetName\",\"SatNav Location\")\n end\nend\n\nfunction clearHudLocations()\n if HUD == \"Dimencia\" then\n dbHud.setStringValue(\"SavedLocations\",\"[]\")\n dbHud.setStringValue(\"SPBAutopilotTargetName\",\"\")\n system.print(\"Dimencia HUD Saved Locations Cleared\")\n end\nend\n\nfunction duplicateSatnavDB()\n local satnavLocation = myDatabank.getStringValue(\"SavedLocations\")\n local lastNewLoc = myDatabank.getIntValue(\"lastNewLoc\")\n if dupSatnavDB then\n dupSatnavDB.clear()\n dupSatnavDB.setStringValue(\"SavedLocations\",satnavLocation)\n dupSatnavDB.setIntValue(\"lastNewLoc\",lastNewLoc)\n system.print(\"SatNav Databank Duplicated Successfully\")\n else\n system.print(\"No space databank linked, duplication aborted\")\n end\nend\n\nbuildPlanetList()\nbuildPlanetLocList(lastPlanetSelected)\nlocal planetCount=#planetList\n\n-----------------------------------------------\n-- Code for on screen buttons\n-----------------------------------------------\n\nfunction DrawSVG(output) screen.setSVG(output) end\n\nfunction AddClickArea(newEntry) table.insert(clickAreas, newEntry) end\n\nfunction RemoveFromClickAreas(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = nil\n break\n end\n end\nend\n\nfunction UpdateClickArea(candidate, newEntry)\n --system.print(\"Candidate: \"..candidate..\" x1\"..newEntry.x1)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = newEntry\n --system.print(\"Click Area: \"..candidate..\" x1\"..clickAreas[k].x1)\n break\n end\n end\nend\n\nfunction DisableClickArea(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n UpdateClickArea(candidate, {\n id = candidate,\n x1 = -1,\n x2 = -1,\n y1 = -1,\n y2 = -1\n })\n break\n end\n end\nend\n\nfunction InitiateClickAreas()\n clickAreas = {}\n \n AddClickArea({id = \"LoadSatNavLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LoadHudLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"NewLocation\", x1 = 700, x2 = 1100, y1 = 900, y2 = 1000})\n AddClickArea({id = \"ClearHudLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"PlanetPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"PlanetPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n \n for i = 1, pageLines do\n AddClickArea({id = string.format(\"PList%d\",i), x1 = 90, x2 = 800, y1 = (170 + i * 55), y2 = (225 + i * 55)})\n AddClickArea({id = string.format(\"LList%d\",i), x1 = 1090, x2 = 1500, y1 = (170 + i * 55), y2 = (225 + i * 55)})\n end\nend\n\nfunction FlushClickAreas() clickAreas = {} end\n\nfunction clearLocDispList()\n for i=1,pageLines do\n displayLocationList[i] = \"\"\n end\nend\n\nfunction CheckClick(x, y, HitTarget)\n HitTarget = HitTarget or \"\"\n if HitTarget == \"\" then\n for k, v in pairs(clickAreas) do\n if v and x >= v.x1 and x <= v.x2 and y >= v.y1 and y <= v.y2 then\n HitTarget = v.id\n break\n end\n end\n end\n \n --system.print(\"Target Hit = \"..HitTarget)\n \n if HitTarget == \"PlanetPageDown\" then\n CurrentPlanetPage = CurrentPlanetPage+1\n DrawPlanetList()\n elseif HitTarget == \"PlanetPageUp\" then\n CurrentPlanetPage = math.max(CurrentPlanetPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LocationPageDown\" then\n CurrentLocationPage = CurrentLocationPage+1\n DrawPlanetList()\n elseif HitTarget == \"LocationPageUp\" then\n CurrentLocationPage = math.max(CurrentLocationPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LoadSatNavLocations\" then\n loadPointsOfInterest()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n elseif HitTarget == \"LoadHudLocations\" then\n loadHudLocations()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end \n elseif HitTarget == \"ClearSatNavLocations\" then\n system.print(\"ClearSavedLocations\")\n clearSavedLocations()\n system.print(\"defaul=\"..displayPlanetList[1])\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n elseif HitTarget == \"ClearHudLocations\" then\n --system.print(\"ClearSavedLocations\")\n clearHudLocations()\n elseif HitTarget == \"NewLocation\" then\n system.print(\"NewLocation\")\n newLocation()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n else\n for i = 1,pageLines do\n if HitTarget == string.format(\"PList%s\",i) then\n --system.print(\"PHitTarget: \"..HitTarget)\n if displayPlanetList[i] ~= \"\" then\n lastPlanetSelected = displayPlanetList[i]\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n DrawPlanetList()\n end\n end\n if HitTarget == string.format(\"LList%s\",i) then\n if displayLocationList[i] ~= \"\" then\n selected = displayLocationList[i]\n if HUD == \"Dimencia\" then\n copySelectedToHud(selected)\n end\n lastLocationSelected = selected\n selected = \"\"\n DrawPlanetList()\n end\n end\n end\n end\nend\n\n-----------------------------------------------\n-- Code for building screen content and displaying it\n-----------------------------------------------\n\nlocal svgBootstrap = [[\n ]]\n\nfunction DrawPlanetList()\n local healthyColor = \"#00aa00\"\n local brokenColor = \"#aa0000\"\n local damagedColor = \"#aaaa00\"\n local integrityColor = \"#aaaaaa\"\n local healthyTextColor = \"white\"\n local brokenTextColor = \"#ff4444\"\n local damagedTextColor = \"#ffff44\"\n local integrityTextColor = \"white\"\n \n\n local screenOutput = \"\"\n\n -- Draw Header\n screenOutput = screenOutput .. svgBootstrap\n \n -- Draw main background\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[(Version: ]]..version..[[)]]\n screenOutput = screenOutput ..\n [[Sat Nav]]\n if HUD == \"Dimencia\" then\n screenOutput = screenOutput ..\n [[(Dimencia HUD enabled)]]\n else \n screenOutput = screenOutput ..\n [[(Standalone mode enabled)]]\n end\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[Planets]]\n \n\n local i = 0\n for j = 1 + (CurrentPlanetPage - 1) * pageLines, pageLines +\n (CurrentPlanetPage - 1) * pageLines, 1 do\n i = i + 1\n if j < #planetList and j>0 then\n local planetName = planetList[j]\n if lastPlanetSelected == planetList[j] then\n screenOutput = screenOutput .. [[]] .. planetName .. \n [[]]\n else\n screenOutput = screenOutput .. [[]] .. planetName .. \n [[]]\n end\n if planetName ~= \"Space\" then\n screenOutput = screenOutput .. [[]] .. planetDistList[planetName] .. \n [[]] \n end\n displayPlanetList[i]=planetList[j]\n else\n displayPlanetList[i]=\"\"\n end\n end\n \n if planetCount > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentPlanetPage .. \" of \" ..\n math.ceil(planetCount / 12) ..\n [[]]\n\n if CurrentPlanetPage < math.ceil(planetCount / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageDown\", {\n id = \"PlanetPageDown\",\n x1 = 70,\n x2 = 270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageDown\")\n end\n\n if planetCount > 1 and CurrentPlanetPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageUp\", {\n id = \"PlanetPageUp\",\n x1 = 280,\n x2 = 480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageUp\")\n end\n end\n -- Start of Location List\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[]].. lastPlanetSelected ..[[ Locations]]\n \n\n local i = 0\n for j = 1 + (CurrentLocationPage - 1) * pageLines, pageLines +\n (CurrentLocationPage - 1) * pageLines, 1 do\n \n i = i + 1\n if j <= #locList and j>0 then\n if lastLocationSelected == locList[j] then\n screenOutput = screenOutput .. [[]] .. locList[j] .. \n [[]]\n else\n screenOutput = screenOutput .. [[]] .. locList[j] .. \n [[]]\n end\n displayLocationList[i]=locList[j]\n screenOutput = screenOutput .. [[]] .. locDistList[locList[j]] .. \n [[]] \n else\n displayLocationList[i]=\"\"\n end\n end\n \n if #locList > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentLocationPage .. \" of \" ..\n math.ceil(#locList / 12) ..\n [[]]\n\n if CurrentLocationPage < math.ceil(#locList / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageDown\", {\n id = \"LocationPageDown\",\n x1 = 1070,\n x2 = 1270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageDown\")\n end\n\n if #locList > 1 and CurrentLocationPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageUp\", {\n id = \"LocationPageUp\",\n x1 = 1280,\n x2 = 1480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageUp\")\n end\n end\n \n-- screenOutput = screenOutput ..\n-- [[]] ..\n-- [[Load SatNav DB]]\n \n screenOutput = screenOutput ..\n [[]] ..\n [[Save Current Location]]\n\n-- screenOutput = screenOutput ..\n-- [[]] ..\n-- [[Clear HUD Locs]]\n\n\n screenOutput = screenOutput .. [[]]\n\n DrawSVG(screenOutput)\n\n forceRedraw = false\nend\n\n-----------------------------------------------\n-- Execute\n-----------------------------------------------\n\nunit.hide()\nInitiateClickAreas()\nDrawPlanetList()\nsystem.print(\"Running\")\nunit.setTimer(\"loadwp\",1)\n\n\n","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"6"},{"code":"function loadLocationTable ()\n\nlocationTable = {{}}\nlocationTable[1] = {\"Alioth Market 1\", \"::pos{0,2,30.3314,101.3106,122.9764}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 2\", \"::pos{0,2,24.4469,88.0409,238.3019}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 3\", \"::pos{0,2,34.9734,87.3012,176.2188}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 4\", \"::pos{0,2,28.3352,99.5187,165.9078}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 5\", \"::pos{0,2,33.3939,87.3299,277.1366}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 6\", \"::pos{0,2,36.0044,101.3503,220.0897}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 7\", \"::pos{0,2,22.5024,98.1449,232.5154}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 8\", \"::pos{0,2,21.2154,93.9616,251.0768}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 9\", \"::pos{0,2,28.7133,85.6389,260.7636}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 10\", \"::pos{0,2,35.9865,91.8393,190.1616}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 11\", \"::pos{0,2,-1.0735,178.5062,69.9428}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 12\", \"::pos{0,2,22.7112,-92.3078,166.8481}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 13\", \"::pos{0,2,-23.3768,-10.5455,178.8458}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 14\", \"::pos{0,2,-73.4716,101.3697,89.5661}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 15\", \"::pos{0,2,61.7831,27.8517,54.9186}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 16\", \"::pos{0,2,23.4406,114.4179,211.1991}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 17\", \"::pos{0,2,37.8637,64.1825,151.5507}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 18\", \"::pos{0,2,49.9360,-170.7565,62.1982}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 19\", \"::pos{0,2,-32.7357,76.3764,209.0805}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 20\", \"::pos{0,2,-35.1535,-95.1230,301.0724}\"} \n \nlocationTable[#locationTable+1] = {\"Madis Market 1\", \"::pos{0,1,2.6476,176.8761,813.0974}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 2\", \"::pos{0,1,10.3552,8.5146,816.2210}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 3\", \"::pos{0,1,-0.2107,82.0779,809.5571}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 4\", \"::pos{0,1,-80.6046,44.9385,822.6188}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 5\", \"::pos{0,1,81.0827,5.3022,823.1976}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 6\", \"::pos{0,1,13.9814,-91.6163,811.0679}\"}\n\nlocationTable[#locationTable+1] = {\"Thades M1: Market\", \"::pos{0,30,-2.9797,-117.7645,203.7519}\"}\nlocationTable[#locationTable+1] = {\"Feli: Market\", \"::pos{0,5,0.9348,178.6658,18417.2812}\"}\n\nlocationTable[#locationTable+1] = {\"Symeon Market 1\", \"::pos{0,110,3.1400,-174.0223,267.1084}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 2\", \"::pos{0,110,-0.9862,88.3038,197.0626}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 3\", \"::pos{0,110,18.1117,11.1108,180.8022}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 4\", \"::pos{0,110,-26.9701,103.3741,186.2557}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 5\", \"::pos{0,110,83.1653,108.7807,142.5796}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 6\", \"::pos{0,110,-79.3167,95.3975,138.5268}\"}\n\nlocationTable[#locationTable+1] = {\"TMV Troghelm\", \"::pos{0,0,2416521.6598,1415126.8118,59323.7340}\"}\nlocationTable[#locationTable+1] = {\"TMV Alioth Factory\", \"::pos{0,2,22.8158,111.1414,103.5685}\"}\nlocationTable[#locationTable+1] = {\"TMV Feli Outpost\", \"::pos{0,5,23.6988,-77.8811,18480.5176}\"}\nlocationTable[#locationTable+1] = {\"TMV Thandes M1 Outpost\", \"::pos{0,30,-22.3548,-168.7352,288.1909}\"}\nlocationTable[#locationTable+1] = {\"TMV Madis Outpost\", \"::pos{0,1,-43.0914,75.0728,749.6641}\"}\nlocationTable[#locationTable+1] = {\"TMV Symoen Outpost\", \"::pos{0,110,-5.3046,32.6900,108.4144}\"}\nlocationTable[#locationTable+1] = {\"TMV Jago Outpost\", \"::pos{0,9,61.3760,-33.7830,10.7593}\"}\n\nend\n\nunit.stopTimer(\"loadwp\")\nloadLocationTable()\nlastNewLoc = myDatabank.getIntValue(\"lastNewLoc\")\n--system.print(\"lastNewLoc\"..lastNewLoc)\nif lastNewLoc == nil or lastNewLoc==0 then\n --this is th first time satnav has run on this databank\n system.print(\"Initialising SatNav Databank\")\n CheckClick(0, 0, \"LoadSatNavLocations\")\n lastNewLoc =1\n myDatabank.setIntValue(\"lastNewLoc\",lastNewLoc)\n system.print(\"Completed SatNav Databank\")\nend\n\n\n","filter":{"args":[{"value":"loadwp"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"7"},{"code":"\nif string.sub(text,1,2) == \"u \" then\n local newLocName = string.sub(text,3,string.len(text))\n updateLocationName(newLocName)\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\nelseif text == \"d SatNav\" then\n deleteLocationName(lastLocationSelected)\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\nelseif text == \"c SatNav\" then\n system.print(\"ClearSatNavLocations\")\n CheckClick(0, 0, \"ClearSatNavLocations\")\nelseif text == \"c Hud\" then\n if HUD == \"Dimencia\" then\n system.print(\"ClearHudLocations\")\n CheckClick(0, 0, \"ClearHudLocations\")\n else\n system.print(\"ClearHudLocations not available in standalone mode\")\n end\nelseif text == \"l SatNav\" then\n system.print(\"LoadSatNavLocations\")\n CheckClick(0, 0, \"LoadSatNavLocations\")\nelseif text == \"l Hud\" then\n if HUD == \"Dimencia\" then\n system.print(\"LoadHudLocations\")\n CheckClick(0, 0, \"LoadHudLocations\")\n else\n system.print(\"LoadHudLocations not available in standalone mode\")\n end\nelseif text == \"x SatNav\" then\n if dupSatnavDB then\n system.print(\"DuplicateSatNavDB\")\n duplicateSatnavDB()\n else\n system.print(\"Please link an empty databank to the programming board\")\n end\nend","filter":{"args":[{"variable":"*"}],"signature":"inputText(text)","slotKey":"-2"},"key":"8"}],"methods":[],"events":[]} diff --git a/SatNav_PB_Paste_2_1_2 b/SatNav_PB_Paste_2_1_2 deleted file mode 100644 index fa3364c..0000000 --- a/SatNav_PB_Paste_2_1_2 +++ /dev/null @@ -1 +0,0 @@ -{"slots":{"0":{"name":"core","type":{"events":[],"methods":[]}},"1":{"name":"screen","type":{"events":[],"methods":[]}},"2":{"name":"db2","type":{"events":[],"methods":[]}},"3":{"name":"db1","type":{"events":[],"methods":[]}},"4":{"name":"dupSatnavDB","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"1"},"key":"0"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"5"},"key":"1"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"6"},"key":"2"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"7"},"key":"3"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"8"},"key":"4"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"9"},"key":"5"},{"code":"--[[\n SatNav version 2_1_2\n Created By TrogLaByte\n\n Discord: Trog#5105\n InGame: TrogLaByte\n \n GNU Public License 3.0. Use whatever you want, be so kind to leave credit.\n\n Thanks to Dorien Grey for his SVG and onscreen button code.\n]] \n-----------------------------------------------\n-- requirements\n-----------------------------------------------\n\nfunction initiateRequiredLibaries()\n --json = require('dkjson')\n vec3 = require('cpml.vec3')\n utils = require('cpml.utils')\n planetRef = require('cpml.planetref')\n referenceTableSource = require('cpml.atlas')\n clamp = utils.clamp\nend\nif pcall(initiateRequiredLibaries) then\n system.print(\"Libaries loaded successfully\")\n else\n system.print(\"Libaries failed to load: check that the following libraries exist:\")\n system.print(\"( is the directory in to which you installed DU)\")\n system.print(\" /DualUniverse/Game/data/lua/dkjson\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/vec3\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/utils\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/planetref\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/atlas\")\n system.print(\"\")\n system.print(\"planetref.lua and atlas.lua can be obtained from the following GitLab url:\")\n system.print(\"https://gitlab.com/JayleBreak/dualuniverse/-/tree/master/DUflightfiles/autoconf/custom\")\n unit.exit()\nend\n-----------------------------------------------\n-- Global Variables\n-----------------------------------------------\n\nlocal version = \"2_1_2\"\n\nlocal UpdateInterval = 1 \nlocal defaultNewLocName = \"SatNav Location\" --export: default name used for new locations\n--[[Original colours are 34b1eb, 6e3de3 and 1e1e1e]]\nlocal PlanetPanelColour = \"99eeff\" --export: Hex code for colour of planet panel and buttons (you need to include the quotes)\nlocal LocPanelColour = \"aa99ff\" --export: Hex code for colour of locations panel and buttons (you need to include the quotes)\nlocal FontPanelColour = \"000000\" --export: Hex code for font colour of planet/locations panel (you need to include the quotes)\nlocal LineHighlightColour = \"ccffff\"--export: Hex code for colour of highlighted lines in planet/location panel (you need to include the quotes)\n\nlocal BackgroundColor = \"#1e1e1e\"\nlocal PlanetBackgroundColor = \"#\" .. PlanetPanelColour\nlocal LocationBackgroundColor = \"#\" .. LocPanelColour\nlocal MainFontColor = \"#\" .. FontPanelColour\nlocal HighlightColor = \"#\" .. LineHighlightColour\n\nlocal lastPlanetSelected = \"Alioth\" --export: The default start planet for displaying locations\n\nlocal clickAreas = {}\nlocal locList={}\npageLines=12\ndisplayPlanetList={}\ndisplayLocationList={}\nCurrentLocationPage = 1\nCurrentPlanetPage = 1\nmyDatabank={}\ndbHud={}\n\nif db1 then db1Keys = db1.getKeys() end\nif db2 then db2Keys = db2.getKeys() end\n\n--if db1Keys then system.print(\"DB1 Keys: \"..string.sub(db1Keys,1,50)) end\n--if db2Keys then system.print(\"DB2 Keys: \"..string.sub(db2Keys,1,50)) end\n\nif db1 and (db1Keys==nil or db1Keys == \"\" or string.match(db1Keys, \"lastNewLoc\")) then\n myDatabank = db1\n system.print(\"SatNav Databank Identified\")\nelseif db2 and (db2Keys==nil or db2Keys == \"\" or string.match(db2Keys, \"lastNewLoc\")) then\n myDatabank = db2\n system.print(\"SatNav Databank Identified\")\nelse \n system.print(\"SatNav databank not found... application will stop\")\n if db1Keys then system.print(\"DB1 Keys: \"..string.sub(db1Keys,1,50)) end\n if db2Keys then system.print(\"DB2 Keys: \"..string.sub(db2Keys,1,50)) end\n unit.exit()\n unit.deactivate()\nend\n\nif myDatabank==db1 and db2 and string.match(db2Keys, \"AutopilotTargetIndex\") then\n dbHud = db2\n system.print(\"Dimencia Hud Identified\")\n HUD = \"Dimencia\"\nelseif myDatabank==db2 and db1 and string.match(db1Keys, \"AutopilotTargetIndex\") then\n dbHud = db1\n system.print(\"Dimencia Hud Identified\")\n HUD = \"Dimencia\"\nelse \n system.print(\"No Dimencia Hud Identified - will run in Stand Alone mode\")\n HUD = \"unknown\"\nend\n\n--unit.exit()\n-----------------------------------------------\n-- set up galaxy data and functions for planets and locations\n-----------------------------------------------\n\ngalaxyReference = planetRef(referenceTableSource)\nhelios = galaxyReference[0] -- PlanetaryReference.PlanetarySystem instance\nplanetList={}\nplanetDistList={}\nlocDistList={}\n\nfunction getBodyId(planetName)\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n if string.lower(helios[tonumber(i)].name) ==string.lower(planetName) then\n return i\n end\n end\n end\n return 0\nend\n\nfunction buildPlanetList()\n local planet={}\n local currentLoc = vec3(core.getConstructWorldPos())\n local shipMass = core.getConstructMass()\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n planet = helios[tonumber(i)]\n planetList[#planetList+1] = planet.name\n local planetDistance = planet:getDistance(currentLoc)\n planetDistList[planet.name] = formatDistance(planetDistance) .. \n string.format(\" [%.0f wc]\", ((planetDistance/200000)*(shipMass/1000)/4000))\n end\n end\n planetList[#planetList+1]=\"Space\"\n table.sort(planetList)\nend\n\nfunction formatDistance(distance)\n if distance < 200000 then\n return string.format(\"%.0f km\",distance/1000)\n elseif distance < 4000000 then\n return string.format(\"%.2f su\",distance/200000)\n else\n return string.format(\"%.0f su\",distance/200000)\n end\nend\n\n-- json parser\n\n-- Extracts values from a JSON string with pattern matching\n-- This is faster than using dkjson when only a few fields are needed\n\n-- Use this only with trusted data sources! Limitations:\n-- * Character escapes are not supported\n-- * Field nesting is ignored\n\nlocal find, gsub = string.find, string.gsub\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return string|nil, number|nil, number|nil\nlocal function extractStringJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*\"([^\"]*)\"]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n return valueStr, startIndex, endIndex\nend\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return number|nil, number|nil, number|nil\nlocal function extractNumberJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*(-?[0-9.e-]+)]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n return tonumber(valueStr), startIndex, endIndex\nend\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return boolean|nil, number|nil, number|nil\nlocal function extractBooleanJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*([truefals]+)]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n\n if valueStr == \"true\" then\n return true, startIndex, endIndex\n elseif valueStr == \"false\" then\n return false, startIndex, endIndex\n else\n return nil\n end\nend\n\n---@param extractJsonValue function\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue any|nil\n---@return any[]\nlocal function extractAllJsonValues (extractJsonValue, json, key, stopAfterIndex, stopAfterValue)\n local values = {}\n local valuesLen = 0\n\n local jsonPos = 1\n local value, valueStartIndex, valueEndIndex -- luacheck: ignore valueStartIndex -- unused\n\n repeat\n value, valueStartIndex, valueEndIndex = extractJsonValue(json, key, jsonPos)\n\n if value ~= nil then\n valuesLen = valuesLen + 1\n values[valuesLen] = value\n\n jsonPos = valueEndIndex + 1\n end\n\n if value == stopAfterValue then break end\n if valuesLen == stopAfterIndex then break end\n until value == nil\n\n return values\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue string|nil\n---@return string[]\nlocal function extractAllStringJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractStringJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue number|nil\n---@return number[]\nlocal function extractAllNumberJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractNumberJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue boolean|nil\n---@return boolean[]\nlocal function extractAllBooleanJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractBooleanJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n-- end json Parser\n\n\nfunction buildPlanetLocList(planetName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n \n local currentLoc = vec3(core.getConstructWorldPos())\n local shipMass = core.getConstructMass()\n local planet={}\n locList={}\n if planetName ~= \"Space\" then\n table.insert(locList, planetName) -- add planet name into the list as a default\n locDistList[planetName] = planetDistList[planetName]\n end\n if #name > 0 then \n for i=1,#name do\n if string.lower(planetname[i]) == string.lower(planetName) or\n string.find(string.lower(planetname[i]),string.lower(planetName))\n then\n table.insert(locList, name[i])\n elseif planetname[i] == \"\" and planetName == \"Space\" then -- a space location\n table.insert(locList, name[i])\n end\n local locDistance = (currentLoc - vec3(posX[i],posY[i],posZ[i])):len()\n if planetName == \"Space\" then\n locDistList[name[i]] = formatDistance(locDistance) ..\n string.format(\" [%.0f wc]\", ((locDistance/200000)*(shipMass/1000)/4000))\n else\n locDistList[name[i]] = formatDistance(locDistance)\n end\n end\n end\n table.sort(locList)\nend\n\nfunction printLocMapPos(locationName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local wayPoint=\"\"\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n local planet={}\n if #name > 0 then \n for i = 1, #name do\n if string.lower(name[i]) == string.lower(locationName) then\n local bodyId = getBodyId(planetname[i])\n planet = helios[tonumber(bodyId)] \n if planet ~= nil then\n worldCoords = planet:convertToMapPosition(vec3(posX[i],posY[i],posZ[i]))\n wayPoint=string.format([[::pos{%d,%d,%f,%f,%f}]],\n worldCoords.systemId,\n worldCoords.bodyId,\n worldCoords.latitude*constants.rad2deg,\n worldCoords.longitude*constants.rad2deg,\n worldCoords.altitude)\n system.print(name[i]..\" @ \"..wayPoint)\n system.setWaypoint(wayPoint)\n return locationName,\n planetname[i],\n atmosphere[i],\n gravity[i],\n posX[i],\n posY[i],\n posZ[i]\n else\n wayPoint=string.format([[::pos{%d,%d,%f,%f,%f}]],\n 0,\n bodyId,\n posX[i],posY[i],posZ[i])\n system.print(name[i]..\" @ \"..wayPoint)\n system.setWaypoint(wayPoint)\n return locationName,\n planetname[i],\n atmosphere[i],\n gravity[i],\n posX[i],\n posY[i],\n posZ[i]\n end\n break\n end \n end\n end\n return \"\"\nend\n\nfunction clearSavedLocations()\n myDatabank.setStringValue(\"SavedLocations\",\"[]\")\n system.print(\"Satnav Databank cleared\")\nend\n\nfunction isDuplicateLocation(locName, locNameList)\n for i=1,#locNameList do\n if locNameList[i] == locName then\n return locName\n end\n end\n return \"\"\nend\n\nfunction saveSavedLocations (name, planetname, atmosphere, gravity, posX, posY, posZ)\n local newSavedLocations = \"[\"\n for i = 1, #name do\n if name[i]~=\"\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..name[i]..\n [[\",\"planetname\":\"]]..planetname[i]..[[\"]]..\n [[,\"atmosphere\":]]..atmosphere[i]..\n [[,\"gravity\":]]..gravity[i]..\n [[,\"position\":{\"x\":]]..posX[i]..\n [[,\"y\":]]..posY[i]..\n [[,\"z\":]]..posZ[i]..[[}}]]\n end\n if i+1<#name then\n newSavedLocations= newSavedLocations..\",\"\n end\n end\n newSavedLocations= newSavedLocations..\"]\" \n --system.print(newSavedLocations)\n myDatabank.setStringValue(\"SavedLocations\",newSavedLocations)\n system.print(\"Satnav Databank Updated\")\nend\n\nfunction updateLocationName(newLocName)\n if newLocName ~= nil and newLocName ~= \"\" and \n lastLocationSelected ~= nil and lastLocationSelected ~= \"\" then\n system.print(\"Updating location name for: \"..lastLocationSelected..\" to: \"..newLocName)\n else\n system.print(\"Invalid update request\")\n return\n end\n local savedLocation = {}\n local oldLocFound = false\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n for i = 1, #name do\n if name[i] == lastLocationSelected then\n --system.print(\"Found: \"..lastLocationSelected)\n name[i] = newLocName\n oldLocFound = true\n break\n end\n end\n \n if oldLocFound then \n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n else\n system.print(\"Old Location Name Not Found\")\n end\nend\n\nfunction deleteLocationName(delLocName)\n if delLocName ~= nil and delLocName ~= \"\" then\n system.print(\"Deleting location name: \"..delLocName)\n else\n system.print(\"Invalid update request\")\n return\n end\n local savedLocation = {}\n local oldLocFound = false\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n for i = 1, #name do\n if name[i] == delLocName then\n --system.print(\"Found: \"..delLocName)\n name[i] = \"\"\n oldLocFound = true\n break\n end\n end\n \n if oldLocFound then \n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n else\n system.print(\"Location Name Not Found\")\n end\nend\n\nfunction loadPointsOfInterest()\n -- get existing locations from SatNav Databank\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n\n\n local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)'\n local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' ..\n num .. ',' .. num .. '}'\n local j=0\n loadLocationTable()\n \n for i = 1, #locationTable do\n local newRef = #name + 1\n if isDuplicateLocation(locationTable[i][1],name) == \"\" then\n name[newRef]=locationTable[i][1]\n local newLocPos = locationTable[i][2]\n --system.print(\"Name: \"..locationTable[i][1]..\" \"..newLocPos)\n local systemId, bodyId, latitude, longitude, altitude =\n string.match(locationTable[i][2], posPattern)\n --system.print(\"BodyId: \".. bodyId)\n if tonumber(bodyId) > 0 then\n local planet = helios[tonumber(bodyId)] \n local worldCoords = planet:convertToWorldCoordinates(newLocPos)\n posX[newRef]=worldCoords[\"x\"]\n posY[newRef]=worldCoords[\"y\"]\n posZ[newRef]=worldCoords[\"z\"]\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=planet.name\n else -- it is a space location\n posX[newRef]=latitude\n posY[newRef]=longitude\n posZ[newRef]=altitude\n gravity[newRef]=0\n atmosphere[newRef]=0\n planetname[newRef]=\"\"\n end \n else\n system.print(\"Duplicate entry for location ignored: \"..locationTable[i][1])\n end\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n --system.print(\"Default SatNav locations loaded\")\nend\n\nfunction loadHudLocations()\n -- get existing locations from SatNav Databank\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n\n local hudLocation = dbHud.getStringValue(\"SavedLocations\")\n local hudatmosphere={}\n local hudgravity={}\n local hudplanetname = {}\n local hudposX\t = {}\n local hudposY\t = {}\n local hudposZ\t = {}\n local hudname\t = {}\n\n hudatmosphere = extractAllNumberJsonValues(hudLocation,\"atmosphere\")\n hudgravity = extractAllNumberJsonValues(hudLocation,\"gravity\")\n hudplanetname = extractAllStringJsonValues(hudLocation,\"planetname\")\n hudposX\t = extractAllNumberJsonValues(hudLocation,\"x\")\n hudposY\t = extractAllNumberJsonValues(hudLocation,\"y\")\n hudposZ\t = extractAllNumberJsonValues(hudLocation,\"z\")\n hudname\t = extractAllStringJsonValues(hudLocation,\"name\")\n\n\n for i = 1, #hudname do\n local newRef = #name + 1\n system.print(\"HudName: \"..hudname[i])\n if isDuplicateLocation(hudname[i],name) == \"\" and\n hudname[i] ~= \"SatNav Location\" then\n name[newRef]=hudname[i]\n posX[newRef]=hudposX[i]\n posY[newRef]=hudposY[i]\n posZ[newRef]=hudposZ[i]\n gravity[newRef]=hudgravity[i]\n atmosphere[newRef]=hudatmosphere[i]\n planetname[newRef]=hudplanetname[i] \n else\n system.print(\"Duplicate entry for location ignored: \"..hudname[i])\n end\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n --system.print(\"Default SatNav locations loaded\")\nend\n\n\nfunction newLocation ()\n local location = system.getWaypointFromPlayerPos()\n local newLocId = myDatabank.getIntValue(\"lastNewLoc\") + 1\n myDatabank.setIntValue(\"lastNewLoc\",newLocId)\n \n local newLocName = defaultNewLocName..\" (\"..newLocId..\")\"\n \n local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)'\n local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' ..\n num .. ',' .. num .. '}'\n \n local savedLocation = {}\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n \n local systemId, bodyId, latitude, longitude, altitude =\n string.match(location, posPattern)\n local worldPos = unit.getMasterPlayerRelativePosition()\n local body = helios:closestBody(worldPos)\n --system.print(json.encode(body))\n --system.print(\"Distance=\"..((vec3(worldPos)-vec3(body.center)):len())/(1000))\n --system.print(\"Calc=\"..((body.radius+body.center):len())/(1000))\n\n newlocAlt = ((vec3(worldPos)-vec3(body.center)):len())/(1000)\n-- system.print(\"New Loc Alt:\"..newlocAlt)\n-- system.print(\"Radius:\"..(((body.radius)/1000) + 200))\n if newlocAlt < (((body.radius)/1000) + 200) then\n local bodyId = getBodyId(body.name)\n --system.print(\"BodyId: \".. bodyId)\n local planet = helios[tonumber(bodyId)] -- PlanetaryReference.BodyParameters instance\n --system.print(\"Planet BodyId: \".. planet.bodyId)\n local worldCoords = planet:convertToWorldCoordinates(location)\n newRef = #name + 1\n name[newRef]=newLocName\n posX[newRef]=worldCoords[\"x\"]\n posY[newRef]=worldCoords[\"y\"]\n posZ[newRef]=worldCoords[\"z\"]\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=body.name\n else\n newRef = #name + 1\n name[newRef]=newLocName\n posX[newRef]=latitude\n posY[newRef]=longitude\n posZ[newRef]=altitude\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=\"Space\"\n\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n system.print(\"New location: \"..newLocName..\" added to SatNav databank\")\n printLocMapPos(newLocName)\nend\n\nfunction copySelectedToHud (locName)\n \n local locName, locplanetname, locatmosphere, locgravity, locX, locY, locZ = \n printLocMapPos(locName)\n if HUD == \"Dimencia\" then\n savedLocation = dbHud.getStringValue(\"SavedLocations\")\n --system.print(\"savedLocation=\"..savedLocation)\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n local newSavedLocations = \"[\"\n for i = 1, #name do\n if name[i] ~= \"SatNav Location\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..name[i]..\n [[\",\"planetname\":\"]]..planetname[i]..[[\"]]..\n [[,\"atmosphere\":]]..atmosphere[i]..\n [[,\"gravity\":]]..gravity[i]..\n [[,\"position\":{\"x\":]]..posX[i]..\n [[,\"y\":]]..posY[i]..\n [[,\"z\":]]..posZ[i]..[[}},]]\n end\n end\n if locplanetname ~= \"\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..\"SatNav Location\"..\n [[\",\"planetname\":\"]]..locplanetname..[[\"]]..\n [[,\"atmosphere\":]]..locatmosphere..\n [[,\"gravity\":]]..locgravity..\n [[,\"position\":{\"x\":]]..locX..\n [[,\"y\":]]..locY..\n [[,\"z\":]]..locZ..[[}}]]\n end\n newSavedLocations= newSavedLocations..\"]\" \n dbHud.setStringValue(\"SavedLocations\",newSavedLocations)\n dbHud.setStringValue(\"SPBAutopilotTargetName\",\"SatNav Location\")\n end\nend\n\nfunction clearHudLocations()\n if HUD == \"Dimencia\" then\n dbHud.setStringValue(\"SavedLocations\",\"[]\")\n dbHud.setStringValue(\"SPBAutopilotTargetName\",\"\")\n system.print(\"Dimencia HUD Saved Locations Cleared\")\n end\nend\n\nfunction duplicateSatnavDB()\n local satnavLocation = myDatabank.getStringValue(\"SavedLocations\")\n local lastNewLoc = myDatabank.getIntValue(\"lastNewLoc\")\n if dupSatnavDB then\n dupSatnavDB.clear()\n dupSatnavDB.setStringValue(\"SavedLocations\",satnavLocation)\n dupSatnavDB.setIntValue(\"lastNewLoc\",lastNewLoc)\n system.print(\"SatNav Databank Duplicated Successfully\")\n else\n system.print(\"No space databank linked, duplication aborted\")\n end\nend\n\nbuildPlanetList()\nbuildPlanetLocList(lastPlanetSelected)\nlocal planetCount=#planetList\n\n-----------------------------------------------\n-- Code for on screen buttons\n-----------------------------------------------\n\nfunction DrawSVG(output) screen.setSVG(output) end\n\nfunction AddClickArea(newEntry) table.insert(clickAreas, newEntry) end\n\nfunction RemoveFromClickAreas(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = nil\n break\n end\n end\nend\n\nfunction UpdateClickArea(candidate, newEntry)\n --system.print(\"Candidate: \"..candidate..\" x1\"..newEntry.x1)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = newEntry\n --system.print(\"Click Area: \"..candidate..\" x1\"..clickAreas[k].x1)\n break\n end\n end\nend\n\nfunction DisableClickArea(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n UpdateClickArea(candidate, {\n id = candidate,\n x1 = -1,\n x2 = -1,\n y1 = -1,\n y2 = -1\n })\n break\n end\n end\nend\n\nfunction InitiateClickAreas()\n clickAreas = {}\n \n AddClickArea({id = \"LoadSatNavLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LoadHudLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"NewLocation\", x1 = 700, x2 = 1100, y1 = 900, y2 = 1000})\n AddClickArea({id = \"ClearHudLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"PlanetPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"PlanetPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n \n for i = 1, pageLines do\n AddClickArea({id = string.format(\"PList%d\",i), x1 = 90, x2 = 800, y1 = (170 + i * 55), y2 = (225 + i * 55)})\n AddClickArea({id = string.format(\"LList%d\",i), x1 = 1090, x2 = 1500, y1 = (170 + i * 55), y2 = (225 + i * 55)})\n end\nend\n\nfunction FlushClickAreas() clickAreas = {} end\n\nfunction clearLocDispList()\n for i=1,pageLines do\n displayLocationList[i] = \"\"\n end\nend\n\nfunction CheckClick(x, y, HitTarget)\n HitTarget = HitTarget or \"\"\n if HitTarget == \"\" then\n for k, v in pairs(clickAreas) do\n if v and x >= v.x1 and x <= v.x2 and y >= v.y1 and y <= v.y2 then\n HitTarget = v.id\n break\n end\n end\n end\n \n --system.print(\"Target Hit = \"..HitTarget)\n \n if HitTarget == \"PlanetPageDown\" then\n CurrentPlanetPage = CurrentPlanetPage+1\n DrawPlanetList()\n elseif HitTarget == \"PlanetPageUp\" then\n CurrentPlanetPage = math.max(CurrentPlanetPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LocationPageDown\" then\n CurrentLocationPage = CurrentLocationPage+1\n DrawPlanetList()\n elseif HitTarget == \"LocationPageUp\" then\n CurrentLocationPage = math.max(CurrentLocationPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LoadSatNavLocations\" then\n loadPointsOfInterest()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n elseif HitTarget == \"LoadHudLocations\" then\n loadHudLocations()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end \n elseif HitTarget == \"ClearSatNavLocations\" then\n system.print(\"ClearSavedLocations\")\n clearSavedLocations()\n system.print(\"defaul=\"..displayPlanetList[1])\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n elseif HitTarget == \"ClearHudLocations\" then\n --system.print(\"ClearSavedLocations\")\n clearHudLocations()\n elseif HitTarget == \"NewLocation\" then\n system.print(\"NewLocation\")\n newLocation()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n else\n for i = 1,pageLines do\n if HitTarget == string.format(\"PList%s\",i) then\n --system.print(\"PHitTarget: \"..HitTarget)\n if displayPlanetList[i] ~= \"\" then\n lastPlanetSelected = displayPlanetList[i]\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n DrawPlanetList()\n end\n end\n if HitTarget == string.format(\"LList%s\",i) then\n if displayLocationList[i] ~= \"\" then\n selected = displayLocationList[i]\n if HUD == \"Dimencia\" then\n copySelectedToHud(selected)\n end\n lastLocationSelected = selected\n selected = \"\"\n DrawPlanetList()\n end\n end\n end\n end\nend\n\n-----------------------------------------------\n-- Code for building screen content and displaying it\n-----------------------------------------------\n\nlocal svgBootstrap = [[\n ]]\n\nfunction DrawPlanetList()\n\n local screenOutput = \"\"\n\n -- Draw Header\n screenOutput = screenOutput .. svgBootstrap\n \n -- Draw main background\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[(Version: ]]..version..[[)]]\n screenOutput = screenOutput ..\n [[Sat Nav]]\n if HUD == \"Dimencia\" then\n screenOutput = screenOutput ..\n [[(Dimencia HUD enabled)]]\n else \n screenOutput = screenOutput ..\n [[(Standalone mode enabled)]]\n end\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[Planets]]\n \n\n local i = 0\n for j = 1 + (CurrentPlanetPage - 1) * pageLines, pageLines +\n (CurrentPlanetPage - 1) * pageLines, 1 do\n i = i + 1\n if j < #planetList and j>0 then\n local planetName = planetList[j] \n if lastPlanetSelected == planetList[j] then\n screenOutput = screenOutput ..\n [[]]\n end\n screenOutput = screenOutput .. [[]] .. planetName .. \n [[]]\n if planetName ~= \"Space\" then\n screenOutput = screenOutput .. [[]] .. planetDistList[planetName] .. \n [[]] \n end\n displayPlanetList[i]=planetList[j]\n else\n displayPlanetList[i]=\"\"\n end\n end\n \n if planetCount > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentPlanetPage .. \" of \" ..\n math.ceil(planetCount / 12) ..\n [[]]\n\n if CurrentPlanetPage < math.ceil(planetCount / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageDown\", {\n id = \"PlanetPageDown\",\n x1 = 70,\n x2 = 270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageDown\")\n end\n\n if planetCount > 1 and CurrentPlanetPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageUp\", {\n id = \"PlanetPageUp\",\n x1 = 280,\n x2 = 480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageUp\")\n end\n end\n -- Start of Location List\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[]].. lastPlanetSelected ..[[ Locations]]\n \n\n local i = 0\n for j = 1 + (CurrentLocationPage - 1) * pageLines, pageLines +\n (CurrentLocationPage - 1) * pageLines, 1 do\n \n i = i + 1\n if j <= #locList and j>0 then\n if lastLocationSelected == locList[j] then\n screenOutput = screenOutput ..\n [[]]\n end\n screenOutput = screenOutput .. [[]] .. locList[j] .. \n [[]]\n displayLocationList[i]=locList[j]\n screenOutput = screenOutput .. [[]] .. locDistList[locList[j]] .. \n [[]] \n else\n displayLocationList[i]=\"\"\n end\n end\n \n if #locList > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentLocationPage .. \" of \" ..\n math.ceil(#locList / 12) ..\n [[]]\n\n if CurrentLocationPage < math.ceil(#locList / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageDown\", {\n id = \"LocationPageDown\",\n x1 = 1070,\n x2 = 1270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageDown\")\n end\n\n if #locList > 1 and CurrentLocationPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageUp\", {\n id = \"LocationPageUp\",\n x1 = 1280,\n x2 = 1480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageUp\")\n end\n end\n \n-- screenOutput = screenOutput ..\n-- [[]] ..\n-- [[Load SatNav DB]]\n \n screenOutput = screenOutput ..\n [[]] ..\n [[Save Current Location]]\n\n-- screenOutput = screenOutput ..\n-- [[]] ..\n-- [[Clear HUD Locs]]\n\n\n screenOutput = screenOutput .. [[]]\n\n DrawSVG(screenOutput)\n\n forceRedraw = false\nend\n\n-----------------------------------------------\n-- Execute\n-----------------------------------------------\n\nunit.hide()\nInitiateClickAreas()\nDrawPlanetList()\nsystem.print(\"Running\")\nunit.setTimer(\"loadwp\",1)\n\n\n","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"6"},{"code":"function loadLocationTable ()\n\nlocationTable = {{}}\nlocationTable[1] = {\"Alioth Market 1\", \"::pos{0,2,30.3314,101.3106,122.9764}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 2\", \"::pos{0,2,24.4469,88.0409,238.3019}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 3\", \"::pos{0,2,34.9734,87.3012,176.2188}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 4\", \"::pos{0,2,28.3352,99.5187,165.9078}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 5\", \"::pos{0,2,33.3939,87.3299,277.1366}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 6\", \"::pos{0,2,36.0044,101.3503,220.0897}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 7\", \"::pos{0,2,22.5024,98.1449,232.5154}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 8\", \"::pos{0,2,21.2154,93.9616,251.0768}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 9\", \"::pos{0,2,28.7133,85.6389,260.7636}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 10\", \"::pos{0,2,35.9865,91.8393,190.1616}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 11\", \"::pos{0,2,-1.0735,178.5062,69.9428}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 12\", \"::pos{0,2,22.7112,-92.3078,166.8481}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 13\", \"::pos{0,2,-23.3768,-10.5455,178.8458}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 14\", \"::pos{0,2,-73.4716,101.3697,89.5661}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 15\", \"::pos{0,2,61.7831,27.8517,54.9186}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 16\", \"::pos{0,2,23.4406,114.4179,211.1991}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 17\", \"::pos{0,2,37.8637,64.1825,151.5507}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 18\", \"::pos{0,2,49.9360,-170.7565,62.1982}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 19\", \"::pos{0,2,-32.7357,76.3764,209.0805}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 20\", \"::pos{0,2,-35.1535,-95.1230,301.0724}\"} \n \nlocationTable[#locationTable+1] = {\"Madis Market 1\", \"::pos{0,1,2.6476,176.8761,813.0974}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 2\", \"::pos{0,1,10.3552,8.5146,816.2210}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 3\", \"::pos{0,1,-0.2107,82.0779,809.5571}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 4\", \"::pos{0,1,-80.6046,44.9385,822.6188}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 5\", \"::pos{0,1,81.0827,5.3022,823.1976}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 6\", \"::pos{0,1,13.9814,-91.6163,811.0679}\"}\n\nlocationTable[#locationTable+1] = {\"Thades M1: Market\", \"::pos{0,30,-2.9797,-117.7645,203.7519}\"}\nlocationTable[#locationTable+1] = {\"Feli: Market\", \"::pos{0,5,0.9348,178.6658,18417.2812}\"}\nlocationTable[#locationTable+1] = {\"Feli: Market 3\", \"::pos{0,5,-0.7500,-17.3248,18473.4238}\"}\n\nlocationTable[#locationTable+1] = {\"Symeon Market 1\", \"::pos{0,110,3.1400,-174.0223,267.1084}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 2\", \"::pos{0,110,-0.9862,88.3038,197.0626}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 3\", \"::pos{0,110,18.1117,11.1108,180.8022}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 4\", \"::pos{0,110,-26.9701,103.3741,186.2557}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 5\", \"::pos{0,110,83.1653,108.7807,142.5796}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 6\", \"::pos{0,110,-79.3167,95.3975,138.5268}\"}\n\nlocationTable[#locationTable+1] = {\"TMV Troghelm\", \"::pos{0,0,2416521.6598,1415126.8118,59323.7340}\"}\nlocationTable[#locationTable+1] = {\"TMV Alioth Factory\", \"::pos{0,2,22.8158,111.1414,103.5685}\"}\nlocationTable[#locationTable+1] = {\"TMV Feli Outpost\", \"::pos{0,5,23.6988,-77.8811,18480.5176}\"}\nlocationTable[#locationTable+1] = {\"TMV Thandes M1 Outpost\", \"::pos{0,30,-22.3548,-168.7352,288.1909}\"}\nlocationTable[#locationTable+1] = {\"TMV Madis Outpost\", \"::pos{0,1,-43.0914,75.0728,749.6641}\"}\nlocationTable[#locationTable+1] = {\"TMV Symoen Outpost\", \"::pos{0,110,-5.3046,32.6900,108.4144}\"}\nlocationTable[#locationTable+1] = {\"TMV Jago Outpost\", \"::pos{0,9,61.3760,-33.7830,10.7593}\"}\n\nend\n\nunit.stopTimer(\"loadwp\")\nloadLocationTable()\nlastNewLoc = myDatabank.getIntValue(\"lastNewLoc\")\n--system.print(\"lastNewLoc\"..lastNewLoc)\nif lastNewLoc == nil or lastNewLoc==0 then\n --this is th first time satnav has run on this databank\n system.print(\"Initialising SatNav Databank\")\n CheckClick(0, 0, \"LoadSatNavLocations\")\n lastNewLoc =1\n myDatabank.setIntValue(\"lastNewLoc\",lastNewLoc)\n system.print(\"Completed SatNav Databank\")\nend\n\n\n","filter":{"args":[{"value":"loadwp"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"7"},{"code":"\nif string.sub(text,1,2) == \"u \" then\n local newLocName = string.sub(text,3,string.len(text))\n updateLocationName(newLocName)\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\nelseif text == \"d SatNav\" then\n deleteLocationName(lastLocationSelected)\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\nelseif text == \"c SatNav\" then\n system.print(\"ClearSatNavLocations\")\n CheckClick(0, 0, \"ClearSatNavLocations\")\nelseif text == \"c Hud\" then\n if HUD == \"Dimencia\" then\n system.print(\"ClearHudLocations\")\n CheckClick(0, 0, \"ClearHudLocations\")\n else\n system.print(\"ClearHudLocations not available in standalone mode\")\n end\nelseif text == \"l SatNav\" then\n system.print(\"LoadSatNavLocations\")\n CheckClick(0, 0, \"LoadSatNavLocations\")\nelseif text == \"l Hud\" then\n if HUD == \"Dimencia\" then\n system.print(\"LoadHudLocations\")\n CheckClick(0, 0, \"LoadHudLocations\")\n else\n system.print(\"LoadHudLocations not available in standalone mode\")\n end\nelseif text == \"x SatNav\" then\n if dupSatnavDB then\n system.print(\"DuplicateSatNavDB\")\n duplicateSatnavDB()\n else\n system.print(\"Please link an empty databank to the programming board\")\n end\nend","filter":{"args":[{"variable":"*"}],"signature":"inputText(text)","slotKey":"-2"},"key":"8"}],"methods":[],"events":[]} From 681c552754a0309571cdc2df74853751e4d88025 Mon Sep 17 00:00:00 2001 From: Merl Date: Sat, 19 Dec 2020 00:25:41 +0100 Subject: [PATCH 3/7] removed old versions and renamed current to SatNav_PB_Paste.json --- SatNav_PB_Paste.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 SatNav_PB_Paste.json diff --git a/SatNav_PB_Paste.json b/SatNav_PB_Paste.json new file mode 100644 index 0000000..fa3364c --- /dev/null +++ b/SatNav_PB_Paste.json @@ -0,0 +1 @@ +{"slots":{"0":{"name":"core","type":{"events":[],"methods":[]}},"1":{"name":"screen","type":{"events":[],"methods":[]}},"2":{"name":"db2","type":{"events":[],"methods":[]}},"3":{"name":"db1","type":{"events":[],"methods":[]}},"4":{"name":"dupSatnavDB","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"1"},"key":"0"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"5"},"key":"1"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"6"},"key":"2"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"7"},"key":"3"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"8"},"key":"4"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"9"},"key":"5"},{"code":"--[[\n SatNav version 2_1_2\n Created By TrogLaByte\n\n Discord: Trog#5105\n InGame: TrogLaByte\n \n GNU Public License 3.0. Use whatever you want, be so kind to leave credit.\n\n Thanks to Dorien Grey for his SVG and onscreen button code.\n]] \n-----------------------------------------------\n-- requirements\n-----------------------------------------------\n\nfunction initiateRequiredLibaries()\n --json = require('dkjson')\n vec3 = require('cpml.vec3')\n utils = require('cpml.utils')\n planetRef = require('cpml.planetref')\n referenceTableSource = require('cpml.atlas')\n clamp = utils.clamp\nend\nif pcall(initiateRequiredLibaries) then\n system.print(\"Libaries loaded successfully\")\n else\n system.print(\"Libaries failed to load: check that the following libraries exist:\")\n system.print(\"( is the directory in to which you installed DU)\")\n system.print(\" /DualUniverse/Game/data/lua/dkjson\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/vec3\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/utils\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/planetref\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/atlas\")\n system.print(\"\")\n system.print(\"planetref.lua and atlas.lua can be obtained from the following GitLab url:\")\n system.print(\"https://gitlab.com/JayleBreak/dualuniverse/-/tree/master/DUflightfiles/autoconf/custom\")\n unit.exit()\nend\n-----------------------------------------------\n-- Global Variables\n-----------------------------------------------\n\nlocal version = \"2_1_2\"\n\nlocal UpdateInterval = 1 \nlocal defaultNewLocName = \"SatNav Location\" --export: default name used for new locations\n--[[Original colours are 34b1eb, 6e3de3 and 1e1e1e]]\nlocal PlanetPanelColour = \"99eeff\" --export: Hex code for colour of planet panel and buttons (you need to include the quotes)\nlocal LocPanelColour = \"aa99ff\" --export: Hex code for colour of locations panel and buttons (you need to include the quotes)\nlocal FontPanelColour = \"000000\" --export: Hex code for font colour of planet/locations panel (you need to include the quotes)\nlocal LineHighlightColour = \"ccffff\"--export: Hex code for colour of highlighted lines in planet/location panel (you need to include the quotes)\n\nlocal BackgroundColor = \"#1e1e1e\"\nlocal PlanetBackgroundColor = \"#\" .. PlanetPanelColour\nlocal LocationBackgroundColor = \"#\" .. LocPanelColour\nlocal MainFontColor = \"#\" .. FontPanelColour\nlocal HighlightColor = \"#\" .. LineHighlightColour\n\nlocal lastPlanetSelected = \"Alioth\" --export: The default start planet for displaying locations\n\nlocal clickAreas = {}\nlocal locList={}\npageLines=12\ndisplayPlanetList={}\ndisplayLocationList={}\nCurrentLocationPage = 1\nCurrentPlanetPage = 1\nmyDatabank={}\ndbHud={}\n\nif db1 then db1Keys = db1.getKeys() end\nif db2 then db2Keys = db2.getKeys() end\n\n--if db1Keys then system.print(\"DB1 Keys: \"..string.sub(db1Keys,1,50)) end\n--if db2Keys then system.print(\"DB2 Keys: \"..string.sub(db2Keys,1,50)) end\n\nif db1 and (db1Keys==nil or db1Keys == \"\" or string.match(db1Keys, \"lastNewLoc\")) then\n myDatabank = db1\n system.print(\"SatNav Databank Identified\")\nelseif db2 and (db2Keys==nil or db2Keys == \"\" or string.match(db2Keys, \"lastNewLoc\")) then\n myDatabank = db2\n system.print(\"SatNav Databank Identified\")\nelse \n system.print(\"SatNav databank not found... application will stop\")\n if db1Keys then system.print(\"DB1 Keys: \"..string.sub(db1Keys,1,50)) end\n if db2Keys then system.print(\"DB2 Keys: \"..string.sub(db2Keys,1,50)) end\n unit.exit()\n unit.deactivate()\nend\n\nif myDatabank==db1 and db2 and string.match(db2Keys, \"AutopilotTargetIndex\") then\n dbHud = db2\n system.print(\"Dimencia Hud Identified\")\n HUD = \"Dimencia\"\nelseif myDatabank==db2 and db1 and string.match(db1Keys, \"AutopilotTargetIndex\") then\n dbHud = db1\n system.print(\"Dimencia Hud Identified\")\n HUD = \"Dimencia\"\nelse \n system.print(\"No Dimencia Hud Identified - will run in Stand Alone mode\")\n HUD = \"unknown\"\nend\n\n--unit.exit()\n-----------------------------------------------\n-- set up galaxy data and functions for planets and locations\n-----------------------------------------------\n\ngalaxyReference = planetRef(referenceTableSource)\nhelios = galaxyReference[0] -- PlanetaryReference.PlanetarySystem instance\nplanetList={}\nplanetDistList={}\nlocDistList={}\n\nfunction getBodyId(planetName)\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n if string.lower(helios[tonumber(i)].name) ==string.lower(planetName) then\n return i\n end\n end\n end\n return 0\nend\n\nfunction buildPlanetList()\n local planet={}\n local currentLoc = vec3(core.getConstructWorldPos())\n local shipMass = core.getConstructMass()\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n planet = helios[tonumber(i)]\n planetList[#planetList+1] = planet.name\n local planetDistance = planet:getDistance(currentLoc)\n planetDistList[planet.name] = formatDistance(planetDistance) .. \n string.format(\" [%.0f wc]\", ((planetDistance/200000)*(shipMass/1000)/4000))\n end\n end\n planetList[#planetList+1]=\"Space\"\n table.sort(planetList)\nend\n\nfunction formatDistance(distance)\n if distance < 200000 then\n return string.format(\"%.0f km\",distance/1000)\n elseif distance < 4000000 then\n return string.format(\"%.2f su\",distance/200000)\n else\n return string.format(\"%.0f su\",distance/200000)\n end\nend\n\n-- json parser\n\n-- Extracts values from a JSON string with pattern matching\n-- This is faster than using dkjson when only a few fields are needed\n\n-- Use this only with trusted data sources! Limitations:\n-- * Character escapes are not supported\n-- * Field nesting is ignored\n\nlocal find, gsub = string.find, string.gsub\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return string|nil, number|nil, number|nil\nlocal function extractStringJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*\"([^\"]*)\"]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n return valueStr, startIndex, endIndex\nend\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return number|nil, number|nil, number|nil\nlocal function extractNumberJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*(-?[0-9.e-]+)]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n return tonumber(valueStr), startIndex, endIndex\nend\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return boolean|nil, number|nil, number|nil\nlocal function extractBooleanJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*([truefals]+)]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n\n if valueStr == \"true\" then\n return true, startIndex, endIndex\n elseif valueStr == \"false\" then\n return false, startIndex, endIndex\n else\n return nil\n end\nend\n\n---@param extractJsonValue function\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue any|nil\n---@return any[]\nlocal function extractAllJsonValues (extractJsonValue, json, key, stopAfterIndex, stopAfterValue)\n local values = {}\n local valuesLen = 0\n\n local jsonPos = 1\n local value, valueStartIndex, valueEndIndex -- luacheck: ignore valueStartIndex -- unused\n\n repeat\n value, valueStartIndex, valueEndIndex = extractJsonValue(json, key, jsonPos)\n\n if value ~= nil then\n valuesLen = valuesLen + 1\n values[valuesLen] = value\n\n jsonPos = valueEndIndex + 1\n end\n\n if value == stopAfterValue then break end\n if valuesLen == stopAfterIndex then break end\n until value == nil\n\n return values\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue string|nil\n---@return string[]\nlocal function extractAllStringJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractStringJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue number|nil\n---@return number[]\nlocal function extractAllNumberJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractNumberJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue boolean|nil\n---@return boolean[]\nlocal function extractAllBooleanJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractBooleanJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n-- end json Parser\n\n\nfunction buildPlanetLocList(planetName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n \n local currentLoc = vec3(core.getConstructWorldPos())\n local shipMass = core.getConstructMass()\n local planet={}\n locList={}\n if planetName ~= \"Space\" then\n table.insert(locList, planetName) -- add planet name into the list as a default\n locDistList[planetName] = planetDistList[planetName]\n end\n if #name > 0 then \n for i=1,#name do\n if string.lower(planetname[i]) == string.lower(planetName) or\n string.find(string.lower(planetname[i]),string.lower(planetName))\n then\n table.insert(locList, name[i])\n elseif planetname[i] == \"\" and planetName == \"Space\" then -- a space location\n table.insert(locList, name[i])\n end\n local locDistance = (currentLoc - vec3(posX[i],posY[i],posZ[i])):len()\n if planetName == \"Space\" then\n locDistList[name[i]] = formatDistance(locDistance) ..\n string.format(\" [%.0f wc]\", ((locDistance/200000)*(shipMass/1000)/4000))\n else\n locDistList[name[i]] = formatDistance(locDistance)\n end\n end\n end\n table.sort(locList)\nend\n\nfunction printLocMapPos(locationName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local wayPoint=\"\"\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n local planet={}\n if #name > 0 then \n for i = 1, #name do\n if string.lower(name[i]) == string.lower(locationName) then\n local bodyId = getBodyId(planetname[i])\n planet = helios[tonumber(bodyId)] \n if planet ~= nil then\n worldCoords = planet:convertToMapPosition(vec3(posX[i],posY[i],posZ[i]))\n wayPoint=string.format([[::pos{%d,%d,%f,%f,%f}]],\n worldCoords.systemId,\n worldCoords.bodyId,\n worldCoords.latitude*constants.rad2deg,\n worldCoords.longitude*constants.rad2deg,\n worldCoords.altitude)\n system.print(name[i]..\" @ \"..wayPoint)\n system.setWaypoint(wayPoint)\n return locationName,\n planetname[i],\n atmosphere[i],\n gravity[i],\n posX[i],\n posY[i],\n posZ[i]\n else\n wayPoint=string.format([[::pos{%d,%d,%f,%f,%f}]],\n 0,\n bodyId,\n posX[i],posY[i],posZ[i])\n system.print(name[i]..\" @ \"..wayPoint)\n system.setWaypoint(wayPoint)\n return locationName,\n planetname[i],\n atmosphere[i],\n gravity[i],\n posX[i],\n posY[i],\n posZ[i]\n end\n break\n end \n end\n end\n return \"\"\nend\n\nfunction clearSavedLocations()\n myDatabank.setStringValue(\"SavedLocations\",\"[]\")\n system.print(\"Satnav Databank cleared\")\nend\n\nfunction isDuplicateLocation(locName, locNameList)\n for i=1,#locNameList do\n if locNameList[i] == locName then\n return locName\n end\n end\n return \"\"\nend\n\nfunction saveSavedLocations (name, planetname, atmosphere, gravity, posX, posY, posZ)\n local newSavedLocations = \"[\"\n for i = 1, #name do\n if name[i]~=\"\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..name[i]..\n [[\",\"planetname\":\"]]..planetname[i]..[[\"]]..\n [[,\"atmosphere\":]]..atmosphere[i]..\n [[,\"gravity\":]]..gravity[i]..\n [[,\"position\":{\"x\":]]..posX[i]..\n [[,\"y\":]]..posY[i]..\n [[,\"z\":]]..posZ[i]..[[}}]]\n end\n if i+1<#name then\n newSavedLocations= newSavedLocations..\",\"\n end\n end\n newSavedLocations= newSavedLocations..\"]\" \n --system.print(newSavedLocations)\n myDatabank.setStringValue(\"SavedLocations\",newSavedLocations)\n system.print(\"Satnav Databank Updated\")\nend\n\nfunction updateLocationName(newLocName)\n if newLocName ~= nil and newLocName ~= \"\" and \n lastLocationSelected ~= nil and lastLocationSelected ~= \"\" then\n system.print(\"Updating location name for: \"..lastLocationSelected..\" to: \"..newLocName)\n else\n system.print(\"Invalid update request\")\n return\n end\n local savedLocation = {}\n local oldLocFound = false\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n for i = 1, #name do\n if name[i] == lastLocationSelected then\n --system.print(\"Found: \"..lastLocationSelected)\n name[i] = newLocName\n oldLocFound = true\n break\n end\n end\n \n if oldLocFound then \n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n else\n system.print(\"Old Location Name Not Found\")\n end\nend\n\nfunction deleteLocationName(delLocName)\n if delLocName ~= nil and delLocName ~= \"\" then\n system.print(\"Deleting location name: \"..delLocName)\n else\n system.print(\"Invalid update request\")\n return\n end\n local savedLocation = {}\n local oldLocFound = false\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n for i = 1, #name do\n if name[i] == delLocName then\n --system.print(\"Found: \"..delLocName)\n name[i] = \"\"\n oldLocFound = true\n break\n end\n end\n \n if oldLocFound then \n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n else\n system.print(\"Location Name Not Found\")\n end\nend\n\nfunction loadPointsOfInterest()\n -- get existing locations from SatNav Databank\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n\n\n local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)'\n local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' ..\n num .. ',' .. num .. '}'\n local j=0\n loadLocationTable()\n \n for i = 1, #locationTable do\n local newRef = #name + 1\n if isDuplicateLocation(locationTable[i][1],name) == \"\" then\n name[newRef]=locationTable[i][1]\n local newLocPos = locationTable[i][2]\n --system.print(\"Name: \"..locationTable[i][1]..\" \"..newLocPos)\n local systemId, bodyId, latitude, longitude, altitude =\n string.match(locationTable[i][2], posPattern)\n --system.print(\"BodyId: \".. bodyId)\n if tonumber(bodyId) > 0 then\n local planet = helios[tonumber(bodyId)] \n local worldCoords = planet:convertToWorldCoordinates(newLocPos)\n posX[newRef]=worldCoords[\"x\"]\n posY[newRef]=worldCoords[\"y\"]\n posZ[newRef]=worldCoords[\"z\"]\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=planet.name\n else -- it is a space location\n posX[newRef]=latitude\n posY[newRef]=longitude\n posZ[newRef]=altitude\n gravity[newRef]=0\n atmosphere[newRef]=0\n planetname[newRef]=\"\"\n end \n else\n system.print(\"Duplicate entry for location ignored: \"..locationTable[i][1])\n end\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n --system.print(\"Default SatNav locations loaded\")\nend\n\nfunction loadHudLocations()\n -- get existing locations from SatNav Databank\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n\n local hudLocation = dbHud.getStringValue(\"SavedLocations\")\n local hudatmosphere={}\n local hudgravity={}\n local hudplanetname = {}\n local hudposX\t = {}\n local hudposY\t = {}\n local hudposZ\t = {}\n local hudname\t = {}\n\n hudatmosphere = extractAllNumberJsonValues(hudLocation,\"atmosphere\")\n hudgravity = extractAllNumberJsonValues(hudLocation,\"gravity\")\n hudplanetname = extractAllStringJsonValues(hudLocation,\"planetname\")\n hudposX\t = extractAllNumberJsonValues(hudLocation,\"x\")\n hudposY\t = extractAllNumberJsonValues(hudLocation,\"y\")\n hudposZ\t = extractAllNumberJsonValues(hudLocation,\"z\")\n hudname\t = extractAllStringJsonValues(hudLocation,\"name\")\n\n\n for i = 1, #hudname do\n local newRef = #name + 1\n system.print(\"HudName: \"..hudname[i])\n if isDuplicateLocation(hudname[i],name) == \"\" and\n hudname[i] ~= \"SatNav Location\" then\n name[newRef]=hudname[i]\n posX[newRef]=hudposX[i]\n posY[newRef]=hudposY[i]\n posZ[newRef]=hudposZ[i]\n gravity[newRef]=hudgravity[i]\n atmosphere[newRef]=hudatmosphere[i]\n planetname[newRef]=hudplanetname[i] \n else\n system.print(\"Duplicate entry for location ignored: \"..hudname[i])\n end\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n --system.print(\"Default SatNav locations loaded\")\nend\n\n\nfunction newLocation ()\n local location = system.getWaypointFromPlayerPos()\n local newLocId = myDatabank.getIntValue(\"lastNewLoc\") + 1\n myDatabank.setIntValue(\"lastNewLoc\",newLocId)\n \n local newLocName = defaultNewLocName..\" (\"..newLocId..\")\"\n \n local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)'\n local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' ..\n num .. ',' .. num .. '}'\n \n local savedLocation = {}\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n \n local systemId, bodyId, latitude, longitude, altitude =\n string.match(location, posPattern)\n local worldPos = unit.getMasterPlayerRelativePosition()\n local body = helios:closestBody(worldPos)\n --system.print(json.encode(body))\n --system.print(\"Distance=\"..((vec3(worldPos)-vec3(body.center)):len())/(1000))\n --system.print(\"Calc=\"..((body.radius+body.center):len())/(1000))\n\n newlocAlt = ((vec3(worldPos)-vec3(body.center)):len())/(1000)\n-- system.print(\"New Loc Alt:\"..newlocAlt)\n-- system.print(\"Radius:\"..(((body.radius)/1000) + 200))\n if newlocAlt < (((body.radius)/1000) + 200) then\n local bodyId = getBodyId(body.name)\n --system.print(\"BodyId: \".. bodyId)\n local planet = helios[tonumber(bodyId)] -- PlanetaryReference.BodyParameters instance\n --system.print(\"Planet BodyId: \".. planet.bodyId)\n local worldCoords = planet:convertToWorldCoordinates(location)\n newRef = #name + 1\n name[newRef]=newLocName\n posX[newRef]=worldCoords[\"x\"]\n posY[newRef]=worldCoords[\"y\"]\n posZ[newRef]=worldCoords[\"z\"]\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=body.name\n else\n newRef = #name + 1\n name[newRef]=newLocName\n posX[newRef]=latitude\n posY[newRef]=longitude\n posZ[newRef]=altitude\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=\"Space\"\n\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n system.print(\"New location: \"..newLocName..\" added to SatNav databank\")\n printLocMapPos(newLocName)\nend\n\nfunction copySelectedToHud (locName)\n \n local locName, locplanetname, locatmosphere, locgravity, locX, locY, locZ = \n printLocMapPos(locName)\n if HUD == \"Dimencia\" then\n savedLocation = dbHud.getStringValue(\"SavedLocations\")\n --system.print(\"savedLocation=\"..savedLocation)\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n local newSavedLocations = \"[\"\n for i = 1, #name do\n if name[i] ~= \"SatNav Location\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..name[i]..\n [[\",\"planetname\":\"]]..planetname[i]..[[\"]]..\n [[,\"atmosphere\":]]..atmosphere[i]..\n [[,\"gravity\":]]..gravity[i]..\n [[,\"position\":{\"x\":]]..posX[i]..\n [[,\"y\":]]..posY[i]..\n [[,\"z\":]]..posZ[i]..[[}},]]\n end\n end\n if locplanetname ~= \"\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..\"SatNav Location\"..\n [[\",\"planetname\":\"]]..locplanetname..[[\"]]..\n [[,\"atmosphere\":]]..locatmosphere..\n [[,\"gravity\":]]..locgravity..\n [[,\"position\":{\"x\":]]..locX..\n [[,\"y\":]]..locY..\n [[,\"z\":]]..locZ..[[}}]]\n end\n newSavedLocations= newSavedLocations..\"]\" \n dbHud.setStringValue(\"SavedLocations\",newSavedLocations)\n dbHud.setStringValue(\"SPBAutopilotTargetName\",\"SatNav Location\")\n end\nend\n\nfunction clearHudLocations()\n if HUD == \"Dimencia\" then\n dbHud.setStringValue(\"SavedLocations\",\"[]\")\n dbHud.setStringValue(\"SPBAutopilotTargetName\",\"\")\n system.print(\"Dimencia HUD Saved Locations Cleared\")\n end\nend\n\nfunction duplicateSatnavDB()\n local satnavLocation = myDatabank.getStringValue(\"SavedLocations\")\n local lastNewLoc = myDatabank.getIntValue(\"lastNewLoc\")\n if dupSatnavDB then\n dupSatnavDB.clear()\n dupSatnavDB.setStringValue(\"SavedLocations\",satnavLocation)\n dupSatnavDB.setIntValue(\"lastNewLoc\",lastNewLoc)\n system.print(\"SatNav Databank Duplicated Successfully\")\n else\n system.print(\"No space databank linked, duplication aborted\")\n end\nend\n\nbuildPlanetList()\nbuildPlanetLocList(lastPlanetSelected)\nlocal planetCount=#planetList\n\n-----------------------------------------------\n-- Code for on screen buttons\n-----------------------------------------------\n\nfunction DrawSVG(output) screen.setSVG(output) end\n\nfunction AddClickArea(newEntry) table.insert(clickAreas, newEntry) end\n\nfunction RemoveFromClickAreas(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = nil\n break\n end\n end\nend\n\nfunction UpdateClickArea(candidate, newEntry)\n --system.print(\"Candidate: \"..candidate..\" x1\"..newEntry.x1)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = newEntry\n --system.print(\"Click Area: \"..candidate..\" x1\"..clickAreas[k].x1)\n break\n end\n end\nend\n\nfunction DisableClickArea(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n UpdateClickArea(candidate, {\n id = candidate,\n x1 = -1,\n x2 = -1,\n y1 = -1,\n y2 = -1\n })\n break\n end\n end\nend\n\nfunction InitiateClickAreas()\n clickAreas = {}\n \n AddClickArea({id = \"LoadSatNavLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LoadHudLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"NewLocation\", x1 = 700, x2 = 1100, y1 = 900, y2 = 1000})\n AddClickArea({id = \"ClearHudLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"PlanetPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"PlanetPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n \n for i = 1, pageLines do\n AddClickArea({id = string.format(\"PList%d\",i), x1 = 90, x2 = 800, y1 = (170 + i * 55), y2 = (225 + i * 55)})\n AddClickArea({id = string.format(\"LList%d\",i), x1 = 1090, x2 = 1500, y1 = (170 + i * 55), y2 = (225 + i * 55)})\n end\nend\n\nfunction FlushClickAreas() clickAreas = {} end\n\nfunction clearLocDispList()\n for i=1,pageLines do\n displayLocationList[i] = \"\"\n end\nend\n\nfunction CheckClick(x, y, HitTarget)\n HitTarget = HitTarget or \"\"\n if HitTarget == \"\" then\n for k, v in pairs(clickAreas) do\n if v and x >= v.x1 and x <= v.x2 and y >= v.y1 and y <= v.y2 then\n HitTarget = v.id\n break\n end\n end\n end\n \n --system.print(\"Target Hit = \"..HitTarget)\n \n if HitTarget == \"PlanetPageDown\" then\n CurrentPlanetPage = CurrentPlanetPage+1\n DrawPlanetList()\n elseif HitTarget == \"PlanetPageUp\" then\n CurrentPlanetPage = math.max(CurrentPlanetPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LocationPageDown\" then\n CurrentLocationPage = CurrentLocationPage+1\n DrawPlanetList()\n elseif HitTarget == \"LocationPageUp\" then\n CurrentLocationPage = math.max(CurrentLocationPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LoadSatNavLocations\" then\n loadPointsOfInterest()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n elseif HitTarget == \"LoadHudLocations\" then\n loadHudLocations()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end \n elseif HitTarget == \"ClearSatNavLocations\" then\n system.print(\"ClearSavedLocations\")\n clearSavedLocations()\n system.print(\"defaul=\"..displayPlanetList[1])\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n elseif HitTarget == \"ClearHudLocations\" then\n --system.print(\"ClearSavedLocations\")\n clearHudLocations()\n elseif HitTarget == \"NewLocation\" then\n system.print(\"NewLocation\")\n newLocation()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n else\n for i = 1,pageLines do\n if HitTarget == string.format(\"PList%s\",i) then\n --system.print(\"PHitTarget: \"..HitTarget)\n if displayPlanetList[i] ~= \"\" then\n lastPlanetSelected = displayPlanetList[i]\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n DrawPlanetList()\n end\n end\n if HitTarget == string.format(\"LList%s\",i) then\n if displayLocationList[i] ~= \"\" then\n selected = displayLocationList[i]\n if HUD == \"Dimencia\" then\n copySelectedToHud(selected)\n end\n lastLocationSelected = selected\n selected = \"\"\n DrawPlanetList()\n end\n end\n end\n end\nend\n\n-----------------------------------------------\n-- Code for building screen content and displaying it\n-----------------------------------------------\n\nlocal svgBootstrap = [[\n ]]\n\nfunction DrawPlanetList()\n\n local screenOutput = \"\"\n\n -- Draw Header\n screenOutput = screenOutput .. svgBootstrap\n \n -- Draw main background\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[(Version: ]]..version..[[)]]\n screenOutput = screenOutput ..\n [[Sat Nav]]\n if HUD == \"Dimencia\" then\n screenOutput = screenOutput ..\n [[(Dimencia HUD enabled)]]\n else \n screenOutput = screenOutput ..\n [[(Standalone mode enabled)]]\n end\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[Planets]]\n \n\n local i = 0\n for j = 1 + (CurrentPlanetPage - 1) * pageLines, pageLines +\n (CurrentPlanetPage - 1) * pageLines, 1 do\n i = i + 1\n if j < #planetList and j>0 then\n local planetName = planetList[j] \n if lastPlanetSelected == planetList[j] then\n screenOutput = screenOutput ..\n [[]]\n end\n screenOutput = screenOutput .. [[]] .. planetName .. \n [[]]\n if planetName ~= \"Space\" then\n screenOutput = screenOutput .. [[]] .. planetDistList[planetName] .. \n [[]] \n end\n displayPlanetList[i]=planetList[j]\n else\n displayPlanetList[i]=\"\"\n end\n end\n \n if planetCount > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentPlanetPage .. \" of \" ..\n math.ceil(planetCount / 12) ..\n [[]]\n\n if CurrentPlanetPage < math.ceil(planetCount / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageDown\", {\n id = \"PlanetPageDown\",\n x1 = 70,\n x2 = 270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageDown\")\n end\n\n if planetCount > 1 and CurrentPlanetPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageUp\", {\n id = \"PlanetPageUp\",\n x1 = 280,\n x2 = 480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageUp\")\n end\n end\n -- Start of Location List\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[]].. lastPlanetSelected ..[[ Locations]]\n \n\n local i = 0\n for j = 1 + (CurrentLocationPage - 1) * pageLines, pageLines +\n (CurrentLocationPage - 1) * pageLines, 1 do\n \n i = i + 1\n if j <= #locList and j>0 then\n if lastLocationSelected == locList[j] then\n screenOutput = screenOutput ..\n [[]]\n end\n screenOutput = screenOutput .. [[]] .. locList[j] .. \n [[]]\n displayLocationList[i]=locList[j]\n screenOutput = screenOutput .. [[]] .. locDistList[locList[j]] .. \n [[]] \n else\n displayLocationList[i]=\"\"\n end\n end\n \n if #locList > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentLocationPage .. \" of \" ..\n math.ceil(#locList / 12) ..\n [[]]\n\n if CurrentLocationPage < math.ceil(#locList / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageDown\", {\n id = \"LocationPageDown\",\n x1 = 1070,\n x2 = 1270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageDown\")\n end\n\n if #locList > 1 and CurrentLocationPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageUp\", {\n id = \"LocationPageUp\",\n x1 = 1280,\n x2 = 1480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageUp\")\n end\n end\n \n-- screenOutput = screenOutput ..\n-- [[]] ..\n-- [[Load SatNav DB]]\n \n screenOutput = screenOutput ..\n [[]] ..\n [[Save Current Location]]\n\n-- screenOutput = screenOutput ..\n-- [[]] ..\n-- [[Clear HUD Locs]]\n\n\n screenOutput = screenOutput .. [[]]\n\n DrawSVG(screenOutput)\n\n forceRedraw = false\nend\n\n-----------------------------------------------\n-- Execute\n-----------------------------------------------\n\nunit.hide()\nInitiateClickAreas()\nDrawPlanetList()\nsystem.print(\"Running\")\nunit.setTimer(\"loadwp\",1)\n\n\n","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"6"},{"code":"function loadLocationTable ()\n\nlocationTable = {{}}\nlocationTable[1] = {\"Alioth Market 1\", \"::pos{0,2,30.3314,101.3106,122.9764}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 2\", \"::pos{0,2,24.4469,88.0409,238.3019}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 3\", \"::pos{0,2,34.9734,87.3012,176.2188}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 4\", \"::pos{0,2,28.3352,99.5187,165.9078}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 5\", \"::pos{0,2,33.3939,87.3299,277.1366}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 6\", \"::pos{0,2,36.0044,101.3503,220.0897}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 7\", \"::pos{0,2,22.5024,98.1449,232.5154}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 8\", \"::pos{0,2,21.2154,93.9616,251.0768}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 9\", \"::pos{0,2,28.7133,85.6389,260.7636}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 10\", \"::pos{0,2,35.9865,91.8393,190.1616}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 11\", \"::pos{0,2,-1.0735,178.5062,69.9428}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 12\", \"::pos{0,2,22.7112,-92.3078,166.8481}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 13\", \"::pos{0,2,-23.3768,-10.5455,178.8458}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 14\", \"::pos{0,2,-73.4716,101.3697,89.5661}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 15\", \"::pos{0,2,61.7831,27.8517,54.9186}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 16\", \"::pos{0,2,23.4406,114.4179,211.1991}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 17\", \"::pos{0,2,37.8637,64.1825,151.5507}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 18\", \"::pos{0,2,49.9360,-170.7565,62.1982}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 19\", \"::pos{0,2,-32.7357,76.3764,209.0805}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 20\", \"::pos{0,2,-35.1535,-95.1230,301.0724}\"} \n \nlocationTable[#locationTable+1] = {\"Madis Market 1\", \"::pos{0,1,2.6476,176.8761,813.0974}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 2\", \"::pos{0,1,10.3552,8.5146,816.2210}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 3\", \"::pos{0,1,-0.2107,82.0779,809.5571}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 4\", \"::pos{0,1,-80.6046,44.9385,822.6188}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 5\", \"::pos{0,1,81.0827,5.3022,823.1976}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 6\", \"::pos{0,1,13.9814,-91.6163,811.0679}\"}\n\nlocationTable[#locationTable+1] = {\"Thades M1: Market\", \"::pos{0,30,-2.9797,-117.7645,203.7519}\"}\nlocationTable[#locationTable+1] = {\"Feli: Market\", \"::pos{0,5,0.9348,178.6658,18417.2812}\"}\nlocationTable[#locationTable+1] = {\"Feli: Market 3\", \"::pos{0,5,-0.7500,-17.3248,18473.4238}\"}\n\nlocationTable[#locationTable+1] = {\"Symeon Market 1\", \"::pos{0,110,3.1400,-174.0223,267.1084}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 2\", \"::pos{0,110,-0.9862,88.3038,197.0626}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 3\", \"::pos{0,110,18.1117,11.1108,180.8022}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 4\", \"::pos{0,110,-26.9701,103.3741,186.2557}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 5\", \"::pos{0,110,83.1653,108.7807,142.5796}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 6\", \"::pos{0,110,-79.3167,95.3975,138.5268}\"}\n\nlocationTable[#locationTable+1] = {\"TMV Troghelm\", \"::pos{0,0,2416521.6598,1415126.8118,59323.7340}\"}\nlocationTable[#locationTable+1] = {\"TMV Alioth Factory\", \"::pos{0,2,22.8158,111.1414,103.5685}\"}\nlocationTable[#locationTable+1] = {\"TMV Feli Outpost\", \"::pos{0,5,23.6988,-77.8811,18480.5176}\"}\nlocationTable[#locationTable+1] = {\"TMV Thandes M1 Outpost\", \"::pos{0,30,-22.3548,-168.7352,288.1909}\"}\nlocationTable[#locationTable+1] = {\"TMV Madis Outpost\", \"::pos{0,1,-43.0914,75.0728,749.6641}\"}\nlocationTable[#locationTable+1] = {\"TMV Symoen Outpost\", \"::pos{0,110,-5.3046,32.6900,108.4144}\"}\nlocationTable[#locationTable+1] = {\"TMV Jago Outpost\", \"::pos{0,9,61.3760,-33.7830,10.7593}\"}\n\nend\n\nunit.stopTimer(\"loadwp\")\nloadLocationTable()\nlastNewLoc = myDatabank.getIntValue(\"lastNewLoc\")\n--system.print(\"lastNewLoc\"..lastNewLoc)\nif lastNewLoc == nil or lastNewLoc==0 then\n --this is th first time satnav has run on this databank\n system.print(\"Initialising SatNav Databank\")\n CheckClick(0, 0, \"LoadSatNavLocations\")\n lastNewLoc =1\n myDatabank.setIntValue(\"lastNewLoc\",lastNewLoc)\n system.print(\"Completed SatNav Databank\")\nend\n\n\n","filter":{"args":[{"value":"loadwp"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"7"},{"code":"\nif string.sub(text,1,2) == \"u \" then\n local newLocName = string.sub(text,3,string.len(text))\n updateLocationName(newLocName)\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\nelseif text == \"d SatNav\" then\n deleteLocationName(lastLocationSelected)\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\nelseif text == \"c SatNav\" then\n system.print(\"ClearSatNavLocations\")\n CheckClick(0, 0, \"ClearSatNavLocations\")\nelseif text == \"c Hud\" then\n if HUD == \"Dimencia\" then\n system.print(\"ClearHudLocations\")\n CheckClick(0, 0, \"ClearHudLocations\")\n else\n system.print(\"ClearHudLocations not available in standalone mode\")\n end\nelseif text == \"l SatNav\" then\n system.print(\"LoadSatNavLocations\")\n CheckClick(0, 0, \"LoadSatNavLocations\")\nelseif text == \"l Hud\" then\n if HUD == \"Dimencia\" then\n system.print(\"LoadHudLocations\")\n CheckClick(0, 0, \"LoadHudLocations\")\n else\n system.print(\"LoadHudLocations not available in standalone mode\")\n end\nelseif text == \"x SatNav\" then\n if dupSatnavDB then\n system.print(\"DuplicateSatNavDB\")\n duplicateSatnavDB()\n else\n system.print(\"Please link an empty databank to the programming board\")\n end\nend","filter":{"args":[{"variable":"*"}],"signature":"inputText(text)","slotKey":"-2"},"key":"8"}],"methods":[],"events":[]} From a0c44cbfd3b88ea5c8e91a8b7153c9349ff2faca Mon Sep 17 00:00:00 2001 From: Merl Date: Sat, 19 Dec 2020 00:33:54 +0100 Subject: [PATCH 4/7] formating and modified DimHud integration code * reformated README.md * the DimHud integration now reloads SavedLocations allowing to change the SatNav target without leaving the seat --- README.md | 166 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 98 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index caf584d..1302ff1 100644 --- a/README.md +++ b/README.md @@ -1,114 +1,144 @@ # Introduction -Welcome to Trog's SatNav for Dual Universe. This is a location/bookmark manager for :pos(.....) locations which includes integration into the Dimecia Hud to enable autopiloting to your stored locations. SatNav can be used in stand alone mode or as integrated into the Dimencia Hud. These instructions have been updated for SatNav version 2_1_2. To install a previous version please contact me directly. +Welcome to Trog's SatNav for Dual Universe. This is a location/bookmark manager for `:pos(.....)` locations which includes integration into the [Dimecia Hud](https://github.com/Dimencia/DU-Orbital-Hud) to enable autopiloting to your stored locations. SatNav can be used in stand alone mode or as integrated into the [Dimencia Hud](https://github.com/Dimencia/DU-Orbital-Hud). These instructions have been updated for SatNav version 2_1_2. To install a previous version please contact me directly. # Installation: -1) Ensure that you have the following libraries installed in your DU (the directory on your local drive in which you installed DU) LUA folder: +1. Ensure that you have the following libraries installed in your DU (the directory on your local drive in which you installed DU) LUA folder: - /DualUniverse/Game/data/lua/cpml/vec3.lua + `/DualUniverse/Game/data/lua/cpml/vec3.lua` - /DualUniverse/Game/data/lua/cpml/utils.lua + `/DualUniverse/Game/data/lua/cpml/utils.lua` - /DualUniverse/Game/data/lua/cpml/planetref.lua + `/DualUniverse/Game/data/lua/cpml/planetref.lua` - /DualUniverse/Game/data/lua/cpml/atlas.lua + `/DualUniverse/Game/data/lua/cpml/atlas.lua` - planetref.lua and atlas.lua can be obtained from the following GitLab url: https://gitlab.com/JayleBreak/dualuniverse/-/blob/master/DUflightfiles/autoconf/custom/atlas.lua and https://gitlab.com/JayleBreak/dualuniverse/-/blob/master/DUflightfiles/autoconf/custom/planetref.lua. On the GitLab pages, click the download button and when prompted for a filename, make sure that the filename is only atlas.lua and planetref.lua and not the given long name. + > `planetref.lua` and `atlas.lua` can be obtained from the following GitLab url: https://gitlab.com/JayleBreak/dualuniverse/-/blob/master/DUflightfiles/autoconf/custom/atlas.lua and https://gitlab.com/JayleBreak/dualuniverse/-/blob/master/DUflightfiles/autoconf/custom/planetref.lua. On the GitLab pages, click the download button and when prompted for a filename, make sure that the filename is only atlas.lua and planetref.lua and not the given long name. - 2) Install a PB onto your ship and link it to: 1) the core, 2) a screen, 3) a new (empty) databank (we shall call this the SatNav databank), 4) Dimencia Hud databank - IN THIS ORDER PLEASE. The SatNav databank should be either completely empty (remove dynamic content while the databank is in you inventory before placing it) or a SatNav databank from version 2_1_0 or 2_1_1. +2. Install a PB onto your ship and link it to: 1) the core, 2) a screen, 3) a new (empty) databank (we shall call this the *SatNav databank*), 4) Dimencia Hud databank - **IN THIS ORDER PLEASE**. The *SatNav databank* should be either completely empty (remove dynamic content while the databank is in you inventory before placing it) or a SatNav databank from version 2_1_0 or 2_1_1. - 3) Copy the most recent SatNav_PB_Paste file (currently that is SatNav_PB_Paste_2_1_2) into you copy paste buffer +3. Copy the most recent `SatNav_PB_Paste.json` file into you copy paste buffer. - 4) In game, right click on your SatNav PB and select 'Advanced' / 'Paste LUA configuration from cliboard' +4. In game, right click on your SatNav PB and select 'Advanced' / 'Paste LUA configuration from cliboard'. - 5) Turn on screen, activate PB and you are ready to go.... good luck! +5. Turn on screen, activate PB and you are ready to go.... good luck! - # Integration with Dimencia Hud: - 1) ensure you have a recent version of the Dimencia Hud already loaded and configured on your pilot seat. Version 2_1_0 requires its own databank and you should not try to use the Dimencia Hud databank for both 3 and 4 (in the installation), this will likely cause problems and so is not supported. +# Integration with Dimencia Hud: +1. Ensure you have a recent version of the [Dimencia Hud](https://github.com/Dimencia/DU-Orbital-Hud) already loaded and configured on your pilot seat. Version 2_1_0 and up requires its own databank and you should not try to use the Dimencia Hud databank for both 3. and 4. (in the installation), this will likely cause problems and so is not supported. - 2) edit the LUA in your pilot seat that has the Dimencia Hud installed +2. Edit the LUA in your pilot seat that has the [Dimencia Hud](https://github.com/Dimencia/DU-Orbital-Hud) installed. - 3) create a new unit.start trigger and insert the following LUA code: - - unit.setTimer("spbTimer",5) - - myAutopilotTarget="" - - - 4) create a new unit.tick(spbTimer) trigger and insert the following LUA code - - prevAutopilotTarget = myAutopilotTarget - - myAutopilotTarget = dbHud.getStringValue("SPBAutopilotTargetName") - - if myAutopilotTarget ~= nil and myAutopilotTarget ~= "" and myAutopilotTarget ~= prevAutopilotTarget then - - for i=1,#AtlasOrdered do - +3. Create a new unit.start trigger and insert the following LUA code: + + ```lua + unit.setTimer("spbTimer",5) + myAutopilotTarget="" + ``` + +4. Create a new unit.tick(spbTimer) trigger and insert the following LUA code: + + ```lua + local print = system.print + prevAutopilotTarget = myAutopilotTarget + myAutopilotTarget = dbHud.getStringValue("SPBAutopilotTargetName") + + if myAutopilotTarget ~= nil and myAutopilotTarget ~= "" and myAutopilotTarget ~= prevAutopilotTarget and myAutopilotTarget ~= "SatNavNotChanged" then + local result = json.decode(dbHud.getStringValue("SavedLocations")) + if result ~= nil then + system.print("Saved Locations updated") + _G["SavedLocations"] = result + + local index = -1 + local newLocation + + for k, v in pairs(SavedLocations) do + if v.name and v.name == "SatNav Location" then + index = k + break + end + end + if index ~= -1 then + newLocation = SavedLocations[index] + index = -1 + for k, v in pairs(atlas[0]) do + if v.name and v.name == "SatNav Location" then + index = k + end + end + if index > -1 then + atlas[0][index] = newLocation + end + UpdateAtlasLocationsList() + MsgText = newLocation.name .. " position updated" + end + end + + for i=1,#AtlasOrdered do if AtlasOrdered[i].name == myAutopilotTarget then - AutopilotTargetIndex = i - + system.print("Index = "..AutopilotTargetIndex.." "..AtlasOrdered[i].name) UpdateAutopilotTarget() - + dbHud.setStringValue("SPBAutopilotTargetName", "SatNavNotChanged") end - - end - end + end + ``` +# Usage: +1. By default the PB is programmed with a selection of locations including the market places on Alioth. These will be automatically loaded into your SatNav databank the first time that you use the application. - # Usaged: - 1) By default the PB is programmed with a selection of locations including the market places on Alioth. These will be automatically loaded into your SatNav databank the first time that you use the application. - - 2) The lefthand (light blue) panel of the SatNav lists all the DU planets. You can page up/down this list using the correspondingly coloured arrow buttons below the table. Clicking on a specific planet will display the list of Stored Locations for than planet in the righthand (purple) panel. +2. The lefthand (light blue) panel of the SatNav lists all the DU planets. You can page up/down this list using the correspondingly coloured arrow buttons below the table. Clicking on a specific planet will display the list of Stored Locations for than planet in the righthand (purple) panel. - 3) You can page up/down the list of Stored Locations using the correspondingly coloured (purple) arrow buttons below the table. Clicking on a specific location will print the locations coordinates into the LUA chat and will set your destination to that location. In addition, and if you have integrated with Dimencia Hud, the selected location will be sent to your pilot seat ready for use the next time you engage autopilot in the Hud. It is also possible to use SatNav while remaining seated in the Pilot Seat and the selected location will be sent to your running Dimencia Hud. +3. You can page up/down the list of Stored Locations using the correspondingly coloured (purple) arrow buttons below the table. Clicking on a specific location will print the locations coordinates into the LUA chat and will set your destination to that location. In addition, and if you have integrated with Dimencia Hud, the selected location will be sent to your pilot seat ready for use the next time you engage autopilot in the Hud. It is also possible to use SatNav while remaining seated in the Pilot Seat and the selected location will be sent to your running Dimencia Hud. - 4) If you wish to add a new location to the SatNav databank this can be done in a couple of ways: +4. If you wish to add a new location to the SatNav databank this can be done in a couple of ways: - a) you can add new locations one at a time by pressing the 'Save Current Location' button which will create a new entry named 'SatNav Location (nnn)'. + a) You can add new locations one at a time by pressing the 'Save Current Location' button which will create a new entry named 'SatNav Location (nnn)'. - b) you can edit the initial default locations in the Programming Board and add new entries (this is best used for bulk entry). Open the PB for LUA editing and access the code in the unit.tick(loadwp) trigger. Then simply edit or add new entries to this table. Once you have the new exntries in the table execute the 'l SatNav' command below (5e) to relad the table. + b) You can edit the initial default locations in the Programming Board and add new entries (this is best used for bulk entry). Open the PB for LUA editing (`CTRL + L`) and access the code in the `unit.tick(loadwp)` trigger. Then simply edit or add new entries to this table. Once you have the new exntries in the table execute the *l SatNav* command below (5e) to relad the table. - 5) With the latest DU patch, SatNav now has a command line capability this provides the following function by typing into the LUA Chat panel: +5) With the latest DU patch, SatNav now has a command line capability this provides the following function by typing into the LUA Chat panel: - a) 'u newLocationName' - you can amend th name of a SatNav location by selecting it from the on screen location list, then typing 'u ' followed by the ew name for that location + a) `u newLocationName` - you can amend the name of a SatNav location by selecting it from the on screen location list, then typing '`u `' followed by the new name for that location. - b) 'd SatNav' - this command will delete the currently selected location from the database - use with care ;-) + b) `d SatNav` - this command will delete the currently selected location from the database - ***use with care ;-)*** - c) 'c SatNav' - this will clear the SatNav databank of all stored locations + c) `c SatNav` - this will clear the SatNav databank of all stored locations - d) 'c Hud' - this will clear all Saved Locations from the Dimencia Hud databank (use with care!) + d) `c Hud` - this will clear all Saved Locations from the Dimencia Hud databank (***use with care!***) - e) 'l SatNav' - this will reload all of the default location from the SatNav PB (including any new ones that you may have added in step 4b above + e) `l SatNav` - this will reload all of the default location from the SatNav PB (including any new ones that you may have added in step 4b above - f) 'l Hud' - this will copy all of the Dimencia Hud stored locations from the Hud's databank into the SatNav databank + f) `l Hud` - this will copy all of the Dimencia Hud stored locations from the Hud's databank into the SatNav databank - g) 'x SatNav' - this command will duplicate/clone the SatNav databank if an additional empty databank has been linked to the PB in slot 5. The purpose of this feature is to enable users to copy their locations to multiple ships. + g) `x SatNav` - this command will duplicate/clone the SatNav databank if an additional empty databank has been linked to the PB in slot 5. The purpose of this feature is to enable users to copy their locations to multiple ships. - 5) When using your Dimencia Hud, you will find that the location you loaded in 3 (above) ha been renamed as 'SatNav Location' and is now available using the Alt+1/Alt+2 keys.. This will also have been set as the destination on the Dim Hud buttons screen. Unlike previous versions of SatNav, we now only copy across a single location to Dim Hud - this is due to a limitation in the Dim Hud which would cause a cpu overload error if we copied all of the SatNav locations across. + 5. When using your [Dimencia Hud](https://github.com/Dimencia/DU-Orbital-Hud), you will find that the location you loaded in 3 (above) has been renamed as `**SatNav Location**` and is now available using the `Alt+1/Alt+2` keys.. This will also have been set as the destination on the Dim Hud buttons screen. + > Unlike previous versions of SatNav, we now only copy across a single location to Dim Hud - this is due to a limitation in the Dim Hud which would cause a CPU overload error if we copied all of the SatNav locations across. - # Known issues: +# Known issues: - The order of linking the core/screen/databanks is extremely important. They should always be: 1) core, 2) screen, 3) satnav databank, 4) Dimencia Hud databank, 5) satanav databank copy (used in the x SatNav command only). +* The order of linking the core/screen/databanks is extremely important. They should always be: 1) core, 2) screen, 3) SatNav databank, 4) Dimencia Hud databank, 5) SatNav databank copy (used in the x SatNav command only). - Some users are struggling to locate the DU LUA library folder on their local drives. This is located below the directory that you originally installed DU. +* Some users are struggling to locate the DU LUA library folder on their local drives. This is located below the directory that you originally installed DU. - Some users are struggling to download the planetref.lua and atlas.lua libraries. These two files can be found in the GitLab URL link provided above, they must be copied in their entirity into the DU Lua library folder. You can check them once you have downloaded by opening the lua files and seeing that they contain the appropriate LUA code. +* Some users are struggling to download the planetref.lua and atlas.lua libraries. These two files can be found in the GitLab URL link provided above, they must be copied in their entirity into the DU Lua library folder. You can check them once you have downloaded by opening the lua files and seeing that they contain the appropriate LUA code. - I have recently experience a problem with DimHud linking to the incorrect databank when I did a clean new DimHud configuration. The outcome of this is that it may corrupt the content of the SatNav databank (for example if DimHud has linked to the SatNav databank). Therefore, the following is my recommendation: - a) before you do a DimHud update, always back up your SatNav databank (using the 'x SatNav' command described above) and then remove the backup copy into your inventory; b) immediately after doing a DimHud update, check the databank that is linked to the DimHud pilot seat. If it is the incorrect databank, then remove the link and manually link to the correct DimHud databank - do this BEFORE activating DimHud for the first time after the update. - - # Version history: +* I have recently experienced a problem with DimHud linking to the incorrect databank when I did a clean new DimHud configuration. The outcome of this is that it may corrupt the content of the SatNav databank (for example if DimHud has linked to the SatNav databank). Therefore, the following is my recommendation: + + a) Before you do a DimHud update, always back up your SatNav databank (using the 'x SatNav' command described above) and then remove the backup copy into your inventory; + + b) Immediately after doing a DimHud update, check the databank that is linked to the DimHud pilot seat. If it is the incorrect databank, then remove the link and manually link to the correct DimHud databank - **do this BEFORE activating DimHud for the first time after the update**. + +# Version history: - 2_0_0 - Released version +* 2_0_0 - Released version - 2_0_1 - pre-release version, use at your own risk. Update includes location/planet distances and warp cell estimates. verification of connection to Dimencia Hud. +* 2_0_1 - pre-release version, use at your own risk. Update includes location/planet distances and warp cell estimates. verification of connection to Dimencia Hud. - 2_0_2 - a few bug fixes and enhancements +* 2_0_2 - a few bug fixes and enhancements - 2_1_0 - updated to avoid cpu overload problems and utilise the new setWaypoint and inputText features of DU 0.23 +* 2_1_0 - updated to avoid cpu overload problems and utilise the new setWaypoint and inputText features of DU 0.23 - 2_1_1 - update includes: 1) attempt to try and avoid installation issues with linking databanks in wrong order; 2) added fix for new Space locations which were always being assigned to planets instead of 'Space'; 3) a few bug fixes +* 2_1_1 - update includes: 1) attempt to try and avoid installation issues with linking databanks in wrong order; 2) added fix for new Space locations which were always being assigned to planets instead of 'Space'; 3) a few bug fixes - 2_1_2 - update includes: 1) improved avoidance of databank linking issues during installation; 3) improved readability of screens: a) highlighting of selected planets/location is now shown by a bar rather than a font colour change; b) 4 LUA parameters have been added to allow users to change the colours for Planet Panel Backgroun; Location Panel Background; Panel font colour; and highlight bar colour. +* 2_1_2 - update includes: 1) improved avoidance of databank linking issues during installation; 3) improved readability of screens: a) highlighting of selected planets/location is now shown by a bar rather than a font colour change; b) 4 LUA parameters have been added to allow users to change the colours for Planet Panel Backgroun; Location Panel Background; Panel font colour; and highlight bar colour. From 1ad0cbf67442ab6ef02de5881cb341b90099bea4 Mon Sep 17 00:00:00 2001 From: Merl Date: Sat, 19 Dec 2020 05:09:52 +0100 Subject: [PATCH 5/7] added textinput option "a ::pos{system,planet,lat,lon,alt} Displayname" --- README.md | 4 ++++ SatNav_PB_Paste.json | 2 +- src/system/inputText.lua | 18 ++++++++++++++++++ src/unit/start.lua | 18 ++++++++++++++---- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1302ff1..77593fb 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,8 @@ Welcome to Trog's SatNav for Dual Universe. This is a location/bookmark manager f) `l Hud` - this will copy all of the Dimencia Hud stored locations from the Hud's databank into the SatNav databank g) `x SatNav` - this command will duplicate/clone the SatNav databank if an additional empty databank has been linked to the PB in slot 5. The purpose of this feature is to enable users to copy their locations to multiple ships. + + h) `a ::pos{system,planet,lat,lon,alt} Displayname` - will add a new Location to SatNav. Input validation is very basic, thus please use with care. 5. When using your [Dimencia Hud](https://github.com/Dimencia/DU-Orbital-Hud), you will find that the location you loaded in 3 (above) has been renamed as `**SatNav Location**` and is now available using the `Alt+1/Alt+2` keys.. This will also have been set as the destination on the Dim Hud buttons screen. > Unlike previous versions of SatNav, we now only copy across a single location to Dim Hud - this is due to a limitation in the Dim Hud which would cause a CPU overload error if we copied all of the SatNav locations across. @@ -142,3 +144,5 @@ Welcome to Trog's SatNav for Dual Universe. This is a location/bookmark manager * 2_1_1 - update includes: 1) attempt to try and avoid installation issues with linking databanks in wrong order; 2) added fix for new Space locations which were always being assigned to planets instead of 'Space'; 3) a few bug fixes * 2_1_2 - update includes: 1) improved avoidance of databank linking issues during installation; 3) improved readability of screens: a) highlighting of selected planets/location is now shown by a bar rather than a font colour change; b) 4 LUA parameters have been added to allow users to change the colours for Planet Panel Backgroun; Location Panel Background; Panel font colour; and highlight bar colour. + +* 2_1_2-merl1 - added textInput "a ::pos{....} Displayname" to add Locations from lua chat console diff --git a/SatNav_PB_Paste.json b/SatNav_PB_Paste.json index fa3364c..4cdc53b 100644 --- a/SatNav_PB_Paste.json +++ b/SatNav_PB_Paste.json @@ -1 +1 @@ -{"slots":{"0":{"name":"core","type":{"events":[],"methods":[]}},"1":{"name":"screen","type":{"events":[],"methods":[]}},"2":{"name":"db2","type":{"events":[],"methods":[]}},"3":{"name":"db1","type":{"events":[],"methods":[]}},"4":{"name":"dupSatnavDB","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"1"},"key":"0"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"5"},"key":"1"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"6"},"key":"2"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"7"},"key":"3"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"8"},"key":"4"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"9"},"key":"5"},{"code":"--[[\n SatNav version 2_1_2\n Created By TrogLaByte\n\n Discord: Trog#5105\n InGame: TrogLaByte\n \n GNU Public License 3.0. Use whatever you want, be so kind to leave credit.\n\n Thanks to Dorien Grey for his SVG and onscreen button code.\n]] \n-----------------------------------------------\n-- requirements\n-----------------------------------------------\n\nfunction initiateRequiredLibaries()\n --json = require('dkjson')\n vec3 = require('cpml.vec3')\n utils = require('cpml.utils')\n planetRef = require('cpml.planetref')\n referenceTableSource = require('cpml.atlas')\n clamp = utils.clamp\nend\nif pcall(initiateRequiredLibaries) then\n system.print(\"Libaries loaded successfully\")\n else\n system.print(\"Libaries failed to load: check that the following libraries exist:\")\n system.print(\"( is the directory in to which you installed DU)\")\n system.print(\" /DualUniverse/Game/data/lua/dkjson\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/vec3\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/utils\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/planetref\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/atlas\")\n system.print(\"\")\n system.print(\"planetref.lua and atlas.lua can be obtained from the following GitLab url:\")\n system.print(\"https://gitlab.com/JayleBreak/dualuniverse/-/tree/master/DUflightfiles/autoconf/custom\")\n unit.exit()\nend\n-----------------------------------------------\n-- Global Variables\n-----------------------------------------------\n\nlocal version = \"2_1_2\"\n\nlocal UpdateInterval = 1 \nlocal defaultNewLocName = \"SatNav Location\" --export: default name used for new locations\n--[[Original colours are 34b1eb, 6e3de3 and 1e1e1e]]\nlocal PlanetPanelColour = \"99eeff\" --export: Hex code for colour of planet panel and buttons (you need to include the quotes)\nlocal LocPanelColour = \"aa99ff\" --export: Hex code for colour of locations panel and buttons (you need to include the quotes)\nlocal FontPanelColour = \"000000\" --export: Hex code for font colour of planet/locations panel (you need to include the quotes)\nlocal LineHighlightColour = \"ccffff\"--export: Hex code for colour of highlighted lines in planet/location panel (you need to include the quotes)\n\nlocal BackgroundColor = \"#1e1e1e\"\nlocal PlanetBackgroundColor = \"#\" .. PlanetPanelColour\nlocal LocationBackgroundColor = \"#\" .. LocPanelColour\nlocal MainFontColor = \"#\" .. FontPanelColour\nlocal HighlightColor = \"#\" .. LineHighlightColour\n\nlocal lastPlanetSelected = \"Alioth\" --export: The default start planet for displaying locations\n\nlocal clickAreas = {}\nlocal locList={}\npageLines=12\ndisplayPlanetList={}\ndisplayLocationList={}\nCurrentLocationPage = 1\nCurrentPlanetPage = 1\nmyDatabank={}\ndbHud={}\n\nif db1 then db1Keys = db1.getKeys() end\nif db2 then db2Keys = db2.getKeys() end\n\n--if db1Keys then system.print(\"DB1 Keys: \"..string.sub(db1Keys,1,50)) end\n--if db2Keys then system.print(\"DB2 Keys: \"..string.sub(db2Keys,1,50)) end\n\nif db1 and (db1Keys==nil or db1Keys == \"\" or string.match(db1Keys, \"lastNewLoc\")) then\n myDatabank = db1\n system.print(\"SatNav Databank Identified\")\nelseif db2 and (db2Keys==nil or db2Keys == \"\" or string.match(db2Keys, \"lastNewLoc\")) then\n myDatabank = db2\n system.print(\"SatNav Databank Identified\")\nelse \n system.print(\"SatNav databank not found... application will stop\")\n if db1Keys then system.print(\"DB1 Keys: \"..string.sub(db1Keys,1,50)) end\n if db2Keys then system.print(\"DB2 Keys: \"..string.sub(db2Keys,1,50)) end\n unit.exit()\n unit.deactivate()\nend\n\nif myDatabank==db1 and db2 and string.match(db2Keys, \"AutopilotTargetIndex\") then\n dbHud = db2\n system.print(\"Dimencia Hud Identified\")\n HUD = \"Dimencia\"\nelseif myDatabank==db2 and db1 and string.match(db1Keys, \"AutopilotTargetIndex\") then\n dbHud = db1\n system.print(\"Dimencia Hud Identified\")\n HUD = \"Dimencia\"\nelse \n system.print(\"No Dimencia Hud Identified - will run in Stand Alone mode\")\n HUD = \"unknown\"\nend\n\n--unit.exit()\n-----------------------------------------------\n-- set up galaxy data and functions for planets and locations\n-----------------------------------------------\n\ngalaxyReference = planetRef(referenceTableSource)\nhelios = galaxyReference[0] -- PlanetaryReference.PlanetarySystem instance\nplanetList={}\nplanetDistList={}\nlocDistList={}\n\nfunction getBodyId(planetName)\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n if string.lower(helios[tonumber(i)].name) ==string.lower(planetName) then\n return i\n end\n end\n end\n return 0\nend\n\nfunction buildPlanetList()\n local planet={}\n local currentLoc = vec3(core.getConstructWorldPos())\n local shipMass = core.getConstructMass()\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n planet = helios[tonumber(i)]\n planetList[#planetList+1] = planet.name\n local planetDistance = planet:getDistance(currentLoc)\n planetDistList[planet.name] = formatDistance(planetDistance) .. \n string.format(\" [%.0f wc]\", ((planetDistance/200000)*(shipMass/1000)/4000))\n end\n end\n planetList[#planetList+1]=\"Space\"\n table.sort(planetList)\nend\n\nfunction formatDistance(distance)\n if distance < 200000 then\n return string.format(\"%.0f km\",distance/1000)\n elseif distance < 4000000 then\n return string.format(\"%.2f su\",distance/200000)\n else\n return string.format(\"%.0f su\",distance/200000)\n end\nend\n\n-- json parser\n\n-- Extracts values from a JSON string with pattern matching\n-- This is faster than using dkjson when only a few fields are needed\n\n-- Use this only with trusted data sources! Limitations:\n-- * Character escapes are not supported\n-- * Field nesting is ignored\n\nlocal find, gsub = string.find, string.gsub\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return string|nil, number|nil, number|nil\nlocal function extractStringJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*\"([^\"]*)\"]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n return valueStr, startIndex, endIndex\nend\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return number|nil, number|nil, number|nil\nlocal function extractNumberJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*(-?[0-9.e-]+)]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n return tonumber(valueStr), startIndex, endIndex\nend\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return boolean|nil, number|nil, number|nil\nlocal function extractBooleanJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*([truefals]+)]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n\n if valueStr == \"true\" then\n return true, startIndex, endIndex\n elseif valueStr == \"false\" then\n return false, startIndex, endIndex\n else\n return nil\n end\nend\n\n---@param extractJsonValue function\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue any|nil\n---@return any[]\nlocal function extractAllJsonValues (extractJsonValue, json, key, stopAfterIndex, stopAfterValue)\n local values = {}\n local valuesLen = 0\n\n local jsonPos = 1\n local value, valueStartIndex, valueEndIndex -- luacheck: ignore valueStartIndex -- unused\n\n repeat\n value, valueStartIndex, valueEndIndex = extractJsonValue(json, key, jsonPos)\n\n if value ~= nil then\n valuesLen = valuesLen + 1\n values[valuesLen] = value\n\n jsonPos = valueEndIndex + 1\n end\n\n if value == stopAfterValue then break end\n if valuesLen == stopAfterIndex then break end\n until value == nil\n\n return values\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue string|nil\n---@return string[]\nlocal function extractAllStringJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractStringJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue number|nil\n---@return number[]\nlocal function extractAllNumberJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractNumberJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue boolean|nil\n---@return boolean[]\nlocal function extractAllBooleanJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractBooleanJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n-- end json Parser\n\n\nfunction buildPlanetLocList(planetName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n \n local currentLoc = vec3(core.getConstructWorldPos())\n local shipMass = core.getConstructMass()\n local planet={}\n locList={}\n if planetName ~= \"Space\" then\n table.insert(locList, planetName) -- add planet name into the list as a default\n locDistList[planetName] = planetDistList[planetName]\n end\n if #name > 0 then \n for i=1,#name do\n if string.lower(planetname[i]) == string.lower(planetName) or\n string.find(string.lower(planetname[i]),string.lower(planetName))\n then\n table.insert(locList, name[i])\n elseif planetname[i] == \"\" and planetName == \"Space\" then -- a space location\n table.insert(locList, name[i])\n end\n local locDistance = (currentLoc - vec3(posX[i],posY[i],posZ[i])):len()\n if planetName == \"Space\" then\n locDistList[name[i]] = formatDistance(locDistance) ..\n string.format(\" [%.0f wc]\", ((locDistance/200000)*(shipMass/1000)/4000))\n else\n locDistList[name[i]] = formatDistance(locDistance)\n end\n end\n end\n table.sort(locList)\nend\n\nfunction printLocMapPos(locationName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local wayPoint=\"\"\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n local planet={}\n if #name > 0 then \n for i = 1, #name do\n if string.lower(name[i]) == string.lower(locationName) then\n local bodyId = getBodyId(planetname[i])\n planet = helios[tonumber(bodyId)] \n if planet ~= nil then\n worldCoords = planet:convertToMapPosition(vec3(posX[i],posY[i],posZ[i]))\n wayPoint=string.format([[::pos{%d,%d,%f,%f,%f}]],\n worldCoords.systemId,\n worldCoords.bodyId,\n worldCoords.latitude*constants.rad2deg,\n worldCoords.longitude*constants.rad2deg,\n worldCoords.altitude)\n system.print(name[i]..\" @ \"..wayPoint)\n system.setWaypoint(wayPoint)\n return locationName,\n planetname[i],\n atmosphere[i],\n gravity[i],\n posX[i],\n posY[i],\n posZ[i]\n else\n wayPoint=string.format([[::pos{%d,%d,%f,%f,%f}]],\n 0,\n bodyId,\n posX[i],posY[i],posZ[i])\n system.print(name[i]..\" @ \"..wayPoint)\n system.setWaypoint(wayPoint)\n return locationName,\n planetname[i],\n atmosphere[i],\n gravity[i],\n posX[i],\n posY[i],\n posZ[i]\n end\n break\n end \n end\n end\n return \"\"\nend\n\nfunction clearSavedLocations()\n myDatabank.setStringValue(\"SavedLocations\",\"[]\")\n system.print(\"Satnav Databank cleared\")\nend\n\nfunction isDuplicateLocation(locName, locNameList)\n for i=1,#locNameList do\n if locNameList[i] == locName then\n return locName\n end\n end\n return \"\"\nend\n\nfunction saveSavedLocations (name, planetname, atmosphere, gravity, posX, posY, posZ)\n local newSavedLocations = \"[\"\n for i = 1, #name do\n if name[i]~=\"\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..name[i]..\n [[\",\"planetname\":\"]]..planetname[i]..[[\"]]..\n [[,\"atmosphere\":]]..atmosphere[i]..\n [[,\"gravity\":]]..gravity[i]..\n [[,\"position\":{\"x\":]]..posX[i]..\n [[,\"y\":]]..posY[i]..\n [[,\"z\":]]..posZ[i]..[[}}]]\n end\n if i+1<#name then\n newSavedLocations= newSavedLocations..\",\"\n end\n end\n newSavedLocations= newSavedLocations..\"]\" \n --system.print(newSavedLocations)\n myDatabank.setStringValue(\"SavedLocations\",newSavedLocations)\n system.print(\"Satnav Databank Updated\")\nend\n\nfunction updateLocationName(newLocName)\n if newLocName ~= nil and newLocName ~= \"\" and \n lastLocationSelected ~= nil and lastLocationSelected ~= \"\" then\n system.print(\"Updating location name for: \"..lastLocationSelected..\" to: \"..newLocName)\n else\n system.print(\"Invalid update request\")\n return\n end\n local savedLocation = {}\n local oldLocFound = false\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n for i = 1, #name do\n if name[i] == lastLocationSelected then\n --system.print(\"Found: \"..lastLocationSelected)\n name[i] = newLocName\n oldLocFound = true\n break\n end\n end\n \n if oldLocFound then \n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n else\n system.print(\"Old Location Name Not Found\")\n end\nend\n\nfunction deleteLocationName(delLocName)\n if delLocName ~= nil and delLocName ~= \"\" then\n system.print(\"Deleting location name: \"..delLocName)\n else\n system.print(\"Invalid update request\")\n return\n end\n local savedLocation = {}\n local oldLocFound = false\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n for i = 1, #name do\n if name[i] == delLocName then\n --system.print(\"Found: \"..delLocName)\n name[i] = \"\"\n oldLocFound = true\n break\n end\n end\n \n if oldLocFound then \n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n else\n system.print(\"Location Name Not Found\")\n end\nend\n\nfunction loadPointsOfInterest()\n -- get existing locations from SatNav Databank\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n\n\n local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)'\n local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' ..\n num .. ',' .. num .. '}'\n local j=0\n loadLocationTable()\n \n for i = 1, #locationTable do\n local newRef = #name + 1\n if isDuplicateLocation(locationTable[i][1],name) == \"\" then\n name[newRef]=locationTable[i][1]\n local newLocPos = locationTable[i][2]\n --system.print(\"Name: \"..locationTable[i][1]..\" \"..newLocPos)\n local systemId, bodyId, latitude, longitude, altitude =\n string.match(locationTable[i][2], posPattern)\n --system.print(\"BodyId: \".. bodyId)\n if tonumber(bodyId) > 0 then\n local planet = helios[tonumber(bodyId)] \n local worldCoords = planet:convertToWorldCoordinates(newLocPos)\n posX[newRef]=worldCoords[\"x\"]\n posY[newRef]=worldCoords[\"y\"]\n posZ[newRef]=worldCoords[\"z\"]\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=planet.name\n else -- it is a space location\n posX[newRef]=latitude\n posY[newRef]=longitude\n posZ[newRef]=altitude\n gravity[newRef]=0\n atmosphere[newRef]=0\n planetname[newRef]=\"\"\n end \n else\n system.print(\"Duplicate entry for location ignored: \"..locationTable[i][1])\n end\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n --system.print(\"Default SatNav locations loaded\")\nend\n\nfunction loadHudLocations()\n -- get existing locations from SatNav Databank\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n\n local hudLocation = dbHud.getStringValue(\"SavedLocations\")\n local hudatmosphere={}\n local hudgravity={}\n local hudplanetname = {}\n local hudposX\t = {}\n local hudposY\t = {}\n local hudposZ\t = {}\n local hudname\t = {}\n\n hudatmosphere = extractAllNumberJsonValues(hudLocation,\"atmosphere\")\n hudgravity = extractAllNumberJsonValues(hudLocation,\"gravity\")\n hudplanetname = extractAllStringJsonValues(hudLocation,\"planetname\")\n hudposX\t = extractAllNumberJsonValues(hudLocation,\"x\")\n hudposY\t = extractAllNumberJsonValues(hudLocation,\"y\")\n hudposZ\t = extractAllNumberJsonValues(hudLocation,\"z\")\n hudname\t = extractAllStringJsonValues(hudLocation,\"name\")\n\n\n for i = 1, #hudname do\n local newRef = #name + 1\n system.print(\"HudName: \"..hudname[i])\n if isDuplicateLocation(hudname[i],name) == \"\" and\n hudname[i] ~= \"SatNav Location\" then\n name[newRef]=hudname[i]\n posX[newRef]=hudposX[i]\n posY[newRef]=hudposY[i]\n posZ[newRef]=hudposZ[i]\n gravity[newRef]=hudgravity[i]\n atmosphere[newRef]=hudatmosphere[i]\n planetname[newRef]=hudplanetname[i] \n else\n system.print(\"Duplicate entry for location ignored: \"..hudname[i])\n end\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n --system.print(\"Default SatNav locations loaded\")\nend\n\n\nfunction newLocation ()\n local location = system.getWaypointFromPlayerPos()\n local newLocId = myDatabank.getIntValue(\"lastNewLoc\") + 1\n myDatabank.setIntValue(\"lastNewLoc\",newLocId)\n \n local newLocName = defaultNewLocName..\" (\"..newLocId..\")\"\n \n local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)'\n local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' ..\n num .. ',' .. num .. '}'\n \n local savedLocation = {}\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n \n local systemId, bodyId, latitude, longitude, altitude =\n string.match(location, posPattern)\n local worldPos = unit.getMasterPlayerRelativePosition()\n local body = helios:closestBody(worldPos)\n --system.print(json.encode(body))\n --system.print(\"Distance=\"..((vec3(worldPos)-vec3(body.center)):len())/(1000))\n --system.print(\"Calc=\"..((body.radius+body.center):len())/(1000))\n\n newlocAlt = ((vec3(worldPos)-vec3(body.center)):len())/(1000)\n-- system.print(\"New Loc Alt:\"..newlocAlt)\n-- system.print(\"Radius:\"..(((body.radius)/1000) + 200))\n if newlocAlt < (((body.radius)/1000) + 200) then\n local bodyId = getBodyId(body.name)\n --system.print(\"BodyId: \".. bodyId)\n local planet = helios[tonumber(bodyId)] -- PlanetaryReference.BodyParameters instance\n --system.print(\"Planet BodyId: \".. planet.bodyId)\n local worldCoords = planet:convertToWorldCoordinates(location)\n newRef = #name + 1\n name[newRef]=newLocName\n posX[newRef]=worldCoords[\"x\"]\n posY[newRef]=worldCoords[\"y\"]\n posZ[newRef]=worldCoords[\"z\"]\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=body.name\n else\n newRef = #name + 1\n name[newRef]=newLocName\n posX[newRef]=latitude\n posY[newRef]=longitude\n posZ[newRef]=altitude\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=\"Space\"\n\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n system.print(\"New location: \"..newLocName..\" added to SatNav databank\")\n printLocMapPos(newLocName)\nend\n\nfunction copySelectedToHud (locName)\n \n local locName, locplanetname, locatmosphere, locgravity, locX, locY, locZ = \n printLocMapPos(locName)\n if HUD == \"Dimencia\" then\n savedLocation = dbHud.getStringValue(\"SavedLocations\")\n --system.print(\"savedLocation=\"..savedLocation)\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n local newSavedLocations = \"[\"\n for i = 1, #name do\n if name[i] ~= \"SatNav Location\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..name[i]..\n [[\",\"planetname\":\"]]..planetname[i]..[[\"]]..\n [[,\"atmosphere\":]]..atmosphere[i]..\n [[,\"gravity\":]]..gravity[i]..\n [[,\"position\":{\"x\":]]..posX[i]..\n [[,\"y\":]]..posY[i]..\n [[,\"z\":]]..posZ[i]..[[}},]]\n end\n end\n if locplanetname ~= \"\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..\"SatNav Location\"..\n [[\",\"planetname\":\"]]..locplanetname..[[\"]]..\n [[,\"atmosphere\":]]..locatmosphere..\n [[,\"gravity\":]]..locgravity..\n [[,\"position\":{\"x\":]]..locX..\n [[,\"y\":]]..locY..\n [[,\"z\":]]..locZ..[[}}]]\n end\n newSavedLocations= newSavedLocations..\"]\" \n dbHud.setStringValue(\"SavedLocations\",newSavedLocations)\n dbHud.setStringValue(\"SPBAutopilotTargetName\",\"SatNav Location\")\n end\nend\n\nfunction clearHudLocations()\n if HUD == \"Dimencia\" then\n dbHud.setStringValue(\"SavedLocations\",\"[]\")\n dbHud.setStringValue(\"SPBAutopilotTargetName\",\"\")\n system.print(\"Dimencia HUD Saved Locations Cleared\")\n end\nend\n\nfunction duplicateSatnavDB()\n local satnavLocation = myDatabank.getStringValue(\"SavedLocations\")\n local lastNewLoc = myDatabank.getIntValue(\"lastNewLoc\")\n if dupSatnavDB then\n dupSatnavDB.clear()\n dupSatnavDB.setStringValue(\"SavedLocations\",satnavLocation)\n dupSatnavDB.setIntValue(\"lastNewLoc\",lastNewLoc)\n system.print(\"SatNav Databank Duplicated Successfully\")\n else\n system.print(\"No space databank linked, duplication aborted\")\n end\nend\n\nbuildPlanetList()\nbuildPlanetLocList(lastPlanetSelected)\nlocal planetCount=#planetList\n\n-----------------------------------------------\n-- Code for on screen buttons\n-----------------------------------------------\n\nfunction DrawSVG(output) screen.setSVG(output) end\n\nfunction AddClickArea(newEntry) table.insert(clickAreas, newEntry) end\n\nfunction RemoveFromClickAreas(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = nil\n break\n end\n end\nend\n\nfunction UpdateClickArea(candidate, newEntry)\n --system.print(\"Candidate: \"..candidate..\" x1\"..newEntry.x1)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = newEntry\n --system.print(\"Click Area: \"..candidate..\" x1\"..clickAreas[k].x1)\n break\n end\n end\nend\n\nfunction DisableClickArea(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n UpdateClickArea(candidate, {\n id = candidate,\n x1 = -1,\n x2 = -1,\n y1 = -1,\n y2 = -1\n })\n break\n end\n end\nend\n\nfunction InitiateClickAreas()\n clickAreas = {}\n \n AddClickArea({id = \"LoadSatNavLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LoadHudLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"NewLocation\", x1 = 700, x2 = 1100, y1 = 900, y2 = 1000})\n AddClickArea({id = \"ClearHudLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"PlanetPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"PlanetPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n \n for i = 1, pageLines do\n AddClickArea({id = string.format(\"PList%d\",i), x1 = 90, x2 = 800, y1 = (170 + i * 55), y2 = (225 + i * 55)})\n AddClickArea({id = string.format(\"LList%d\",i), x1 = 1090, x2 = 1500, y1 = (170 + i * 55), y2 = (225 + i * 55)})\n end\nend\n\nfunction FlushClickAreas() clickAreas = {} end\n\nfunction clearLocDispList()\n for i=1,pageLines do\n displayLocationList[i] = \"\"\n end\nend\n\nfunction CheckClick(x, y, HitTarget)\n HitTarget = HitTarget or \"\"\n if HitTarget == \"\" then\n for k, v in pairs(clickAreas) do\n if v and x >= v.x1 and x <= v.x2 and y >= v.y1 and y <= v.y2 then\n HitTarget = v.id\n break\n end\n end\n end\n \n --system.print(\"Target Hit = \"..HitTarget)\n \n if HitTarget == \"PlanetPageDown\" then\n CurrentPlanetPage = CurrentPlanetPage+1\n DrawPlanetList()\n elseif HitTarget == \"PlanetPageUp\" then\n CurrentPlanetPage = math.max(CurrentPlanetPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LocationPageDown\" then\n CurrentLocationPage = CurrentLocationPage+1\n DrawPlanetList()\n elseif HitTarget == \"LocationPageUp\" then\n CurrentLocationPage = math.max(CurrentLocationPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LoadSatNavLocations\" then\n loadPointsOfInterest()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n elseif HitTarget == \"LoadHudLocations\" then\n loadHudLocations()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end \n elseif HitTarget == \"ClearSatNavLocations\" then\n system.print(\"ClearSavedLocations\")\n clearSavedLocations()\n system.print(\"defaul=\"..displayPlanetList[1])\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n elseif HitTarget == \"ClearHudLocations\" then\n --system.print(\"ClearSavedLocations\")\n clearHudLocations()\n elseif HitTarget == \"NewLocation\" then\n system.print(\"NewLocation\")\n newLocation()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n else\n for i = 1,pageLines do\n if HitTarget == string.format(\"PList%s\",i) then\n --system.print(\"PHitTarget: \"..HitTarget)\n if displayPlanetList[i] ~= \"\" then\n lastPlanetSelected = displayPlanetList[i]\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n DrawPlanetList()\n end\n end\n if HitTarget == string.format(\"LList%s\",i) then\n if displayLocationList[i] ~= \"\" then\n selected = displayLocationList[i]\n if HUD == \"Dimencia\" then\n copySelectedToHud(selected)\n end\n lastLocationSelected = selected\n selected = \"\"\n DrawPlanetList()\n end\n end\n end\n end\nend\n\n-----------------------------------------------\n-- Code for building screen content and displaying it\n-----------------------------------------------\n\nlocal svgBootstrap = [[\n ]]\n\nfunction DrawPlanetList()\n\n local screenOutput = \"\"\n\n -- Draw Header\n screenOutput = screenOutput .. svgBootstrap\n \n -- Draw main background\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[(Version: ]]..version..[[)]]\n screenOutput = screenOutput ..\n [[Sat Nav]]\n if HUD == \"Dimencia\" then\n screenOutput = screenOutput ..\n [[(Dimencia HUD enabled)]]\n else \n screenOutput = screenOutput ..\n [[(Standalone mode enabled)]]\n end\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[Planets]]\n \n\n local i = 0\n for j = 1 + (CurrentPlanetPage - 1) * pageLines, pageLines +\n (CurrentPlanetPage - 1) * pageLines, 1 do\n i = i + 1\n if j < #planetList and j>0 then\n local planetName = planetList[j] \n if lastPlanetSelected == planetList[j] then\n screenOutput = screenOutput ..\n [[]]\n end\n screenOutput = screenOutput .. [[]] .. planetName .. \n [[]]\n if planetName ~= \"Space\" then\n screenOutput = screenOutput .. [[]] .. planetDistList[planetName] .. \n [[]] \n end\n displayPlanetList[i]=planetList[j]\n else\n displayPlanetList[i]=\"\"\n end\n end\n \n if planetCount > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentPlanetPage .. \" of \" ..\n math.ceil(planetCount / 12) ..\n [[]]\n\n if CurrentPlanetPage < math.ceil(planetCount / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageDown\", {\n id = \"PlanetPageDown\",\n x1 = 70,\n x2 = 270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageDown\")\n end\n\n if planetCount > 1 and CurrentPlanetPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageUp\", {\n id = \"PlanetPageUp\",\n x1 = 280,\n x2 = 480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageUp\")\n end\n end\n -- Start of Location List\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[]].. lastPlanetSelected ..[[ Locations]]\n \n\n local i = 0\n for j = 1 + (CurrentLocationPage - 1) * pageLines, pageLines +\n (CurrentLocationPage - 1) * pageLines, 1 do\n \n i = i + 1\n if j <= #locList and j>0 then\n if lastLocationSelected == locList[j] then\n screenOutput = screenOutput ..\n [[]]\n end\n screenOutput = screenOutput .. [[]] .. locList[j] .. \n [[]]\n displayLocationList[i]=locList[j]\n screenOutput = screenOutput .. [[]] .. locDistList[locList[j]] .. \n [[]] \n else\n displayLocationList[i]=\"\"\n end\n end\n \n if #locList > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentLocationPage .. \" of \" ..\n math.ceil(#locList / 12) ..\n [[]]\n\n if CurrentLocationPage < math.ceil(#locList / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageDown\", {\n id = \"LocationPageDown\",\n x1 = 1070,\n x2 = 1270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageDown\")\n end\n\n if #locList > 1 and CurrentLocationPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageUp\", {\n id = \"LocationPageUp\",\n x1 = 1280,\n x2 = 1480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageUp\")\n end\n end\n \n-- screenOutput = screenOutput ..\n-- [[]] ..\n-- [[Load SatNav DB]]\n \n screenOutput = screenOutput ..\n [[]] ..\n [[Save Current Location]]\n\n-- screenOutput = screenOutput ..\n-- [[]] ..\n-- [[Clear HUD Locs]]\n\n\n screenOutput = screenOutput .. [[]]\n\n DrawSVG(screenOutput)\n\n forceRedraw = false\nend\n\n-----------------------------------------------\n-- Execute\n-----------------------------------------------\n\nunit.hide()\nInitiateClickAreas()\nDrawPlanetList()\nsystem.print(\"Running\")\nunit.setTimer(\"loadwp\",1)\n\n\n","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"6"},{"code":"function loadLocationTable ()\n\nlocationTable = {{}}\nlocationTable[1] = {\"Alioth Market 1\", \"::pos{0,2,30.3314,101.3106,122.9764}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 2\", \"::pos{0,2,24.4469,88.0409,238.3019}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 3\", \"::pos{0,2,34.9734,87.3012,176.2188}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 4\", \"::pos{0,2,28.3352,99.5187,165.9078}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 5\", \"::pos{0,2,33.3939,87.3299,277.1366}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 6\", \"::pos{0,2,36.0044,101.3503,220.0897}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 7\", \"::pos{0,2,22.5024,98.1449,232.5154}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 8\", \"::pos{0,2,21.2154,93.9616,251.0768}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 9\", \"::pos{0,2,28.7133,85.6389,260.7636}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 10\", \"::pos{0,2,35.9865,91.8393,190.1616}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 11\", \"::pos{0,2,-1.0735,178.5062,69.9428}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 12\", \"::pos{0,2,22.7112,-92.3078,166.8481}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 13\", \"::pos{0,2,-23.3768,-10.5455,178.8458}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 14\", \"::pos{0,2,-73.4716,101.3697,89.5661}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 15\", \"::pos{0,2,61.7831,27.8517,54.9186}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 16\", \"::pos{0,2,23.4406,114.4179,211.1991}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 17\", \"::pos{0,2,37.8637,64.1825,151.5507}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 18\", \"::pos{0,2,49.9360,-170.7565,62.1982}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 19\", \"::pos{0,2,-32.7357,76.3764,209.0805}\"}\nlocationTable[#locationTable+1] = {\"Alioth Market 20\", \"::pos{0,2,-35.1535,-95.1230,301.0724}\"} \n \nlocationTable[#locationTable+1] = {\"Madis Market 1\", \"::pos{0,1,2.6476,176.8761,813.0974}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 2\", \"::pos{0,1,10.3552,8.5146,816.2210}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 3\", \"::pos{0,1,-0.2107,82.0779,809.5571}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 4\", \"::pos{0,1,-80.6046,44.9385,822.6188}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 5\", \"::pos{0,1,81.0827,5.3022,823.1976}\"}\nlocationTable[#locationTable+1] = {\"Madis Market 6\", \"::pos{0,1,13.9814,-91.6163,811.0679}\"}\n\nlocationTable[#locationTable+1] = {\"Thades M1: Market\", \"::pos{0,30,-2.9797,-117.7645,203.7519}\"}\nlocationTable[#locationTable+1] = {\"Feli: Market\", \"::pos{0,5,0.9348,178.6658,18417.2812}\"}\nlocationTable[#locationTable+1] = {\"Feli: Market 3\", \"::pos{0,5,-0.7500,-17.3248,18473.4238}\"}\n\nlocationTable[#locationTable+1] = {\"Symeon Market 1\", \"::pos{0,110,3.1400,-174.0223,267.1084}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 2\", \"::pos{0,110,-0.9862,88.3038,197.0626}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 3\", \"::pos{0,110,18.1117,11.1108,180.8022}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 4\", \"::pos{0,110,-26.9701,103.3741,186.2557}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 5\", \"::pos{0,110,83.1653,108.7807,142.5796}\"}\nlocationTable[#locationTable+1] = {\"Symeon Market 6\", \"::pos{0,110,-79.3167,95.3975,138.5268}\"}\n\nlocationTable[#locationTable+1] = {\"TMV Troghelm\", \"::pos{0,0,2416521.6598,1415126.8118,59323.7340}\"}\nlocationTable[#locationTable+1] = {\"TMV Alioth Factory\", \"::pos{0,2,22.8158,111.1414,103.5685}\"}\nlocationTable[#locationTable+1] = {\"TMV Feli Outpost\", \"::pos{0,5,23.6988,-77.8811,18480.5176}\"}\nlocationTable[#locationTable+1] = {\"TMV Thandes M1 Outpost\", \"::pos{0,30,-22.3548,-168.7352,288.1909}\"}\nlocationTable[#locationTable+1] = {\"TMV Madis Outpost\", \"::pos{0,1,-43.0914,75.0728,749.6641}\"}\nlocationTable[#locationTable+1] = {\"TMV Symoen Outpost\", \"::pos{0,110,-5.3046,32.6900,108.4144}\"}\nlocationTable[#locationTable+1] = {\"TMV Jago Outpost\", \"::pos{0,9,61.3760,-33.7830,10.7593}\"}\n\nend\n\nunit.stopTimer(\"loadwp\")\nloadLocationTable()\nlastNewLoc = myDatabank.getIntValue(\"lastNewLoc\")\n--system.print(\"lastNewLoc\"..lastNewLoc)\nif lastNewLoc == nil or lastNewLoc==0 then\n --this is th first time satnav has run on this databank\n system.print(\"Initialising SatNav Databank\")\n CheckClick(0, 0, \"LoadSatNavLocations\")\n lastNewLoc =1\n myDatabank.setIntValue(\"lastNewLoc\",lastNewLoc)\n system.print(\"Completed SatNav Databank\")\nend\n\n\n","filter":{"args":[{"value":"loadwp"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"7"},{"code":"\nif string.sub(text,1,2) == \"u \" then\n local newLocName = string.sub(text,3,string.len(text))\n updateLocationName(newLocName)\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\nelseif text == \"d SatNav\" then\n deleteLocationName(lastLocationSelected)\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\nelseif text == \"c SatNav\" then\n system.print(\"ClearSatNavLocations\")\n CheckClick(0, 0, \"ClearSatNavLocations\")\nelseif text == \"c Hud\" then\n if HUD == \"Dimencia\" then\n system.print(\"ClearHudLocations\")\n CheckClick(0, 0, \"ClearHudLocations\")\n else\n system.print(\"ClearHudLocations not available in standalone mode\")\n end\nelseif text == \"l SatNav\" then\n system.print(\"LoadSatNavLocations\")\n CheckClick(0, 0, \"LoadSatNavLocations\")\nelseif text == \"l Hud\" then\n if HUD == \"Dimencia\" then\n system.print(\"LoadHudLocations\")\n CheckClick(0, 0, \"LoadHudLocations\")\n else\n system.print(\"LoadHudLocations not available in standalone mode\")\n end\nelseif text == \"x SatNav\" then\n if dupSatnavDB then\n system.print(\"DuplicateSatNavDB\")\n duplicateSatnavDB()\n else\n system.print(\"Please link an empty databank to the programming board\")\n end\nend","filter":{"args":[{"variable":"*"}],"signature":"inputText(text)","slotKey":"-2"},"key":"8"}],"methods":[],"events":[]} +{"slots":{"0":{"name":"core","type":{"events":[],"methods":[]}},"1":{"name":"screen","type":{"events":[],"methods":[]}},"2":{"name":"db2","type":{"events":[],"methods":[]}},"3":{"name":"db1","type":{"events":[],"methods":[]}},"4":{"name":"dupSatnavDB","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"1"},"key":"0"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"6"},"key":"1"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"7"},"key":"2"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"8"},"key":"3"},{"code":"clickMouseX = x*1920\nclickMouseY = y*1120\nCheckClick(clickMouseX, clickMouseY)","filter":{"args":[{"variable":"*"},{"variable":"*"}],"signature":"mouseDown(x,y)","slotKey":"9"},"key":"4"},{"code":"--[[\n SatNav version 2_1_2-merl1\n Created By TrogLaByte\n\n Discord: Trog#5105\n InGame: TrogLaByte\n \n GNU Public License 3.0. Use whatever you want, be so kind to leave credit.\n\n Thanks to Dorien Grey for his SVG and onscreen button code.\n]] \n-----------------------------------------------\n-- requirements\n-----------------------------------------------\n\nfunction initiateRequiredLibaries()\n --json = require('dkjson')\n vec3 = require('cpml.vec3')\n utils = require('cpml.utils')\n planetRef = require('cpml.planetref')\n referenceTableSource = require('cpml.atlas')\n clamp = utils.clamp\nend\nif pcall(initiateRequiredLibaries) then\n system.print(\"Libaries loaded successfully\")\n else\n system.print(\"Libaries failed to load: check that the following libraries exist:\")\n system.print(\"( is the directory in to which you installed DU)\")\n system.print(\" /DualUniverse/Game/data/lua/dkjson\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/vec3\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/utils\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/planetref\")\n system.print(\" /DualUniverse/Game/data/lua/cpml/atlas\")\n system.print(\"\")\n system.print(\"planetref.lua and atlas.lua can be obtained from the following GitLab url:\")\n system.print(\"https://gitlab.com/JayleBreak/dualuniverse/-/tree/master/DUflightfiles/autoconf/custom\")\n unit.exit()\nend\n-----------------------------------------------\n-- Global Variables\n-----------------------------------------------\n\nlocal version = \"2_1_2\"\n\nlocal UpdateInterval = 1 \nlocal defaultNewLocName = \"SatNav Location\" --export: default name used for new locations\n--[[Original colours are 34b1eb, 6e3de3 and 1e1e1e]]\nlocal PlanetPanelColour = \"99eeff\" --export: Hex code for colour of planet panel and buttons (you need to include the quotes)\nlocal LocPanelColour = \"aa99ff\" --export: Hex code for colour of locations panel and buttons (you need to include the quotes)\nlocal FontPanelColour = \"000000\" --export: Hex code for font colour of planet/locations panel (you need to include the quotes)\nlocal LineHighlightColour = \"ccffff\"--export: Hex code for colour of highlighted lines in planet/location panel (you need to include the quotes)\n\nlocal BackgroundColor = \"#1e1e1e\"\nlocal PlanetBackgroundColor = \"#\" .. PlanetPanelColour\nlocal LocationBackgroundColor = \"#\" .. LocPanelColour\nlocal MainFontColor = \"#\" .. FontPanelColour\nlocal HighlightColor = \"#\" .. LineHighlightColour\n\nlocal lastPlanetSelected = \"Alioth\" --export: The default start planet for displaying locations\n\nlocal clickAreas = {}\nlocal locList={}\npageLines=12\ndisplayPlanetList={}\ndisplayLocationList={}\nCurrentLocationPage = 1\nCurrentPlanetPage = 1\nmyDatabank={}\ndbHud={}\n\nif db1 then db1Keys = db1.getKeys() end\nif db2 then db2Keys = db2.getKeys() end\n\n--if db1Keys then system.print(\"DB1 Keys: \"..string.sub(db1Keys,1,50)) end\n--if db2Keys then system.print(\"DB2 Keys: \"..string.sub(db2Keys,1,50)) end\n\nif db1 and (db1Keys==nil or db1Keys == \"\" or string.match(db1Keys, \"lastNewLoc\")) then\n myDatabank = db1\n system.print(\"SatNav Databank Identified\")\nelseif db2 and (db2Keys==nil or db2Keys == \"\" or string.match(db2Keys, \"lastNewLoc\")) then\n myDatabank = db2\n system.print(\"SatNav Databank Identified\")\nelse \n system.print(\"SatNav databank not found... application will stop\")\n if db1Keys then system.print(\"DB1 Keys: \"..string.sub(db1Keys,1,50)) end\n if db2Keys then system.print(\"DB2 Keys: \"..string.sub(db2Keys,1,50)) end\n unit.exit()\n unit.deactivate()\nend\n\nif myDatabank==db1 and db2 and string.match(db2Keys, \"AutopilotTargetIndex\") then\n dbHud = db2\n system.print(\"Dimencia Hud Identified\")\n HUD = \"Dimencia\"\nelseif myDatabank==db2 and db1 and string.match(db1Keys, \"AutopilotTargetIndex\") then\n dbHud = db1\n system.print(\"Dimencia Hud Identified\")\n HUD = \"Dimencia\"\nelse \n system.print(\"No Dimencia Hud Identified - will run in Stand Alone mode\")\n HUD = \"unknown\"\nend\n\n--unit.exit()\n-----------------------------------------------\n-- set up galaxy data and functions for planets and locations\n-----------------------------------------------\n\ngalaxyReference = planetRef(referenceTableSource)\nhelios = galaxyReference[0] -- PlanetaryReference.PlanetarySystem instance\nplanetList={}\nplanetDistList={}\nlocDistList={}\n\nfunction getBodyId(planetName)\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n if string.lower(helios[tonumber(i)].name) ==string.lower(planetName) then\n return i\n end\n end\n end\n return 0\nend\n\nfunction buildPlanetList()\n local planet={}\n local currentLoc = vec3(core.getConstructWorldPos())\n local shipMass = core.getConstructMass()\n for i=1,200 do\n if helios[tonumber(i)] ~= nil then\n planet = helios[tonumber(i)]\n planetList[#planetList+1] = planet.name\n local planetDistance = planet:getDistance(currentLoc)\n planetDistList[planet.name] = formatDistance(planetDistance) .. \n string.format(\" [%.0f wc]\", ((planetDistance/200000)*(shipMass/1000)/4000))\n end\n end\n planetList[#planetList+1]=\"Space\"\n table.sort(planetList)\nend\n\nfunction formatDistance(distance)\n if distance < 200000 then\n return string.format(\"%.0f km\",distance/1000)\n elseif distance < 4000000 then\n return string.format(\"%.2f su\",distance/200000)\n else\n return string.format(\"%.0f su\",distance/200000)\n end\nend\n\n-- json parser\n\n-- Extracts values from a JSON string with pattern matching\n-- This is faster than using dkjson when only a few fields are needed\n\n-- Use this only with trusted data sources! Limitations:\n-- * Character escapes are not supported\n-- * Field nesting is ignored\n\nlocal find, gsub = string.find, string.gsub\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return string|nil, number|nil, number|nil\nlocal function extractStringJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*\"([^\"]*)\"]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n return valueStr, startIndex, endIndex\nend\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return number|nil, number|nil, number|nil\nlocal function extractNumberJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*(-?[0-9.e-]+)]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n return tonumber(valueStr), startIndex, endIndex\nend\n\n---@param json string\n---@param key string\n---@param init number|nil\n---@return boolean|nil, number|nil, number|nil\nlocal function extractBooleanJsonValue (json, key, init)\n local pattern = [[\"]] .. key .. [[\"%s*:%s*([truefals]+)]]\n local startIndex, endIndex, valueStr = find(json, pattern, init)\n\n if valueStr == \"true\" then\n return true, startIndex, endIndex\n elseif valueStr == \"false\" then\n return false, startIndex, endIndex\n else\n return nil\n end\nend\n\n---@param extractJsonValue function\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue any|nil\n---@return any[]\nlocal function extractAllJsonValues (extractJsonValue, json, key, stopAfterIndex, stopAfterValue)\n local values = {}\n local valuesLen = 0\n\n local jsonPos = 1\n local value, valueStartIndex, valueEndIndex -- luacheck: ignore valueStartIndex -- unused\n\n repeat\n value, valueStartIndex, valueEndIndex = extractJsonValue(json, key, jsonPos)\n\n if value ~= nil then\n valuesLen = valuesLen + 1\n values[valuesLen] = value\n\n jsonPos = valueEndIndex + 1\n end\n\n if value == stopAfterValue then break end\n if valuesLen == stopAfterIndex then break end\n until value == nil\n\n return values\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue string|nil\n---@return string[]\nlocal function extractAllStringJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractStringJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue number|nil\n---@return number[]\nlocal function extractAllNumberJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractNumberJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n---@param json string\n---@param key string\n---@param stopAfterIndex number|nil\n---@param stopAfterValue boolean|nil\n---@return boolean[]\nlocal function extractAllBooleanJsonValues (json, key, stopAfterIndex, stopAfterValue)\n return extractAllJsonValues(extractBooleanJsonValue, json, key, stopAfterIndex, stopAfterValue)\nend\n\n-- end json Parser\n\n\nfunction buildPlanetLocList(planetName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n \n local currentLoc = vec3(core.getConstructWorldPos())\n local shipMass = core.getConstructMass()\n local planet={}\n locList={}\n if planetName ~= \"Space\" then\n table.insert(locList, planetName) -- add planet name into the list as a default\n locDistList[planetName] = planetDistList[planetName]\n end\n if #name > 0 then \n for i=1,#name do\n if string.lower(planetname[i]) == string.lower(planetName) or\n string.find(string.lower(planetname[i]),string.lower(planetName))\n then\n table.insert(locList, name[i])\n elseif planetname[i] == \"\" and planetName == \"Space\" then -- a space location\n table.insert(locList, name[i])\n end\n local locDistance = (currentLoc - vec3(posX[i],posY[i],posZ[i])):len()\n if planetName == \"Space\" then\n locDistList[name[i]] = formatDistance(locDistance) ..\n string.format(\" [%.0f wc]\", ((locDistance/200000)*(shipMass/1000)/4000))\n else\n locDistList[name[i]] = formatDistance(locDistance)\n end\n end\n end\n table.sort(locList)\nend\n\nfunction printLocMapPos(locationName)\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local wayPoint=\"\"\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n local planet={}\n if #name > 0 then \n for i = 1, #name do\n if string.lower(name[i]) == string.lower(locationName) then\n local bodyId = getBodyId(planetname[i])\n planet = helios[tonumber(bodyId)] \n if planet ~= nil then\n worldCoords = planet:convertToMapPosition(vec3(posX[i],posY[i],posZ[i]))\n wayPoint=string.format([[::pos{%d,%d,%f,%f,%f}]],\n worldCoords.systemId,\n worldCoords.bodyId,\n worldCoords.latitude*constants.rad2deg,\n worldCoords.longitude*constants.rad2deg,\n worldCoords.altitude)\n system.print(name[i]..\" @ \"..wayPoint)\n system.setWaypoint(wayPoint)\n return locationName,\n planetname[i],\n atmosphere[i],\n gravity[i],\n posX[i],\n posY[i],\n posZ[i]\n else\n wayPoint=string.format([[::pos{%d,%d,%f,%f,%f}]],\n 0,\n bodyId,\n posX[i],posY[i],posZ[i])\n system.print(name[i]..\" @ \"..wayPoint)\n system.setWaypoint(wayPoint)\n return locationName,\n planetname[i],\n atmosphere[i],\n gravity[i],\n posX[i],\n posY[i],\n posZ[i]\n end\n break\n end \n end\n end\n return \"\"\nend\n\nfunction clearSavedLocations()\n myDatabank.setStringValue(\"SavedLocations\",\"[]\")\n system.print(\"Satnav Databank cleared\")\nend\n\nfunction isDuplicateLocation(locName, locNameList)\n for i=1,#locNameList do\n if locNameList[i] == locName then\n return locName\n end\n end\n return \"\"\nend\n\nfunction saveSavedLocations (name, planetname, atmosphere, gravity, posX, posY, posZ)\n local newSavedLocations = \"[\"\n for i = 1, #name do\n if name[i]~=\"\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..name[i]..\n [[\",\"planetname\":\"]]..planetname[i]..[[\"]]..\n [[,\"atmosphere\":]]..atmosphere[i]..\n [[,\"gravity\":]]..gravity[i]..\n [[,\"position\":{\"x\":]]..posX[i]..\n [[,\"y\":]]..posY[i]..\n [[,\"z\":]]..posZ[i]..[[}}]]\n end\n if i+1<#name then\n newSavedLocations= newSavedLocations..\",\"\n end\n end\n newSavedLocations= newSavedLocations..\"]\" \n --system.print(newSavedLocations)\n myDatabank.setStringValue(\"SavedLocations\",newSavedLocations)\n system.print(\"Satnav Databank Updated\")\nend\n\nfunction updateLocationName(newLocName)\n if newLocName ~= nil and newLocName ~= \"\" and \n lastLocationSelected ~= nil and lastLocationSelected ~= \"\" then\n system.print(\"Updating location name for: \"..lastLocationSelected..\" to: \"..newLocName)\n else\n system.print(\"Invalid update request\")\n return\n end\n local savedLocation = {}\n local oldLocFound = false\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n for i = 1, #name do\n if name[i] == lastLocationSelected then\n --system.print(\"Found: \"..lastLocationSelected)\n name[i] = newLocName\n oldLocFound = true\n break\n end\n end\n \n if oldLocFound then \n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n else\n system.print(\"Old Location Name Not Found\")\n end\nend\n\nfunction deleteLocationName(delLocName)\n if delLocName ~= nil and delLocName ~= \"\" then\n system.print(\"Deleting location name: \"..delLocName)\n else\n system.print(\"Invalid update request\")\n return\n end\n local savedLocation = {}\n local oldLocFound = false\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n for i = 1, #name do\n if name[i] == delLocName then\n --system.print(\"Found: \"..delLocName)\n name[i] = \"\"\n oldLocFound = true\n break\n end\n end\n \n if oldLocFound then \n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n else\n system.print(\"Location Name Not Found\")\n end\nend\n\nfunction loadPointsOfInterest()\n -- get existing locations from SatNav Databank\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n\n\n local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)'\n local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' ..\n num .. ',' .. num .. '}'\n local j=0\n loadLocationTable()\n \n for i = 1, #locationTable do\n local newRef = #name + 1\n if isDuplicateLocation(locationTable[i][1],name) == \"\" then\n name[newRef]=locationTable[i][1]\n local newLocPos = locationTable[i][2]\n --system.print(\"Name: \"..locationTable[i][1]..\" \"..newLocPos)\n local systemId, bodyId, latitude, longitude, altitude =\n string.match(locationTable[i][2], posPattern)\n --system.print(\"BodyId: \".. bodyId)\n if tonumber(bodyId) > 0 then\n local planet = helios[tonumber(bodyId)] \n local worldCoords = planet:convertToWorldCoordinates(newLocPos)\n posX[newRef]=worldCoords[\"x\"]\n posY[newRef]=worldCoords[\"y\"]\n posZ[newRef]=worldCoords[\"z\"]\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=planet.name\n else -- it is a space location\n posX[newRef]=latitude\n posY[newRef]=longitude\n posZ[newRef]=altitude\n gravity[newRef]=0\n atmosphere[newRef]=0\n planetname[newRef]=\"\"\n end \n else\n system.print(\"Duplicate entry for location ignored: \"..locationTable[i][1])\n end\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n --system.print(\"Default SatNav locations loaded\")\nend\n\nfunction loadHudLocations()\n -- get existing locations from SatNav Databank\n local savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n\n local hudLocation = dbHud.getStringValue(\"SavedLocations\")\n local hudatmosphere={}\n local hudgravity={}\n local hudplanetname = {}\n local hudposX\t = {}\n local hudposY\t = {}\n local hudposZ\t = {}\n local hudname\t = {}\n\n hudatmosphere = extractAllNumberJsonValues(hudLocation,\"atmosphere\")\n hudgravity = extractAllNumberJsonValues(hudLocation,\"gravity\")\n hudplanetname = extractAllStringJsonValues(hudLocation,\"planetname\")\n hudposX\t = extractAllNumberJsonValues(hudLocation,\"x\")\n hudposY\t = extractAllNumberJsonValues(hudLocation,\"y\")\n hudposZ\t = extractAllNumberJsonValues(hudLocation,\"z\")\n hudname\t = extractAllStringJsonValues(hudLocation,\"name\")\n\n\n for i = 1, #hudname do\n local newRef = #name + 1\n system.print(\"HudName: \"..hudname[i])\n if isDuplicateLocation(hudname[i],name) == \"\" and\n hudname[i] ~= \"SatNav Location\" then\n name[newRef]=hudname[i]\n posX[newRef]=hudposX[i]\n posY[newRef]=hudposY[i]\n posZ[newRef]=hudposZ[i]\n gravity[newRef]=hudgravity[i]\n atmosphere[newRef]=hudatmosphere[i]\n planetname[newRef]=hudplanetname[i] \n else\n system.print(\"Duplicate entry for location ignored: \"..hudname[i])\n end\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n --system.print(\"Default SatNav locations loaded\")\nend\n\n\nfunction newLocation (xnewLocName, newLocPos)\n local location\n if xnewLocName and newLocPos then\n location = newLocPos\n else\n location = system.getWaypointFromPlayerPos()\n end\n local newLocId = myDatabank.getIntValue(\"lastNewLoc\") + 1\n myDatabank.setIntValue(\"lastNewLoc\",newLocId)\n \n local newLocName\n if xnewLocName then\n newLocName = xnewLocName\n else\n newLocName = defaultNewLocName..\" (\"..newLocId..\")\"\n end\n \n local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)'\n local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' ..\n num .. ',' .. num .. '}'\n \n local savedLocation = {}\n savedLocation = myDatabank.getStringValue(\"SavedLocations\")\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n \n local systemId, bodyId, latitude, longitude, altitude =\n string.match(location, posPattern)\n local worldPos = unit.getMasterPlayerRelativePosition()\n local body = helios:closestBody(worldPos)\n --system.print(json.encode(body))\n --system.print(\"Distance=\"..((vec3(worldPos)-vec3(body.center)):len())/(1000))\n --system.print(\"Calc=\"..((body.radius+body.center):len())/(1000))\n\n newlocAlt = ((vec3(worldPos)-vec3(body.center)):len())/(1000)\n-- system.print(\"New Loc Alt:\"..newlocAlt)\n-- system.print(\"Radius:\"..(((body.radius)/1000) + 200))\n if newlocAlt < (((body.radius)/1000) + 200) then\n local bodyId = getBodyId(body.name)\n --system.print(\"BodyId: \".. bodyId)\n local planet = helios[tonumber(bodyId)] -- PlanetaryReference.BodyParameters instance\n --system.print(\"Planet BodyId: \".. planet.bodyId)\n local worldCoords = planet:convertToWorldCoordinates(location)\n newRef = #name + 1\n name[newRef]=newLocName\n posX[newRef]=worldCoords[\"x\"]\n posY[newRef]=worldCoords[\"y\"]\n posZ[newRef]=worldCoords[\"z\"]\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=body.name\n else\n newRef = #name + 1\n name[newRef]=newLocName\n posX[newRef]=latitude\n posY[newRef]=longitude\n posZ[newRef]=altitude\n gravity[newRef]=core.g()\n atmosphere[newRef]=unit.getAtmosphereDensity()\n planetname[newRef]=\"Space\"\n\n end\n saveSavedLocations(name, planetname, atmosphere, gravity, posX, posY, posZ)\n system.print(\"New location: \"..newLocName..\" added to SatNav databank\")\n printLocMapPos(newLocName)\nend\n\nfunction copySelectedToHud (locName)\n \n local locName, locplanetname, locatmosphere, locgravity, locX, locY, locZ = \n printLocMapPos(locName)\n if HUD == \"Dimencia\" then\n savedLocation = dbHud.getStringValue(\"SavedLocations\")\n --system.print(\"savedLocation=\"..savedLocation)\n local atmosphere={}\n local gravity={}\n local planetname = {}\n local posX\t = {}\n local posY\t = {}\n local posZ\t = {}\n local name\t = {}\n atmosphere = extractAllNumberJsonValues(savedLocation,\"atmosphere\")\n gravity = extractAllNumberJsonValues(savedLocation,\"gravity\")\n planetname = extractAllStringJsonValues(savedLocation,\"planetname\")\n posX\t = extractAllNumberJsonValues(savedLocation,\"x\")\n posY\t = extractAllNumberJsonValues(savedLocation,\"y\")\n posZ\t = extractAllNumberJsonValues(savedLocation,\"z\")\n name\t = extractAllStringJsonValues(savedLocation,\"name\")\n local newSavedLocations = \"[\"\n for i = 1, #name do\n if name[i] ~= \"SatNav Location\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..name[i]..\n [[\",\"planetname\":\"]]..planetname[i]..[[\"]]..\n [[,\"atmosphere\":]]..atmosphere[i]..\n [[,\"gravity\":]]..gravity[i]..\n [[,\"position\":{\"x\":]]..posX[i]..\n [[,\"y\":]]..posY[i]..\n [[,\"z\":]]..posZ[i]..[[}},]]\n end\n end\n if locplanetname ~= \"\" then\n newSavedLocations = newSavedLocations..\n \"{\"..[[\"name\":\"]]..\"SatNav Location\"..\n [[\",\"planetname\":\"]]..locplanetname..[[\"]]..\n [[,\"atmosphere\":]]..locatmosphere..\n [[,\"gravity\":]]..locgravity..\n [[,\"position\":{\"x\":]]..locX..\n [[,\"y\":]]..locY..\n [[,\"z\":]]..locZ..[[}}]]\n end\n newSavedLocations= newSavedLocations..\"]\" \n dbHud.setStringValue(\"SavedLocations\",newSavedLocations)\n dbHud.setStringValue(\"SPBAutopilotTargetName\",\"SatNav Location\")\n end\nend\n\nfunction clearHudLocations()\n if HUD == \"Dimencia\" then\n dbHud.setStringValue(\"SavedLocations\",\"[]\")\n dbHud.setStringValue(\"SPBAutopilotTargetName\",\"\")\n system.print(\"Dimencia HUD Saved Locations Cleared\")\n end\nend\n\nfunction duplicateSatnavDB()\n local satnavLocation = myDatabank.getStringValue(\"SavedLocations\")\n local lastNewLoc = myDatabank.getIntValue(\"lastNewLoc\")\n if dupSatnavDB then\n dupSatnavDB.clear()\n dupSatnavDB.setStringValue(\"SavedLocations\",satnavLocation)\n dupSatnavDB.setIntValue(\"lastNewLoc\",lastNewLoc)\n system.print(\"SatNav Databank Duplicated Successfully\")\n else\n system.print(\"No space databank linked, duplication aborted\")\n end\nend\n\nbuildPlanetList()\nbuildPlanetLocList(lastPlanetSelected)\nlocal planetCount=#planetList\n\n-----------------------------------------------\n-- Code for on screen buttons\n-----------------------------------------------\n\nfunction DrawSVG(output) screen.setSVG(output) end\n\nfunction AddClickArea(newEntry) table.insert(clickAreas, newEntry) end\n\nfunction RemoveFromClickAreas(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = nil\n break\n end\n end\nend\n\nfunction UpdateClickArea(candidate, newEntry)\n --system.print(\"Candidate: \"..candidate..\" x1\"..newEntry.x1)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n clickAreas[k] = newEntry\n --system.print(\"Click Area: \"..candidate..\" x1\"..clickAreas[k].x1)\n break\n end\n end\nend\n\nfunction DisableClickArea(candidate)\n for k, v in pairs(clickAreas) do\n if v.id == candidate then\n UpdateClickArea(candidate, {\n id = candidate,\n x1 = -1,\n x2 = -1,\n y1 = -1,\n y2 = -1\n })\n break\n end\n end\nend\n\nfunction InitiateClickAreas()\n clickAreas = {}\n \n AddClickArea({id = \"LoadSatNavLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LoadHudLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"NewLocation\", x1 = 700, x2 = 1100, y1 = 900, y2 = 1000})\n AddClickArea({id = \"ClearHudLocations\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"PlanetPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"PlanetPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageDown\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n AddClickArea({id = \"LocationPageUp\", x1 = -1, x2 = -1, y1 = -1, y2 = -1})\n \n for i = 1, pageLines do\n AddClickArea({id = string.format(\"PList%d\",i), x1 = 90, x2 = 800, y1 = (170 + i * 55), y2 = (225 + i * 55)})\n AddClickArea({id = string.format(\"LList%d\",i), x1 = 1090, x2 = 1500, y1 = (170 + i * 55), y2 = (225 + i * 55)})\n end\nend\n\nfunction FlushClickAreas() clickAreas = {} end\n\nfunction clearLocDispList()\n for i=1,pageLines do\n displayLocationList[i] = \"\"\n end\nend\n\nfunction CheckClick(x, y, HitTarget)\n HitTarget = HitTarget or \"\"\n if HitTarget == \"\" then\n for k, v in pairs(clickAreas) do\n if v and x >= v.x1 and x <= v.x2 and y >= v.y1 and y <= v.y2 then\n HitTarget = v.id\n break\n end\n end\n end\n \n --system.print(\"Target Hit = \"..HitTarget)\n \n if HitTarget == \"PlanetPageDown\" then\n CurrentPlanetPage = CurrentPlanetPage+1\n DrawPlanetList()\n elseif HitTarget == \"PlanetPageUp\" then\n CurrentPlanetPage = math.max(CurrentPlanetPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LocationPageDown\" then\n CurrentLocationPage = CurrentLocationPage+1\n DrawPlanetList()\n elseif HitTarget == \"LocationPageUp\" then\n CurrentLocationPage = math.max(CurrentLocationPage-1,0)\n DrawPlanetList()\n elseif HitTarget == \"LoadSatNavLocations\" then\n loadPointsOfInterest()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n elseif HitTarget == \"LoadHudLocations\" then\n loadHudLocations()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end \n elseif HitTarget == \"ClearSatNavLocations\" then\n system.print(\"ClearSavedLocations\")\n clearSavedLocations()\n system.print(\"defaul=\"..displayPlanetList[1])\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n elseif HitTarget == \"ClearHudLocations\" then\n --system.print(\"ClearSavedLocations\")\n clearHudLocations()\n elseif HitTarget == \"NewLocation\" then\n system.print(\"NewLocation\")\n newLocation()\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n else\n for i = 1,pageLines do\n if HitTarget == string.format(\"PList%s\",i) then\n --system.print(\"PHitTarget: \"..HitTarget)\n if displayPlanetList[i] ~= \"\" then\n lastPlanetSelected = displayPlanetList[i]\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n DrawPlanetList()\n end\n end\n if HitTarget == string.format(\"LList%s\",i) then\n if displayLocationList[i] ~= \"\" then\n selected = displayLocationList[i]\n if HUD == \"Dimencia\" then\n copySelectedToHud(selected)\n end\n lastLocationSelected = selected\n selected = \"\"\n DrawPlanetList()\n end\n end\n end\n end\nend\n\n-----------------------------------------------\n-- Code for building screen content and displaying it\n-----------------------------------------------\n\nlocal svgBootstrap = [[\n ]]\n\nfunction DrawPlanetList()\n\n local screenOutput = \"\"\n\n -- Draw Header\n screenOutput = screenOutput .. svgBootstrap\n \n -- Draw main background\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[(Version: ]]..version..[[)]]\n screenOutput = screenOutput ..\n [[Sat Nav]]\n if HUD == \"Dimencia\" then\n screenOutput = screenOutput ..\n [[(Dimencia HUD enabled)]]\n else \n screenOutput = screenOutput ..\n [[(Standalone mode enabled)]]\n end\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[Planets]]\n \n\n local i = 0\n for j = 1 + (CurrentPlanetPage - 1) * pageLines, pageLines +\n (CurrentPlanetPage - 1) * pageLines, 1 do\n i = i + 1\n if j < #planetList and j>0 then\n local planetName = planetList[j] \n if lastPlanetSelected == planetList[j] then\n screenOutput = screenOutput ..\n [[]]\n end\n screenOutput = screenOutput .. [[]] .. planetName .. \n [[]]\n if planetName ~= \"Space\" then\n screenOutput = screenOutput .. [[]] .. planetDistList[planetName] .. \n [[]] \n end\n displayPlanetList[i]=planetList[j]\n else\n displayPlanetList[i]=\"\"\n end\n end\n \n if planetCount > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentPlanetPage .. \" of \" ..\n math.ceil(planetCount / 12) ..\n [[]]\n\n if CurrentPlanetPage < math.ceil(planetCount / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageDown\", {\n id = \"PlanetPageDown\",\n x1 = 70,\n x2 = 270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageDown\")\n end\n\n if planetCount > 1 and CurrentPlanetPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"PlanetPageUp\", {\n id = \"PlanetPageUp\",\n x1 = 280,\n x2 = 480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"PlanetPageUp\")\n end\n end\n -- Start of Location List\n screenOutput = screenOutput ..\n [[]]\n screenOutput = screenOutput ..\n [[]] \n screenOutput = screenOutput ..\n [[]].. lastPlanetSelected ..[[ Locations]]\n \n\n local i = 0\n for j = 1 + (CurrentLocationPage - 1) * pageLines, pageLines +\n (CurrentLocationPage - 1) * pageLines, 1 do\n \n i = i + 1\n if j <= #locList and j>0 then\n if lastLocationSelected == locList[j] then\n screenOutput = screenOutput ..\n [[]]\n end\n screenOutput = screenOutput .. [[]] .. locList[j] .. \n [[]]\n displayLocationList[i]=locList[j]\n screenOutput = screenOutput .. [[]] .. locDistList[locList[j]] .. \n [[]] \n else\n displayLocationList[i]=\"\"\n end\n end\n \n if #locList > 12 then\n screenOutput = screenOutput ..\n [[Page ]] ..\n CurrentLocationPage .. \" of \" ..\n math.ceil(#locList / 12) ..\n [[]]\n\n if CurrentLocationPage < math.ceil(#locList / 12) then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageDown\", {\n id = \"LocationPageDown\",\n x1 = 1070,\n x2 = 1270,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageDown\")\n end\n\n if #locList > 1 and CurrentLocationPage > 1 then\n screenOutput = screenOutput .. [[\n \n \n ]]\n UpdateClickArea(\"LocationPageUp\", {\n id = \"LocationPageUp\",\n x1 = 1280,\n x2 = 1480,\n y1 = 1050,\n y2 = 1105\n })\n else\n DisableClickArea(\"LocationPageUp\")\n end\n end\n \n-- screenOutput = screenOutput ..\n-- [[]] ..\n-- [[Load SatNav DB]]\n \n screenOutput = screenOutput ..\n [[]] ..\n [[Save Current Location]]\n\n-- screenOutput = screenOutput ..\n-- [[]] ..\n-- [[Clear HUD Locs]]\n\n\n screenOutput = screenOutput .. [[]]\n\n DrawSVG(screenOutput)\n\n forceRedraw = false\nend\n\n-----------------------------------------------\n-- Execute\n-----------------------------------------------\n\nunit.hide()\nInitiateClickAreas()\nDrawPlanetList()\nsystem.print(\"Running\")\nunit.setTimer(\"loadwp\",1)\n","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"5"},{"code":"function loadLocationTable ()\n locationTable = {{}}\n locationTable[1] = {\"Alioth Market 1\", \"::pos{0,2,30.3314,101.3106,122.9764}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 2\", \"::pos{0,2,24.4469,88.0409,238.3019}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 3\", \"::pos{0,2,34.9734,87.3012,176.2188}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 4\", \"::pos{0,2,28.3352,99.5187,165.9078}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 5\", \"::pos{0,2,33.3939,87.3299,277.1366}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 6\", \"::pos{0,2,36.0044,101.3503,220.0897}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 7\", \"::pos{0,2,22.5024,98.1449,232.5154}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 8\", \"::pos{0,2,21.2154,93.9616,251.0768}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 9\", \"::pos{0,2,28.7133,85.6389,260.7636}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 10\", \"::pos{0,2,35.9865,91.8393,190.1616}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 11\", \"::pos{0,2,-1.0735,178.5062,69.9428}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 12\", \"::pos{0,2,22.7112,-92.3078,166.8481}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 13\", \"::pos{0,2,-23.3768,-10.5455,178.8458}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 14\", \"::pos{0,2,-73.4716,101.3697,89.5661}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 15\", \"::pos{0,2,61.7831,27.8517,54.9186}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 16\", \"::pos{0,2,23.4406,114.4179,211.1991}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 17\", \"::pos{0,2,37.8637,64.1825,151.5507}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 18\", \"::pos{0,2,49.9360,-170.7565,62.1982}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 19\", \"::pos{0,2,-32.7357,76.3764,209.0805}\"}\n locationTable[#locationTable+1] = {\"Alioth Market 20\", \"::pos{0,2,-35.1535,-95.1230,301.0724}\"} \n \n locationTable[#locationTable+1] = {\"Madis Market 1\", \"::pos{0,1,2.6476,176.8761,813.0974}\"}\n locationTable[#locationTable+1] = {\"Madis Market 2\", \"::pos{0,1,10.3552,8.5146,816.2210}\"}\n locationTable[#locationTable+1] = {\"Madis Market 3\", \"::pos{0,1,-0.2107,82.0779,809.5571}\"}\n locationTable[#locationTable+1] = {\"Madis Market 4\", \"::pos{0,1,-80.6046,44.9385,822.6188}\"}\n locationTable[#locationTable+1] = {\"Madis Market 5\", \"::pos{0,1,81.0827,5.3022,823.1976}\"}\n locationTable[#locationTable+1] = {\"Madis Market 6\", \"::pos{0,1,13.9814,-91.6163,811.0679}\"}\n\n locationTable[#locationTable+1] = {\"Thades M1: Market\", \"::pos{0,30,-2.9797,-117.7645,203.7519}\"}\n locationTable[#locationTable+1] = {\"Feli: Market\", \"::pos{0,5,0.9348,178.6658,18417.2812}\"}\n locationTable[#locationTable+1] = {\"Feli: Market 3\", \"::pos{0,5,-0.7500,-17.3248,18473.4238}\"}\n\n locationTable[#locationTable+1] = {\"Symeon Market 1\", \"::pos{0,110,3.1400,-174.0223,267.1084}\"}\n locationTable[#locationTable+1] = {\"Symeon Market 2\", \"::pos{0,110,-0.9862,88.3038,197.0626}\"}\n locationTable[#locationTable+1] = {\"Symeon Market 3\", \"::pos{0,110,18.1117,11.1108,180.8022}\"}\n locationTable[#locationTable+1] = {\"Symeon Market 4\", \"::pos{0,110,-26.9701,103.3741,186.2557}\"}\n locationTable[#locationTable+1] = {\"Symeon Market 5\", \"::pos{0,110,83.1653,108.7807,142.5796}\"}\n locationTable[#locationTable+1] = {\"Symeon Market 6\", \"::pos{0,110,-79.3167,95.3975,138.5268}\"}\n\n locationTable[#locationTable+1] = {\"TMV Troghelm\", \"::pos{0,0,2416521.6598,1415126.8118,59323.7340}\"}\n locationTable[#locationTable+1] = {\"TMV Alioth Factory\", \"::pos{0,2,22.8158,111.1414,103.5685}\"}\n locationTable[#locationTable+1] = {\"TMV Feli Outpost\", \"::pos{0,5,23.6988,-77.8811,18480.5176}\"}\n locationTable[#locationTable+1] = {\"TMV Thandes M1 Outpost\", \"::pos{0,30,-22.3548,-168.7352,288.1909}\"}\n locationTable[#locationTable+1] = {\"TMV Madis Outpost\", \"::pos{0,1,-43.0914,75.0728,749.6641}\"}\n locationTable[#locationTable+1] = {\"TMV Symoen Outpost\", \"::pos{0,110,-5.3046,32.6900,108.4144}\"}\n locationTable[#locationTable+1] = {\"TMV Jago Outpost\", \"::pos{0,9,61.3760,-33.7830,10.7593}\"}\nend\n\nunit.stopTimer(\"loadwp\")\nloadLocationTable()\nlastNewLoc = myDatabank.getIntValue(\"lastNewLoc\")\n--system.print(\"lastNewLoc\"..lastNewLoc)\nif lastNewLoc == nil or lastNewLoc==0 then\n --this is th first time satnav has run on this databank\n system.print(\"Initialising SatNav Databank\")\n CheckClick(0, 0, \"LoadSatNavLocations\")\n lastNewLoc =1\n myDatabank.setIntValue(\"lastNewLoc\",lastNewLoc)\n system.print(\"Completed SatNav Databank\")\nend","filter":{"args":[{"value":"loadwp"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"6"},{"code":"if string.sub(text,1,2) == \"u \" then\n local newLocName = string.sub(text,3,string.len(text))\n updateLocationName(newLocName)\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\nelseif text == \"d SatNav\" then\n deleteLocationName(lastLocationSelected)\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\nelseif text == \"c SatNav\" then\n system.print(\"ClearSatNavLocations\")\n CheckClick(0, 0, \"ClearSatNavLocations\")\nelseif text == \"c Hud\" then\n if HUD == \"Dimencia\" then\n system.print(\"ClearHudLocations\")\n CheckClick(0, 0, \"ClearHudLocations\")\n else\n system.print(\"ClearHudLocations not available in standalone mode\")\n end\nelseif text == \"l SatNav\" then\n system.print(\"LoadSatNavLocations\")\n CheckClick(0, 0, \"LoadSatNavLocations\")\nelseif text == \"l Hud\" then\n if HUD == \"Dimencia\" then\n system.print(\"LoadHudLocations\")\n CheckClick(0, 0, \"LoadHudLocations\")\n else\n system.print(\"LoadHudLocations not available in standalone mode\")\n end\nelseif text == \"x SatNav\" then\n if dupSatnavDB then\n system.print(\"DuplicateSatNavDB\")\n duplicateSatnavDB()\n else\n system.print(\"Please link an empty databank to the programming board\")\n end\nelseif string.sub(text,1,2) == \"a \" then\n local newLocNamePos = text:find(\"}\") \n if newLocNamePos > 0 then\n -- @TODO: add more validation\n local newLocPos = string.sub(text,3,newLocNamePos)\n local newLocName = string.sub(text, newLocNamePos + 2, string.len(text))\n newLocation(newLocName, newLocPos)\n if displayPlanetList[1] ~= \"\" then\n lastPlanetSelected = displayPlanetList[1]\n lastLocationSelected = \"\"\n buildPlanetLocList(lastPlanetSelected)\n clearLocDispList()\n selected = \"\"\n CurrentLocationPage=1\n CurrentPlanetPage=1\n DrawPlanetList()\n end\n end\nend","filter":{"args":[{"variable":"*"}],"signature":"inputText(text)","slotKey":"-2"},"key":"7"}],"methods":[],"events":[]} \ No newline at end of file diff --git a/src/system/inputText.lua b/src/system/inputText.lua index 4e0aacc..d06d037 100644 --- a/src/system/inputText.lua +++ b/src/system/inputText.lua @@ -50,4 +50,22 @@ elseif text == "x SatNav" then else system.print("Please link an empty databank to the programming board") end +elseif string.sub(text,1,2) == "a " then + local newLocNamePos = text:find("}") + if newLocNamePos > 0 then + -- @TODO: add more validation + local newLocPos = string.sub(text,3,newLocNamePos) + local newLocName = string.sub(text, newLocNamePos + 2, string.len(text)) + newLocation(newLocName, newLocPos) + if displayPlanetList[1] ~= "" then + lastPlanetSelected = displayPlanetList[1] + lastLocationSelected = "" + buildPlanetLocList(lastPlanetSelected) + clearLocDispList() + selected = "" + CurrentLocationPage=1 + CurrentPlanetPage=1 + DrawPlanetList() + end + end end \ No newline at end of file diff --git a/src/unit/start.lua b/src/unit/start.lua index a5c9ce7..ab2ceac 100644 --- a/src/unit/start.lua +++ b/src/unit/start.lua @@ -1,5 +1,5 @@ --[[ - SatNav version 2_1_2 + SatNav version 2_1_2-merl1 Created By TrogLaByte Discord: Trog#5105 @@ -603,12 +603,22 @@ function loadHudLocations() end -function newLocation () - local location = system.getWaypointFromPlayerPos() +function newLocation (xnewLocName, newLocPos) + local location + if xnewLocName and newLocPos then + location = newLocPos + else + location = system.getWaypointFromPlayerPos() + end local newLocId = myDatabank.getIntValue("lastNewLoc") + 1 myDatabank.setIntValue("lastNewLoc",newLocId) - local newLocName = defaultNewLocName.." ("..newLocId..")" + local newLocName + if xnewLocName then + newLocName = xnewLocName + else + newLocName = defaultNewLocName.." ("..newLocId..")" + end local num = ' *([+-]?%d+%.?%d*e?[+-]?%d*)' local posPattern = '::pos{' .. num .. ',' .. num .. ',' .. num .. ',' .. From dbf5ad9c0845e22a633e3a99f077026f4928c605 Mon Sep 17 00:00:00 2001 From: Merl Date: Sat, 19 Dec 2020 06:49:07 +0100 Subject: [PATCH 6/7] clearified warning when using "a " option --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 77593fb..357d53c 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,8 @@ Welcome to Trog's SatNav for Dual Universe. This is a location/bookmark manager g) `x SatNav` - this command will duplicate/clone the SatNav databank if an additional empty databank has been linked to the PB in slot 5. The purpose of this feature is to enable users to copy their locations to multiple ships. - h) `a ::pos{system,planet,lat,lon,alt} Displayname` - will add a new Location to SatNav. Input validation is very basic, thus please use with care. + h) `a ::pos{system,planet,lat,lon,alt} Displayname` - will add a new Location to SatNav. Input validation is very basic, thus **please use with care**. + > **There is no real input validation implemented yet and you might very well corrupt your databank.** 5. When using your [Dimencia Hud](https://github.com/Dimencia/DU-Orbital-Hud), you will find that the location you loaded in 3 (above) has been renamed as `**SatNav Location**` and is now available using the `Alt+1/Alt+2` keys.. This will also have been set as the destination on the Dim Hud buttons screen. > Unlike previous versions of SatNav, we now only copy across a single location to Dim Hud - this is due to a limitation in the Dim Hud which would cause a CPU overload error if we copied all of the SatNav locations across. From 9c3ffb22517125f3c2978de604972d7c808a9a4d Mon Sep 17 00:00:00 2001 From: Florian Betz Date: Sun, 4 Apr 2021 13:34:20 +0200 Subject: [PATCH 7/7] Added hint to official Repo Added hint to official Repo --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 357d53c..7fa0a0a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ +```diff +- This is not the official SatNav Github. It is a working copy for my personal experiments and contributions. +- It will most propably be outdated or broken. +``` +# All credits for SatNav go to @TROG111 +##You can find the official SatNav Git at [https://github.com/TROG111/SatNav](https://github.com/TROG111/SatNav). + + + # Introduction Welcome to Trog's SatNav for Dual Universe. This is a location/bookmark manager for `:pos(.....)` locations which includes integration into the [Dimecia Hud](https://github.com/Dimencia/DU-Orbital-Hud) to enable autopiloting to your stored locations. SatNav can be used in stand alone mode or as integrated into the [Dimencia Hud](https://github.com/Dimencia/DU-Orbital-Hud). These instructions have been updated for SatNav version 2_1_2. To install a previous version please contact me directly.