Change "modSystem" to "modApplyAt"

This commit is contained in:
SweetSea-ButImNotSweet
2024-01-06 07:18:52 +07:00
parent c47ddf2900
commit 72d5e46056
3 changed files with 60 additions and 49 deletions

View File

@@ -175,6 +175,17 @@ local function _newEmptyPlayer(id,mini)
}
return P
end
local function _executeMod(P)
local applyStatus=GAME.modApplyAt
for i=1,#GAME.mod do
if GAME.mod[i]>0 then
local M=MODOPT[i]
if applyStatus~='always' or M.noAlwaysNeeded then
M.func(P,M.list and M.list[GAME.mod[i]])
end
end
end
end
local function _loadGameEnv(P)-- Load gameEnv
P.gameEnv={}-- Current game setting environment
local ENV=P.gameEnv
@@ -199,39 +210,21 @@ local function _loadGameEnv(P)-- Load gameEnv
ENV[k]=TABLE.copy(v)
end
end
if ENV.allowMod then
if GAME.modPatch then
if not GAME.modCodeList then GAME.modCodeList={} end
if not GAME.modCodeList[P.id] then GAME.modCodeList[P.id]={} end
if not GAME.ApplyModsTask then
GAME.ApplyModsTask=function()
while GAME.playing do
for _,p in pairs(GAME.modCodeList) do
for _,c in pairs(p) do pcall(c) end
end
coroutine.yield()
end
-- Kill mod patching function when game stopped
TASK.removeTask_code(GAME.ApplyModsTask)
TABLE.cut(GAME.modCodeList)
GAME.modCodeList=nil
GAME.ApplyModsTask=nil
end
TASK.new(GAME.ApplyModsTask)
end
end
for i=1,#GAME.mod do
if GAME.mod[i]>0 then
local M=MODOPT[i]
if not GAME.modPatch or M.executeFirst or M.onlyOnce then
M.func(P,M.list and M.list[GAME.mod[i]])
elseif GAME.modPatch and not M.onlyOnce then
table.insert(GAME.modCodeList[P.id],function() M.func(P,M.list and M.list[GAME.mod[i]],true) end)
end
end
end
end
-- if not GAME.modCodeList then GAME.modCodeList={} end
-- if not GAME.modCodeList[P.id] then GAME.modCodeList[P.id]={} end
-- if ENV.allowMod then
-- for i=1,#GAME.mod do
-- if GAME.mod[i]>0 then
-- local M=MODOPT[i]
-- if not GAME.modPatch or M.executeFirst or M.onlyOnce then
-- M.func(P,M.list and M.list[GAME.mod[i]])
-- elseif GAME.modPatch and not M.onlyOnce then
-- table.insert(GAME.modCodeList[P.id],function() M.func(P,M.list and M.list[GAME.mod[i]],true) end)
-- end
-- end
-- end
-- end
end
local function _loadRemoteEnv(P,confStr)-- Load gameEnv
confStr=JSON.decode(confStr)
@@ -315,6 +308,28 @@ local function _applyGameEnv(P)-- Finish gameEnv processing
MES.new('warn',"Wrong event set type: "..type(ENV.eventSet))
end
end
-- if GAME.modPatch then
-- if not GAME.ApplyModsTask then
-- GAME.ApplyModsTask=function()
-- while GAME.playing do
-- for _,p in pairs(GAME.modCodeList) do
-- for _,c in pairs(p) do pcall(c) end
-- end
-- coroutine.yield()
-- end
-- -- Kill mod patching function when game stopped
-- TASK.removeTask_code(GAME.ApplyModsTask)
-- TABLE.cut(GAME.modCodeList)
-- GAME.modCodeList=nil
-- GAME.ApplyModsTask=nil
-- end
-- TASK.new(GAME.ApplyModsTask)
-- end
-- end
if ENV.allowMod and GAME.modApplyAt=='postInit' then
_executeMod(P)
end
P._20G=ENV.drop==0
P.dropDelay=ENV.drop
@@ -364,10 +379,14 @@ local function _applyGameEnv(P)-- Finish gameEnv processing
ENV.nextPos=false
end
local seqGen=coroutine.create(getSeqGen(ENV.sequence))
local seqCalled=false
local initSZOcount=0
local bagLineCounter=0
local seqGen,seqCalled,initSZOcount,bagLineCounter
function P:resetSeqGen()
seqGen=coroutine.create(getSeqGen(ENV.sequence))
seqCalled=false
initSZOcount=0
bagLineCounter=0
end
P:resetSeqGen()
function P:newNext()
local status,piece
if seqCalled then