Refactoring theme.lua (#1168)

This commit is contained in:
SweetSea
2024-11-02 19:18:43 +07:00
committed by GitHub
parent 6c40fb098f
commit 46396efd09
2 changed files with 44 additions and 48 deletions

View File

@@ -164,7 +164,7 @@ do-- function applySettings()
BG.set() BG.set()
if SETTING.lockBG then if SETTING.lockBG then
BG.lock() BG.lock()
elseif reason=='lockBG' then -- Don't load theme too soon! elseif reason=='lockBG' then -- We only reload theme again when at settings scene.
THEME.set(THEME.calculate(),GAME.playing) THEME.set(THEME.calculate(),GAME.playing)
end end
elseif SETTING.bg=='off' then elseif SETTING.bg=='off' then

View File

@@ -12,7 +12,7 @@ function THEME.calculate(Y,M,D)
Y,M,D=os.date('%Y'),os.date('%m'),os.date('%d') Y,M,D=os.date('%Y'),os.date('%m'),os.date('%d')
end end
-- Festival calculate within one statement -- Festival calculate within one statement
return if not SETTING.noTheme then return
-- Christmas -- Christmas
M=='12' and math.abs(D-25)<4 and M=='12' and math.abs(D-25)<4 and
'xmas' or 'xmas' or
@@ -51,58 +51,54 @@ function THEME.calculate(Y,M,D)
(M=='03' or M=='04' or M=='05' or M=='06') and 'zday1' or (M=='03' or M=='04' or M=='05' or M=='06') and 'zday1' or
(M=='07' or M=='08' or M=='09' or M=='10') and 'zday2' or (M=='07' or M=='08' or M=='09' or M=='10') and 'zday2' or
(M=='11' or M=='12' or M=='01' or M=='02') and 'zday3' (M=='11' or M=='12' or M=='01' or M=='02') and 'zday3'
) or
-- Normal
(
(M=='02' or M=='03' or M=='04') and 'season1' or
(M=='05' or M=='06' or M=='07') and 'season2' or
(M=='08' or M=='09' or M=='10') and 'season3' or
(M=='11' or M=='12' or M=='01') and 'season4'
) )
end
-- If there is theme and theme is enabled, then we will never reach here
return -- Normal
(
(M=='02' or M=='03' or M=='04') and 'season1' or
(M=='05' or M=='06' or M=='07') and 'season2' or
(M=='08' or M=='09' or M=='10') and 'season3' or
(M=='11' or M=='12' or M=='01') and 'season4'
)
end end
function THEME.set(theme,keepBGM,force) ---@param theme string
if type(theme)=='string' and theme:sub(1,6)=='season' then ---@param keepBGM boolean|false|nil
function THEME.set(theme,keepBGM)
if type(theme)~='string' then
return
elseif theme:sub(1,6)=='season' then
BG.setDefault(SETTING.defaultBG) BG.setDefault(SETTING.defaultBG)
BGM.setDefault(({season1='null',season2='nil',season3='vacuum',season4='space'})[theme]) BGM.setDefault(({season1='null',season2='nil',season3='vacuum',season4='space'})[theme])
elseif not SETTING.noTheme or force then elseif theme=='xmas' then
if theme=='xmas' then BG.setDefault('snow')
BG.setDefault('snow') BGM.setDefault('xmas')
BGM.setDefault('xmas') MES.new('info',"==Merry Christmas==")
MES.new('info',"==Merry Christmas==") elseif theme=='birth' then
elseif theme=='birth' then BG.setDefault('firework')
BG.setDefault('firework') BGM.setDefault('magicblock')
BGM.setDefault('magicblock') elseif theme=='sprfes' then
elseif theme=='sprfes' then BG.setDefault('firework')
BG.setDefault('firework') BGM.setDefault('spring festival')
BGM.setDefault('spring festival') MES.new('info',"★☆新年快乐☆★")
MES.new('info',"★☆新年快乐☆★") elseif theme=='halloween' then
elseif theme=='halloween' then BG.setDefault('glow')
BG.setDefault('glow') BGM.setDefault('antispace')
BGM.setDefault('antispace') MES.new('info',">>Happy halloween<<")
MES.new('info',">>Happy halloween<<") elseif theme:sub(1,4)=='zday' then
elseif theme=='zday1' then BG.setDefault('lanterns')
BG.setDefault('lanterns') BGM.setDefault(({zday1='overzero',zday2='jazz nihilism',zday3='empty'})[theme])
BGM.setDefault('overzero') elseif theme=='fool' then
elseif theme=='zday2' then BG.setDefault('blockrain')
BG.setDefault('lanterns') BGM.setDefault('how feeling')
BGM.setDefault('jazz nihilism') elseif theme=='edm' then
elseif theme=='zday3' then BG.setDefault('lightning2')
BG.setDefault('lanterns') BGM.setDefault('malate')
BGM.setDefault('empty') MES.new('music'," 红 色 电 音\n 极 地 大 冲 击\n 只要你敢触电——\n 7月14日、15日 天地人间完全放电\n不用麻醉一样情不自禁HI起来飞起来")
elseif theme=='fool' then
BG.setDefault('blockrain')
BGM.setDefault('how feeling')
elseif theme=='edm' then
BG.setDefault('lightning2')
BGM.setDefault('malate')
MES.new('music'," 红 色 电 音\n 极 地 大 冲 击\n 只要你敢触电——\n 7月14日、15日 天地人间完全放电\n不用麻醉一样情不自禁HI起来飞起来")
else
return
end
else else
return THEME.set(THEME.calculate('0',os.date('%m'),'0'),keepBGM,true) return
end end
THEME.cur=theme THEME.cur=theme