prefs object
This commit is contained in:
parent
30f089aee2
commit
e389e6aa0d
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -4,6 +4,8 @@ instead (1.2.0) unstable; urgency=low
|
|||
* browse feature (win32 and gtk);
|
||||
* clever sorting;
|
||||
* remove games;
|
||||
* local appdata mode;
|
||||
* prefs object;
|
||||
|
||||
-- Peter Kosyh <p.kosyh@gmail.com> Tue, 01 Jun 2010 17:40:00 +0300
|
||||
|
||||
|
|
|
@ -70,15 +70,22 @@ int game_select(const char *name)
|
|||
chdir(game_cwd);
|
||||
for (i = 0; i<games_nr; i ++) {
|
||||
if (!strcmp(games[i].dir, name)) {
|
||||
instead_done();
|
||||
if (instead_init())
|
||||
return -1;
|
||||
if (chdir(games[i].path))
|
||||
return -1;
|
||||
if (instead_load(MAIN_FILE))
|
||||
return -1;
|
||||
instead_eval("game:ini()"); instead_clear();
|
||||
char *oldgame = curgame_dir;
|
||||
curgame_dir = games[i].dir;
|
||||
instead_done();
|
||||
if (instead_init()) {
|
||||
curgame_dir = oldgame;
|
||||
return -1;
|
||||
}
|
||||
if (chdir(games[i].path)) {
|
||||
curgame_dir = oldgame;
|
||||
return -1;
|
||||
}
|
||||
if (instead_load(MAIN_FILE)) {
|
||||
curgame_dir = oldgame;
|
||||
return -1;
|
||||
}
|
||||
instead_eval("game:ini()"); instead_clear();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -347,7 +354,6 @@ int game_load(int nr)
|
|||
{
|
||||
char *s;
|
||||
s = game_save_path(0, nr);
|
||||
|
||||
if (s && !access(s, R_OK)) {
|
||||
char cmd[PATH_MAX];
|
||||
snprintf(cmd, sizeof(cmd) - 1, "load %s", s);
|
||||
|
|
|
@ -406,7 +406,7 @@ static const luaL_Reg base_funcs[] = {
|
|||
{"doencfile", luaB_doencfile},
|
||||
{"print", luaB_print}, /* for some mystic, it is needed in win version (with -debug) */
|
||||
{"is_sound", luaB_is_sound},
|
||||
{"savespath", luaB_get_savepath},
|
||||
{"get_savepath", luaB_get_savepath},
|
||||
{"set_timer", luaB_set_timer},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
|
|
@ -212,10 +212,8 @@ char *game_cfg_path(void)
|
|||
char *game_save_path(int cr, int nr)
|
||||
{
|
||||
char *app = appdir();
|
||||
|
||||
if (!curgame_dir)
|
||||
return NULL;
|
||||
|
||||
if (!access("saves", R_OK)) {
|
||||
if (nr)
|
||||
snprintf(save_path, sizeof(save_path) - 1, "saves/save%d", nr);
|
||||
|
|
|
@ -4,6 +4,7 @@ stead = {
|
|||
string = string,
|
||||
math = math,
|
||||
io = io,
|
||||
os = os,
|
||||
call_top = 0,
|
||||
cctx = { txt = nil, self = nil },
|
||||
timer = function()
|
||||
|
@ -1895,6 +1896,28 @@ input = obj { -- input object
|
|||
end ]]
|
||||
};
|
||||
|
||||
prefs = obj {
|
||||
nam = 'preferences',
|
||||
ini = function(s)
|
||||
local name = get_savepath() .. '/prefs';
|
||||
local f, err = loadfile(name);
|
||||
if not f then return nil end
|
||||
f();
|
||||
end,
|
||||
store = function(s)
|
||||
local name = get_savepath() .. '/prefs';
|
||||
local h = stead.io.open(name,"w");
|
||||
if not h then return false end
|
||||
savemembers(h, s, 'prefs', true);
|
||||
h:flush();
|
||||
h:close();
|
||||
end,
|
||||
purge = function(s)
|
||||
local name = get_savepath() .. '/prefs';
|
||||
return stead.os.remove(name);
|
||||
end
|
||||
};
|
||||
|
||||
function vobj_save(self, name, h, need)
|
||||
local dsc;
|
||||
local w
|
||||
|
@ -2157,6 +2180,12 @@ if is_sound == nil then
|
|||
end
|
||||
end
|
||||
|
||||
if get_savepath == nil then
|
||||
function get_savepath()
|
||||
return "./"
|
||||
end
|
||||
end
|
||||
|
||||
function autosave(slot)
|
||||
game.autosave = true;
|
||||
game.autosave_slot = slot;
|
||||
|
|
Loading…
Reference in a new issue