corrected and enhanced mission portability

This commit is contained in:
David Pierron 2020-09-29 20:46:22 +02:00
parent afbd4a4716
commit 3bae591c04
2 changed files with 82 additions and 31 deletions

View File

@ -263,31 +263,67 @@ class Operation:
trigger.add_action(DoScriptFile(fileref)) trigger.add_action(DoScriptFile(fileref))
self.current_mission.triggerrules.triggers.append(trigger) self.current_mission.triggerrules.triggers.append(trigger)
# set a LUA table with data from Liberation that we want to set
# at the moment it contains Liberation's install path, and an overridable definition for the JTACAutoLase function
# later, we'll add data about the units and points having been generated, in order to facilitate the configuration of the plugin lua scripts
state_location = "[[" + os.path.abspath("state.json") + "]]"
lua = """
-- setting configuration table
env.info("DCSLiberation|: setting configuration table")
-- all data in this table is overridable.
dcsLiberation = {}
-- the base location for state.json; if non-existent, it'll be replaced with LIBERATION_EXPORT_DIR, TEMP, or DCS working directory
dcsLiberation.installPath=""" + state_location + """
-- 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
if ctld then
dcsLiberation.JTACAutoLase=ctld.JTACAutoLase
elseif JTACAutoLase then
dcsLiberation.JTACAutoLase=JTACAutoLase
end
-- later, we'll add more data to the table
--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 # Inject DCS-Liberation script if not done already in the plugins
if not "json.lua" in listOfPluginsScripts : # don't load the script twice if not "dcs_liberation.lua" in listOfPluginsScripts : # don't load the script twice
trigger = TriggerStart(comment="Load DCS Liberation script") trigger = TriggerStart(comment="Load DCS Liberation script")
fileref = self.current_mission.map_resource.add_resource_file("./resources/scripts/dcs_liberation.lua") fileref = self.current_mission.map_resource.add_resource_file("./resources/scripts/dcs_liberation.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)
# Load Ciribob's JTACAutoLase script if not done already in the plugins # Inject Ciribob's JTACAutoLase if not done already in the plugins
if not "JTACAutoLase.lua" in listOfPluginsScripts: # don't load JTACAutoLase twice if not "JTACAutoLase.lua" in listOfPluginsScripts : # don't load the script twice
load_autolase = TriggerStart(comment="Load JTAC script") trigger = TriggerStart(comment="Load JTACAutoLase.lua script")
with open("./resources/scripts/JTACAutoLase.lua") as f: 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)
script = f.read() # add a configuration for JTACAutoLase and start lasing for all JTACs
script = script + "\n" smoke = "true"
if hasattr(self.game.settings, "jtac_smoke_on"):
if not self.game.settings.jtac_smoke_on:
smoke = "false"
smoke = "true" lua = """
if hasattr(self.game.settings, "jtac_smoke_on"): -- setting and starting JTACs
if not self.game.settings.jtac_smoke_on: env.info("DCSLiberation|: setting and starting JTACs")
smoke = "false" """
for jtac in jtacs:
lua += f"if dcsLiberation.JTACAutoLase then dcsLiberation.JTACAutoLase('{jtac.unit_name}', {jtac.code}, {smoke}, 'vehicle') end\n"
for jtac in jtacs: trigger = TriggerStart(comment="Start JTACs")
script += f"\nJTACAutoLase('{jtac.unit_name}', {jtac.code}, {smoke}, 'vehicle')\n" trigger.add_action(DoScript(String(lua)))
self.current_mission.triggerrules.triggers.append(trigger)
load_autolase.add_action(DoScript(String(script)))
self.current_mission.triggerrules.triggers.append(load_autolase)
self.assign_channels_to_flights() self.assign_channels_to_flights()

View File

@ -39,31 +39,46 @@ write_state = function()
-- messageAll("Done writing DCS Liberation state.") -- messageAll("Done writing DCS Liberation state.")
end end
debriefing_file_location = nil debriefing_file_location = nil
if not debriefing_file_location then 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 if os then
debriefing_file_location = os.getenv("LIBERATION_EXPORT_DIR") debriefing_file_location = os.getenv("LIBERATION_EXPORT_DIR")
if debriefing_file_location then debriefing_file_location = debriefing_file_location .. "\\" end if debriefing_file_location then debriefing_file_location = debriefing_file_location .. "\\" end
end end
end if debriefing_file_location then
if not debriefing_file_location then logger:info("Using LIBERATION_EXPORT_DIR environment variable for state.json")
if os then else
debriefing_file_location = os.getenv("TEMP") if os then
if debriefing_file_location then debriefing_file_location = debriefing_file_location .. "\\" end debriefing_file_location = os.getenv("TEMP")
end if debriefing_file_location then debriefing_file_location = debriefing_file_location .. "\\" end
end end
if not debriefing_file_location then if debriefing_file_location then
if lfs then logger:info("Using TEMP environment variable for state.json")
debriefing_file_location = lfs.writedir() 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
end end
if debriefing_file_location then if debriefing_file_location then
debriefing_file_location = debriefing_file_location .. "state.json" 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 end
logger:info(string.format("DCS Liberation state will be written as json to [[%s]]",debriefing_file_location))
write_state_error_handling = function() write_state_error_handling = function()
if pcall(write_state) then if pcall(write_state) then
-- messageAll("Written DCS Liberation state to "..debriefing_file_location) -- messageAll("Written DCS Liberation state to "..debriefing_file_location)