[NEW] Mòdul Live scene per a escenes de joc

[NEW] Modificat mòdul flow per a poder afegir registres que no se van a executar inmediatament i així programar escenes encadenades
This commit is contained in:
2026-05-09 22:31:11 +02:00
parent 6a555a55f2
commit 83720a8b69
6 changed files with 77 additions and 27 deletions
+28 -26
View File
@@ -25,7 +25,8 @@ flow={
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
safe_show = false,
add_stack = {}, -- pila per a pasar a stack en quan arribe el següent executar
}
@@ -37,7 +38,9 @@ function flow:safe()
end
function flow:registrar(nom, _path)
print("[FLOW] REGISTRAR => "..nom)
self.registre[nom]= {ptr=0, path=_path}
print(self.registre[nom].ptr)
end
function flow:borrar(nom)
@@ -45,41 +48,31 @@ function flow:borrar(nom)
self.registre[nom].path=nil
end
function flow:add(nom)
print("[FLOW] add "..nom)
self.add_stack[#self.add_stack+1] = nom
end
function flow:executar(nom, stacking)
-- print("FLOW EXEC "..nom)
print("[FLOW] EXEC "..nom)
if stacking then
table.insert(self.stack, self.actiu)
-- table.insert(self.stack, self.actiu)
self.stack[#self.stack+1] = self.actiu
-- print(" APILAT "..self.actiu.."!")
if #self.add_stack>0 then
for i, v in ipairs(self.add_stack) do
self.stack[#self.stack+1] = v
end
self.add_stack={}
end
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()
print("[FLOW] NEXT "..self.actiu);
local ptr = self.registre[self.actiu].ptr
local steps = #self.registre[self.actiu].path
-- print("FLOW_NEXT= "..self.actiu..", "..ptr..", "..steps)
@@ -94,7 +87,9 @@ function flow:next()
end
function flow:finish()
print("[FLOW] FINISH "..self.actiu);
self.actiu = table.remove(self.stack)
print("[FLOW] ACTIU "..self.actiu);
if self.actiu==nil then
-- no queda res en la pila
self.actiu="flow"
@@ -103,7 +98,14 @@ function flow:finish()
-- 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
-- Per si es un estat afegit amb add
if self.registre[self.actiu].ptr ==0 then
self.registre[self.actiu].ptr = 1
end
end
local curr_flow = self.registre[self.actiu]
local ptr = self.registre[self.actiu].ptr
game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr]
end