summaryrefslogtreecommitdiff
path: root/saedit/sae.c
diff options
context:
space:
mode:
authorVasily_Makarov <danilka.pro@gmail.com>2012-02-09 12:07:10 +0400
committerVasily_Makarov <danilka.pro@gmail.com>2012-02-09 12:07:10 +0400
commitcc459a0b40bb56f6559c855ecb5b956b9ee6a90b (patch)
tree8698d1e99eec34b24f14f21c176871b88863fa18 /saedit/sae.c
parent6545f58904d754db19800a1cd21f472eb13339bd (diff)
downloadtools-cc459a0b40bb56f6559c855ecb5b956b9ee6a90b.tar.gz
tools-cc459a0b40bb56f6559c855ecb5b956b9ee6a90b.tar.bz2
tools-cc459a0b40bb56f6559c855ecb5b956b9ee6a90b.tar.xz
tools-cc459a0b40bb56f6559c855ecb5b956b9ee6a90b.zip
SAE: Changed error structure
Diffstat (limited to 'saedit/sae.c')
-rw-r--r--saedit/sae.c200
1 files changed, 100 insertions, 100 deletions
diff --git a/saedit/sae.c b/saedit/sae.c
index e2627a7..2b9abb6 100644
--- a/saedit/sae.c
+++ b/saedit/sae.c
@@ -12,122 +12,122 @@
#include "sae.h"
void kill_timeout(guint tag) {
- if (tag > 0)
- g_source_remove(tag);
+ if (tag > 0)
+ g_source_remove(tag);
}
Frame *frame_new(int index, int offsetX, int offsetY, int delay) {
- Frame *res = g_new0(Frame, 1);
- res->index = index;
- res->offsetX = offsetX;
- res->offsetY = offsetY;
- res->delay = delay;
- return res;
+ Frame *res = g_new0(Frame, 1);
+ res->index = index;
+ res->offsetX = offsetX;
+ res->offsetY = offsetY;
+ res->delay = delay;
+ return res;
}
Imageset *imageset_new() {
- Imageset *res = g_new0(Imageset, 1);
- res->width = SPRITE_WIDTH_DEFAULT;
- res->height = SPRITE_HEIGHT_DEFAULT;
- return res;
+ Imageset *res = g_new0(Imageset, 1);
+ res->width = SPRITE_WIDTH_DEFAULT;
+ res->height = SPRITE_HEIGHT_DEFAULT;
+ return res;
}
SAEInfo *sae_info_new() {
- SAEInfo *res = g_new0(SAEInfo, 1);
- res->ground = sae_info_ground_new();
- res->sprite = frame_new(-1, 0, 0, 0);
- res->imageset = imageset_new();
- return res;
+ SAEInfo *res = g_new0(SAEInfo, 1);
+ res->ground = sae_info_ground_new();
+ res->sprite = frame_new(-1, 0, 0, 0);
+ res->imageset = imageset_new();
+ return res;
}
GdkPixbuf *sae_info_ground_new() {
- GdkPixbuf *ground = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, GRID_SIZE * 3, GRID_SIZE * 3);
- gdk_pixbuf_fill(ground, 0x00000000);
- return ground;
+ GdkPixbuf *ground = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, GRID_SIZE * 3, GRID_SIZE * 3);
+ gdk_pixbuf_fill(ground, 0x00000000);
+ return ground;
}
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);
+ 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);
}
gboolean set_up_animation_by_direction(SAEInfo *sae_info, const gchar *direction) {
- if (sae_info->imageset->spriteset == NULL)
- return FALSE;
- sae_info->animation = NULL;
-
- GList *list = g_list_find_custom(sae_info->animations,
- xml_attr_new("direction", 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;
-
- int offsetX = 0, offsetY = 0,
- delay = 0,
- start = -1, end = -1,
- repeat = 1;
-
- 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);
-
- 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");
- if (start_attr != NULL)
- sscanf(start_attr, "%d", &start);
-
- gchar *end_attr = xml_node_get_attr_value(node, "end");
- if (end_attr != NULL)
- sscanf(end_attr, "%d", &end);
-
- gchar *repeat_attr = xml_node_get_attr_value(node, "repeat");
- if (repeat_attr != NULL)
- sscanf(repeat_attr, "%d", &repeat);
- }
-
- if (start >= 0) {
- 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;
- }
- }
- }
- }
- list = g_list_next(list);
- }
- if (sae_info->animation == NULL)
- return FALSE;
-
- return TRUE;
+ if (sae_info->imageset->spriteset == NULL)
+ return FALSE;
+ sae_info->animation = NULL;
+
+ GList *list = g_list_find_custom(sae_info->animations,
+ xml_attr_new("direction", 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;
+
+ int offsetX = 0, offsetY = 0,
+ delay = 0,
+ start = -1, end = -1,
+ repeat = 1;
+
+ 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);
+
+ 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");
+ if (start_attr != NULL)
+ sscanf(start_attr, "%d", &start);
+
+ gchar *end_attr = xml_node_get_attr_value(node, "end");
+ if (end_attr != NULL)
+ sscanf(end_attr, "%d", &end);
+
+ gchar *repeat_attr = xml_node_get_attr_value(node, "repeat");
+ if (repeat_attr != NULL)
+ sscanf(repeat_attr, "%d", &repeat);
+ }
+
+ if (start >= 0) {
+ 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;
+ }
+ }
+ }
+ }
+ list = g_list_next(list);
+ }
+ if (sae_info->animation == NULL)
+ return FALSE;
+
+ return TRUE;
}