Exemplo n.º 1
0
/* load_sprite: load all the sprites in SPRITE_INDEX and their graphics */
void load_sprites(void)
{
    size_t i, y;
    char bmpname[NAME_LN];
    scew_tree *t = NULL;
    scew_parser *p = NULL;
    scew_element *e = NULL;
    scew_element *r = NULL;
    SPRITE *s = NULL;

    /* setup the parser */
    p = scew_parser_create();
    scew_parser_ignore_whitespaces(p, 1);
    if (!scew_parser_load_file(p, SPRITE_INDEX)) {
        printf("%s\n", scew_error_expat_string(scew_error_code()));
        return;
    }
    t = scew_parser_tree(p);
    r = scew_tree_root(t);
    s = create_sprite();

    /* read all the sprites from SPRITE_INDEX */
    /* parse the SPRITE_INDEX file and outline the list with their names */
    e = scew_element_next(r, e);
    while (e) {
        strncpy(s->long_name, (char *) scew_element_name(e), LONG_NAME_LN);
        s->x = s->y = 0;
        sprite_list = append_sprite_list(s, sprite_list, &sprite_list_sz);
        e = scew_element_next(r, e);
    }

    /* load all their graphics and the sprite data */
    gfx_list = complete_sprite_list(sprite_list, sprite_list_sz, gfx_list,
                                    &gfx_list_sz);

    /* create a list_element for each of them and put them in a list */
    y = SPRITE_WIN.y;
    for (i = 0; i < sprite_list_sz; i++) {
        sprintf(bmpname, "%s0", sprite_list[i].name);
        spr_elem_lst = add_list_element(rec(SPRITE_WIN.x, y, LIST_ELEM_W,
                                            LIST_ELEM_H), 0, DEFAULT_COLOR,
                                        SEL_COLOR, sprite_list[i].name,
                                        search_gfx_list(bmpname, gfx_list,
                                                        gfx_list_sz),
                                        spr_elem_lst, &spr_elem_lst_sz);
        y += LIST_ELEM_H;
    }

    /* cleanup */
    scew_element_free(r);
    destroy_sprite(s);
    scew_element_free(e);
    scew_parser_free(p);
}
Exemplo n.º 2
0
/* get_grid_item: updates the grid_item with fresh data */
void get_grid_item(void)
{
    int x, y;
    scew_attribute *a = NULL;
    scew_element *e = NULL;
    scew_element *sub_e = NULL;
    scew_element *r = NULL;

    POINT p;

    if (!maptree)
        return;

    p = get_mouse_pos();
    x = p.x - (p.x % TILE_W);
    y = p.y - (p.y % TILE_H) + map_offset;

    r = scew_tree_root(maptree);

    if (mode == TILE_MODE) {
        e = scew_element_by_name(r, "Tiles");
    } else if (mode == SPRITE_MODE) {
        e = scew_element_by_name(r, "Sprites");
    } else
        return;

    sub_e = scew_element_next(e, sub_e);

    while (sub_e) {
        a = scew_attribute_by_name(sub_e, "x");
        if (x == atoi(scew_attribute_value(a))) {
            a = scew_attribute_by_name(sub_e, "y");
            if (y == atoi(scew_attribute_value(a))) {
                grid_item.x = x;
                grid_item.y = y;
                grid_item.mode = mode;

                a = scew_attribute_by_name(sub_e, "name");
                strncpy(grid_item.name, scew_attribute_value(a), NAME_LN);

                if (mode == TILE_MODE) {
                    a = scew_attribute_by_name(sub_e, "passable");
                    grid_item.passable = atoi(scew_attribute_value(a));
                } else {
                    grid_item.passable = -1;
                }
                break;
            }
        }
        sub_e = scew_element_next(e, sub_e);
    }
}
Exemplo n.º 3
0
Arquivo: sdew.c Projeto: naadsm/sdew
/*******************************************************************************
 *  Function:  Element_Next
 *
 *  This function returns a void * representing a pointer to a valid
 *  scew_element structure, which is the next child element of the _parent
 *  parameter, or if _parent is NULL, then the next sibling of the _element
 *  parameter.
 *
 *  Parameters:
 *    _parent:  void * which represents a pointer to a scew_element.  This
 *              pointer must have been created previously by some other function
 *              in this library.
 *    _element:  void * which represents a pointer to a scew_element.  This
 *              pointer must have been created previously by some other function
 *              in this library.
 *
 *  Returns:
 *    void *:  Representing a pointer to a valid scew_element structure, which
 *             meets the constraints of the input parameters, or NULL on error.
 *
 ******************************************************************************/
DLLIMPORT void *Element_Next( void *_parent, void *_element )
{
   void *ret_val = NULL;

   ret_val = scew_element_next( (scew_element *)_parent, (scew_element *)_element );
   return ret_val;
}
Exemplo n.º 4
0
void
element_print(scew_element const* element, FILE* out, unsigned int indent)
{
    unsigned int closed = 0;
    XML_Char const* contents;
    scew_element* child = NULL;
    scew_attribute* attribute = NULL;

    if (element == NULL)
    {
        return;
    }

    indent_print(out, indent);
    scew_fprintf(out, _XT("<%s"), scew_element_name(element));
    attribute = NULL;
    while ((attribute = scew_attribute_next(element, attribute)) != NULL)
    {
        attribute_print(attribute, out);
    }

    contents = scew_element_contents(element);
    if ((contents == NULL) && (element->child == NULL)
        && (element->parent != NULL))
    {
		scew_fprintf(out, _XT("/>\n"));
        closed = 1;
    }
    else
    {
        scew_fprintf(out, _XT(">"));
        if (contents == NULL)
        {
            scew_fprintf(out, _XT("\n"));
        }
    }

    child = NULL;
    while ((child = scew_element_next(element, child)) != NULL)
    {
        element_print(child, out, indent + 1);
    }

    if (contents != NULL)
    {
        scew_fprintf(out, _XT("%s"), contents);
    }
    else if (!closed)
    {
        indent_print(out, indent);
    }

    if (!closed)
    {
        scew_fprintf(out, _XT("</%s>\n"), scew_element_name(element));
    }
}
Exemplo n.º 5
0
scew_element*
scew_element_by_name(scew_element const* parent, XML_Char const* name)
{
    scew_element* element = NULL;

    assert(parent != NULL);

    if (name == NULL)
    {
        return NULL;
    }

    element = scew_element_next(parent, 0);
    while (element && scew_strcmp(element->name, name))
    {
        element = scew_element_next(parent, element);
    }

    return element;
}