Moved bookmarks file to live in user folder, auto create default if it does not exists

This commit is contained in:
Andreas Engberg
2024-04-19 11:08:52 +02:00
parent bb9f7c6840
commit 9011f7f6e0
2 changed files with 22 additions and 4 deletions

View File

@@ -1,2 +0,0 @@
Group (optional),Name (required),Globe (optional),Lat (required if globe),Lon (required if globe),Altitude (optional if globe),x (required if not globe),y (required if not globe),z (required if not globe),Scale (optional),LineWidth (optional)
NASA,Kennedy Space Center,Earth,28.6658276,-80.70282839,,,,,,
1 Group (optional) Name (required) Globe (optional) Lat (required if globe) Lon (required if globe) Altitude (optional if globe) x (required if not globe) y (required if not globe) z (required if not globe) Scale (optional) LineWidth (optional)
2 NASA Kennedy Space Center Earth 28.6658276 -80.70282839

View File

@@ -4,12 +4,32 @@ local bookmarkHelper = asset.require("util/generate_bookmarks")
-- ensure that it is loaded first
asset.require("scene/solarsystem/planets/earth/earth")
local localBookmarks = openspace.absPath("${USER}/bookmarks/localbookmarks.csv")
-- Returns true if the file exists and can be opened for reading and false otherwise
function file_exists(name)
local f=io.open(name,"r")
return f~=nil and io.close(f)
end
-- Create bookmarks file if it does not exist
if not file_exists(localBookmarks) then
local file = io.open(localBookmarks, "w")
file:write(
"Group (optional),Name (required),Globe (optional),Lat (required if globe)," ..
"Lon (required if globe),Altitude (optional if globe),x (required if not globe)," ..
"y (required if not globe),z (required if not globe),Scale (optional)," ..
"LineWidth (optional)\n" ..
"NASA,Kennedy Space Center,Earth,28.6658276,-80.70282839,,,,,,\n"
)
file:close()
end
local nodes = bookmarkHelper.loadBookmarks(
"Local Bookmarks",
"${ASSETS}/customization/localbookmarks.csv"
"${USER}/bookmarks/localbookmarks.csv"
)
asset.onInitialize(function()
for _, n in ipairs(nodes) do
local success, error = pcall(openspace.addSceneGraphNode, n)