mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Merge pull request #161 from VEAF/make-mission-portable
Make mission portable
This commit is contained in:
commit
f68e6387e6
@ -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
|
# 2.1.2
|
||||||
|
|
||||||
## Fixes :
|
## Fixes :
|
||||||
|
|||||||
@ -250,41 +250,80 @@ class Operation:
|
|||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
# Inject Mist Script if not done already in the plugins
|
# 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
|
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")
|
trigger = TriggerStart(comment="Load Mist Lua framework")
|
||||||
fileref = self.current_mission.map_resource.add_resource_file("./resources/scripts/mist_4_3_74.lua")
|
fileref = self.current_mission.map_resource.add_resource_file("./resources/scripts/mist_4_3_74.lua")
|
||||||
trigger.add_action(DoScriptFile(fileref))
|
trigger.add_action(DoScriptFile(fileref))
|
||||||
self.current_mission.triggerrules.triggers.append(trigger)
|
self.current_mission.triggerrules.triggers.append(trigger)
|
||||||
|
|
||||||
# Inject Liberation script
|
# Inject JSON library if not done already in the plugins
|
||||||
load_dcs_libe = TriggerStart(comment="Load DCS Liberation Script")
|
if not "json.lua" in listOfPluginsScripts : # don't load the script twice
|
||||||
with open("./resources/scripts/dcs_liberation.lua") as f:
|
trigger = TriggerStart(comment="Load JSON Lua library")
|
||||||
script = f.read()
|
fileref = self.current_mission.map_resource.add_resource_file("./resources/scripts/json.lua")
|
||||||
json_location = "[["+os.path.abspath("resources\\scripts\\json.lua")+"]]"
|
trigger.add_action(DoScriptFile(fileref))
|
||||||
state_location = "[[" + os.path.abspath("state.json") + "]]"
|
self.current_mission.triggerrules.triggers.append(trigger)
|
||||||
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)
|
|
||||||
|
|
||||||
# Load Ciribob's JTACAutoLase script if not done already in the plugins
|
# set a LUA table with data from Liberation that we want to set
|
||||||
if not "JTACAutoLase.lua" in listOfPluginsScripts: # don't load JTACAutoLase twice
|
# at the moment it contains Liberation's install path, and an overridable definition for the JTACAutoLase function
|
||||||
load_autolase = TriggerStart(comment="Load JTAC script")
|
# later, we'll add data about the units and points having been generated, in order to facilitate the configuration of the plugin lua scripts
|
||||||
with open("./resources/scripts/JTACAutoLase.lua") as f:
|
state_location = "[[" + os.path.abspath("state.json") + "]]"
|
||||||
|
lua = """
|
||||||
|
-- setting configuration table
|
||||||
|
env.info("DCSLiberation|: setting configuration table")
|
||||||
|
|
||||||
script = f.read()
|
-- all data in this table is overridable.
|
||||||
script = script + "\n"
|
dcsLiberation = {}
|
||||||
|
|
||||||
smoke = "true"
|
-- the base location for state.json; if non-existent, it'll be replaced with LIBERATION_EXPORT_DIR, TEMP, or DCS working directory
|
||||||
if hasattr(self.game.settings, "jtac_smoke_on"):
|
dcsLiberation.installPath=""" + state_location + """
|
||||||
if not self.game.settings.jtac_smoke_on:
|
|
||||||
smoke = "false"
|
|
||||||
|
|
||||||
for jtac in jtacs:
|
-- you can override dcsLiberation.JTACAutoLase to make it use your own function ; it will be called with these parameters : ({jtac.unit_name}, {jtac.code}, {smoke}, 'vehicle') for all JTACs
|
||||||
script += f"\nJTACAutoLase('{jtac.unit_name}', {jtac.code}, {smoke}, 'vehicle')\n"
|
if ctld then
|
||||||
|
dcsLiberation.JTACAutoLase=ctld.JTACAutoLase
|
||||||
|
elseif JTACAutoLase then
|
||||||
|
dcsLiberation.JTACAutoLase=JTACAutoLase
|
||||||
|
end
|
||||||
|
|
||||||
load_autolase.add_action(DoScript(String(script)))
|
-- later, we'll add more data to the table
|
||||||
self.current_mission.triggerrules.triggers.append(load_autolase)
|
--dcsLiberation.POIs = {}
|
||||||
|
--dcsLiberation.BASEs = {}
|
||||||
|
--dcsLiberation.JTACs = {}
|
||||||
|
"""
|
||||||
|
|
||||||
|
trigger = TriggerStart(comment="Set DCS Liberation data")
|
||||||
|
trigger.add_action(DoScript(String(lua)))
|
||||||
|
self.current_mission.triggerrules.triggers.append(trigger)
|
||||||
|
|
||||||
|
# Inject DCS-Liberation script if not done already in the plugins
|
||||||
|
if not "dcs_liberation.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)
|
||||||
|
|
||||||
|
# Inject Ciribob's JTACAutoLase if not done already in the plugins
|
||||||
|
if not "JTACAutoLase.lua" in listOfPluginsScripts : # don't load the script twice
|
||||||
|
trigger = TriggerStart(comment="Load JTACAutoLase.lua script")
|
||||||
|
fileref = self.current_mission.map_resource.add_resource_file("./resources/scripts/JTACAutoLase.lua")
|
||||||
|
trigger.add_action(DoScriptFile(fileref))
|
||||||
|
self.current_mission.triggerrules.triggers.append(trigger)
|
||||||
|
|
||||||
|
# add a configuration for JTACAutoLase and start lasing for all JTACs
|
||||||
|
smoke = "true"
|
||||||
|
if hasattr(self.game.settings, "jtac_smoke_on"):
|
||||||
|
if not self.game.settings.jtac_smoke_on:
|
||||||
|
smoke = "false"
|
||||||
|
|
||||||
|
lua = """
|
||||||
|
-- setting and starting JTACs
|
||||||
|
env.info("DCSLiberation|: setting and starting JTACs")
|
||||||
|
"""
|
||||||
|
for jtac in jtacs:
|
||||||
|
lua += f"if dcsLiberation.JTACAutoLase then dcsLiberation.JTACAutoLase('{jtac.unit_name}', {jtac.code}, {smoke}, 'vehicle') end\n"
|
||||||
|
|
||||||
|
trigger = TriggerStart(comment="Start JTACs")
|
||||||
|
trigger.add_action(DoScript(String(lua)))
|
||||||
|
self.current_mission.triggerrules.triggers.append(trigger)
|
||||||
|
|
||||||
self.assign_channels_to_flights()
|
self.assign_channels_to_flights()
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,5 @@
|
|||||||
local jsonlib = {{json_file_abs_location}}
|
|
||||||
json = loadfile(jsonlib)()
|
|
||||||
|
|
||||||
logger = mist.Logger:new("DCSLiberation", "info")
|
logger = mist.Logger:new("DCSLiberation", "info")
|
||||||
|
logger:info("Check that json.lua is loaded : json = "..tostring(json))
|
||||||
debriefing_file_location = {{debriefing_file_location}}
|
|
||||||
|
|
||||||
killed_aircrafts = {}
|
killed_aircrafts = {}
|
||||||
killed_ground_units = {}
|
killed_ground_units = {}
|
||||||
@ -32,12 +28,56 @@ write_state = function()
|
|||||||
["mission_ended"] = mission_ended,
|
["mission_ended"] = mission_ended,
|
||||||
["destroyed_objects_positions"] = destroyed_objects_positions,
|
["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:write(json:encode(game_state))
|
||||||
fp:close()
|
fp:close()
|
||||||
-- logger.info("Done writing DCS Liberation state")
|
-- logger.info("Done writing DCS Liberation state")
|
||||||
-- messageAll("Done writing DCS Liberation state.")
|
-- messageAll("Done writing DCS Liberation state.")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
debriefing_file_location = nil
|
||||||
|
if dcsLiberation then
|
||||||
|
debriefing_file_location = dcsLiberation.installPath
|
||||||
|
end
|
||||||
|
if debriefing_file_location then
|
||||||
|
logger:info("Using DCS Liberation install folder for state.json")
|
||||||
|
else
|
||||||
|
if os then
|
||||||
|
debriefing_file_location = os.getenv("LIBERATION_EXPORT_DIR")
|
||||||
|
if debriefing_file_location then debriefing_file_location = debriefing_file_location .. "\\" end
|
||||||
|
end
|
||||||
|
if debriefing_file_location then
|
||||||
|
logger:info("Using LIBERATION_EXPORT_DIR environment variable for state.json")
|
||||||
|
else
|
||||||
|
if os then
|
||||||
|
debriefing_file_location = os.getenv("TEMP")
|
||||||
|
if debriefing_file_location then debriefing_file_location = debriefing_file_location .. "\\" end
|
||||||
|
end
|
||||||
|
if debriefing_file_location then
|
||||||
|
logger:info("Using TEMP environment variable for state.json")
|
||||||
|
else
|
||||||
|
if lfs then
|
||||||
|
debriefing_file_location = lfs.writedir()
|
||||||
|
end
|
||||||
|
if debriefing_file_location then
|
||||||
|
logger:info("Using DCS working directory for state.json")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if debriefing_file_location then
|
||||||
|
local filename = "state.json"
|
||||||
|
if not debriefing_file_location:sub(-#filename) == filename then
|
||||||
|
debriefing_file_location = debriefing_file_location .. filename
|
||||||
|
end
|
||||||
|
logger:info(string.format("DCS Liberation state will be written as json to [[%s]]",debriefing_file_location))
|
||||||
|
else
|
||||||
|
logger:error("No usable storage path for state.json")
|
||||||
|
end
|
||||||
|
|
||||||
write_state_error_handling = function()
|
write_state_error_handling = function()
|
||||||
if pcall(write_state) then
|
if pcall(write_state) then
|
||||||
|
|||||||
@ -968,7 +968,7 @@ function OBJDEF:new(args)
|
|||||||
return setmetatable(new, OBJDEF)
|
return setmetatable(new, OBJDEF)
|
||||||
end
|
end
|
||||||
|
|
||||||
return OBJDEF:new()
|
json = OBJDEF:new()
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Version history:
|
-- Version history:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user