diff options
author | Paul Gilbert | 2016-02-19 19:45:17 -0500 |
---|---|---|
committer | Paul Gilbert | 2016-02-19 19:45:17 -0500 |
commit | 8c9a1c2159251570185de73a7c90003e863f3c7e (patch) | |
tree | ef03495f2628e0d5260a4beec938971b7f7cb897 /engines/titanic | |
parent | ad8450209a553fd06540cd01ab29f936c0d0dc29 (diff) | |
download | scummvm-rg350-8c9a1c2159251570185de73a7c90003e863f3c7e.tar.gz scummvm-rg350-8c9a1c2159251570185de73a7c90003e863f3c7e.tar.bz2 scummvm-rg350-8c9a1c2159251570185de73a7c90003e863f3c7e.zip |
TITANIC: Implementing CProjectItem::loadData
Diffstat (limited to 'engines/titanic')
-rw-r--r-- | engines/titanic/objects/project_item.cpp | 48 | ||||
-rw-r--r-- | engines/titanic/objects/project_item.h | 4 | ||||
-rw-r--r-- | engines/titanic/objects/tree_item.cpp | 28 | ||||
-rw-r--r-- | engines/titanic/objects/tree_item.h | 15 |
4 files changed, 93 insertions, 2 deletions
diff --git a/engines/titanic/objects/project_item.cpp b/engines/titanic/objects/project_item.cpp index e75f0e01e9..599af89057 100644 --- a/engines/titanic/objects/project_item.cpp +++ b/engines/titanic/objects/project_item.cpp @@ -73,8 +73,54 @@ void CProjectItem::clear() { } -void CProjectItem::loadData(SimpleFile *file) { +CProjectItem *CProjectItem::loadData(SimpleFile *file) { + if (!file->IsClassStart()) + return nullptr; + + CProjectItem *root = nullptr; + CTreeItem *parent = nullptr; + CTreeItem *item = nullptr; + + do { + CString entryString = file->readString(); + + if (entryString == "ALONG") { + // Move along, nothing needed + } else if (entryString == "UP") { + // Move up + if (parent == nullptr || + (parent = parent->getParent()) == nullptr) + break; + } else if (entryString == "DOWN") { + // Move down + if (parent == nullptr) + parent = item; + else + parent = parent->getLastChild(); + } else { + // Create new class instance + item = dynamic_cast<CTreeItem *>(CSaveableObject::createInstance(entryString)); + assert(item); + + if (root) { + // Already created root project + item->addUnder(parent); + } else { + // TODO: Validate this is correct + root = dynamic_cast<CProjectItem *>(item); + assert(root); + + _filename = root->_filename; + } + + // Load the data for the item + item->load(file); + } + + file->IsClassStart(); + } while (file->IsClassStart()); + return root; } void CProjectItem::saveData(SimpleFile *file, CTreeItem *item) const { diff --git a/engines/titanic/objects/project_item.h b/engines/titanic/objects/project_item.h index 6277af85c3..60fee9b912 100644 --- a/engines/titanic/objects/project_item.h +++ b/engines/titanic/objects/project_item.h @@ -31,10 +31,12 @@ namespace Titanic { class CProjectItem : public CFileItem { private: + CString _filename; +private: /** * Load project data from the passed file */ - void loadData(SimpleFile *file); + CProjectItem *loadData(SimpleFile *file); /** * Save project data to the passed file diff --git a/engines/titanic/objects/tree_item.cpp b/engines/titanic/objects/tree_item.cpp index dcd0e4606f..bf0ae3e735 100644 --- a/engines/titanic/objects/tree_item.cpp +++ b/engines/titanic/objects/tree_item.cpp @@ -52,4 +52,32 @@ CTreeItem *CTreeItem::getLastChild() { return _firstChild->getLastSibling(); } +void CTreeItem::addUnder(CTreeItem *newParent) { + if (newParent->_firstChild) + addSibling(newParent->getLastSibling()); + else + setParent(newParent); +} + +void CTreeItem::setParent(CTreeItem *newParent) { + _parent = newParent; + _priorSibling = nullptr; + _nextSibling = newParent->_firstChild; + + if (newParent->_firstChild) + newParent->_firstChild->_priorSibling = this; + newParent->_firstChild = this; +} + +void CTreeItem::addSibling(CTreeItem *item) { + _priorSibling = item->_nextSibling; + _nextSibling = item->_nextSibling; + _parent = item->_parent; + + if (item->_nextSibling) + item->_nextSibling->_priorSibling = this; + item->_nextSibling = this; +} + + } // End of namespace Titanic diff --git a/engines/titanic/objects/tree_item.h b/engines/titanic/objects/tree_item.h index 454c3ca8ca..d3c1d34911 100644 --- a/engines/titanic/objects/tree_item.h +++ b/engines/titanic/objects/tree_item.h @@ -81,6 +81,21 @@ public: * Get the last child of the item, if any */ CTreeItem *getLastChild(); + + /** + * Adds the item under another tree item + */ + void addUnder(CTreeItem *newParent); + + /** + * Sets the parent for the item + */ + void setParent(CTreeItem *newParent); + + /** + * Adds the item as a sibling of another item + */ + void addSibling(CTreeItem *item); }; } // End of namespace Titanic |