From 1f51847fd3b4b568abfea9811a6ba3465a8dee4b Mon Sep 17 00:00:00 2001 From: Proddy Date: Thu, 27 Jun 2024 04:39:51 +0100 Subject: [PATCH] Splitter file handlers Better to let the mod launcher handle extensions and path matching --- Randomiser/CustomFiles.ini | 20 +- Randomiser/Resources/HandleCON.lua | 28 ++ Randomiser/Resources/HandleGambleRaceInit.lua | 4 + Randomiser/Resources/HandleGambleRaceLoad.lua | 28 ++ Randomiser/Resources/HandleGeneric.lua | 35 +++ Randomiser/Resources/HandleLevelInit.lua | 4 + Randomiser/Resources/HandleLevelLoad.lua | 29 ++ Randomiser/Resources/HandleMFK.lua | 28 ++ Randomiser/Resources/HandleMissionInit.lua | 4 + Randomiser/Resources/HandleMissionLoad.lua | 34 ++ Randomiser/Resources/HandleP3D.lua | 28 ++ Randomiser/Resources/HandleStreetRaceInit.lua | 4 + Randomiser/Resources/HandleStreetRaceLoad.lua | 29 ++ .../Resources/HandleSundayDriveInit.lua | 4 + .../Resources/HandleSundayDriveLoad.lua | 34 ++ Randomiser/Resources/ModuleHandler.lua | 294 ------------------ 16 files changed, 312 insertions(+), 295 deletions(-) create mode 100644 Randomiser/Resources/HandleCON.lua create mode 100644 Randomiser/Resources/HandleGambleRaceInit.lua create mode 100644 Randomiser/Resources/HandleGambleRaceLoad.lua create mode 100644 Randomiser/Resources/HandleGeneric.lua create mode 100644 Randomiser/Resources/HandleLevelInit.lua create mode 100644 Randomiser/Resources/HandleLevelLoad.lua create mode 100644 Randomiser/Resources/HandleMFK.lua create mode 100644 Randomiser/Resources/HandleMissionInit.lua create mode 100644 Randomiser/Resources/HandleMissionLoad.lua create mode 100644 Randomiser/Resources/HandleP3D.lua create mode 100644 Randomiser/Resources/HandleStreetRaceInit.lua create mode 100644 Randomiser/Resources/HandleStreetRaceLoad.lua create mode 100644 Randomiser/Resources/HandleSundayDriveInit.lua create mode 100644 Randomiser/Resources/HandleSundayDriveLoad.lua delete mode 100644 Randomiser/Resources/ModuleHandler.lua diff --git a/Randomiser/CustomFiles.ini b/Randomiser/CustomFiles.ini index f8a581d..2595f57 100644 --- a/Randomiser/CustomFiles.ini +++ b/Randomiser/CustomFiles.ini @@ -1,2 +1,20 @@ [PathHandlers] -*=Resources/ModuleHandler.lua \ No newline at end of file +*=Resources/HandleGeneric.lua +*.mfk=Resources/HandleMFK.lua +*.con=Resources/HandleCON.lua +*.p3d=Resources/HandleP3D.lua + +scripts\\missions\\level0?\\level.mfk=Resources/HandleLevelLoad.lua +scripts\\missions\\level0?\\leveli.mfk=Resources/HandleLevelInit.lua + +scripts\\missions\\level0?\\m?sdl.mfk=Resources/HandleSundayDriveLoad.lua +scripts\\missions\\level0?\\m?sdi.mfk=Resources/HandleSundayDriveInit.lua + +scripts\\missions\\level0?\\m?l.mfk=Resources/HandleMissionLoad.lua +scripts\\missions\\level0?\\m?i.mfk=Resources/HandleMissionInit.lua + +scripts\\missions\\level0?\\sr?l.mfk=Resources/HandleStreetRaceLoad.lua +scripts\\missions\\level0?\\sr?i.mfk=Resources/HandleStreetRaceInit.lua + +scripts\\missions\\level0?\\gr?l.mfk=Resources/HandleGambleRaceLoad.lua +scripts\\missions\\level0?\\gr?i.mfk=Resources/HandleGambleRaceInit.lua \ No newline at end of file diff --git a/Randomiser/Resources/HandleCON.lua b/Randomiser/Resources/HandleCON.lua new file mode 100644 index 0000000..8564cd5 --- /dev/null +++ b/Randomiser/Resources/HandleCON.lua @@ -0,0 +1,28 @@ +local Path = GetPath() +local GamePath + +local CON + +local isChanged = false +for moduleN=1,#Modules do + local module = Modules[moduleN] + local handlers = module.Handlers.CON + + for handlerN=1,#handlers do + local handler = handlers[handlerN] + + if WildcardMatch(Path, handler.Path, true, true) then + GamePath = GamePath or GetGamePath(Path) + CON = CON or MFKLexer.Lexer:Parse(ReadFile(GamePath)) + + print("ModuleHandler", "Running CON module: " .. module.Name) + local success, changed = pcall(handler.Callback, Path, CON) + assert(success, string.format("Error running CON handler from module \"%s\":\n%s", module.Name, changed)) + isChanged = isChanged or changed + end + end +end + +if isChanged then + CON:Output() +end \ No newline at end of file diff --git a/Randomiser/Resources/HandleGambleRaceInit.lua b/Randomiser/Resources/HandleGambleRaceInit.lua new file mode 100644 index 0000000..39764d8 --- /dev/null +++ b/Randomiser/Resources/HandleGambleRaceInit.lua @@ -0,0 +1,4 @@ +if GambleRaceInit then + Output(GambleRaceInit) + GambleRaceInit = nil +end \ No newline at end of file diff --git a/Randomiser/Resources/HandleGambleRaceLoad.lua b/Randomiser/Resources/HandleGambleRaceLoad.lua new file mode 100644 index 0000000..1e64557 --- /dev/null +++ b/Randomiser/Resources/HandleGambleRaceLoad.lua @@ -0,0 +1,28 @@ +local Path = GetPath() +local GamePath = GetGamePath(Path) + +local GambleRaceLoad +local GambleRaceInit + +local isChanged = false +for moduleN=1,#Modules do + local module = Modules[moduleN] + local handlers = module.Handlers.Race[CurrentLevel][4] + + for handlerN=1,#handlers do + local handler = handlers[handlerN] + + GambleRaceLoad = MissionLoad or MFKLexer.Lexer:Parse(ReadFile(GamePath)) + GambleRaceInit = MissionInit or MFKLexer.Lexer:Parse(ReadFile(GamePath:sub(1, -6) .. "i.mfk")) + + print("ModuleHandler", "Running gamble race module: " .. module.Name) + local success, changed = pcall(handler, CurrentLevel, 4, GambleRaceLoad, GambleRaceInit) + assert(success, string.format("Error running gamble race handler from module \"%s\":\n%s", module.Name, changed)) + isChanged = isChanged or changed + end +end + +if isChanged then + GambleRaceLoad:Output() + _G.GambleRaceInit = tostring(GambleRaceInit) +end diff --git a/Randomiser/Resources/HandleGeneric.lua b/Randomiser/Resources/HandleGeneric.lua new file mode 100644 index 0000000..357497f --- /dev/null +++ b/Randomiser/Resources/HandleGeneric.lua @@ -0,0 +1,35 @@ +if IsWriting() then + return +end + +local Path = GetPath() +local GamePath = GetGamePath(Path) + +local contents +local isChanged = false +for moduleN=1,#Modules do + local module = Modules[moduleN] + local handlers = module.Handlers.Generic + + for handlerN=1,#handlers do + local handler = handlers[handlerN] + + if WildcardMatch(Path, handler.Path, true, true) then + if Exists(GamePath, true, false) then + contents = contents or ReadFile(GamePath) + end + + print("ModuleHandler", "Running generic module: " .. module.Name) + local success, changed, newContents = pcall(handler.Callback, contents) + assert(success, string.format("Error running generic handler from module \"%s\":\n%s", module.Name, changed)) + if changed then + contents = newContents + isChanged = true + end + end + end +end + +if isChanged then + Output(contents) +end \ No newline at end of file diff --git a/Randomiser/Resources/HandleLevelInit.lua b/Randomiser/Resources/HandleLevelInit.lua new file mode 100644 index 0000000..278dfb6 --- /dev/null +++ b/Randomiser/Resources/HandleLevelInit.lua @@ -0,0 +1,4 @@ +if LevelInit then + Output(LevelInit) + LevelInit = nil +end \ No newline at end of file diff --git a/Randomiser/Resources/HandleLevelLoad.lua b/Randomiser/Resources/HandleLevelLoad.lua new file mode 100644 index 0000000..f8d2b7a --- /dev/null +++ b/Randomiser/Resources/HandleLevelLoad.lua @@ -0,0 +1,29 @@ +local Path = GetPath() +local GamePath = GetGamePath(Path) + +CurrentLevel = tonumber(Path:match("level0(%d)")) +local LevelLoad +local LevelInit + +local isChanged = false +for moduleN=1,#Modules do + local module = Modules[moduleN] + local handlers = module.Handlers.Level[CurrentLevel] + + for handlerN=1,#handlers do + local handler = handlers[handlerN] + + LevelLoad = LevelLoad or MFKLexer.Lexer:Parse(ReadFile(GamePath)) + LevelInit = LevelInit or MFKLexer.Lexer:Parse(ReadFile(GamePath:sub(1, -5) .. "i.mfk")) + + print("ModuleHandler", "Running level module: " .. module.Name) + local success, changed = pcall(handler, CurrentLevel, LevelLoad, LevelInit) + assert(success, string.format("Error running level handler from module \"%s\":\n%s", module.Name, changed)) + isChanged = isChanged or changed + end +end + +if isChanged then + LevelLoad:Output() + _G.LevelInit = tostring(LevelInit) +end \ No newline at end of file diff --git a/Randomiser/Resources/HandleMFK.lua b/Randomiser/Resources/HandleMFK.lua new file mode 100644 index 0000000..955357e --- /dev/null +++ b/Randomiser/Resources/HandleMFK.lua @@ -0,0 +1,28 @@ +local Path = GetPath() +local GamePath + +local MFK + +local isChanged = false +for moduleN=1,#Modules do + local module = Modules[moduleN] + local handlers = module.Handlers.MFK + + for handlerN=1,#handlers do + local handler = handlers[handlerN] + + if WildcardMatch(Path, handler.Path, true, true) then + GamePath = GamePath or GetGamePath(Path) + MFK = MFK or MFKLexer.Lexer:Parse(ReadFile(GamePath)) + + print("ModuleHandler", "Running MFK module: " .. module.Name) + local success, changed = pcall(handler.Callback, Path, MFK) + assert(success, string.format("Error running MFK handler from module \"%s\":\n%s", module.Name, changed)) + isChanged = isChanged or changed + end + end +end + +if isChanged then + MFK:Output() +end \ No newline at end of file diff --git a/Randomiser/Resources/HandleMissionInit.lua b/Randomiser/Resources/HandleMissionInit.lua new file mode 100644 index 0000000..35bde0b --- /dev/null +++ b/Randomiser/Resources/HandleMissionInit.lua @@ -0,0 +1,4 @@ +if MissionInit then + Output(MissionInit) + MissionInit = nil +end \ No newline at end of file diff --git a/Randomiser/Resources/HandleMissionLoad.lua b/Randomiser/Resources/HandleMissionLoad.lua new file mode 100644 index 0000000..50baae5 --- /dev/null +++ b/Randomiser/Resources/HandleMissionLoad.lua @@ -0,0 +1,34 @@ +local Path = GetPath() +local GamePath = GetGamePath(Path) + +CurrentMission = tonumber(Path:match("m(%d)l%.mfk")) +local MissionLoad +local MissionInit + +local isChanged = false +for moduleN=1,#Modules do + local module = Modules[moduleN] + local handlers + if CurrentLevel == 1 then + handlers = module.Handlers.Mission[CurrentLevel][CurrentMission + 1] + else + handlers = module.Handlers.Mission[CurrentLevel][CurrentMission] + end + + for handlerN=1,#handlers do + local handler = handlers[handlerN] + + MissionLoad = MissionLoad or MFKLexer.Lexer:Parse(ReadFile(GamePath)) + MissionInit = MissionInit or MFKLexer.Lexer:Parse(ReadFile(GamePath:sub(1, -6) .. "i.mfk")) + + print("ModuleHandler", "Running mission module: " .. module.Name) + local success, changed = pcall(handler, CurrentLevel, CurrentMission, MissionLoad, MissionInit) + assert(success, string.format("Error running mission handler from module \"%s\":\n%s", module.Name, changed)) + isChanged = isChanged or changed + end +end + +if isChanged then + MissionLoad:Output() + _G.MissionInit = tostring(MissionInit) +end diff --git a/Randomiser/Resources/HandleP3D.lua b/Randomiser/Resources/HandleP3D.lua new file mode 100644 index 0000000..9264f9f --- /dev/null +++ b/Randomiser/Resources/HandleP3D.lua @@ -0,0 +1,28 @@ +local Path = GetPath() +local GamePath + +local P3DFile + +local isChanged = false +for moduleN=1,#Modules do + local module = Modules[moduleN] + local handlers = module.Handlers.P3D + + for handlerN=1,#handlers do + local handler = handlers[handlerN] + + if WildcardMatch(Path, handler.Path, true, true) then + GamePath = GamePath or GetGamePath(Path) + P3DFile = P3DFile or P3D.P3DFile(GamePath) + + print("ModuleHandler", "Running P3D module: " .. module.Name) + local success, changed = pcall(handler.Callback, Path, P3DFile) + assert(success, string.format("Error running P3D handler from module \"%s\":\n%s", module.Name, changed)) + isChanged = isChanged or changed + end + end +end + +if isChanged then + P3DFile:Output() +end \ No newline at end of file diff --git a/Randomiser/Resources/HandleStreetRaceInit.lua b/Randomiser/Resources/HandleStreetRaceInit.lua new file mode 100644 index 0000000..be101e0 --- /dev/null +++ b/Randomiser/Resources/HandleStreetRaceInit.lua @@ -0,0 +1,4 @@ +if StreetRaceInit then + Output(StreetRaceInit) + StreetRaceInit = nil +end \ No newline at end of file diff --git a/Randomiser/Resources/HandleStreetRaceLoad.lua b/Randomiser/Resources/HandleStreetRaceLoad.lua new file mode 100644 index 0000000..f19d268 --- /dev/null +++ b/Randomiser/Resources/HandleStreetRaceLoad.lua @@ -0,0 +1,29 @@ +local Path = GetPath() +local GamePath = GetGamePath(Path) + +CurrentStreetRace = tonumber(Path:match("sr(%d)l%.mfk")) +local StreetRaceLoad +local StreetRaceInit + +local isChanged = false +for moduleN=1,#Modules do + local module = Modules[moduleN] + local handlers = module.Handlers.Race[CurrentLevel][CurrentStreetRace] + + for handlerN=1,#handlers do + local handler = handlers[handlerN] + + StreetRaceLoad = MissionLoad or MFKLexer.Lexer:Parse(ReadFile(GamePath)) + StreetRaceInit = MissionInit or MFKLexer.Lexer:Parse(ReadFile(GamePath:sub(1, -6) .. "i.mfk")) + + print("ModuleHandler", "Running street race module: " .. module.Name) + local success, changed = pcall(handler, CurrentLevel, CurrentStreetRace, StreetRaceLoad, StreetRaceInit) + assert(success, string.format("Error running street race handler from module \"%s\":\n%s", module.Name, changed)) + isChanged = isChanged or changed + end +end + +if isChanged then + StreetRaceLoad:Output() + _G.StreetRaceInit = tostring(StreetRaceInit) +end diff --git a/Randomiser/Resources/HandleSundayDriveInit.lua b/Randomiser/Resources/HandleSundayDriveInit.lua new file mode 100644 index 0000000..c3f04f9 --- /dev/null +++ b/Randomiser/Resources/HandleSundayDriveInit.lua @@ -0,0 +1,4 @@ +if SundayDriveInit then + Output(SundayDriveInit) + SundayDriveInit = nil +end \ No newline at end of file diff --git a/Randomiser/Resources/HandleSundayDriveLoad.lua b/Randomiser/Resources/HandleSundayDriveLoad.lua new file mode 100644 index 0000000..1817645 --- /dev/null +++ b/Randomiser/Resources/HandleSundayDriveLoad.lua @@ -0,0 +1,34 @@ +local Path = GetPath() +local GamePath = GetGamePath(Path) + +CurrentSundayDrive = tonumber(Path:match("m(%d)sdl%.mfk")) +local SundayDriveLoad +local SundayDriveInit + +local isChanged = false +for moduleN=1,#Modules do + local module = Modules[moduleN] + local handlers + if CurrentLevel == 1 then + handlers = module.Handlers.SundayDrive[CurrentLevel][CurrentSundayDrive + 1] + else + handlers = module.Handlers.SundayDrive[CurrentLevel][CurrentSundayDrive] + end + + for handlerN=1,#handlers do + local handler = handlers[handlerN] + + SundayDriveLoad = SundayDriveLoad or MFKLexer.Lexer:Parse(ReadFile(GamePath)) + SundayDriveInit = SundayDriveInit or MFKLexer.Lexer:Parse(ReadFile(GamePath:sub(1, -6) .. "i.mfk")) + + print("ModuleHandler", "Running sunday drive module: " .. module.Name) + local success, changed = pcall(handler, CurrentLevel, CurrentSundayDrive, SundayDriveLoad, SundayDriveInit) + assert(success, string.format("Error running sunday drive handler from module \"%s\":\n%s", module.Name, changed)) + isChanged = isChanged or changed + end +end + +if isChanged then + SundayDriveLoad:Output() + _G.SundayDriveInit = tostring(SundayDriveInit) +end \ No newline at end of file diff --git a/Randomiser/Resources/ModuleHandler.lua b/Randomiser/Resources/ModuleHandler.lua deleted file mode 100644 index 9eb5623..0000000 --- a/Randomiser/Resources/ModuleHandler.lua +++ /dev/null @@ -1,294 +0,0 @@ -if IsWriting() then - return -end - -local Path = GetPath() -local GamePath = GetGamePath(Path) -local Extension = GetFileExtension(Path):lower() - -assert(Modules ~= nil and #Modules ~= 0, "ModuleHandler requires a Modules table") - -local LevelLoadPattern = "scripts\\missions\\level0%d\\level.mfk" -local LevelInitPattern = "scripts\\missions\\level0%d\\leveli.mfk" - -local SundayDriveLoadPattern = "scripts\\missions\\level0%d\\m%dsdl.mfk" -local SundayDriveInitPattern = "scripts\\missions\\level0%d\\md%dsdi.mfk" - -local MissionLoadPattern = "scripts\\missions\\level0%d\\m%dl.mfk" -local MissionInitPattern = "scripts\\missions\\level0%d\\m%di.mfk" - -local StreetRaceLoadPattern = "scripts\\missions\\level0%d\\sr%dl.mfk" -local StreetRaceInitPattern = "scripts\\missions\\level0%d\\sr%di.mfk" -if Extension == ".mfk" then - if Path:match(LevelLoadPattern) then - CurrentLevel = tonumber(Path:match("level0(%d)")) - local LevelLoad - local LevelInit - - local isChanged = false - for moduleN=1,#Modules do - local module = Modules[moduleN] - local handlers = module.Handlers.Level[CurrentLevel] - - for handlerN=1,#handlers do - local handler = handlers[handlerN] - - LevelLoad = LevelLoad or MFKLexer.Lexer:Parse(ReadFile(GamePath)) - LevelInit = LevelInit or MFKLexer.Lexer:Parse(ReadFile(GamePath:sub(1, -5) .. "i.mfk")) - - print("ModuleHandler", "Running level module: " .. module.Name) - local success, changed = pcall(handler, CurrentLevel, LevelLoad, LevelInit) - assert(success, string.format("Error running level handler from module \"%s\":\n%s", module.Name, changed)) - isChanged = isChanged or changed - end - end - - if isChanged then - LevelLoad:Output() - _G.LevelInit = tostring(LevelInit) - end - return - end - if Path:match(LevelInitPattern) then - if LevelInit then - Output(LevelInit) - LevelInit = nil - end - return - end - - if Path:match(SundayDriveLoadPattern) then - CurrentMission = tonumber(Path:match("m(%d)sdl%.mfk")) - local MissionLoad - local MissionInit - - local isChanged = false - for moduleN=1,#Modules do - local module = Modules[moduleN] - local handlers - if CurrentLevel == 1 then - handlers = module.Handlers.SundayDrive[CurrentLevel][CurrentMission + 1] - else - handlers = module.Handlers.SundayDrive[CurrentLevel][CurrentMission] - end - - for handlerN=1,#handlers do - local handler = handlers[handlerN] - - MissionLoad = MissionLoad or MFKLexer.Lexer:Parse(ReadFile(GamePath)) - MissionInit = MissionInit or MFKLexer.Lexer:Parse(ReadFile(GamePath:sub(1, -6) .. "i.mfk")) - - print("ModuleHandler", "Running sunday drive module: " .. module.Name) - local success, changed = pcall(handler, CurrentLevel, CurrentMission, MissionLoad, MissionInit) - assert(success, string.format("Error running sunday drive handler from module \"%s\":\n%s", module.Name, changed)) - isChanged = isChanged or changed - end - end - - if isChanged then - MissionLoad:Output() - _G.MissionInit = tostring(MissionInit) - end - return - end - if Path:match(SundayDriveInitPattern) then - if MissionInit then - Output(MissionInit) - MissionInit = nil - end - return - end - - if Path:match(MissionLoadPattern) then - CurrentMission = tonumber(Path:match("m(%d)l%.mfk")) - local MissionLoad - local MissionInit - - local isChanged = false - for moduleN=1,#Modules do - local module = Modules[moduleN] - local handlers - if CurrentLevel == 1 then - handlers = module.Handlers.Mission[CurrentLevel][CurrentMission + 1] - else - handlers = module.Handlers.Mission[CurrentLevel][CurrentMission] - end - - for handlerN=1,#handlers do - local handler = handlers[handlerN] - - MissionLoad = MissionLoad or MFKLexer.Lexer:Parse(ReadFile(GamePath)) - MissionInit = MissionInit or MFKLexer.Lexer:Parse(ReadFile(GamePath:sub(1, -6) .. "i.mfk")) - - print("ModuleHandler", "Running mission module: " .. module.Name) - local success, changed = pcall(handler, CurrentLevel, CurrentMission, MissionLoad, MissionInit) - assert(success, string.format("Error running mission handler from module \"%s\":\n%s", module.Name, changed)) - isChanged = isChanged or changed - end - end - - if isChanged then - MissionLoad:Output() - _G.MissionInit = tostring(MissionInit) - end - return - end - if Path:match(MissionInitPattern) then - if MissionInit then - Output(MissionInit) - MissionInit = nil - end - return - end - - if Path:match(StreetRaceLoadPattern) then - CurrentStreetRace = tonumber(Path:match("sr(%d)l%.mfk")) - local StreetRaceLoad - local StreetRaceInit - - local isChanged = false - for moduleN=1,#Modules do - local module = Modules[moduleN] - local handlers = module.Handlers.Race[CurrentLevel][CurrentStreetRace] - - for handlerN=1,#handlers do - local handler = handlers[handlerN] - - StreetRaceLoad = MissionLoad or MFKLexer.Lexer:Parse(ReadFile(GamePath)) - StreetRaceInit = MissionInit or MFKLexer.Lexer:Parse(ReadFile(GamePath:sub(1, -6) .. "i.mfk")) - - print("ModuleHandler", "Running street race module: " .. module.Name) - local success, changed = pcall(handler, CurrentLevel, CurrentStreetRace, StreetRaceLoad, StreetRaceInit) - assert(success, string.format("Error running street race handler from module \"%s\":\n%s", module.Name, changed)) - isChanged = isChanged or changed - end - end - - if isChanged then - StreetRaceLoad:Output() - _G.StreetRaceInit = tostring(StreetRaceInit) - end - return - end - if Path:match(StreetRaceInitPattern) then - if StreetRaceInit then - Output(StreetRaceInit) - StreetRaceInit = nil - end - return - end - - local MFK - - local isChanged = false - for moduleN=1,#Modules do - local module = Modules[moduleN] - local handlers = module.Handlers.MFK - - for handlerN=1,#handlers do - local handler = handlers[handlerN] - - if WildcardMatch(Path, handler.Path, true, true) then - MFK = MFK or MFKLexer.Lexer:Parse(ReadFile(GamePath)) - - print("ModuleHandler", "Running MFK module: " .. module.Name) - local success, changed = pcall(handler.Callback, Path, MFK) - assert(success, string.format("Error running MFK handler from module \"%s\":\n%s", module.Name, changed)) - isChanged = isChanged or changed - end - end - end - - if isChanged then - MFK:Output() - end - - return -end - -if Extension == ".con" then - local CON - - local isChanged = false - for moduleN=1,#Modules do - local module = Modules[moduleN] - local handlers = module.Handlers.CON - - for handlerN=1,#handlers do - local handler = handlers[handlerN] - - if WildcardMatch(Path, handler.Path, true, true) then - CON = CON or MFKLexer.Lexer:Parse(ReadFile(GamePath)) - - print("ModuleHandler", "Running CON module: " .. module.Name) - local success, changed = pcall(handler.Callback, Path, CON) - assert(success, string.format("Error running CON handler from module \"%s\":\n%s", module.Name, changed)) - isChanged = isChanged or changed - end - end - end - - if isChanged then - CON:Output() - end - - return -end - -if Extension == ".p3d" then - local P3DFile - - local isChanged = false - for moduleN=1,#Modules do - local module = Modules[moduleN] - local handlers = module.Handlers.P3D - - for handlerN=1,#handlers do - local handler = handlers[handlerN] - - if WildcardMatch(Path, handler.Path, true, true) then - P3DFile = P3DFile or P3D.P3DFile(GamePath) - - print("ModuleHandler", "Running P3D module: " .. module.Name) - local success, changed = pcall(handler.Callback, Path, P3DFile) - assert(success, string.format("Error running P3D handler from module \"%s\":\n%s", module.Name, changed)) - isChanged = isChanged or changed - end - end - end - - if isChanged then - P3DFile:Output() - end - - return -end - -local contents -local isChanged = false -for moduleN=1,#Modules do - local module = Modules[moduleN] - local handlers = module.Handlers.Generic - - for handlerN=1,#handlers do - local handler = handlers[handlerN] - - if WildcardMatch(Path, handler.Path, true, true) then - if Exists(GamePath, true, false) then - contents = contents or ReadFile(GamePath) - end - - print("ModuleHandler", "Running generic module: " .. module.Name) - local success, changed, newContents = pcall(handler.Callback, contents) - assert(success, string.format("Error running generic handler from module \"%s\":\n%s", module.Name, changed)) - if changed then - contents = newContents - isChanged = true - end - end - end -end - -if isChanged then - Output(contents) -end \ No newline at end of file