mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Make mission portable
use inline json.lua and write to %LIBERATION_EXPORT_DIR%, %TEMP% or the DCS working directory
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -968,7 +968,7 @@ function OBJDEF:new(args)
|
||||
return setmetatable(new, OBJDEF)
|
||||
end
|
||||
|
||||
return OBJDEF:new()
|
||||
json = OBJDEF:new()
|
||||
|
||||
--
|
||||
-- Version history:
|
||||
|
||||
Reference in New Issue
Block a user