prefs object

This commit is contained in:
p.kosyh 2010-06-05 09:56:55 +00:00
parent 30f089aee2
commit e389e6aa0d
5 changed files with 47 additions and 12 deletions

2
debian/changelog vendored
View file

@ -4,6 +4,8 @@ instead (1.2.0) unstable; urgency=low
* browse feature (win32 and gtk); * browse feature (win32 and gtk);
* clever sorting; * clever sorting;
* remove games; * remove games;
* local appdata mode;
* prefs object;
-- Peter Kosyh <p.kosyh@gmail.com> Tue, 01 Jun 2010 17:40:00 +0300 -- Peter Kosyh <p.kosyh@gmail.com> Tue, 01 Jun 2010 17:40:00 +0300

View file

@ -70,15 +70,22 @@ int game_select(const char *name)
chdir(game_cwd); chdir(game_cwd);
for (i = 0; i<games_nr; i ++) { for (i = 0; i<games_nr; i ++) {
if (!strcmp(games[i].dir, name)) { if (!strcmp(games[i].dir, name)) {
instead_done(); char *oldgame = curgame_dir;
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();
curgame_dir = games[i].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; return 0;
} }
} }
@ -347,7 +354,6 @@ int game_load(int nr)
{ {
char *s; char *s;
s = game_save_path(0, nr); s = game_save_path(0, nr);
if (s && !access(s, R_OK)) { if (s && !access(s, R_OK)) {
char cmd[PATH_MAX]; char cmd[PATH_MAX];
snprintf(cmd, sizeof(cmd) - 1, "load %s", s); snprintf(cmd, sizeof(cmd) - 1, "load %s", s);

View file

@ -406,7 +406,7 @@ static const luaL_Reg base_funcs[] = {
{"doencfile", luaB_doencfile}, {"doencfile", luaB_doencfile},
{"print", luaB_print}, /* for some mystic, it is needed in win version (with -debug) */ {"print", luaB_print}, /* for some mystic, it is needed in win version (with -debug) */
{"is_sound", luaB_is_sound}, {"is_sound", luaB_is_sound},
{"savespath", luaB_get_savepath}, {"get_savepath", luaB_get_savepath},
{"set_timer", luaB_set_timer}, {"set_timer", luaB_set_timer},
{NULL, NULL} {NULL, NULL}
}; };

View file

@ -212,10 +212,8 @@ char *game_cfg_path(void)
char *game_save_path(int cr, int nr) char *game_save_path(int cr, int nr)
{ {
char *app = appdir(); char *app = appdir();
if (!curgame_dir) if (!curgame_dir)
return NULL; return NULL;
if (!access("saves", R_OK)) { if (!access("saves", R_OK)) {
if (nr) if (nr)
snprintf(save_path, sizeof(save_path) - 1, "saves/save%d", nr); snprintf(save_path, sizeof(save_path) - 1, "saves/save%d", nr);

View file

@ -4,6 +4,7 @@ stead = {
string = string, string = string,
math = math, math = math,
io = io, io = io,
os = os,
call_top = 0, call_top = 0,
cctx = { txt = nil, self = nil }, cctx = { txt = nil, self = nil },
timer = function() timer = function()
@ -1895,6 +1896,28 @@ input = obj { -- input object
end ]] 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) function vobj_save(self, name, h, need)
local dsc; local dsc;
local w local w
@ -2157,6 +2180,12 @@ if is_sound == nil then
end end
end end
if get_savepath == nil then
function get_savepath()
return "./"
end
end
function autosave(slot) function autosave(slot)
game.autosave = true; game.autosave = true;
game.autosave_slot = slot; game.autosave_slot = slot;