aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic
diff options
context:
space:
mode:
authorPaul Gilbert2016-02-18 23:07:01 -0500
committerPaul Gilbert2016-02-18 23:07:01 -0500
commitad8450209a553fd06540cd01ab29f936c0d0dc29 (patch)
tree3a018c9b4697bbde0274e9bfbeced1c439d190dc /engines/titanic
parente2aca904ec8c0e0f23124b00b4b1eb525105f95e (diff)
downloadscummvm-rg350-ad8450209a553fd06540cd01ab29f936c0d0dc29.tar.gz
scummvm-rg350-ad8450209a553fd06540cd01ab29f936c0d0dc29.tar.bz2
scummvm-rg350-ad8450209a553fd06540cd01ab29f936c0d0dc29.zip
TITANIC: Implement overall game saving code
Diffstat (limited to 'engines/titanic')
-rw-r--r--engines/titanic/compressed_file.h2
-rw-r--r--engines/titanic/objects/project_item.cpp55
-rw-r--r--engines/titanic/objects/project_item.h31
-rw-r--r--engines/titanic/objects/tree_item.cpp28
-rw-r--r--engines/titanic/objects/tree_item.h53
5 files changed, 160 insertions, 9 deletions
diff --git a/engines/titanic/compressed_file.h b/engines/titanic/compressed_file.h
index 56e2c23343..cd9cf8377d 100644
--- a/engines/titanic/compressed_file.h
+++ b/engines/titanic/compressed_file.h
@@ -68,7 +68,7 @@ private:
int sub1(Method3Fn fn, int v);
- void sub2();
+ void sub2() {}
public:
Decompressor();
diff --git a/engines/titanic/objects/project_item.cpp b/engines/titanic/objects/project_item.cpp
index 90f85d97b9..e75f0e01e9 100644
--- a/engines/titanic/objects/project_item.cpp
+++ b/engines/titanic/objects/project_item.cpp
@@ -27,7 +27,15 @@
namespace Titanic {
-void CProjectItem::load(int id) {
+void CProjectItem::save(SimpleFile *file, int indent) const {
+ error("TODO");
+}
+
+void CProjectItem::load(SimpleFile *file) {
+ error("TODO");
+}
+
+void CProjectItem::loadGame(int slotId) {
CompressedFile file;
Common::InSaveFile *saveFile = nullptr;
@@ -35,16 +43,28 @@ void CProjectItem::load(int id) {
clear();
// Open either an existing savegame slot or the new game template
- if (id > 0) {
+ if (slotId > 0) {
saveFile = g_system->getSavefileManager()->openForLoading(
- Common::String::format("slot%d.gam", id));
+ Common::String::format("slot%d.gam", slotId));
file.open(saveFile);
} else {
file.open("newgame.st");
}
// Load the contents in
- loadData(file);
+ loadData(&file);
+
+ file.close();
+}
+
+void CProjectItem::saveGame(int slotId) {
+ CompressedFile file;
+ Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(
+ Common::String::format("slot%d.gam", slotId));
+ file.open(saveFile);
+
+ // Save the contents out
+ saveData(&file, this);
file.close();
}
@@ -53,8 +73,33 @@ void CProjectItem::clear() {
}
-void CProjectItem::loadData(SimpleFile &file) {
+void CProjectItem::loadData(SimpleFile *file) {
}
+void CProjectItem::saveData(SimpleFile *file, CTreeItem *item) const {
+ while (item) {
+ item->saveHeader(file, 0);
+ item->save(file, 1);
+ item->saveFooter(file, 0);
+
+
+ CTreeItem *child = item->getFirstChild();
+ if (child) {
+ file->write("\n{\n", 3);
+ file->writeQuotedString("DOWN");
+ file->write("\n}\n", 3);
+ saveData(file, child);
+ file->write("\n{\n", 3);
+ file->writeQuotedString("UP");
+ } else {
+ file->write("\n{\n", 3);
+ file->writeQuotedString("ALONG");
+ }
+
+ file->write("\n}\n", 3);
+ item = item->getNextSibling();
+ }
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/objects/project_item.h b/engines/titanic/objects/project_item.h
index 93f6e17ef0..6277af85c3 100644
--- a/engines/titanic/objects/project_item.h
+++ b/engines/titanic/objects/project_item.h
@@ -34,12 +34,37 @@ private:
/**
* Load project data from the passed file
*/
- void loadData(SimpleFile &file);
+ void loadData(SimpleFile *file);
+
+ /**
+ * Save project data to the passed file
+ */
+ void saveData(SimpleFile *file, CTreeItem *item) const;
public:
/**
- * Load the entire project data for a given Id
+ * Return the class name
+ */
+ virtual const char *getClassName() const { return "CProjectItem"; }
+
+ /**
+ * Save the data for the class to file
+ */
+ virtual void save(SimpleFile *file, int indent) const;
+
+ /**
+ * Load the data for the class from file
+ */
+ virtual void load(SimpleFile *file);
+
+ /**
+ * Load the entire project data for a given slot Id
+ */
+ void loadGame(int slotId);
+
+ /**
+ * Save the entire project data to a given savegame slot
*/
- void load(int id);
+ void saveGame(int slotId);
/**
* Clear any currently loaded project
diff --git a/engines/titanic/objects/tree_item.cpp b/engines/titanic/objects/tree_item.cpp
index 06128ce354..dcd0e4606f 100644
--- a/engines/titanic/objects/tree_item.cpp
+++ b/engines/titanic/objects/tree_item.cpp
@@ -24,4 +24,32 @@
namespace Titanic {
+CTreeItem::CTreeItem() : _parent(nullptr), _firstChild(nullptr),
+ _nextSibling(nullptr), _priorSibling(nullptr), _field14(0) {
+}
+
+void CTreeItem::save(SimpleFile *file, int indent) const {
+ file->writeNumberLine(0, indent);
+ CMessageTarget::save(file, indent);
+}
+
+void CTreeItem::load(SimpleFile *file) {
+ file->readNumber();
+ CMessageTarget::load(file);
+}
+
+CTreeItem *CTreeItem::getLastSibling() {
+ CTreeItem *item = this;
+ while (item->getNextSibling())
+ item = item->getNextSibling();
+
+ return item;
+}
+
+CTreeItem *CTreeItem::getLastChild() {
+ if (!_firstChild)
+ return nullptr;
+ return _firstChild->getLastSibling();
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/objects/tree_item.h b/engines/titanic/objects/tree_item.h
index 170a0e905d..454c3ca8ca 100644
--- a/engines/titanic/objects/tree_item.h
+++ b/engines/titanic/objects/tree_item.h
@@ -28,6 +28,59 @@
namespace Titanic {
class CTreeItem: public CMessageTarget {
+private:
+ CTreeItem *_parent;
+ CTreeItem *_nextSibling;
+ CTreeItem *_priorSibling;
+ CTreeItem *_firstChild;
+ int _field14;
+public:
+ CTreeItem();
+
+ /**
+ * Return the class name
+ */
+ virtual const char *getClassName() const { return "CTreeItem"; }
+
+ /**
+ * Save the data for the class to file
+ */
+ virtual void save(SimpleFile *file, int indent) const;
+
+ /**
+ * Load the data for the class from file
+ */
+ virtual void load(SimpleFile *file);
+
+ /**
+ * Get the parent for the given item
+ */
+ CTreeItem *getParent() const { return _parent; }
+
+ /**
+ * Get the next sibling
+ */
+ CTreeItem *getNextSibling() { return _nextSibling; }
+
+ /**
+ * Get the prior sibling
+ */
+ CTreeItem *getPriorSibling() { return _priorSibling; }
+
+ /**
+ * Get the last sibling of this sibling
+ */
+ CTreeItem *getLastSibling();
+
+ /**
+ * Get the first child of the item, if any
+ */
+ CTreeItem *getFirstChild() { return _firstChild; }
+
+ /**
+ * Get the last child of the item, if any
+ */
+ CTreeItem *getLastChild();
};
} // End of namespace Titanic