45ea1b33bf
[FIX] Ajustada posició del peu en habitació 27 [FIX] Modificat trigger_event per a que es disparen en una habitació concreta i també segons distancia sense haver de colisionar [FIX] Ending stage 1 [FIX] ELiminades llunes duplicades [NEW] Dialeg per a l'abad
113 lines
3.2 KiB
Lua
113 lines
3.2 KiB
Lua
-- 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
|
|
|
|
states={
|
|
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,
|
|
add_stack = {}, -- pila per a pasar a stack en quan arribe el següent executar
|
|
}
|
|
|
|
|
|
function states:safe()
|
|
if not states.safe_show then
|
|
print("[STATES] No hi ha res en la pila")
|
|
states.safe_show = true
|
|
end
|
|
end
|
|
|
|
function states:registrar(nom, _path)
|
|
print("[STATES] REGISTRAR => "..nom)
|
|
self.registre[nom]= {ptr=0, path=_path}
|
|
print(self.registre[nom].ptr)
|
|
end
|
|
|
|
function states:borrar(nom)
|
|
self.registre[nom].ptr=0
|
|
self.registre[nom].path=nil
|
|
end
|
|
|
|
function states:add(nom)
|
|
print("[STATES] add "..nom)
|
|
self.add_stack[#self.add_stack+1] = nom
|
|
end
|
|
|
|
function states:executar(nom, stacking)
|
|
print("[STATES] EXEC "..nom)
|
|
if stacking then
|
|
-- 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 states:next()
|
|
print("[STATES] NEXT "..self.actiu);
|
|
local ptr = self.registre[self.actiu].ptr
|
|
local steps = #self.registre[self.actiu].path
|
|
-- print("STATES_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
|
|
|
|
return self.actiu, self.registre[self.actiu].ptr
|
|
end
|
|
|
|
function states:finish()
|
|
print("[STATES] FINISH "..self.actiu);
|
|
self.actiu = table.remove(self.stack)
|
|
print("[STATES] ACTIU "..self.actiu);
|
|
if self.actiu==nil then
|
|
-- no queda res en la pila
|
|
self.actiu="states"
|
|
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
|
|
|
|
-- 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_states = self.registre[self.actiu]
|
|
local ptr = self.registre[self.actiu].ptr
|
|
game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr]
|
|
end
|
|
|
|
states:registrar("states",{states.safe})
|