Permalink
Browse files

implement project data saving

  • Loading branch information...
1 parent d7e46f7 commit 308e1bf6af209d08b889677dd99a6f3c5dd47b08 @sre sre committed Jan 29, 2012
Showing with 86 additions and 12 deletions.
  1. +46 −2 src/controller_main.vala
  2. +16 −4 src/model_party.vala
  3. +24 −6 src/model_vehicle.vala
View
48 src/controller_main.vala
@@ -229,8 +229,52 @@ public class MainController : Controller {
* Saves XML data to the .rproject and game.xml files.
*/
private void save_project_data () throws Error {
- /* TODO */
- warning("saving of project data not yet supported!");
+ XmlNode root, node;
+ string path_game = base_path + "data/game.xml";
+ string path_project = base_path + project_filename;
+ var writer = new XmlWriter ();
+
+ /* update project file */
+ root = new XmlNode ("project");
+
+ node = new XmlNode ("current_layer");
+ node.content = this.main_view.get_current_layer ().to_int ().to_string ();
+ root.add_child (node);
+
+ node = new XmlNode ("current_map");
+ node.content = this.current_map.to_string ();
+ root.add_child (node);
+
+ node = new XmlNode ("current_scale");
+ node.content = this.main_view.get_current_scale ().to_int ().to_string ();
+ root.add_child (node);
+
+ writer.set_root (root);
+ writer.generate ();
+ writer.write (path_project);
+
+ /* update game file */
+ root = new XmlNode ("game");
+
+ node = new XmlNode ("title");
+ node.content = this.game_title;
+ root.add_child (node);
+
+ this.party.save_data(out node);
+ root.add_child (node);
+
+ this.boat.save_data(out node);
+ root.add_child (node);
+
+ this.ship.save_data(out node);
+ root.add_child (node);
+
+ this.airship.save_data(out node);
+ root.add_child (node);
+
+ writer.set_root (root);
+ writer.generate ();
+ writer.write (path_game);
}
/**
View
20 src/model_party.vala
@@ -18,7 +18,7 @@
*/
/**
- * Represents the party object in the editor.
+ * Represents the party object in the editor.
*/
public class Party : Model {
/*
@@ -39,7 +39,7 @@ public class Party : Model {
/**
* Loads the party data from an XmlNode object.
- *
+ *
* @param data An XmlNode that contains the party data.
*/
public override void load_data (XmlNode? data) {
@@ -79,7 +79,19 @@ public class Party : Model {
* @param data An XmlNode that contains the party data.
*/
public override void save_data (out XmlNode data) {
- /* TODO */
- data = null;
+ XmlNode node;
+ data = new XmlNode("party");
+
+ node = new XmlNode("map");
+ node.content = this.map_id.to_string ();
+ data.add_child(node);
+
+ node = new XmlNode("x_coordinate");
+ node.content = this.x.to_string ();
+ data.add_child(node);
+
+ node = new XmlNode("y_coordinate");
+ node.content = this.y.to_string ();
+ data.add_child(node);
}
}
View
30 src/model_vehicle.vala
@@ -18,7 +18,7 @@
*/
/**
- * Represents a vehicle object in the editor.
+ * Represents a vehicle object in the editor.
*/
public class Vehicle : Model {
/*
@@ -38,16 +38,22 @@ public class Vehicle : Model {
public int y {get; set; default = 0;}
/**
+ * The vehicle type
+ */
+ private string type;
+
+ /**
* Loads the vehicle data from an XmlNode object.
- *
+ *
* @param data An XmlNode that contains the vehicle data.
*/
public override void load_data (XmlNode? data) {
int map_id = 0;
int x = 0;
int y = 0;
-
+
if (data != null) {
+ type = data.name;
XmlNode node = data.children;
while (node != null) {
switch (node.name) {
@@ -75,11 +81,23 @@ public class Vehicle : Model {
/**
* Saves the vehicle data to an XmlNode object.
- *
+ *
* @param data An XmlNode that contains the vehicle data.
*/
public override void save_data (out XmlNode data) {
- /* TODO */
- data = null;
+ XmlNode node;
+ data = new XmlNode(this.type);
+
+ node = new XmlNode("map");
+ node.content = this.map_id.to_string ();
+ data.add_child(node);
+
+ node = new XmlNode("x_coordinate");
+ node.content = this.x.to_string ();
+ data.add_child(node);
+
+ node = new XmlNode("y_coordinate");
+ node.content = this.y.to_string ();
+ data.add_child(node);
}
}

0 comments on commit 308e1bf

Please sign in to comment.