zoomedit:
* Instance: Added createLevel and loadLevel methods.
This commit is contained in:
parent
3e81e7e05f
commit
b27a517af7
5 changed files with 61 additions and 16 deletions
|
@ -24,10 +24,12 @@ namespace Data {
|
||||||
|
|
||||||
Info::Info(xmlpp::Element *node) {
|
Info::Info(xmlpp::Element *node) {
|
||||||
nameNode = dynamic_cast<xmlpp::Element*>(node->get_children("name").front());
|
nameNode = dynamic_cast<xmlpp::Element*>(node->get_children("name").front());
|
||||||
name = nameNode->get_child_text()->get_content();
|
if(nameNode->has_child_text())
|
||||||
|
name = nameNode->get_child_text()->get_content();
|
||||||
|
|
||||||
descNode = dynamic_cast<xmlpp::Element*>(node->get_children("desc").front());
|
descNode = dynamic_cast<xmlpp::Element*>(node->get_children("desc").front());
|
||||||
desc = descNode->get_child_text()->get_content();
|
if(descNode->has_child_text())
|
||||||
|
desc = descNode->get_child_text()->get_content();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ class Info {
|
||||||
|
|
||||||
void setName(const Glib::ustring &n) {
|
void setName(const Glib::ustring &n) {
|
||||||
name = n;
|
name = n;
|
||||||
nameNode->get_child_text()->set_content(n);
|
nameNode->set_child_text(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Glib::ustring& getDescription() const {
|
const Glib::ustring& getDescription() const {
|
||||||
|
@ -52,7 +52,7 @@ class Info {
|
||||||
|
|
||||||
void setDescription(const Glib::ustring &d) {
|
void setDescription(const Glib::ustring &d) {
|
||||||
desc = d;
|
desc = d;
|
||||||
descNode->get_child_text()->set_content(d);
|
descNode->set_child_text(d);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace ZoomEdit {
|
||||||
|
|
||||||
guint Instance::instances = 0;
|
guint Instance::instances = 0;
|
||||||
|
|
||||||
Instance::Instance() : window(NULL), levelXml(NULL), level(NULL) {
|
Instance::Instance(const Glib::ustring &file) : window(NULL), levelXml(NULL), level(NULL) {
|
||||||
instances++;
|
instances++;
|
||||||
|
|
||||||
#ifdef GLIBMM_EXCEPTIONS_ENABLED
|
#ifdef GLIBMM_EXCEPTIONS_ENABLED
|
||||||
|
@ -57,11 +57,10 @@ Instance::Instance() : window(NULL), levelXml(NULL), level(NULL) {
|
||||||
|
|
||||||
window->signal_hide().connect(sigc::mem_fun(this, &Instance::destroy));
|
window->signal_hide().connect(sigc::mem_fun(this, &Instance::destroy));
|
||||||
|
|
||||||
levelXml = new xmlpp::DomParser("level.lvl");
|
if(file.empty())
|
||||||
xmlpp::Document *doc = levelXml->get_document();
|
createLevel();
|
||||||
|
else
|
||||||
if(doc && doc->get_root_node())
|
loadLevel(file);
|
||||||
level = new Data::Level(doc->get_root_node());
|
|
||||||
|
|
||||||
window->show();
|
window->show();
|
||||||
}
|
}
|
||||||
|
@ -81,10 +80,51 @@ Instance::~Instance() {
|
||||||
Gtk::Main::quit();
|
Gtk::Main::quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Instance::create() {
|
void Instance::createLevel() {
|
||||||
Instance *instance = new Instance();
|
if(level)
|
||||||
|
delete level;
|
||||||
|
|
||||||
if(!instance->xml) {
|
if(levelXml)
|
||||||
|
delete levelXml;
|
||||||
|
|
||||||
|
levelXml = new xmlpp::DomParser;
|
||||||
|
xmlpp::Document *doc = levelXml->get_document();
|
||||||
|
|
||||||
|
xmlpp::Element *root = doc->create_root_node("level");
|
||||||
|
|
||||||
|
xmlpp::Element *info = root->add_child("info");
|
||||||
|
info->add_child("name");
|
||||||
|
info->add_child("desc");
|
||||||
|
xmlpp::Element *start = info->add_child("start");
|
||||||
|
start->set_attribute("x", "0");
|
||||||
|
start->set_attribute("y", "0");
|
||||||
|
start->set_attribute("z", "0");
|
||||||
|
|
||||||
|
root->add_child("rooms");
|
||||||
|
root->add_child("gates");
|
||||||
|
root->add_child("textures");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Instance::loadLevel(const Glib::ustring &file) {
|
||||||
|
if(level)
|
||||||
|
delete level;
|
||||||
|
|
||||||
|
if(levelXml)
|
||||||
|
delete levelXml;
|
||||||
|
|
||||||
|
levelXml = new xmlpp::DomParser(file);
|
||||||
|
xmlpp::Document *doc = levelXml->get_document();
|
||||||
|
|
||||||
|
if(doc && doc->get_root_node())
|
||||||
|
level = new Data::Level(doc->get_root_node());
|
||||||
|
|
||||||
|
return (level != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Instance::create(const Glib::ustring &file) {
|
||||||
|
Instance *instance = new Instance(file);
|
||||||
|
|
||||||
|
if(!instance->level) {
|
||||||
delete instance;
|
delete instance;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,10 @@ class Instance {
|
||||||
public:
|
public:
|
||||||
virtual ~Instance();
|
virtual ~Instance();
|
||||||
|
|
||||||
static bool create();
|
void createLevel();
|
||||||
|
bool loadLevel(const Glib::ustring &file);
|
||||||
|
|
||||||
|
static bool create(const Glib::ustring &file = Glib::ustring());
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static guint instances;
|
static guint instances;
|
||||||
|
@ -49,7 +52,7 @@ class Instance {
|
||||||
xmlpp::DomParser *levelXml;
|
xmlpp::DomParser *levelXml;
|
||||||
Data::Level *level;
|
Data::Level *level;
|
||||||
|
|
||||||
Instance();
|
Instance(const Glib::ustring &file);
|
||||||
|
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ int main(int argc, char *argv[]) {
|
||||||
Gtk::Main gtk(&argc, &argv);
|
Gtk::Main gtk(&argc, &argv);
|
||||||
gtk_gl_init(&argc, &argv);
|
gtk_gl_init(&argc, &argv);
|
||||||
|
|
||||||
if(!ZoomEdit::Instance::create())
|
if(!ZoomEdit::Instance::create("level.lvl"))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
gtk.run();
|
gtk.run();
|
||||||
|
|
Reference in a new issue