-- 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={ 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() if not flow.safe_show then print("[FLOW] No hi ha res en la pila") flow.safe_show = true end end 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 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 return self.actiu, self.registre[self.actiu].ptr end 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 flow:registrar("flow",{flow.safe})