summaryrefslogtreecommitdiff
path: root/src/material/material.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/material/material.c')
-rw-r--r--src/material/material.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/material/material.c b/src/material/material.c
new file mode 100644
index 0000000..65e13d2
--- /dev/null
+++ b/src/material/material.c
@@ -0,0 +1,77 @@
+#include <kalmia.h>
+#include "util/util.h"
+#include "xml/xml.h"
+
+
+int kai_read_instance_effect(struct ka_instance_effect_t *dest, struct kai_tag_t *src)
+{
+ KAI_CHECK_TAG_TYPE("instance_effect");
+
+ char *url = kai_tag_attr_to_dup(src, "url");
+ if (url == NULL) { return -1; }
+
+ dest->sid = kai_tag_attr_to_dup(src, "sid");
+ dest->name = kai_tag_attr_to_dup(src, "name");
+ dest->url = url;
+
+ return 0;
+}
+
+void kai_release_instance_effect(struct ka_instance_effect_t i)
+{
+ free(i.sid);
+ free(i.name);
+ free(i.url);
+}
+
+
+int kai_read_material(struct ka_material_t *dest, struct kai_tag_t *src)
+{
+ KAI_CHECK_TAG_TYPE("material");
+
+ struct kai_tag_t *child = kai_tag_get_first_child_with_type(src, "instance_effect");
+ if (child == NULL) { return -1; }
+ int result = kai_read_instance_effect(&(dest->instance_effect), child);
+ if (result != 0) { return -1; }
+
+ dest->id = kai_tag_attr_to_dup(src, "id");
+ dest->name = kai_tag_attr_to_dup(src, "name");
+
+ return 0;
+}
+
+void kai_release_material(struct ka_material_t m)
+{
+ free(m.id);
+ free(m.name);
+ kai_release_instance_effect(m.instance_effect);
+}
+
+
+int kai_read_library_materials(struct ka_library_materials_t *dest, struct kai_tag_t *src)
+{
+ int result;
+ KAI_FILL_ARRAY_FROM_TAGS(
+ result,
+ dest->material, dest->material_count, struct ka_material_t,
+ src, "material",
+ kai_read_material, kai_release_material
+ );
+ if (result != 0) { return -1; }
+
+ dest->id = kai_tag_attr_to_dup(src, "id");
+ dest->name = kai_tag_attr_to_dup(src, "name");
+
+ return 0;
+}
+
+void kai_release_library_materials(struct ka_library_materials_t l)
+{
+ free(l.id);
+ free(l.name);
+ int i;
+ for (i=0; i<l.material_count; i++) {
+ kai_release_material(l.material[i]);
+ }
+ free(l.material);
+}