Skip to content

Commit

Permalink
游戏模式文件整理,优化模式加载流程
Browse files Browse the repository at this point in the history
  • Loading branch information
MrZ626 committed Aug 14, 2022
1 parent 3492f01 commit 72e3ac1
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 33 deletions.
38 changes: 25 additions & 13 deletions assets/game/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,36 @@ do -- function layoutFuncs.default():
end

local modeLib={}
local modeMeta={
__index={
initialize=NULL,
settings={},
layout='default',
checkFinish=function() return true end,
result=NULL,
scorePage=NULL,
},
__metatable=true,
}
local function getMode(name)
if modeLib[name] then
return modeLib[name]
else
local path='assets/game/mode/'..name..'.lua'
if FILE.isSafe(path) then
local M=FILE.load(path,'-lua -canskip')
if not M then error("No mode called "..tostring(name)) end
if M.initialize ==nil then M.initialize= NULL else assert(type(M.initialize) =='function',"[mode].initialize must be function") end
if M.settings ==nil then M.settings= {} else assert(type(M.settings) =='table', "[mode].settings must be table (if exist)") end
if M.layout ==nil then M.layout= 'default' else assert(type(layoutFuncs[M.layout])=='funcion', "[mode].layout wrong") end
if M.checkFinish==nil then M.checkFinish=NULL else assert(type(M.checkFinish) =='function',"[mode].checkFinish must be function (if exist)") end
if M.result ==nil then M.result= NULL else assert(type(M.result) =='function',"[mode].result must be function (if exist)") end
if M.scorePage ==nil then M.scorePage= NULL else assert(type(M.scorePage) =='function',"[mode].scorePage must be function (if exist)") end
modeLib[name]=M
M.name=name
return M
end
assert(love.filesystem.getInfo(path) and FILE.isSafe(path),"No mode called "..tostring(name))
local M=FILE.load(path,'-lua -canskip')
assert(type(M)=='table')
setmetatable(M,modeMeta)
assert(type(M.initialize) =='function',"[mode].initialize must be function")
assert(type(M.settings) =='table', "[mode].settings must be table")
assert(type(layoutFuncs[M.layout])=='function',"[mode].layout type wrong")
assert(type(M.checkFinish) =='function',"[mode].checkFinish must be function")
assert(type(M.result) =='function',"[mode].result must be function")
assert(type(M.scorePage) =='function',"[mode].scorePage must be function")

M.name=name
modeLib[name]=M
return M
end
end

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,4 @@ return {
end,
},
}},
checkFinish=function()
return true
end,
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,4 @@ return {
end,
},
}},
checkFinish=function()
return true
end,
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion assets/scene/keyset_list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ scene.widgetList={
WIDGET.new{type='button', name='sys', x=140, y=490, w=200,h=60,text=LANG"keyset_sys_select", fontSize=20, color='lB',code=selAct('sys', 'select' )},
WIDGET.new{type='button', name='sys', x=140, y=560, w=200,h=60,text=LANG"keyset_sys_back", fontSize=20, color='lB',code=selAct('sys', 'back' )},

WIDGET.new{type='button', name='test',pos={1,1},x=-300,y=-80, w=160,h=80,text=LANG'keyset_test',fontSize=45,code=function() SCN.go('game_simp',nil,keyMode..'_test') end},
WIDGET.new{type='button', name='test',pos={1,1},x=-300,y=-80, w=160,h=80,text=LANG'keyset_test',fontSize=45,code=function() SCN.go('game_simp',nil,keyMode..'/test') end},

WIDGET.new{type='button',pos={1,1},x=-120,y=-80,w=160,h=80,sound='back',fontSize=60,text=CHAR.icon.back,code=WIDGET.c_backScn},
}
Expand Down
8 changes: 4 additions & 4 deletions assets/scene/main_1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ end
function scene.keyDown(key,isRep)
if isRep then return end
if key=='return' then
SCN.go('game_simp',nil,'mino_sprint')
SCN.go('game_simp',nil,'mino/sprint')
elseif key=='c' then
SCN.go('_console')
elseif key=='escape' then
Expand All @@ -25,9 +25,9 @@ function scene.draw()
end

scene.widgetList={
WIDGET.new{type='button_fill',pos={.5,.5},x=-400,y=-20,w=360,h=140, color='R',text='Sprint', fontSize=40,cornerR=0,code=function() SCN.go('game_simp',nil,'mino_sprint') end},
WIDGET.new{type='button_fill',pos={.5,.5},x=0, y=-20,w=360,h=140, color='R',text='Marathon',fontSize=40,cornerR=0,code=function() SCN.go('game_simp',nil,'mino_marathon') end},
WIDGET.new{type='button_fill',pos={.5,.5},x=400, y=-20,w=360,h=140, color='R',text='Ultra', fontSize=40,cornerR=0,code=function() SCN.go('game_simp',nil,'mino_ultra') end},
WIDGET.new{type='button_fill',pos={.5,.5},x=-400,y=-20,w=360,h=140, color='R',text='Sprint', fontSize=40,cornerR=0,code=function() SCN.go('game_simp',nil,'mino/sprint') end},
WIDGET.new{type='button_fill',pos={.5,.5},x=0, y=-20,w=360,h=140, color='R',text='Marathon',fontSize=40,cornerR=0,code=function() SCN.go('game_simp',nil,'mino/marathon') end},
WIDGET.new{type='button_fill',pos={.5,.5},x=400, y=-20,w=360,h=140, color='R',text='Ultra', fontSize=40,cornerR=0,code=function() SCN.go('game_simp',nil,'mino/ultra') end},
WIDGET.new{type='button_fill',pos={.5,.5},x=-200,y=160,w=360,h=140, color='B',text='Tutorial',fontSize=40,cornerR=0,code=WIDGET.c_goScn'tutorial_1'},
WIDGET.new{type='button_fill',pos={.5,.5},x=200, y=160,w=360,h=140, color='Y',text='Sandbox', fontSize=40,cornerR=0,code=WIDGET.c_goScn'sandbox_1'},

Expand Down
6 changes: 3 additions & 3 deletions assets/scene/main_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ end
scene.widgetList={
WIDGET.new{type='button',pos={.5,.75}, x=-450,w=120,fontSize=80, text=CHAR.icon.language, code=WIDGET.c_goScn'setting_lang'},
WIDGET.new{type='button',pos={.5,.75}, x=-600,w=120,fontSize=90, text=CHAR.icon.music, code=WIDGET.c_goScn'musicroom'},
WIDGET.new{type='button',pos={.20,.2}, w=420,h=200, fontSize=50, text='MARATHON', code=function() SCN.go('game_simp',nil,'mino_marathon') end},
WIDGET.new{type='button',pos={.50,.2}, w=420,h=200, fontSize=70, text='SPRINT', code=function() SCN.go('game_simp',nil,'mino_sprint') end},
WIDGET.new{type='button',pos={.80,.2}, w=420,h=200, fontSize=50, text='ULTRA', code=function() SCN.go('game_simp',nil,'mino_ultra') end},
WIDGET.new{type='button',pos={.20,.2}, w=420,h=200, fontSize=50, text='MARATHON', code=function() SCN.go('game_simp',nil,'mino/marathon') end},
WIDGET.new{type='button',pos={.50,.2}, w=420,h=200, fontSize=70, text='SPRINT', code=function() SCN.go('game_simp',nil,'mino/sprint') end},
WIDGET.new{type='button',pos={.80,.2}, w=420,h=200, fontSize=50, text='ULTRA', code=function() SCN.go('game_simp',nil,'mino/ultra') end},
WIDGET.new{type='button',pos={.20,.45}, w=420,h=200, fontSize=70, text='BATTLE', code=function() SCN.go('game_simp',nil,'battle') end},
WIDGET.new{type='button_fill',pos={.50,.45}, w=420,h=200, fontSize=70, text='', code=NULL},
WIDGET.new{type='button_fill',pos={.80,.45}, w=420,h=200, fontSize=60, text='', code=NULL},
Expand Down
2 changes: 1 addition & 1 deletion assets/scene/setting_gem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ scene.widgetList={
WIDGET.new{type='button', pos={0,1},x=160,y=-80,w=160,h=80, text=CHAR.icon.keyboard,fontSize=60,code=function() SCN.go('keyset_list',nil,'gem') end},
WIDGET.new{type='button', pos={0,1},x=340,y=-80,w=160,h=80, text=LANG'keyset_touch',fontSize=45,code=WIDGET.c_goScn'keyset_touch'},
WIDGET.new{type='switch', pos={0,1},x=480,y=-80,h=50, text='',disp=TABLE.func_getVal(SETTINGS.system,'touchControl'),code=TABLE.func_revVal(SETTINGS.system,'touchControl')},
WIDGET.new{type='button', pos={1,1},x=-300,y=-80,w=160,h=80, text=LANG'keyset_test',fontSize=45,code=function() SCN.go('game_simp',nil,'gem_test') end},
WIDGET.new{type='button', pos={1,1},x=-300,y=-80,w=160,h=80, text=LANG'keyset_test',fontSize=45,code=function() SCN.go('game_simp',nil,'gem/test') end},

WIDGET.new{type='button',pos={1,1},x=-120,y=-80,w=160,h=80,sound='back',fontSize=60,text=CHAR.icon.back,code=WIDGET.c_backScn},
}
Expand Down
2 changes: 1 addition & 1 deletion assets/scene/setting_mino.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ scene.widgetList={
WIDGET.new{type='button', pos={0,1},x=160,y=-80,w=160,h=80, text=CHAR.icon.keyboard,fontSize=60,code=function() SCN.go('keyset_list',nil,'mino') end},
WIDGET.new{type='button', pos={0,1},x=340,y=-80,w=160,h=80, text=LANG'keyset_touch',fontSize=45,code=WIDGET.c_goScn'keyset_touch'},
WIDGET.new{type='switch', pos={0,1},x=480,y=-80,h=50, text='',disp=TABLE.func_getVal(SETTINGS.system,'touchControl'),code=TABLE.func_revVal(SETTINGS.system,'touchControl')},
WIDGET.new{type='button', pos={1,1},x=-300,y=-80,w=160,h=80, text=LANG'keyset_test',fontSize=45,code=function() SCN.go('game_simp',nil,'mino_test') end},
WIDGET.new{type='button', pos={1,1},x=-300,y=-80,w=160,h=80, text=LANG'keyset_test',fontSize=45,code=function() SCN.go('game_simp',nil,'mino/test') end},

WIDGET.new{type='button',pos={1,1},x=-120,y=-80,w=160,h=80,sound='back',fontSize=60,text=CHAR.icon.back,code=WIDGET.c_backScn},
}
Expand Down
2 changes: 1 addition & 1 deletion assets/scene/setting_puyo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ scene.widgetList={
WIDGET.new{type='button', pos={0,1},x=160,y=-80,w=160,h=80, text=CHAR.icon.keyboard,fontSize=60,code=function() SCN.go('keyset_list',nil,'puyo') end},
WIDGET.new{type='button', pos={0,1},x=340,y=-80,w=160,h=80, text=LANG'keyset_touch',fontSize=45,code=WIDGET.c_goScn'keyset_touch'},
WIDGET.new{type='switch', pos={0,1},x=480,y=-80,h=50, text='',disp=TABLE.func_getVal(SETTINGS.system,'touchControl'),code=TABLE.func_revVal(SETTINGS.system,'touchControl')},
WIDGET.new{type='button', pos={1,1},x=-300,y=-80,w=160,h=80, text=LANG'keyset_test',fontSize=45,code=function() SCN.go('game_simp',nil,'puyo_test') end},
WIDGET.new{type='button', pos={1,1},x=-300,y=-80,w=160,h=80, text=LANG'keyset_test',fontSize=45,code=function() SCN.go('game_simp',nil,'puyo/test') end},

WIDGET.new{type='button',pos={1,1},x=-120,y=-80,w=160,h=80,sound='back',fontSize=60,text=CHAR.icon.back,code=WIDGET.c_backScn},
}
Expand Down
4 changes: 1 addition & 3 deletions assets/skin/puyo_jelly.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
local gc=love.graphics
local gc_push,gc_pop=gc.push,gc.pop
local gc_translate,gc_scale=gc.translate,gc.scale
local gc_translate=gc.translate
local gc_setColor=gc.setColor
local gc_rectangle=gc.rectangle

local min=math.min

local S={}
S.base='puyo_default'

Expand Down

0 comments on commit 72e3ac1

Please sign in to comment.