diff --git a/changelog.md b/changelog.md index 865636e7..30da09d0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,6 @@ +# 2.x.x +* **[Mission Generator]** Use inline loading of the JSON.lua library, and save to either %LIBERATION_EXPORT_DIR%, to %TEMP%, or to DCS working directory + # 2.1.2 ## Fixes : diff --git a/game/operation/operation.py b/game/operation/operation.py index 2449746e..0e39bf1e 100644 --- a/game/operation/operation.py +++ b/game/operation/operation.py @@ -250,22 +250,25 @@ class Operation: print(e) # Inject Mist Script if not done already in the plugins - if not "mist.lua" in listOfPluginsScripts and not "mist_4_3_74.lua" in listOfPluginsScripts: # don't load mist twice - trigger = TriggerStart(comment="Load Mist Lua Framework") + if not "mist.lua" in listOfPluginsScripts and not "mist_4_3_74.lua" in listOfPluginsScripts: # don't load the script twice + trigger = TriggerStart(comment="Load Mist Lua framework") fileref = self.current_mission.map_resource.add_resource_file("./resources/scripts/mist_4_3_74.lua") trigger.add_action(DoScriptFile(fileref)) self.current_mission.triggerrules.triggers.append(trigger) - # Inject Liberation script - load_dcs_libe = TriggerStart(comment="Load DCS Liberation Script") - with open("./resources/scripts/dcs_liberation.lua") as f: - script = f.read() - json_location = "[["+os.path.abspath("resources\\scripts\\json.lua")+"]]" - state_location = "[[" + os.path.abspath("state.json") + "]]" - script = script.replace("{{json_file_abs_location}}", json_location) - script = script.replace("{{debriefing_file_location}}", state_location) - load_dcs_libe.add_action(DoScript(String(script))) - self.current_mission.triggerrules.triggers.append(load_dcs_libe) + # Inject JSON library if not done already in the plugins + if not "json.lua" in listOfPluginsScripts : # don't load the script twice + trigger = TriggerStart(comment="Load JSON Lua library") + fileref = self.current_mission.map_resource.add_resource_file("./resources/scripts/json.lua") + trigger.add_action(DoScriptFile(fileref)) + self.current_mission.triggerrules.triggers.append(trigger) + + # Inject DCS-Liberation script if not done already in the plugins + if not "json.lua" in listOfPluginsScripts : # don't load the script twice + trigger = TriggerStart(comment="Load DCS Liberation script") + fileref = self.current_mission.map_resource.add_resource_file("./resources/scripts/dcs_liberation.lua") + trigger.add_action(DoScriptFile(fileref)) + self.current_mission.triggerrules.triggers.append(trigger) # Load Ciribob's JTACAutoLase script if not done already in the plugins if not "JTACAutoLase.lua" in listOfPluginsScripts: # don't load JTACAutoLase twice diff --git a/resources/scripts/dcs_liberation.lua b/resources/scripts/dcs_liberation.lua index 5c594d35..bb0939b7 100644 --- a/resources/scripts/dcs_liberation.lua +++ b/resources/scripts/dcs_liberation.lua @@ -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) diff --git a/resources/scripts/json.lua b/resources/scripts/json.lua index 8b3ddb1f..632c6840 100644 --- a/resources/scripts/json.lua +++ b/resources/scripts/json.lua @@ -968,7 +968,7 @@ function OBJDEF:new(args) return setmetatable(new, OBJDEF) end -return OBJDEF:new() +json = OBJDEF:new() -- -- Version history: