requre feature, goto module added
This commit is contained in:
parent
59ac861cb4
commit
60d0ba5ac6
|
@ -21,6 +21,8 @@ extern char *err_msg; /* last error message */
|
|||
extern char game_cwd[PATH_MAX]; /* current game cwd */
|
||||
extern char *curgame_dir;
|
||||
|
||||
extern char *game_local_stead_path(void);
|
||||
|
||||
extern char *game_local_games_path(int cr);
|
||||
extern char *game_tmp_path(void);
|
||||
extern int game_theme_select(const char *name);
|
||||
|
|
|
@ -413,8 +413,27 @@ static const luaL_Reg base_funcs[] = {
|
|||
|
||||
int instead_init(void)
|
||||
{
|
||||
char *p;
|
||||
static char stead_path[PATH_MAX];
|
||||
setlocale(LC_ALL,"");
|
||||
setlocale(LC_NUMERIC,"C"); /* to avoid . -> , in numbers */
|
||||
setlocale(LC_NUMERIC,"C"); /* to avoid . -> , in numbers */
|
||||
|
||||
if (STEAD_PATH[0] == '.') {
|
||||
strcpy(stead_path, game_cwd);
|
||||
strcat(stead_path, "/");
|
||||
strcat(stead_path, STEAD_PATH);
|
||||
} else {
|
||||
strcpy(stead_path, STEAD_PATH);
|
||||
}
|
||||
strcat(stead_path, "/?.lua");
|
||||
p = game_local_stead_path();
|
||||
if (p) {
|
||||
strcat(stead_path, ";");
|
||||
strcat(stead_path, p);
|
||||
strcat(stead_path, "/?.lua");
|
||||
}
|
||||
|
||||
setenv("LUA_PATH", stead_path, 1);
|
||||
// strcpy(curcp, "UTF-8");
|
||||
/* initialize Lua */
|
||||
L = lua_open();
|
||||
|
@ -426,7 +445,7 @@ int instead_init(void)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dofile(L,STEAD_PATH"/gui.lua")) {
|
||||
if (dofile(L,STEAD_PATH"/gui.lua")) {
|
||||
instead_clear();
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ static char save_path[PATH_MAX];
|
|||
static char cfg_path[PATH_MAX];
|
||||
static char local_games_path[PATH_MAX];
|
||||
static char local_themes_path[PATH_MAX];
|
||||
static char local_stead_path[PATH_MAX];
|
||||
|
||||
|
||||
void nsleep(int u)
|
||||
|
@ -190,6 +191,15 @@ char *game_local_themes_path(void)
|
|||
return local_themes_path;
|
||||
}
|
||||
|
||||
char *game_local_stead_path(void)
|
||||
{
|
||||
char *app = appdir();
|
||||
if (!app)
|
||||
return NULL;
|
||||
snprintf(local_stead_path, sizeof(local_stead_path) - 1 , "%s/stead", app);
|
||||
return local_stead_path;
|
||||
}
|
||||
|
||||
char *game_cfg_path(void)
|
||||
{
|
||||
char *app = appdir();
|
||||
|
|
|
@ -16,6 +16,7 @@ extern char *curgame_dir;
|
|||
|
||||
static char local_games_path[PATH_MAX];
|
||||
static char local_themes_path[PATH_MAX];
|
||||
static char local_stead_path[PATH_MAX];
|
||||
|
||||
static char save_path[PATH_MAX];
|
||||
static char cfg_path[PATH_MAX];
|
||||
|
@ -132,6 +133,13 @@ char *game_local_themes_path(void)
|
|||
snprintf(local_themes_path, sizeof(local_themes_path) - 1 , "%s/themes", app_dir());
|
||||
return local_themes_path;
|
||||
}
|
||||
|
||||
char *game_local_stead_path(void)
|
||||
{
|
||||
snprintf(local_stead_path, sizeof(local_stead_path) - 1 , "%s/stead", app_dir());
|
||||
return local_stead_path;
|
||||
}
|
||||
|
||||
#if 0
|
||||
char *home_dir( void )
|
||||
{
|
||||
|
|
90
stead/goto.lua
Normal file
90
stead/goto.lua
Normal file
|
@ -0,0 +1,90 @@
|
|||
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
|
||||
|
||||
local v, r;
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
local res = v;
|
||||
v = nil;
|
||||
|
||||
if not isVroom(ref(where)) then
|
||||
self.where = deref(where);
|
||||
end
|
||||
|
||||
if not back or not isDialog(ref(self.where)) or isDialog(ref(where)) then
|
||||
v, r = call(ref(where), 'enter', deref(was));
|
||||
if r == false then
|
||||
self.where = was;
|
||||
return par('^^', res, v), ret(r)
|
||||
end
|
||||
need_scene = true;
|
||||
if ref(where) ~= ref(self.where) then -- jump !!!
|
||||
need_scene = false;
|
||||
end
|
||||
end
|
||||
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
|
||||
|
||||
|
||||
if need_scene then -- or isForcedsc(ref(where)) then -- i'am not sure...
|
||||
return par('^^',res,ref(where):scene());
|
||||
end
|
||||
return res;
|
||||
end
|
|
@ -1163,98 +1163,6 @@ function go(self, where, back)
|
|||
return res;
|
||||
end
|
||||
|
||||
function newgo(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
|
||||
|
||||
local v, r;
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
local res = v;
|
||||
v = nil;
|
||||
|
||||
if not isVroom(ref(where)) then
|
||||
self.where = deref(where);
|
||||
end
|
||||
|
||||
if not back or not isDialog(ref(self.where)) or isDialog(ref(where)) then
|
||||
v, r = call(ref(where), 'enter', deref(was));
|
||||
if r == false then
|
||||
self.where = was;
|
||||
return par('^^', res, v), ret(r)
|
||||
end
|
||||
need_scene = true;
|
||||
if ref(where) ~= ref(self.where) then -- jump !!!
|
||||
need_scene = false;
|
||||
end
|
||||
end
|
||||
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
|
||||
|
||||
|
||||
if need_scene then -- or isForcedsc(ref(where)) then -- i'am not sure...
|
||||
return par('^^',res,ref(where):scene());
|
||||
end
|
||||
return res;
|
||||
end
|
||||
|
||||
|
||||
function player_goto(self, where)
|
||||
local v, r = go(self, where, false);
|
||||
return v, r;
|
||||
|
|
Loading…
Reference in a new issue