config &config::add_child(const std::string &key, config &&val) { check_valid(val); child_list &v = children[key]; v.push_back(new config(std::move(val))); ordered_children.push_back(child_pos(children.find(key), v.size() - 1)); return *v.back(); }
static int child_pos(struct sprite *s, struct srt *srt, struct sprite_trans *ts, struct sprite *t, int pos[2]) { struct sprite_trans temp; struct matrix temp_matrix; struct sprite_trans *st = trans_mul(&s->t, ts, &temp, &temp_matrix); if (s == t) { struct matrix tmp; if (st->mat == NULL) { matrix_identity(&tmp); } else { tmp = *st->mat; } matrix_srt(&tmp, srt); switch (s->type) { case TYPE_PICTURE: picture_pos(tmp.m, s->s.pic, srt, st, pos); return 0; case TYPE_LABEL: label_pos(tmp.m, s->s.label, srt, st, pos); return 0; case TYPE_ANIMATION: case TYPE_PANNEL: pos[0] = tmp.m[4] / SCREEN_SCALE; pos[1] = tmp.m[5] / SCREEN_SCALE; return 0; default: return 1; } } if (s->type != TYPE_ANIMATION){ return 1; } struct pack_animation *ani = s->s.ani; int frame = real_frame(s) + s->start_frame; struct pack_frame * pf = &ani->frame[frame]; int i; for (i=0;i<pf->n;i++) { struct pack_part *pp = &pf->part[i]; int index = pp->component_id; struct sprite * child = s->data.children[index]; if (child == NULL) { continue; } struct sprite_trans temp2; struct matrix temp_matrix2; struct sprite_trans *ct = trans_mul(&pp->t, st, &temp2, &temp_matrix2); if (child_pos(child, srt, ct, t, pos) == 0) { return 0; } } return 1; }
void config::splice_children(config &src, const std::string &key) { check_valid(src); child_map::iterator i_src = src.children.find(key); if (i_src == src.children.end()) return; src.ordered_children.erase(std::remove_if(src.ordered_children.begin(), src.ordered_children.end(), remove_ordered(i_src)), src.ordered_children.end()); child_list &dst = children[key]; child_map::iterator i_dst = children.find(key); unsigned before = dst.size(); dst.insert(dst.end(), i_src->second.begin(), i_src->second.end()); src.children.erase(i_src); // key might be a reference to i_src->first, so it is no longer usable. for (unsigned j = before; j < dst.size(); ++j) { ordered_children.push_back(child_pos(i_dst, j)); } }
int sprite_pos(struct sprite *s, struct srt *srt, struct sprite *t, int pos[2]) { return child_pos(s, srt, NULL, t, pos); }