[FIX] Sistema de navegació entre pantalles (flow)
- Optimitzat el logo. Ara necessita menys memòria aprofitant les funcions de paleta
This commit is contained in:
145
data/flow.lua
145
data/flow.lua
@@ -1,63 +1,110 @@
|
||||
-- flow={
|
||||
-- level=1,
|
||||
-- step={0},
|
||||
-- actiu="",
|
||||
-- pila={},
|
||||
-- paths={ {flow_safe} },
|
||||
-- registre={}
|
||||
-- -- sub_path_enable = false,
|
||||
-- -- sub_step = 0,
|
||||
-- -- sub_path={}
|
||||
-- }
|
||||
|
||||
-- function flow:print()
|
||||
-- print("> STEP= "..self.step.." / "..#self.path)
|
||||
-- if self.sub_path_enable then
|
||||
-- print("> SUB_PATH_ENABLE= TRUE")
|
||||
-- else
|
||||
-- print("> SUB_PATH_ENABLE= FALSE")
|
||||
-- end
|
||||
-- print("> SUB_STEP= "..self.sub_step.." / "..#self.sub_path)
|
||||
-- print("")
|
||||
-- end
|
||||
|
||||
flow={
|
||||
level=1,
|
||||
step={0},
|
||||
paths={ {flow_safe} },
|
||||
registre={ }
|
||||
-- sub_path_enable = false,
|
||||
-- sub_step = 0,
|
||||
-- sub_path={}
|
||||
registre={}, -- {nom {ptr (a l'estat actual), path (llista de funcions ordenada)} ...}
|
||||
actiu = "", -- nom del registre actiu
|
||||
stack = {}, -- guarda els canvis de registre per a poder tornar a l'estat anterior
|
||||
safe_show = false
|
||||
}
|
||||
|
||||
function flow_safe()
|
||||
print("FLOW SAFE")
|
||||
|
||||
function flow:safe()
|
||||
if not flow.safe_show then
|
||||
print("[FLOW] No hi ha res en la pila")
|
||||
flow.safe_show = true
|
||||
end
|
||||
end
|
||||
|
||||
function flow:print()
|
||||
print("> STEP= "..self.step.." / "..#self.path)
|
||||
if self.sub_path_enable then
|
||||
print("> SUB_PATH_ENABLE= TRUE")
|
||||
else
|
||||
print("> SUB_PATH_ENABLE= FALSE")
|
||||
end
|
||||
print("> SUB_STEP= "..self.sub_step.." / "..#self.sub_path)
|
||||
print("")
|
||||
function flow:registrar(nom, _path)
|
||||
self.registre[nom]= {ptr=0, path=_path}
|
||||
end
|
||||
|
||||
function flow:borrar(nom)
|
||||
self.registre[nom].ptr=0
|
||||
self.registre[nom].path=nil
|
||||
end
|
||||
|
||||
function flow:executar(nom, stacking)
|
||||
print("FLOW EXEC "..nom)
|
||||
if stacking then
|
||||
table.insert(self.stack, self.actiu)
|
||||
print(" APILAT "..self.actiu.."!")
|
||||
end
|
||||
self.actiu=nom
|
||||
self.registre[self.actiu].ptr=0
|
||||
self:next()
|
||||
end
|
||||
|
||||
-- function flow:next()
|
||||
-- local ptr = self.registre[self.actiu].ptr
|
||||
-- local steps = #self.registre[self.actiu].path
|
||||
-- print("FLOW_NEXT= "..self.actiu..", "..ptr..", "..steps)
|
||||
-- if ptr+1>steps then
|
||||
-- self.actiu = table.remove(self.stack)
|
||||
-- if self.actiu==nil then
|
||||
-- -- no queda res en la pila
|
||||
-- self.actiu="flow"
|
||||
-- self.registre[self.actiu].ptr = 1
|
||||
-- else
|
||||
-- -- ultim element afegit a la pila
|
||||
-- -- No se fa cap acció lo que implica que se restaura l'estat en el
|
||||
-- -- que s'estava abans de l'ultima cridada
|
||||
-- end
|
||||
-- else
|
||||
-- self.registre[self.actiu].ptr = ptr+1
|
||||
-- end
|
||||
--
|
||||
-- game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr]
|
||||
-- return self.actiu, self.registre[self.actiu].ptr
|
||||
-- end
|
||||
|
||||
function flow:next()
|
||||
local level_step = self.step[self.level]
|
||||
local level_path = self.paths[self.level]
|
||||
-- print("LEVEL= "..self.level)
|
||||
-- print("LEVEL_STEP= "..level_step)
|
||||
if level_step+1 > #level_path then
|
||||
-- Si s'ha acabat la llista pujar de nivell
|
||||
if self.level>1 then self.level=self.level-1 end
|
||||
level_step = self.step[self.level]
|
||||
-- level_path = self.paths[self.level]
|
||||
local ptr = self.registre[self.actiu].ptr
|
||||
local steps = #self.registre[self.actiu].path
|
||||
print("FLOW_NEXT= "..self.actiu..", "..ptr..", "..steps)
|
||||
if ptr+1>steps then
|
||||
self:finish()
|
||||
else
|
||||
self.registre[self.actiu].ptr = ptr+1
|
||||
game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr]
|
||||
end
|
||||
|
||||
-- següent pas
|
||||
level_step = level_step+1
|
||||
game_update = self.paths[self.level][level_step]
|
||||
|
||||
-- result = self.step[self.level]
|
||||
self.step[self.level] = level_step
|
||||
return self.actiu, self.registre[self.actiu].ptr
|
||||
end
|
||||
|
||||
function flow:restore()
|
||||
local level_step = self.step[self.level]
|
||||
game_update = self.paths[self.level][level_step]
|
||||
function flow:finish()
|
||||
self.actiu = table.remove(self.stack)
|
||||
if self.actiu==nil then
|
||||
-- no queda res en la pila
|
||||
self.actiu="flow"
|
||||
self.registre[self.actiu].ptr = 1
|
||||
else
|
||||
-- ultim element afegit a la pila
|
||||
-- No se fa cap acció lo que implica que se restaura l'estat en el
|
||||
-- que s'estava abans de l'ultima cridada
|
||||
end
|
||||
game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr]
|
||||
end
|
||||
|
||||
function flow:call(nom)
|
||||
game_update = self.registre[nom]
|
||||
end
|
||||
|
||||
function flow:add_path( path )
|
||||
self.level = self.level+1
|
||||
self.step[self.level] = 0
|
||||
self.paths[self.level] = path
|
||||
end
|
||||
|
||||
function flow:add(name, fn)
|
||||
self.registre[name] = fn
|
||||
end
|
||||
flow:registrar("flow",{flow.safe})
|
||||
|
||||
Reference in New Issue
Block a user