refactor GAME.mod (#1006)

Co-authored-by: MrZ_26 <1046101471@qq.com>
This commit is contained in:
Imple Lee
2023-10-08 18:56:44 +08:00
committed by GitHub
parent 323f8a72aa
commit 4e41024ba8
9 changed files with 105 additions and 84 deletions

View File

@@ -328,9 +328,9 @@ do-- function DATA.saveReplay()
local noRecList={"custom","solo","round","techmino"} local noRecList={"custom","solo","round","techmino"}
local function _getModList() local function _getModList()
local res={} local res={}
for _,v in next,GAME.mod do for number,sel in next,GAME.mod do
if v.sel>0 then if sel>0 then
ins(res,{v.no,v.sel}) ins(res,{MODOPT[number].no,sel})
end end
end end
return res return res

View File

@@ -504,8 +504,8 @@ function mergeStat(stat,delta)-- Merge delta stat. to global stat.
end end
end end
function scoreValid()-- Check if any unranked mods are activated function scoreValid()-- Check if any unranked mods are activated
for _,M in next,GAME.mod do for number,sel in next,GAME.mod do
if M.unranked then if sel>0 and MODOPT[number].unranked then
return false return false
end end
end end
@@ -994,17 +994,23 @@ do-- function dumpBasicConfig()
end end
end end
do-- function resetGameData(args) do-- function resetGameData(args)
local function task_showMods() local function task_showMods() -- TODO
local time=0 coroutine.yield()
while true do local counter=0
for number,sel in next,GAME.mod do
if sel>0 then
if counter==0 then
coroutine.yield()
else
for _=1,20 do
coroutine.yield() coroutine.yield()
if time%20==0 then
local M=GAME.mod[time/20+1]
if not M then return end
SFX.play('collect',.2)
TEXT.show(M.id,640+(time/20%5-2)*80,26,45,'spin')
end end
time=time+1 end
local M=MODOPT[number]
SFX.play('collect',.2)
TEXT.show(M.id,640+(counter%5-2)*80,26,45,'spin')
counter=counter+1
end
end end
end end
local gameSetting={ local gameSetting={
@@ -1126,6 +1132,14 @@ do-- function checkWarning(P,dt)
end end
end end
end end
function usingMod()
for _,sel in next,GAME.mod do
if sel>0 then
return true
end
end
return false
end
@@ -1176,6 +1190,9 @@ function drawWarning()
gc_pop() gc_pop()
end end
end end
function setModBackgroundColor()
gc_setColor(.42,.26,.62,.62+.26*math.sin(TIME()*12.6))
end

View File

@@ -496,7 +496,7 @@ do-- Mod data
} }
for i=1,#MODOPT do for i=1,#MODOPT do
local M=MODOPT[i] local M=MODOPT[i]
M.sel,M.time=0,0 M.time=0
M.color=COLOR[M.color] M.color=COLOR[M.color]
end end
end end
@@ -520,7 +520,7 @@ do-- Game data tables
seed=1046101471, -- Game seed seed=1046101471, -- Game seed
curMode=false, -- Current gamemode object curMode=false, -- Current gamemode object
mod={}, -- List of loaded mods mod=TABLE.new(0,#MODOPT),-- List of loaded mods
modeEnv=false, -- Current gamemode environment modeEnv=false, -- Current gamemode environment
setting={}, -- Game settings setting={}, -- Game settings
rep={}, -- Recording list, key,time,key,time... rep={}, -- Recording list, key,time,key,time...

View File

@@ -199,8 +199,11 @@ local function _loadGameEnv(P)-- Load gameEnv
end end
end end
if ENV.allowMod then if ENV.allowMod then
for _,M in next,GAME.mod do for i=1,#GAME.mod do
M.func(P,M.list and M.list[M.sel]) if GAME.mod[i]>0 then
local M=MODOPT[i]
M.func(P,M.list and M.list[GAME.mod[i]])
end
end end
end end
end end

View File

@@ -21,6 +21,7 @@ local sList={
eventSet=EVENTSETS, eventSet=EVENTSETS,
holdMode={'hold','swap'}, holdMode={'hold','swap'},
} }
local modUsed
local scene={} local scene={}
@@ -28,6 +29,7 @@ function scene.enter()
destroyPlayers() destroyPlayers()
BG.set(CUSTOMENV.bg) BG.set(CUSTOMENV.bg)
BGM.play(CUSTOMENV.bgm) BGM.play(CUSTOMENV.bgm)
modUsed=usingMod()
end end
function scene.leave() function scene.leave()
saveFile(CUSTOMENV,'conf/customEnv') saveFile(CUSTOMENV,'conf/customEnv')
@@ -171,8 +173,8 @@ function scene.draw()
gc.print(CUSTOMENV.sequence,610,250) gc.print(CUSTOMENV.sequence,610,250)
-- Mod indicator -- Mod indicator
if #GAME.mod>0 then if modUsed then
gc.setColor(.42,.26,.62,.62+.26*math.sin(TIME()*12.6)) setModBackgroundColor()
gc.rectangle('fill',1110-230/2,200-90/2,230,90,5,5) gc.rectangle('fill',1110-230/2,200-90/2,230,90,5,5)
end end

View File

@@ -2,31 +2,17 @@ local scene={}
local selected-- Mod selected local selected-- Mod selected
local function _modComp(a,b)
return a.no<b.no
end
local function _remMod(M)
local i=TABLE.find(GAME.mod,M)
if i then
table.remove(GAME.mod,i)
end
end
local function _toggleMod(M,back) local function _toggleMod(M,back)
if M.sel==0 then local number=M.no+1
table.insert(GAME.mod,M) assert(MODOPT[number]==M)
table.sort(GAME.mod,_modComp)
end
if M.list then if M.list then
if back then if back then
M.sel=(M.sel-1)%(#M.list+1) GAME.mod[number]=(GAME.mod[number]-1)%(#M.list+1)
else else
M.sel=(M.sel+1)%(#M.list+1) GAME.mod[number]=(GAME.mod[number]+1)%(#M.list+1)
end end
else else
M.sel=1-M.sel GAME.mod[number]=1-GAME.mod[number]
end
if M.sel==0 then
_remMod(M)
end end
if M.unranked then if M.unranked then
SFX.play('touch',.6) SFX.play('touch',.6)
@@ -70,10 +56,14 @@ end
function scene.keyDown(key) function scene.keyDown(key)
if key=='tab' or key=='delete' then if key=='tab' or key=='delete' then
if GAME.mod[1] then local modUsed=false
while GAME.mod[1] do for i=1,#GAME.mod do
table.remove(GAME.mod).sel=0 if GAME.mod[i]>0 then
modUsed=true
end end
GAME.mod[i]=0
end
if modUsed then
scene.widgetList.unranked.hide=scoreValid() scene.widgetList.unranked.hide=scoreValid()
SFX.play('hold') SFX.play('hold')
end end
@@ -91,8 +81,9 @@ function scene.keyDown(key)
end end
function scene.update() function scene.update()
for _,M in next,MODOPT do for number,sel in next,GAME.mod do
if M.sel==0 then local M=MODOPT[number]
if sel==0 then
if M.time>0 then if M.time>0 then
M.time=M.time-1 M.time=M.time-1
end end
@@ -106,7 +97,8 @@ end
function scene.draw() function scene.draw()
setFont(40) setFont(40)
GC.setLineWidth(5) GC.setLineWidth(5)
for _,M in next,MODOPT do for number,M in next,MODOPT do
local sel=GAME.mod[number]
GC.push('transform') GC.push('transform')
GC.translate(M.x,M.y) GC.translate(M.x,M.y)
local t=M.time*.01-- t range:0~0.1 local t=M.time*.01-- t range:0~0.1
@@ -126,16 +118,16 @@ function scene.draw()
GC.circle('line',0,0,rad,side) GC.circle('line',0,0,rad,side)
GC.setColor(COLOR.Z) GC.setColor(COLOR.Z)
GC.mStr(M.id,0,-27) GC.mStr(M.id,0,-27)
if M.sel>0 and M.list then if sel>0 and M.list then
setFont(25) setFont(25)
GC.setColor(1,1,1,10*t) GC.setColor(1,1,1,10*t)
GC.mStr(M.list[M.sel],20,8) GC.mStr(M.list[sel],20,8)
setFont(40) setFont(40)
end end
if M.list then if M.list then
GC.setColor(1,1,1,t*6) GC.setColor(1,1,1,t*6)
GC.arc('line','open',0,0,rad+6,0,(M.sel/#M.list)*6.2832) GC.arc('line','open',0,0,rad+6,0,(sel/#M.list)*6.2832)
end end
GC.pop() GC.pop()
end end

View File

@@ -24,6 +24,7 @@ local touchDist
local grid local grid
local min_x,max_x=-1500,1350 local min_x,max_x=-1500,1350
local min_y,max_y=-1900,660 local min_y,max_y=-1900,660
local modUsed
local scene={} local scene={}
@@ -42,6 +43,7 @@ function scene.enter()
end end
end end
end end
modUsed=usingMod()
end end
local function _getK() local function _getK()
@@ -223,8 +225,8 @@ local function _drawModeShape(M,S,drawType)
end end
function scene.draw() function scene.draw()
-- Mod indicator -- Mod indicator
if #GAME.mod>0 then if modUsed then
gc_setColor(.42,.26,.62,.62+.26*math.sin(TIME()*12.6)) setModBackgroundColor()
gc_rectangle('fill',140-220/2,655-80/2,220,80,5,5) gc_rectangle('fill',140-220/2,655-80/2,220,80,5,5)
end end

View File

@@ -4,6 +4,7 @@ local GC=GC
local scene={} local scene={}
local modUsed
local page local page
local timer1,timer2-- Animation timer local timer1,timer2-- Animation timer
local form-- Form of clear & spins local form-- Form of clear & spins
@@ -16,6 +17,7 @@ local trophy-- Current trophy
local trophyColor-- Current trophy color local trophyColor-- Current trophy color
function scene.enter() function scene.enter()
modUsed=usingMod()
page=0 page=0
if type(SCN.prev)=='string' and SCN.prev:find("setting") then if type(SCN.prev)=='string' and SCN.prev:find("setting") then
TEXT.show(text.needRestart,640,410,50,'fly',.6) TEXT.show(text.needRestart,640,410,50,'fly',.6)
@@ -316,7 +318,7 @@ function scene.draw()
GC.push('transform') GC.push('transform')
GC.translate(131,600) GC.translate(131,600)
GC.scale(.65) GC.scale(.65)
if #GAME.mod>0 then if modUsed then
GC.setLineWidth(2) GC.setLineWidth(2)
if scoreValid() then if scoreValid() then
GC.setColor(.7,.7,.7,timer1) GC.setColor(.7,.7,.7,timer1)
@@ -330,8 +332,8 @@ function scene.draw()
GC.rectangle('fill',-5,-5,500,150,8) GC.rectangle('fill',-5,-5,500,150,8)
end end
FONT.set(35) FONT.set(35)
for _,M in next,MODOPT do for number,M in next,MODOPT do
if M.sel>0 then if GAME.mod[number]>0 then
_=M.color _=M.color
GC.setColor(_[1],_[2],_[3],timer1) GC.setColor(_[1],_[2],_[3],timer1)
GC.mStr(M.id,35+M.no%8*60,math.floor(M.no/8)*45) GC.mStr(M.id,35+M.no%8*60,math.floor(M.no/8)*45)

View File

@@ -32,6 +32,7 @@ local listBox=WIDGET.newListBox{name='list',x=50,y=50,w=1200,h=520,lineH=40,draw
end} end}
local scene={} local scene={}
local mods={}
local function _playRep(fileName) local function _playRep(fileName)
local rep=DATA.parseReplay(fileName,true) local rep=DATA.parseReplay(fileName,true)
@@ -40,11 +41,12 @@ local function _playRep(fileName)
elseif MODES[rep.mode] then elseif MODES[rep.mode] then
GAME.seed=rep.seed GAME.seed=rep.seed
GAME.setting=rep.setting GAME.setting=rep.setting
TABLE.cut(GAME.mod) if #mods==0 then
for i=1,#MODOPT do MODOPT[i].sel=0 end mods=GAME.mod
end
GAME.mod=TABLE.new(0,#MODOPT)
for _,m in next,rep.mod do for _,m in next,rep.mod do
MODOPT[m[1]+1].sel=m[2] GAME.mod[m[1]+1]=m[2]
table.insert(GAME.mod,MODOPT[m[1]+1])
end end
GAME.rep={} GAME.rep={}
DATA.pumpRecording(rep.data,GAME.rep) DATA.pumpRecording(rep.data,GAME.rep)
@@ -74,8 +76,9 @@ function scene.enter()
_updateButtonVisibility() _updateButtonVisibility()
end end
function scene.leave() function scene.leave()
for i=1,#MODOPT do MODOPT[i].sel=0 end if #mods>0 then
TABLE.cut(GAME.mod) GAME.mod,mods=mods,{}
end
end end
function scene.keyDown(key) function scene.keyDown(key)