Make mission portable

use inline json.lua and write to %LIBERATION_EXPORT_DIR%, %TEMP%
or the DCS working directory
This commit is contained in:
David Pierron
2020-09-29 17:27:35 +02:00
parent a98da14c6f
commit afbd4a4716
4 changed files with 49 additions and 18 deletions

View File

@@ -1,9 +1,5 @@
local jsonlib = {{json_file_abs_location}}
json = loadfile(jsonlib)()
logger = mist.Logger:new("DCSLiberation", "info")
debriefing_file_location = {{debriefing_file_location}}
logger:info("Check that json.lua is loaded : json = "..tostring(json))
killed_aircrafts = {}
killed_ground_units = {}
@@ -32,6 +28,11 @@ write_state = function()
["mission_ended"] = mission_ended,
["destroyed_objects_positions"] = destroyed_objects_positions,
}
if not json then
local message = string.format("Unable to save DCS Liberation state to %s, JSON library is not loaded !",debriefing_file_location)
logger:error(message)
messageAll(message)
end
fp:write(json:encode(game_state))
fp:close()
-- logger.info("Done writing DCS Liberation state")
@@ -39,6 +40,30 @@ write_state = function()
end
debriefing_file_location = nil
if not debriefing_file_location then
if os then
debriefing_file_location = os.getenv("LIBERATION_EXPORT_DIR")
if debriefing_file_location then debriefing_file_location = debriefing_file_location .. "\\" end
end
end
if not debriefing_file_location then
if os then
debriefing_file_location = os.getenv("TEMP")
if debriefing_file_location then debriefing_file_location = debriefing_file_location .. "\\" end
end
end
if not debriefing_file_location then
if lfs then
debriefing_file_location = lfs.writedir()
end
end
if debriefing_file_location then
debriefing_file_location = debriefing_file_location .. "state.json"
end
logger:info(string.format("DCS Liberation state will be written as json to [[%s]]",debriefing_file_location))
write_state_error_handling = function()
if pcall(write_state) then
-- messageAll("Written DCS Liberation state to "..debriefing_file_location)

View File

@@ -968,7 +968,7 @@ function OBJDEF:new(args)
return setmetatable(new, OBJDEF)
end
return OBJDEF:new()
json = OBJDEF:new()
--
-- Version history: