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()
if SETTING.lockBG then
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)
end
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')
end
-- Festival calculate within one statement
return
if not SETTING.noTheme then return
-- Christmas
M=='12' and math.abs(D-25)<4 and
'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=='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'
) 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
function THEME.set(theme,keepBGM,force)
if type(theme)=='string' and theme:sub(1,6)=='season' then
---@param theme string
---@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)
BGM.setDefault(({season1='null',season2='nil',season3='vacuum',season4='space'})[theme])
elseif not SETTING.noTheme or force then
if theme=='xmas' then
BG.setDefault('snow')
BGM.setDefault('xmas')
MES.new('info',"==Merry Christmas==")
elseif theme=='birth' then
BG.setDefault('firework')
BGM.setDefault('magicblock')
elseif theme=='sprfes' then
BG.setDefault('firework')
BGM.setDefault('spring festival')
MES.new('info',"★☆新年快乐☆★")
elseif theme=='halloween' then
BG.setDefault('glow')
BGM.setDefault('antispace')
MES.new('info',">>Happy halloween<<")
elseif theme=='zday1' then
BG.setDefault('lanterns')
BGM.setDefault('overzero')
elseif theme=='zday2' then
BG.setDefault('lanterns')
BGM.setDefault('jazz nihilism')
elseif theme=='zday3' then
BG.setDefault('lanterns')
BGM.setDefault('empty')
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
elseif theme=='xmas' then
BG.setDefault('snow')
BGM.setDefault('xmas')
MES.new('info',"==Merry Christmas==")
elseif theme=='birth' then
BG.setDefault('firework')
BGM.setDefault('magicblock')
elseif theme=='sprfes' then
BG.setDefault('firework')
BGM.setDefault('spring festival')
MES.new('info',"★☆新年快乐☆★")
elseif theme=='halloween' then
BG.setDefault('glow')
BGM.setDefault('antispace')
MES.new('info',">>Happy halloween<<")
elseif theme:sub(1,4)=='zday' then
BG.setDefault('lanterns')
BGM.setDefault(({zday1='overzero',zday2='jazz nihilism',zday3='empty'})[theme])
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 THEME.set(THEME.calculate('0',os.date('%m'),'0'),keepBGM,true)
return
end
THEME.cur=theme