From 79f321fb817597e23d9c0bdd9df8239dfe9bc607 Mon Sep 17 00:00:00 2001 From: SweetSea <106439598+SweetSea-ButImNotSweet@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:45:27 +0700 Subject: [PATCH 1/2] Refactored theme.lua --- parts/gameFuncs.lua | 2 +- parts/theme.lua | 99 ++++++++++++++++++++++----------------------- 2 files changed, 49 insertions(+), 52 deletions(-) diff --git a/parts/gameFuncs.lua b/parts/gameFuncs.lua index 73ca7584d..ad2ebada6 100644 --- a/parts/gameFuncs.lua +++ b/parts/gameFuncs.lua @@ -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 diff --git a/parts/theme.lua b/parts/theme.lua index 0e6ae6170..7213ca3f2 100644 --- a/parts/theme.lua +++ b/parts/theme.lua @@ -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,63 +51,60 @@ 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) - if type(theme)=='string' and 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 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 - else - return THEME.set(THEME.calculate('0',os.date('%m'),'0')) - end +local themeBG={ + zday1='lanterns',zday2='lanterns',zday3='lanterns', + xmas ='snow', + birth ='magicblock', + sprfes ='firework', + halloween='glow', + fool ='blockrain', + edm ='lightning2' +} +local themeBGM={ + season1='null',season2='nil',season3='vacuum',season4='space', + zday1='overzero',zday2='jazz nihilism',zday3='empty', + + xmas ='xmas', + birth ='magicblock', + sprfes ='spring festival', + halloween='antispace', + fool ='how feeling', + edm ='malate' +} +local themeMessages={ + xmas ="==Merry Christmas==", + sprfes ="★☆新年快乐☆★", + halloween=">>Happy halloween<<", + edm =" 红 色 电 音\n 极 地 大 冲 击\n 只要你敢触电——\n 7月14日、15日 天地人间完全放电\n不用麻醉,一样情不自禁HI起来,飞起来" +} +function THEME.set(theme,keepBGM) + if not (themeBG[theme] or themeBGM[theme]) then return end THEME.cur=theme + + BG.setDefault(themeBG[theme] or SETTING.defaultBG) + BGM.setDefault(themeBGM[theme]) + BG.set() if not keepBGM then BGM.play() end + + if themeMessages[theme] then + MES.new(theme=='edm' and 'music' or 'info',themeMessages[theme]) + end + return true end From 9ccc0ec8c6268ff97c05c4629414682d83ec86f5 Mon Sep 17 00:00:00 2001 From: SweetSea <106439598+SweetSea-ButImNotSweet@users.noreply.github.com> Date: Sat, 2 Nov 2024 09:14:11 +0700 Subject: [PATCH 2/2] Revert some of theme.set --- parts/theme.lua | 73 ++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/parts/theme.lua b/parts/theme.lua index 281d93578..d129de6bf 100644 --- a/parts/theme.lua +++ b/parts/theme.lua @@ -64,47 +64,46 @@ function THEME.calculate(Y,M,D) ) end -local themeBG={ - zday1='lanterns',zday2='lanterns',zday3='lanterns', - - xmas ='snow', - birth ='magicblock', - sprfes ='firework', - halloween='glow', - fool ='blockrain', - edm ='lightning2' -} -local themeBGM={ - season1='null',season2='nil',season3='vacuum',season4='space', - zday1='overzero',zday2='jazz nihilism',zday3='empty', - - xmas ='xmas', - birth ='magicblock', - sprfes ='spring festival', - halloween='antispace', - fool ='how feeling', - edm ='malate' -} -local themeMessages={ - xmas ="==Merry Christmas==", - sprfes ="★☆新年快乐☆★", - halloween=">>Happy halloween<<", - edm =" 红 色 电 音\n 极 地 大 冲 击\n 只要你敢触电——\n 7月14日、15日 天地人间完全放电\n不用麻醉,一样情不自禁HI起来,飞起来" -} +---@param theme string +---@param keepBGM boolean|false|nil function THEME.set(theme,keepBGM) - if not (themeBG[theme] or themeBGM[theme]) then return end - THEME.cur=theme - - BG.setDefault(themeBG[theme] or SETTING.defaultBG) - BGM.setDefault(themeBGM[theme]) + 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 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 + end + THEME.cur=theme BG.set() if not keepBGM then BGM.play() end - - if themeMessages[theme] then - MES.new(theme=='edm' and 'music' or 'info',themeMessages[theme]) - end - return true end