diff options
author | Micksha <ms-shaman@gmx.de> | 2019-04-13 19:55:05 +0000 |
---|---|---|
committer | Micksha <ms-shaman@gmx.de> | 2019-04-13 19:55:05 +0000 |
commit | add8a9e8bc83fbf022c66001f2150d90a6f234ab (patch) | |
tree | b771ad105e5a73733ede7559e22467f13a2880a8 /saedit/context.c | |
parent | 8c75e651f00048dda32db85b2bff34e131960864 (diff) | |
parent | 168ad9d6c730e93d76c801da607df84355187a39 (diff) | |
download | evol-tools-add8a9e8bc83fbf022c66001f2150d90a6f234ab.tar.gz evol-tools-add8a9e8bc83fbf022c66001f2150d90a6f234ab.tar.bz2 evol-tools-add8a9e8bc83fbf022c66001f2150d90a6f234ab.tar.xz evol-tools-add8a9e8bc83fbf022c66001f2150d90a6f234ab.zip |
Merge branch 'saedit' into 'master's20190422
update saedit to saedit2
See merge request evol/evol-tools!23
Diffstat (limited to 'saedit/context.c')
-rw-r--r-- | saedit/context.c | 227 |
1 files changed, 227 insertions, 0 deletions
diff --git a/saedit/context.c b/saedit/context.c new file mode 100644 index 0000000..2a14de5 --- /dev/null +++ b/saedit/context.c @@ -0,0 +1,227 @@ +#include <gtk/gtk.h> +#include "context.h" +#include "imageset.h" +#include "action.h" +#include "animation.h" +#include "xml.h" +#include "config.h" +#include "xmlsetup.h" + +struct _SpriteContext { + gchar *cdf_filename; + GList *imagesets; + GList *actions; + GList *includes; +}; + +SpriteContext * +sprite_context_new ( + const gchar *cdf_filename +) { + SpriteContext *context = (SpriteContext *) g_new0 (SpriteContext, 1); + context->cdf_filename = g_strdup (cdf_filename); + return context; +} + +void +sprite_context_add_imageset ( + SpriteContext *context, + XMLNode *node +) { + Imageset *imgset; + + g_return_if_fail (g_strcmp0 (node->name, "imageset") == 0); + + imgset = imageset_new (node, context->cdf_filename); + if (imgset == NULL) + return; + + if (g_list_find_custom ( + context->imagesets, imgset, + (GCompareFunc) imageset_compare_by_name) != NULL + ) { + imageset_free (imgset); + return; + } + + context->imagesets = g_list_append (context->imagesets, imgset); +} + +void +sprite_context_add_action ( + SpriteContext *context, + XMLNode *node, + gint included_from +) { + Action *action; + + g_return_if_fail (g_strcmp0 (node->name, "action") == 0); + + action = action_new (context, node, included_from); + if (action == NULL) + return; + + if (g_list_find_custom ( + context->actions, action, + (GCompareFunc) action_compare_by_hp_and_name) != NULL + ) { + action_free (action); + return; + } + + context->actions = g_list_append (context->actions, action); +} + +void +sprite_context_add_sprite ( + SpriteContext *context, + XMLNode *node, + gint included_from +) { + GList *list; + g_return_if_fail (node != NULL); + g_return_if_fail (g_strcmp0 (node->name, "sprite") == 0); + + list = node->sub_nodes; + for (; list != NULL; list = g_list_next (list)) { + XMLNode *current = (XMLNode *) list->data; + gchar *name = current->name; + if (g_strcmp0 (name, "include") == 0) { + XMLNode *sprite; + gchar *filename, *file; + + file = xml_node_get_attr_value (current, "file"); + if (file == NULL) { + /* TODO: report error */ + continue; + } + + if (g_list_find_custom ( + context->includes, file, + (GCompareFunc) g_strcmp0) != NULL + ) { + /* TODO: such file was already included */ + g_free (file); + continue; + } + + context->includes = g_list_append ( + context->includes, file + ); + + filename = config_data_path_get_full_sprite_path (file); + + sprite = xml_parse_file (filename); + g_free (filename); + + if (sprite == NULL) { + /* TODO: report error */ + continue; + } + + if (g_strcmp0 (sprite->name, "sprite") != 0) { + /* TODO: report error */ + continue; + } + + if (included_from == -1) + included_from = current->line_no; + + sprite_context_add_sprite ( + context, + sprite, + included_from + ); + + xml_free (sprite); + } else + if (g_strcmp0 (name, "imageset") == 0) { + sprite_context_add_imageset (context, current); + } else + if (g_strcmp0 (name, "action") == 0) { + sprite_context_add_action (context, current, included_from); + } else + if (g_strcmp0 (name, "saedit") == 0) { + if (included_from == -1) { /* we are in the main context */ + xml_setup_setup (current); + } + } else { + /* TODO: sprite contains something unknown */ + } + } +} + +Action * +sprite_context_get_action ( + const SpriteContext *context, + gint hp, + const gchar *name +) { + GList *action = context->actions; + + while (action != NULL) { + if (action_hp_and_name_equals ( + (Action *) action->data, + hp, + name + )) { + return (Action *) action->data; + } + + action = g_list_next (action); + } + + return NULL; +} + +Imageset * +sprite_context_get_imageset ( + const SpriteContext *context, + const gchar *name +) { + GList *imageset = context->imagesets; + + while (imageset != NULL) { + if (imageset_name_equals ( + (Imageset *) imageset->data, + name + )) { + return (Imageset *) imageset->data; + } + + imageset = g_list_next (imageset); + } + + return NULL; +} + +GList * +sprite_context_get_actions ( + const SpriteContext *context +) { + return g_list_copy (context->actions); +} + +void +sprite_context_free ( + SpriteContext *context +) { + g_list_free_full ( + context->imagesets, + (GDestroyNotify) imageset_free + ); + + g_list_free_full ( + context->actions, + (GDestroyNotify) action_free + ); + + g_list_free_full ( + context->includes, + (GDestroyNotify) g_free + ); + + g_free (context->cdf_filename); + + g_free (context); +} |