X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=libchimara%2Fchimara-if.c;h=0554d93fc3530a6ea190034e972de3cdafcbfbf3;hb=aa30979369091c96bca34499c28cb01bc16efb1d;hp=af1179c49fd0db5219caed2d2bca7d7be8f80cc8;hpb=cae962752aef9b5edd99c7353842d18807d38fa9;p=projects%2Fchimara%2Fchimara.git diff --git a/libchimara/chimara-if.c b/libchimara/chimara-if.c index af1179c..0554d93 100644 --- a/libchimara/chimara-if.c +++ b/libchimara/chimara-if.c @@ -10,6 +10,10 @@ #include "chimara-marshallers.h" #include "init.h" +#ifndef PLUGINDIR +#define PLUGINDIR "." +#endif + /** * SECTION:chimara-if * @short_description: Widget which plays an interactive fiction game @@ -27,13 +31,13 @@ */ static gboolean supported_formats[CHIMARA_IF_NUM_FORMATS][CHIMARA_IF_NUM_INTERPRETERS] = { - /* Frotz Nitfol Glulxe Git */ - { TRUE, TRUE, FALSE, FALSE }, /* Z5 */ - { TRUE, TRUE, FALSE, FALSE }, /* Z6 */ - { TRUE, TRUE, FALSE, FALSE }, /* Z8 */ - { TRUE, TRUE, FALSE, FALSE }, /* Zblorb */ - { FALSE, FALSE, TRUE, TRUE }, /* Glulx */ - { FALSE, FALSE, TRUE, TRUE } /* Gblorb */ + /* Frotz Nitfol Glulxe Git Bocfel */ + { TRUE, TRUE, FALSE, FALSE, TRUE }, /* Z5 */ + { TRUE, TRUE, FALSE, FALSE, TRUE }, /* Z6 */ + { TRUE, TRUE, FALSE, FALSE, TRUE }, /* Z8 */ + { TRUE, TRUE, FALSE, FALSE, TRUE }, /* Zblorb */ + { FALSE, FALSE, TRUE, TRUE, FALSE }, /* Glulx */ + { FALSE, FALSE, TRUE, TRUE, FALSE } /* Gblorb */ }; static gchar *format_names[CHIMARA_IF_NUM_FORMATS] = { N_("Z-code version 5"), @@ -44,10 +48,10 @@ static gchar *format_names[CHIMARA_IF_NUM_FORMATS] = { N_("Blorbed Glulx") }; static gchar *interpreter_names[CHIMARA_IF_NUM_INTERPRETERS] = { - N_("Frotz"), N_("Nitfol"), N_("Glulxe"), N_("Git") + N_("Frotz"), N_("Nitfol"), N_("Glulxe"), N_("Git"), N_("Bocfel") }; static gchar *plugin_names[CHIMARA_IF_NUM_INTERPRETERS] = { - "frotz", "nitfol", "glulxe", "git" + "frotz", "nitfol", "glulxe", "git", "bocfel" }; typedef enum _ChimaraIFFlags { @@ -155,6 +159,8 @@ chimara_if_text_buffer_output(ChimaraGlk *glk, guint32 win_rock, gchar *output) static void chimara_if_init(ChimaraIF *self) { + chimara_init(); /* This is a library entry point */ + CHIMARA_IF_USE_PRIVATE(self, priv); priv->preferred_interpreter[CHIMARA_IF_FORMAT_Z5] = CHIMARA_IF_INTERPRETER_FROTZ; priv->preferred_interpreter[CHIMARA_IF_FORMAT_Z6] = CHIMARA_IF_INTERPRETER_NITFOL; @@ -280,18 +286,6 @@ chimara_if_command(ChimaraIF *self, gchar *input, gchar *response) /* Default signal handler */ } -/* COMPAT: G_PARAM_STATIC_STRINGS only appeared in GTK 2.13.0 */ -#ifndef G_PARAM_STATIC_STRINGS - -/* COMPAT: G_PARAM_STATIC_NAME and friends only appeared in GTK 2.8 */ -#if GTK_CHECK_VERSION(2,8,0) -#define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB) -#else -#define G_PARAM_STATIC_STRINGS (0) -#endif - -#endif - static void chimara_if_class_init(ChimaraIFClass *klass) { @@ -558,7 +552,7 @@ chimara_if_get_preferred_interpreter(ChimaraIF *self, ChimaraIFFormat format) /** * chimara_if_run_game: * @self: A #ChimaraIF widget. - * @gamefile: Path to an interactive fiction game file. + * @game_path: Path to an interactive fiction game file. * @error: Return location for an error, or %NULL. * * Autodetects the type of a game file and runs it using an appropriate @@ -570,27 +564,28 @@ chimara_if_get_preferred_interpreter(ChimaraIF *self, ChimaraIFFormat format) * case @error is set. */ gboolean -chimara_if_run_game(ChimaraIF *self, gchar *gamefile, GError **error) +chimara_if_run_game(ChimaraIF *self, const char *game_path, GError **error) { g_return_val_if_fail(self && CHIMARA_IS_IF(self), FALSE); - g_return_val_if_fail(gamefile, FALSE); + g_return_val_if_fail(game_path, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); CHIMARA_IF_USE_PRIVATE(self, priv); /* Find out what format the game is */ /* TODO: Look inside the file instead of just looking at the extension */ ChimaraIFFormat format = CHIMARA_IF_FORMAT_Z5; - if(g_str_has_suffix(gamefile, ".z5")) + if(g_str_has_suffix(game_path, ".z5")) format = CHIMARA_IF_FORMAT_Z5; - else if(g_str_has_suffix(gamefile, ".z6")) + else if(g_str_has_suffix(game_path, ".z6")) format = CHIMARA_IF_FORMAT_Z6; - else if(g_str_has_suffix(gamefile, ".z8")) + else if(g_str_has_suffix(game_path, ".z8")) format = CHIMARA_IF_FORMAT_Z8; - else if(g_str_has_suffix(gamefile, ".zlb") || g_str_has_suffix(gamefile, ".zblorb")) + else if(g_str_has_suffix(game_path, ".zlb") || g_str_has_suffix(game_path, ".zblorb")) format = CHIMARA_IF_FORMAT_Z_BLORB; - else if(g_str_has_suffix(gamefile, ".ulx")) + else if(g_str_has_suffix(game_path, ".ulx")) format = CHIMARA_IF_FORMAT_GLULX; - else if(g_str_has_suffix(gamefile, ".blb") || g_str_has_suffix(gamefile, ".blorb") || g_str_has_suffix(gamefile, ".glb") || g_str_has_suffix(gamefile, ".gblorb")) + else if(g_str_has_suffix(game_path, ".blb") || g_str_has_suffix(game_path, ".blorb") || g_str_has_suffix(game_path, ".glb") || g_str_has_suffix(game_path, ".gblorb")) format = CHIMARA_IF_FORMAT_GLULX_BLORB; /* Now decide what interpreter to use */ @@ -675,7 +670,7 @@ chimara_if_run_game(ChimaraIF *self, gchar *gamefile, GError **error) } /* Game file and external blorb file */ - args = g_slist_prepend(args, gamefile); + args = g_slist_prepend(args, (gpointer)game_path); if(priv->graphics_file && (interpreter == CHIMARA_IF_INTERPRETER_FROTZ || interpreter == CHIMARA_IF_INTERPRETER_NITFOL) && g_file_test(priv->graphics_file, G_FILE_TEST_EXISTS)) { @@ -692,17 +687,17 @@ chimara_if_run_game(ChimaraIF *self, gchar *gamefile, GError **error) int count; GSList *ptr; for(count = 0, ptr = args; ptr; count++, ptr = g_slist_next(ptr)) - argv[count] = ptr->data; + argv[count] = g_strdup(ptr->data); /* Set the story name */ /* We peek into ChimaraGlk's private data here, because GObject has no equivalent to "protected" */ CHIMARA_GLK_USE_PRIVATE(self, glk_priv); - glk_priv->story_name = g_path_get_basename(gamefile); + glk_priv->story_name = g_path_get_basename(game_path); g_object_notify(G_OBJECT(self), "story-name"); gboolean retval = chimara_glk_run(CHIMARA_GLK(self), pluginpath, argc, argv, error); - g_free(argv); + g_strfreev(argv); if(terpnumstr) g_free(terpnumstr); if(randomstr) @@ -718,6 +713,31 @@ chimara_if_run_game(ChimaraIF *self, gchar *gamefile, GError **error) return retval; } +/** + * chimara_if_run_game_file: + * @self: A #ChimaraIF widget. + * @game_file: a #GFile pointing to an interactive fiction game file. + * @error: Return location for an error, or %NULL. + * + * Autodetects the type of a game file and runs it using an appropriate + * interpreter plugin. See chimara_if_run_game() for more information. + * + * Returns: %TRUE if the game was started successfully, %FALSE if not, in which + * case @error is set. + */ +gboolean +chimara_if_run_game_file(ChimaraIF *self, GFile *game_file, GError **error) +{ + g_return_val_if_fail(self || CHIMARA_IS_IF(self), FALSE); + g_return_val_if_fail(game_file || G_IS_FILE(game_file), FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + char *path = g_file_get_path(game_file); + gboolean retval = chimara_if_run_game(self, path, error); + g_free(path); + return retval; +} + /** * chimara_if_get_format: * @self: A #ChimaraIF widget.