steed/stead/goto.lua

139 lines
2.9 KiB
Lua
Raw Normal View History

2010-06-07 13:18:44 +03:00
go = function (self, where, back)
local was = self.where;
local need_scene = false;
local ret
if not stead.in_goto_call then
ret = function(rc) stead.in_goto_call = false return nil end
else
ret = function(rc) return rc end
end
stead.in_goto_call = true
if where == nil then
return nil, ret(false)
end
if not isRoom(ref(where)) then
error ("Trying to go nowhere: "..where);
end
if not isRoom(ref(self.where)) then
error ("Trying to go from nowhere: "..self.where);
end
if stead.in_entered_call or stead.in_onexit_call then
error ("Do not use goto from left/entered action! Use exit/enter action instead:" .. self.where);
end
2010-06-23 20:25:23 +03:00
local v, r, jump;
2010-06-07 13:18:44 +03:00
if not isVroom(ref(where)) and not stead.in_exit_call then
stead.in_exit_call = true -- to break recurse
v,r = call(ref(self.where), 'exit', where);
stead.in_exit_call = nil
if r == false then
return v, ret(r)
end
2010-06-23 20:25:23 +03:00
if self.where ~= was then
where = deref(self.where) -- jump
jump = true
end
2010-06-07 13:18:44 +03:00
end
local res = v;
v = nil;
if not isVroom(ref(where)) then
self.where = deref(where);
end
2010-06-23 20:25:23 +03:00
if not jump and (not back or not isDialog(ref(was)) or isDialog(ref(where))) then
2010-06-16 13:25:29 +03:00
v, r = call(ref(where), 'enter', deref(was));
if r == false then
self.where = was;
return par('^^', res, v), ret(r)
end
2010-06-16 13:09:41 +03:00
2010-06-16 13:25:29 +03:00
need_scene = true;
if ref(where) ~= ref(self.where) then -- jump !!!
need_scene = false;
end
2010-06-07 13:18:44 +03:00
end
2010-06-16 13:09:41 +03:00
2010-06-07 13:18:44 +03:00
res = par('^^',res,v);
if not back then
ref(where).__from__ = deref(was);
end
ret()
if not stead.in_goto_call then
local to = self.where
self.where = was
stead.in_onexit_call = true
v = call(ref(was), 'left', deref(to));
stead.in_onexit_call = false
res = par('^^',res,v);
self.where = deref(to)
stead.in_entered_call = true
v = call(ref(to), 'entered', deref(was));
stead.in_entered_call = false
res = par('^^',res,v);
end
2010-06-23 13:35:53 +03:00
PLAYER_MOVED = true
2010-06-07 13:18:44 +03:00
if need_scene then -- or isForcedsc(ref(where)) then -- i'am not sure...
2010-06-23 13:35:53 +03:00
NEED_SCENE = true
-- return par('^^',res,ref(where):scene());
2010-06-07 13:18:44 +03:00
end
return res;
end
2010-06-22 12:00:29 +03:00
2010-06-23 13:35:53 +03:00
iface.fmt = function(self, cmd, st, moved, r, av, objs, pv) -- st -- changed state (main win), move -- loc changed
local l
if st then
av = txtem(av);
pv = txtem(pv);
r = txtem(r)
if isForcedsc(here()) or NEED_SCENE then
l = here():scene();
end
end
if moved then
vv = stead.fmt(stead.cat(stead.par("^^", r, av, l, objs, pv), '^'));
else
vv = stead.fmt(stead.cat(stead.par("^^", l, r, av, objs, pv), '^'));
end
return vv
end
2010-06-23 15:09:33 +03:00
go = stead.hook(go, function(f, ...)
2010-06-22 12:00:29 +03:00
local r,v = f(unpack(arg))
2010-06-23 09:05:25 +03:00
if type(r) == 'string' and cctx() then
2010-06-22 12:00:29 +03:00
pr (r)
end
if stead.in_life_call then
ACTION_TEXT = nil
end
2010-06-22 12:00:29 +03:00
return r,v
end)
2010-06-23 13:35:53 +03:00
2010-06-23 15:09:33 +03:00
iface.cmd = stead.hook(iface.cmd, function(f, ...)
2010-06-23 13:35:53 +03:00
NEED_SCENE = nil
return f(unpack(arg))
end)
2010-06-23 15:09:33 +03:00
player = stead.inherit(player, function(v)
2010-06-23 13:35:53 +03:00
v.look = function(s)
NEED_SCENE = true
end
return v
end)
pl = player(pl) -- reinit