aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2016-03-08 19:35:30 -0500
committerPaul Gilbert2016-03-08 19:35:30 -0500
commiteff4ed1ac1b432744de77014f3a7001753580b0e (patch)
treecb20c0a2bafb8a044f700593691d3092ae00293f
parentd1a29a1d1ad3ab60737f3a9a837907cd72562b63 (diff)
downloadscummvm-rg350-eff4ed1ac1b432744de77014f3a7001753580b0e.tar.gz
scummvm-rg350-eff4ed1ac1b432744de77014f3a7001753580b0e.tar.bz2
scummvm-rg350-eff4ed1ac1b432744de77014f3a7001753580b0e.zip
TITANIC: Fleshing out CProjectItem methods
-rw-r--r--engines/titanic/core/project_item.cpp62
-rw-r--r--engines/titanic/core/project_item.h31
-rw-r--r--engines/titanic/core/tree_item.h4
3 files changed, 97 insertions, 0 deletions
diff --git a/engines/titanic/core/project_item.cpp b/engines/titanic/core/project_item.cpp
index 354e373a53..e1f5ec4b34 100644
--- a/engines/titanic/core/project_item.cpp
+++ b/engines/titanic/core/project_item.cpp
@@ -294,4 +294,66 @@ CPetControl *CProjectItem::getPetControl() {
return nullptr;
}
+CRoomItem *CProjectItem::findFirstRoom() {
+ return dynamic_cast<CRoomItem *>(findChildInstance(*CRoomItem::_type));
+}
+
+CTreeItem *CProjectItem::findChildInstance(ClassDef &classDef) {
+ CTreeItem *treeItem = getFirstChild();
+ if (treeItem == nullptr)
+ return nullptr;
+
+ do {
+ CTreeItem *childItem = treeItem->getFirstChild();
+ if (childItem) {
+ do {
+ if (childItem->isInstanceOf(classDef))
+ return childItem;
+ } while ((childItem = childItem->getNextSibling()) != nullptr);
+ }
+ } while ((treeItem = treeItem->getNextSibling()) != nullptr);
+
+ return nullptr;
+}
+
+CRoomItem *CProjectItem::findNextRoom(CRoomItem *priorRoom) {
+ return dynamic_cast<CRoomItem *>(findSiblingInstanceOf(*CRoomItem::_type, priorRoom));
+}
+
+CTreeItem *CProjectItem::findSiblingInstanceOf(ClassDef &classDef, CTreeItem *startItem) {
+ CTreeItem *treeItem = startItem->getParent()->getNextSibling();
+ if (treeItem == nullptr)
+ return nullptr;
+
+ return findChildInstance(classDef);
+}
+
+CDontSaveFileItem *CProjectItem::getDontSaveFileItem() {
+ for (CTreeItem *treeItem = getFirstChild(); treeItem; treeItem = treeItem->getNextSibling()) {
+ if (treeItem->isInstanceOf(*CDontSaveFileItem::_type))
+ return dynamic_cast<CDontSaveFileItem *>(treeItem);
+ }
+
+ return nullptr;
+}
+
+CRoomItem *CProjectItem::findHiddenRoom() const {
+ return dynamic_cast<CRoomItem *>(findByName("HiddenRoom"));
+}
+
+CNamedItem *CProjectItem::findByName(const CString &name, int maxChars) const {
+ /*
+ CString nameLower = name;
+ nameLower.toLowercase();
+
+ CTreeItem *treeItem = this;
+ while (treeItem) {
+ CString nodeName = treeItem->getName();
+
+ }
+ */
+ return nullptr;
+}
+
+
} // End of namespace Titanic
diff --git a/engines/titanic/core/project_item.h b/engines/titanic/core/project_item.h
index 81b1869a6b..07a585237b 100644
--- a/engines/titanic/core/project_item.h
+++ b/engines/titanic/core/project_item.h
@@ -25,8 +25,10 @@
#include "common/scummsys.h"
#include "titanic/simple_file.h"
+#include "titanic/core/dont_save_file_item.h"
#include "titanic/core/file_item.h"
#include "titanic/core/list.h"
+#include "titanic/game/room_item.h"
namespace Titanic {
@@ -75,6 +77,16 @@ private:
* Called during save, iterates through the children to do some stuff
*/
void buildFilesList();
+
+ /**
+ * Finds the first child instance of a given class type
+ */
+ CTreeItem *findChildInstance(ClassDef &classDef);
+
+ /**
+ * Finds the next sibling occurance of a given class type
+ */
+ CTreeItem *findSiblingInstanceOf(ClassDef &classDef, CTreeItem *startItem);
private:
/**
* Load project data from the passed file
@@ -138,6 +150,25 @@ public:
* Set the proejct's name
*/
void setFilename(const CString &name) { _filename = name; }
+
+ /**
+ * Returns a reference to the first room item in the project
+ */
+ CRoomItem *findFirstRoom();
+
+ /**
+ * Returns a reference to the next room following the specified room
+ */
+ CRoomItem *findNextRoom(CRoomItem *priorRoom);
+
+ /**
+ * Returns the don't save file item, if it exists in the project
+ */
+ CDontSaveFileItem *getDontSaveFileItem();
+
+ CRoomItem *findHiddenRoom() const;
+
+ CNamedItem *findByName(const CString &name, int maxChars = 0) const;
};
} // End of namespace Titanic
diff --git a/engines/titanic/core/tree_item.h b/engines/titanic/core/tree_item.h
index eed30a3ecb..4e1581b1f6 100644
--- a/engines/titanic/core/tree_item.h
+++ b/engines/titanic/core/tree_item.h
@@ -96,6 +96,10 @@ public:
*/
CTreeItem *getLastChild();
+ /**
+ * Given all the recursive children of the tree item, gives the next
+ * item in sequence to the passed starting item
+ */
CTreeItem *scan(CTreeItem *item);
/**