THEME做成独立模块
This commit is contained in:
@@ -40,6 +40,7 @@ LANG= require"Zframework.languages"
|
|||||||
TASK= require"Zframework.task"
|
TASK= require"Zframework.task"
|
||||||
FILE= require"Zframework.file"
|
FILE= require"Zframework.file"
|
||||||
PROFILE=require"Zframework.profile"
|
PROFILE=require"Zframework.profile"
|
||||||
|
THEME= require"Zframework.theme"
|
||||||
|
|
||||||
local ms,kb=love.mouse,love.keyboard
|
local ms,kb=love.mouse,love.keyboard
|
||||||
|
|
||||||
|
|||||||
74
Zframework/theme.lua
Normal file
74
Zframework/theme.lua
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
local THEME={
|
||||||
|
cur=false,--Current theme
|
||||||
|
}
|
||||||
|
local themeColor={
|
||||||
|
xmas={COLOR.red,COLOR.white,COLOR.green},
|
||||||
|
sprfes={COLOR.red,COLOR.orange,COLOR.yellow},
|
||||||
|
}
|
||||||
|
|
||||||
|
function THEME.calculate(Y,M,D)
|
||||||
|
if not Y then Y,M,D=os.date"%Y",os.date"%m",os.date"%d"end
|
||||||
|
--Festival calculate within one statement
|
||||||
|
return
|
||||||
|
--Christmas
|
||||||
|
M=="12"and math.abs(D-25)<4 and
|
||||||
|
"xmas"or
|
||||||
|
|
||||||
|
--Spring festival
|
||||||
|
M<"03"and math.abs((({
|
||||||
|
--Festival days. Jan 26=26, Feb 1=32, etc.
|
||||||
|
24,43,32,22,40,29,49,38,26,45,
|
||||||
|
34,23,41,31,50,39,28,47,36,25,
|
||||||
|
43,32,22,41,29,48,37,26,44,34,
|
||||||
|
23,42,31,50,39,28,46,35,24,43,
|
||||||
|
32,22,41,30,48,37,26,45,33,23,
|
||||||
|
42,32,50,39,28,46,35,24,43,33,
|
||||||
|
21,40,
|
||||||
|
})[Y-2000]or -26)-((M-1)*31+D))<6 and
|
||||||
|
"sprfes"or
|
||||||
|
|
||||||
|
--Z day (Feb./Mar./Apr./May./June 26)
|
||||||
|
math.abs(M-4)<=2 and D+0==26 and
|
||||||
|
"zday"or
|
||||||
|
|
||||||
|
"classic"
|
||||||
|
end
|
||||||
|
|
||||||
|
function THEME.set(theme)
|
||||||
|
if theme=="classic"then
|
||||||
|
BG.setDefault("space")
|
||||||
|
BGM.setDefault("blank")
|
||||||
|
elseif theme=="xmas"then
|
||||||
|
BG.setDefault("snow")
|
||||||
|
BGM.setDefault("mXmas")
|
||||||
|
LOG.print("==============",COLOR.red)
|
||||||
|
LOG.print("Merry Christmas!",COLOR.white)
|
||||||
|
LOG.print("==============",COLOR.red)
|
||||||
|
elseif theme=="sprfes"then
|
||||||
|
BG.setDefault("firework")
|
||||||
|
BGM.setDefault("spring festival")
|
||||||
|
LOG.print(" ★☆☆★",COLOR.red)
|
||||||
|
LOG.print("新年快乐!",COLOR.white)
|
||||||
|
LOG.print(" ★☆☆★",COLOR.red)
|
||||||
|
elseif theme=="zday"then
|
||||||
|
BG.setDefault("lanterns")
|
||||||
|
BGM.setDefault("overzero")
|
||||||
|
else
|
||||||
|
return
|
||||||
|
end
|
||||||
|
THEME.cur=theme
|
||||||
|
BG.set()
|
||||||
|
BGM.play()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function THEME.getThemeColor(theme)
|
||||||
|
if not theme then theme=THEME.cur end
|
||||||
|
return themeColor[theme]
|
||||||
|
end
|
||||||
|
|
||||||
|
function THEME.fresh()
|
||||||
|
THEME.set(THEME.calculate(os.date"%Y",os.date"%m",os.date"%d"))
|
||||||
|
end
|
||||||
|
|
||||||
|
return THEME
|
||||||
@@ -974,19 +974,13 @@ function WIDGET.set(list)
|
|||||||
for i=1,#list do
|
for i=1,#list do
|
||||||
list[i]:reset()
|
list[i]:reset()
|
||||||
end
|
end
|
||||||
if THEME and SCN.cur~="custom_field"then
|
if SCN.cur~="custom_field"then
|
||||||
local c1,c2,c3
|
local colorList=THEME.getThemeColor()
|
||||||
if THEME=="xMas"then
|
if not colorList then return end
|
||||||
c1,c2,c3=COLOR.red,COLOR.white,COLOR.green
|
|
||||||
elseif THEME=="sprFes"then
|
|
||||||
c1,c2,c3=COLOR.red,COLOR.orange,COLOR.yellow
|
|
||||||
else
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local rnd=math.random
|
local rnd=math.random
|
||||||
for _,W in next,list do
|
for _,W in next,list do
|
||||||
if W.color and not W.fText then
|
if W.color and not W.fText then
|
||||||
W.color=rnd()<.3 and c1 or rnd()<.5 and c2 or c3
|
W.color=colorList[rnd(#colorList)]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
40
main.lua
40
main.lua
@@ -29,32 +29,6 @@ WSCONN=false
|
|||||||
LATEST_VERSION=false
|
LATEST_VERSION=false
|
||||||
ERRDATA={}
|
ERRDATA={}
|
||||||
|
|
||||||
--Festival check within one statement
|
|
||||||
THEME=(
|
|
||||||
--Christmas
|
|
||||||
os.date"%m"=="12"and math.abs(os.date"%d"-25)<4 and
|
|
||||||
"Xmas"or
|
|
||||||
|
|
||||||
--Spring festival
|
|
||||||
os.date"%m"<"03"and math.abs((({
|
|
||||||
--Festival days. Jan 26=26, Feb 1=32, etc.
|
|
||||||
24,43,32,22,40,29,49,38,26,45,
|
|
||||||
34,23,41,31,50,39,28,47,36,25,
|
|
||||||
43,32,22,41,29,48,37,26,44,34,
|
|
||||||
23,42,31,50,39,28,46,35,24,43,
|
|
||||||
32,22,41,30,48,37,26,45,33,23,
|
|
||||||
42,32,50,39,28,46,35,24,43,33,
|
|
||||||
21,40,
|
|
||||||
})[os.date"%Y"-2000]or -26)-((os.date"%m"-1)*31+os.date"%d"))<6 and
|
|
||||||
"sprFes"or
|
|
||||||
|
|
||||||
--Z day (Feb./Mar./Apr./May./June 26)
|
|
||||||
math.abs(os.date"%m"-4)<=2 and os.date"%d"+0==26 and
|
|
||||||
"zDay"or
|
|
||||||
|
|
||||||
false
|
|
||||||
)
|
|
||||||
|
|
||||||
--System setting
|
--System setting
|
||||||
math.randomseed(os.time()*626)
|
math.randomseed(os.time()*626)
|
||||||
love.keyboard.setKeyRepeat(true)
|
love.keyboard.setKeyRepeat(true)
|
||||||
@@ -406,18 +380,4 @@ do
|
|||||||
STAT.version=VERSION_CODE
|
STAT.version=VERSION_CODE
|
||||||
FILE.save(STAT,"conf/data","q")
|
FILE.save(STAT,"conf/data","q")
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if THEME=="Xmas"then
|
|
||||||
BG.setDefault("snow")
|
|
||||||
BGM.setDefault("mXmas")
|
|
||||||
elseif THEME=="sprFes"then
|
|
||||||
BG.setDefault("firework")
|
|
||||||
BGM.setDefault("spring festival")
|
|
||||||
elseif THEME=="zDay"then
|
|
||||||
BG.setDefault("lanterns")
|
|
||||||
BGM.setDefault("overzero")
|
|
||||||
else
|
|
||||||
BG.setDefault("space")
|
|
||||||
BGM.setDefault("blank")
|
|
||||||
end
|
end
|
||||||
@@ -470,30 +470,13 @@ function commands.setbg(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function commands.theme(name)
|
function commands.theme(name)
|
||||||
if name=="classic"then
|
if name~=""then
|
||||||
THEME=false
|
if THEME.set(name)then
|
||||||
BG.setDefault("space")
|
log("Theme set to: "..name)
|
||||||
BGM.setDefault("blank")
|
else
|
||||||
BGM.play()
|
|
||||||
elseif name=="xmas"then
|
|
||||||
THEME="xMas"
|
|
||||||
BG.setDefault("snow")
|
|
||||||
BGM.setDefault("mXmas")
|
|
||||||
BGM.play()
|
|
||||||
elseif name=="sprfes"then
|
|
||||||
THEME="sprFes"
|
|
||||||
BG.setDefault("firework")
|
|
||||||
BGM.setDefault("spring festival")
|
|
||||||
BGM.play()
|
|
||||||
elseif name=="zday"then
|
|
||||||
THEME="zDay"
|
|
||||||
BG.setDefault("lanterns")
|
|
||||||
BGM.setDefault("overzero")
|
|
||||||
BGM.play()
|
|
||||||
else
|
|
||||||
if name~=""then
|
|
||||||
log("No theme called "..name)
|
log("No theme called "..name)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
log{C.water,"Usage: theme [themeName]"}
|
log{C.water,"Usage: theme [themeName]"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ local scene={}
|
|||||||
local t1,t2,animateType
|
local t1,t2,animateType
|
||||||
|
|
||||||
function scene.sceneInit()
|
function scene.sceneInit()
|
||||||
BG.set()
|
|
||||||
BGM.play()
|
|
||||||
t1,t2=0,0--Timer
|
t1,t2=0,0--Timer
|
||||||
animateType={rnd(5),rnd(5),rnd(5),rnd(5),rnd(5),rnd(5),rnd(5),rnd(5)}--Random animation type
|
animateType={rnd(5),rnd(5),rnd(5),rnd(5),rnd(5),rnd(5),rnd(5),rnd(5)}--Random animation type
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -182,15 +182,7 @@ local loadingThread=coroutine.create(function()
|
|||||||
authToken=USER.authToken,
|
authToken=USER.authToken,
|
||||||
})
|
})
|
||||||
]]
|
]]
|
||||||
if THEME=="Xmas"then
|
THEME.fresh()
|
||||||
LOG.print("==============",COLOR.red)
|
|
||||||
LOG.print("Merry Christmas!",COLOR.white)
|
|
||||||
LOG.print("==============",COLOR.red)
|
|
||||||
elseif THEME=="sprFes"then
|
|
||||||
LOG.print(" ★☆☆★",COLOR.red)
|
|
||||||
LOG.print("新年快乐!",COLOR.white)
|
|
||||||
LOG.print(" ★☆☆★",COLOR.red)
|
|
||||||
end
|
|
||||||
while true do
|
while true do
|
||||||
if math.random()<.126 then
|
if math.random()<.126 then
|
||||||
upFloor()
|
upFloor()
|
||||||
|
|||||||
Reference in New Issue
Block a user