diff --git a/Zenitha b/Zenitha index d021614b..c15d606f 160000 --- a/Zenitha +++ b/Zenitha @@ -1 +1 @@ -Subproject commit d021614b84ba6beddfaf18e8dfa8c06b555dfaee +Subproject commit c15d606f25577898bce650dfc21a3e7a878611a1 diff --git a/assets/game/basePlayer.lua b/assets/game/basePlayer.lua index 8563d2cd..85a9e6c4 100644 --- a/assets/game/basePlayer.lua +++ b/assets/game/basePlayer.lua @@ -701,7 +701,7 @@ local function dump(L,t) elseif T=='boolean' then k='['..k..']=' elseif T=='function' then - k='[\"'..regFuncToStr(k)..'\"]=' + k='[\"'..regFuncToStr[k]..'\"]=' else k='[\"*'..tostring(k)..'\"]=' -- error("Wrong key type: "..T) @@ -715,7 +715,7 @@ local function dump(L,t) elseif T=='table' then v=t<10 and dump(v,t+1) or "*table" elseif T=='function' then - v=regFuncToStr(v) + v='\"'..(regFuncToStr[v] or "*function:unknown")..'\"' elseif T=='userdata' then T=v:type() if T=='RandomGenerator' then @@ -731,11 +731,14 @@ local function dump(L,t) end return s..'}' end -function P:dump() +function P:serialize() local data=dump(self,0) print(data) return data end +function P:unserialize() + -- TODO +end -------------------------------------------------------------- return P diff --git a/assets/game/init.lua b/assets/game/init.lua index f439f742..14ef7276 100644 --- a/assets/game/init.lua +++ b/assets/game/init.lua @@ -8,7 +8,7 @@ defaultMinoColor=setmetatable({ 36,52,4,24, },{__index=function() return math.random(64) end}) defaultPuyoColor=setmetatable({2,12,42,22,52},{__index=function() return math.random(64) end}) -mechLib=require'assets.game.mechanicLib' +mechLib=TABLE.newResourceTable(require'assets.game.mechanicLib',function(path) return FILE.load(path,'-lua') end) regFuncLib(mechLib,"mechLib") require'assets.game.rotsys_mino' @@ -171,7 +171,12 @@ GAME.camera.moveSpeed=12 --- @return Techmino.Mode function GAME.getMode(name) - if modeLib[name] and not love.keyboard.isDown('f5') then + if love.keyboard.isDown('f5') then + modeLib[name]=nil + mechLib=TABLE.newResourceTable(require'assets.game.mechanicLib',function(path) return FILE.load(path,'-lua') end) + regFuncLib(mechLib,"mechLib") + end + if modeLib[name] then return modeLib[name] else local path='assets/game/mode/'..name..'.lua' diff --git a/assets/game/mechanicLib/init.lua b/assets/game/mechanicLib/init.lua index a42b3721..1a431619 100644 --- a/assets/game/mechanicLib/init.lua +++ b/assets/game/mechanicLib/init.lua @@ -3,6 +3,10 @@ --- @alias Techmino.Mech.puyo table --- @alias Techmino.Mech.gem table +-- Fake require function, make both human and language server happy +-- Those files will be loaded in another way, not require +local function require(path) return path:gsub('%.','/')..'.lua' end + return { common={ timer=require'assets.game.mechanicLib.common.timer', diff --git a/assets/game/minoPlayer.lua b/assets/game/minoPlayer.lua index e8d51a4a..a1857aa8 100644 --- a/assets/game/minoPlayer.lua +++ b/assets/game/minoPlayer.lua @@ -2066,7 +2066,7 @@ function MP:initialize() self:loadScript(self.settings.script) - -- self:dump() + -- self:serialize() end -------------------------------------------------------------- diff --git a/assets/gamefunc.lua b/assets/gamefunc.lua index 883f4f3b..31222d4d 100644 --- a/assets/gamefunc.lua +++ b/assets/gamefunc.lua @@ -68,26 +68,30 @@ function bgmPack(name,...) return tracks end -local interiorModeMeta={__call=function(self) - local success,errInfo=pcall(GAME.getMode,self.name) - if success then - SCN.go('game_in','none',self.name) - else - MSG.new('warn',Text.noMode:repD(STRING.simplifyPath(tostring(self.name)),errInfo)) +local interiorModeMeta={ + __call=function(self) + local success,errInfo=pcall(GAME.getMode,self.name) + if success then + SCN.go('game_in','none',self.name) + else + MSG.new('warn',Text.noMode:repD(STRING.simplifyPath(tostring(self.name)),errInfo)) + end end -end} +} function playInterior(name) return setmetatable({name=name},interiorModeMeta) end -local exteriorModeMeta={__call=function(self) - local success,errInfo=pcall(GAME.getMode,self.name) - if success then - SCN.go('game_out','fade',self.name) - else - MSG.new('warn',Text.noMode:repD(STRING.simplifyPath(tostring(self.name)),errInfo)) +local exteriorModeMeta={ + __call=function(self) + local success,errInfo=pcall(GAME.getMode,self.name) + if success then + SCN.go('game_out','fade',self.name) + else + MSG.new('warn',Text.noMode:repD(STRING.simplifyPath(tostring(self.name)),errInfo)) + end end -end} +} function playExterior(name) return setmetatable({name=name},exteriorModeMeta) end @@ -123,8 +127,8 @@ function saveKey() FILE.save({ mino=KEYMAP.mino:export(), puyo=KEYMAP.puyo:export(), - gem= KEYMAP.gem:export(), - sys= KEYMAP.sys:export(), + gem=KEYMAP.gem:export(), + sys=KEYMAP.sys:export(), },'conf/keymap','-json') end function saveTouch() @@ -223,8 +227,8 @@ function setSafeEnv(func) setfenv(func,TABLE.copy(sandBoxEnv)) end -local funcToStr={} -local strToFunc={} +regFuncToStr={} +regStrToFunc={} --- Flatten a table of functions into string-to-function and function-to-string maps --- @param obj table|function --- @param path string @@ -234,21 +238,7 @@ function regFuncLib(obj,path) regFuncLib(v,path.."."..k) end elseif type(obj)=='function' then - funcToStr[obj]=path - strToFunc[path]=obj + regFuncToStr[obj]=path + regStrToFunc[path]=obj end end ---- Get the flattened string of a function ---- @param func function ---- @return string -function regFuncToStr(func) - print("Converting FuncToStr:"..tostring(func)) - return funcToStr[func] -end ---- Get the function of a flattened string ---- @param str string ---- @return function -function regStrToFunc(str) - print("Converting StrToFunc:"..tostring(str)) - return strToFunc[str] -end