summaryrefslogtreecommitdiff
path: root/saedit
diff options
context:
space:
mode:
authorVasily_Makarov <danilka.pro@gmail.com>2012-03-31 23:35:49 +0400
committerVasily_Makarov <danilka.pro@gmail.com>2012-03-31 23:35:49 +0400
commit36e5c2a02596020c0f261b0d8222e254009cb040 (patch)
treeac8ec3472ea13023f8fe572e2f4b5fe7ac55f1b7 /saedit
parent4d8df469f5c04c9559cf480b0e5bad2b40d213f6 (diff)
downloadtools-36e5c2a02596020c0f261b0d8222e254009cb040.tar.gz
tools-36e5c2a02596020c0f261b0d8222e254009cb040.tar.bz2
tools-36e5c2a02596020c0f261b0d8222e254009cb040.tar.xz
tools-36e5c2a02596020c0f261b0d8222e254009cb040.zip
SAE: Added sequence value and pause support
Diffstat (limited to 'saedit')
-rw-r--r--saedit/sae.c122
1 files changed, 101 insertions, 21 deletions
diff --git a/saedit/sae.c b/saedit/sae.c
index 2b9abb6..3d42858 100644
--- a/saedit/sae.c
+++ b/saedit/sae.c
@@ -47,9 +47,41 @@ GdkPixbuf *sae_info_ground_new() {
}
GdkPixbuf* get_sprite_by_index(size_t index, SAEInfo *sae_info) {
- size_t w = sae_info->imageset->spriteset_width/sae_info->imageset->width;
- if (sae_info->imageset->spriteset == NULL) return NULL;
- return gdk_pixbuf_new_subpixbuf(sae_info->imageset->spriteset, index%w*sae_info->imageset->width, index/w*sae_info->imageset->height, sae_info->imageset->width, sae_info->imageset->height);
+
+ if (index == -1) {
+ GdkPixbuf *res = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8,
+ sae_info->imageset->width,
+ sae_info->imageset->height);
+ gdk_pixbuf_fill(res, 0x00000000);
+ return res;
+ }
+
+ if (index >= 0) {
+ size_t w = sae_info->imageset->spriteset_width/sae_info->imageset->width;
+ if (sae_info->imageset->spriteset == NULL) return NULL;
+
+ return gdk_pixbuf_new_subpixbuf(sae_info->imageset->spriteset,
+ index%w*sae_info->imageset->width,
+ index/w*sae_info->imageset->height,
+ sae_info->imageset->width,
+ sae_info->imageset->height);
+ }
+
+ return NULL;
+}
+
+inline void _add_frame(SAEInfo *sae_info, size_t index, size_t offsetX, size_t offsetY, size_t delay, size_t line) {
+
+ Frame *sprite = frame_new(index, offsetX, offsetY, delay);
+ sprite->line_number = line;
+ sprite->pixbuf = get_sprite_by_index(index, sae_info);
+
+ if (sae_info->animation != NULL)
+ sae_info->animation = g_list_append(sae_info->animation, sprite);
+ else {
+ sae_info->animation = g_list_alloc();
+ sae_info->animation->data = sprite;
+ }
}
gboolean set_up_animation_by_direction(SAEInfo *sae_info, const gchar *direction) {
@@ -62,36 +94,41 @@ gboolean set_up_animation_by_direction(SAEInfo *sae_info, const gchar *direction
(GCompareFunc)xml_node_compare_with_attr_func);
if (list == NULL)
return FALSE;
- int count = 0;
+
XMLNode *anode = list->data;
list = anode->sub_nodes;
while (list != NULL) {
XMLNode *node = list->data;
+ //sequence tag attributes
int offsetX = 0, offsetY = 0,
delay = 0,
start = -1, end = -1,
repeat = 1;
+ gchar *value = NULL;
+
+ gchar *ofX_attr, *ofY_attr;
+ ofX_attr = xml_node_get_attr_value(node, "offsetX");
+ if (ofX_attr != NULL)
+ sscanf(ofX_attr, "%d", &offsetX);
- gchar *ofX_param, *ofY_param;
- ofX_param = xml_node_get_attr_value(node, "offsetX");
- if (ofX_param != NULL)
- sscanf(ofX_param, "%d", &offsetX);
- ofY_param = xml_node_get_attr_value(node, "offsetY");
- if (ofY_param != NULL)
- sscanf(ofY_param, "%d", &offsetY);
+ ofY_attr = xml_node_get_attr_value(node, "offsetY");
+ if (ofY_attr != NULL)
+ sscanf(ofY_attr, "%d", &offsetY);
gchar *delay_attr = xml_node_get_attr_value(node, "delay");
if (delay_attr != NULL)
sscanf(delay_attr, "%d", &delay);
if (g_str_equal(node->name, "frame")) {
+
gchar *index_attr = xml_node_get_attr_value(node, "index");
if (index_attr != NULL) {
sscanf(index_attr, "%d", &start);
end = start;
}
+
} else if (g_str_equal(node->name, "sequence")) {
gchar *start_attr = xml_node_get_attr_value(node, "start");
@@ -102,28 +139,71 @@ gboolean set_up_animation_by_direction(SAEInfo *sae_info, const gchar *direction
if (end_attr != NULL)
sscanf(end_attr, "%d", &end);
+ value = xml_node_get_attr_value(node, "value");
+
+ gchar *repeat_attr = xml_node_get_attr_value(node, "repeat");
+ if (repeat_attr != NULL)
+ sscanf(repeat_attr, "%d", &repeat);
+
+ } else if (g_str_equal(node->name, "pause")) {
+
+ value = "p";
+
gchar *repeat_attr = xml_node_get_attr_value(node, "repeat");
if (repeat_attr != NULL)
sscanf(repeat_attr, "%d", &repeat);
+
}
- if (start >= 0) {
+ if (start >= 0) { //start-end case
+
int r = 0, i = 0;
for (r = 1; r <= repeat; r++) {
for (i = start; i <= end; i++) {
- Frame *sprite = frame_new(i, offsetX, offsetY, delay);
- sprite->line_number = node->line_number;
- sprite->pixbuf = get_sprite_by_index(i, sae_info);
- count++;
- if (sae_info->animation != NULL)
- sae_info->animation = g_list_append(sae_info->animation, sprite);
- else {
- sae_info->animation = g_list_alloc();
- sae_info->animation->data = sprite;
+ _add_frame(sae_info, i, offsetX, offsetY, delay, node->line_number);
+ }
+ }
+
+ } else
+ if (value != NULL) { //value case
+
+ gchar **values = g_strsplit(value, ",", 0);
+
+ int r;
+ for (r = 0; r < repeat; r++) { //TODO: remove multiparsing
+ gchar **iter = values;
+ while (*iter != NULL) {
+
+ if (g_str_equal(*iter, "p")) { //pause
+
+ _add_frame(sae_info, -1, 0, 0, delay, node->line_number);
+
+ } else {
+
+ int f, s;
+
+ if (sscanf(*iter, "%u-%u", &f, &s) == 2) {
+
+ int i;
+ for (i = f; i <= s; i++) {
+ _add_frame(sae_info, i, offsetX, offsetY, delay, node->line_number);
+ }
+
+ } else if (sscanf(*iter, "%u", &f) == 1) {
+
+ _add_frame(sae_info, f, offsetX, offsetY, delay, node->line_number);
+
+ }
+
}
+ iter++;
}
}
+
+ g_strfreev(values);
+
}
+
list = g_list_next(list);
}
if (sae_info->animation == NULL)