Skip to content

Commit

Permalink
F5+R会刷新所有机制库函数而不是只模式函数了
Browse files Browse the repository at this point in the history
整理代码 框架跟进
  • Loading branch information
MrZ626 committed Sep 28, 2023
1 parent 1598e8d commit 1adc575
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Zenitha
Submodule Zenitha updated 1 files
+46 −4 tableExtend.lua
9 changes: 6 additions & 3 deletions assets/game/basePlayer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
9 changes: 7 additions & 2 deletions assets/game/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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'
Expand Down
4 changes: 4 additions & 0 deletions assets/game/mechanicLib/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
--- @alias Techmino.Mech.puyo table<string, table|fun(P:Techmino.Player.puyo|any):any>
--- @alias Techmino.Mech.gem table<string, table|fun(P:Techmino.Player.gem|any):any>

-- 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',
Expand Down
2 changes: 1 addition & 1 deletion assets/game/minoPlayer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2066,7 +2066,7 @@ function MP:initialize()

self:loadScript(self.settings.script)

-- self:dump()
-- self:serialize()
end
--------------------------------------------------------------

Expand Down
58 changes: 24 additions & 34 deletions assets/gamefunc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit 1adc575

Please sign in to comment.