跳转空场景保护

This commit is contained in:
MrZ626
2020-12-05 22:52:50 +08:00
parent f05dc45c03
commit ebe3424b01

View File

@@ -6,7 +6,6 @@ local scenes={}
local SCN={ local SCN={
cur="NULL",--Current scene name cur="NULL",--Current scene name
scenes=scenes,
swapping=false,--If Swapping swapping=false,--If Swapping
stat={ stat={
tar=nil, --Swapping target tar=nil, --Swapping target
@@ -17,6 +16,8 @@ local SCN={
}, },
seq={"quit","slowFade"},--Back sequence seq={"quit","slowFade"},--Back sequence
scenes=scenes,
--Events --Events
update=nil, update=nil,
draw=nil, draw=nil,
@@ -53,9 +54,10 @@ function SCN.swapUpdate()
end end
end end
function SCN.init(s,org) function SCN.init(s,org)
local S=scenes[s]
SCN.cur=s SCN.cur=s
WIDGET.set(s) WIDGET.set(s)
local S=scenes[s]
SCN.sceneInit=S.sceneInit SCN.sceneInit=S.sceneInit
SCN.sceneBack=S.sceneBack SCN.sceneBack=S.sceneBack
SCN.update=S.update SCN.update=S.update
@@ -74,7 +76,8 @@ function SCN.init(s,org)
SCN.gamepadDown=S.gamepadDown SCN.gamepadDown=S.gamepadDown
SCN.gamepadUp=S.gamepadUp SCN.gamepadUp=S.gamepadUp
SCN.socketRead=S.socketRead SCN.socketRead=S.socketRead
if SCN.sceneInit then SCN.sceneInit(org)end
if S.sceneInit then S.sceneInit(org)end
end end
function SCN.push(tar,style) function SCN.push(tar,style)
if not SCN.swapping then if not SCN.swapping then
@@ -126,17 +129,25 @@ local swap={
end}, end},
}--Scene swapping animations }--Scene swapping animations
function SCN.swapTo(tar,style)--Parallel scene swapping, cannot back function SCN.swapTo(tar,style)--Parallel scene swapping, cannot back
local S=SCN.stat if scenes[tar]then
if not SCN.swapping and tar~=SCN.cur then local S=SCN.stat
if not style then style="fade"end if not SCN.swapping and tar~=SCN.cur then
SCN.swapping=true if not style then style="fade"end
S.tar,S.style=tar,style SCN.swapping=true
S.time,S.mid,S.draw=unpack(swap[style]) S.tar,S.style=tar,style
S.time,S.mid,S.draw=unpack(swap[style])
end
else
LOG.print("No Scene: "..tar,"warn")
end end
end end
function SCN.go(tar,style)--Normal scene swapping, can back function SCN.go(tar,style)--Normal scene swapping, can back
SCN.push() if scenes[tar]then
SCN.swapTo(tar,style) SCN.push()
SCN.swapTo(tar,style)
else
LOG.print("No Scene: "..tar,"warn")
end
end end
function SCN.back() function SCN.back()
--Leave scene --Leave scene