1 /******************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
7 #include <libxml/parser.h>
8 #include <libxml/tree.h>
13 #include "resourcer.h"
17 World::World(Resourcer
* rc
, GameWindow
* wnd
)
18 : rc(rc
), wnd(wnd
), area(NULL
), player(NULL
)
30 if (!processDescriptor()) // Try to load in descriptor.
33 // FIXME The player entity doesn't have a descriptor yet.
34 player
= new Entity(rc
, "_NONE_", xml
.playersprite
);
38 area
= new Area(rc
, player
, xml
.entry
.area
);
40 wnd
->setCaption(Gosu::widen(xml
.name
));
44 void World::buttonDown(const Gosu::Button btn
)
46 area
->buttonDown(btn
);
54 bool World::needsRedraw() const
56 return area
->needsRedraw();
59 bool World::processDescriptor()
61 static const std::string descriptor
= "world.conf";
64 xmlDoc
* doc
= rc
->getXMLDoc(descriptor
);
67 const xmlNode
* root
= xmlDocGetRootElement(doc
);
73 xmlNode
* node
= root
->xmlChildrenNode
; // <world>
74 node
= node
->xmlChildrenNode
; // decend into children of <world>
75 for (; node
!= NULL
; node
= node
->next
) {
76 if (!xmlStrncmp(node
->name
, BAD_CAST("name"), 5)) {
77 str
= xmlNodeGetContent(node
);
78 xml
.name
= (char*)str
;
80 if (!xmlStrncmp(node
->name
, BAD_CAST("author"), 7)) {
81 str
= xmlNodeGetContent(node
);
82 xml
.author
= (char*)str
;
84 if (!xmlStrncmp(node
->name
, BAD_CAST("type"), 5)) {
85 str
= xmlNodeGetContent(node
);
87 if (xmlStrncmp(str
, BAD_CAST("local"), 6))
90 if (xmlStrncmp(str
, BAD_CAST("network"), 8))
95 Log::err(descriptor
, "Invalid <type> value");
99 if (!xmlStrncmp(node
->name
, BAD_CAST("player"), 7)) {
100 str
= xmlGetProp(node
, BAD_CAST("sprite"));
101 xml
.playersprite
= (char*)str
;
103 if (!xmlStrncmp(node
->name
, BAD_CAST("entrypoint"), 11)) {
104 str
= xmlGetProp(node
, BAD_CAST("area"));
105 xml
.entry
.area
= (char*)str
;
107 str
= xmlGetProp(node
, BAD_CAST("x"));
108 xml
.entry
.coords
.x
= atol((char*)str
);
110 str
= xmlGetProp(node
, BAD_CAST("y"));
111 xml
.entry
.coords
.y
= atol((char*)str
);
113 str
= xmlGetProp(node
, BAD_CAST("z"));
114 xml
.entry
.coords
.z
= atol((char*)str
);
116 if (!xmlStrncmp(node
->name
, BAD_CAST("eventscripts"), 13)) {
117 node
= node
->xmlChildrenNode
; // decend
119 if (!xmlStrncmp(node
->name
, BAD_CAST("script"), 7)) {
120 str
= xmlNodeGetContent(node
);
121 xml
.scripts
.push_back((char*)str
);