-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better to let the mod launcher handle extensions and path matching
- Loading branch information
Showing
16 changed files
with
312 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,20 @@ | ||
[PathHandlers] | ||
*=Resources/ModuleHandler.lua | ||
*=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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
if GambleRaceInit then | ||
Output(GambleRaceInit) | ||
GambleRaceInit = nil | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
if LevelInit then | ||
Output(LevelInit) | ||
LevelInit = nil | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
if MissionInit then | ||
Output(MissionInit) | ||
MissionInit = nil | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
if StreetRaceInit then | ||
Output(StreetRaceInit) | ||
StreetRaceInit = nil | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
if SundayDriveInit then | ||
Output(SundayDriveInit) | ||
SundayDriveInit = nil | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.