aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2016-03-15 23:49:18 -0400
committerPaul Gilbert2016-03-15 23:49:18 -0400
commit6a26539abbf7951f4783935b336dcabfbf548055 (patch)
tree8f6ab74db373985e6e5d78867445b7e16a09b63a /engines
parent3c29a101309b2d74cedf345c2d7314ef82fd9367 (diff)
downloadscummvm-rg350-6a26539abbf7951f4783935b336dcabfbf548055.tar.gz
scummvm-rg350-6a26539abbf7951f4783935b336dcabfbf548055.tar.bz2
scummvm-rg350-6a26539abbf7951f4783935b336dcabfbf548055.zip
TITANIC: Fleshing out resource key and view loading
Diffstat (limited to 'engines')
-rw-r--r--engines/titanic/core/resource_key.cpp34
-rw-r--r--engines/titanic/core/resource_key.h11
-rw-r--r--engines/titanic/core/view_item.cpp6
-rw-r--r--engines/titanic/core/view_item.h5
-rw-r--r--engines/titanic/files_manager.cpp15
-rw-r--r--engines/titanic/files_manager.h8
-rw-r--r--engines/titanic/game_manager.cpp4
-rw-r--r--engines/titanic/game_manager.h2
-rw-r--r--engines/titanic/main_game_window.cpp9
-rw-r--r--engines/titanic/main_game_window.h2
-rw-r--r--engines/titanic/string.cpp11
-rw-r--r--engines/titanic/string.h10
-rw-r--r--engines/titanic/titanic.cpp6
-rw-r--r--engines/titanic/titanic.h1
14 files changed, 115 insertions, 9 deletions
diff --git a/engines/titanic/core/resource_key.cpp b/engines/titanic/core/resource_key.cpp
index eee749f15a..685e026d23 100644
--- a/engines/titanic/core/resource_key.cpp
+++ b/engines/titanic/core/resource_key.cpp
@@ -20,6 +20,7 @@
*
*/
+#include "common/file.h"
#include "titanic/simple_file.h"
#include "titanic/core/resource_key.h"
@@ -36,12 +37,41 @@ void CResourceKey::save(SimpleFile *file, int indent) const {
void CResourceKey::load(SimpleFile *file) {
int val = file->readNumber();
- if (val == 1) {
+ if (val == 0 || val == 1) {
file->readBuffer();
- _value = file->readString();
+ CString str = file->readString();
+ setValue(str);
}
CSaveableObject::load(file);
}
+void CResourceKey::setValue(const CString &name) {
+ CString nameStr = name;
+ nameStr.toLowercase();
+ _key = nameStr;
+
+ _value = nameStr;
+ int idx = _value.lastIndexOf('\\');
+ if (idx >= 0)
+ _value = _value.mid(idx + 1);
+}
+
+CString CResourceKey::exists() {
+ CString name = _key;
+
+ // Check for the resource being within an ST container file
+ int idx = name.indexOf('#');
+ if (idx >= 0) {
+ CString str = name.left(idx);
+ name = name.mid(idx + 1);
+ name += ".st";
+ }
+
+ // The original did tests for the file in the different
+ // asset paths, which aren't needed in ScummVM
+ Common::File f;
+ return f.exists(name) ? name : CString();
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/core/resource_key.h b/engines/titanic/core/resource_key.h
index b38448aa4f..a165a11e1a 100644
--- a/engines/titanic/core/resource_key.h
+++ b/engines/titanic/core/resource_key.h
@@ -32,6 +32,8 @@ class CResourceKey: public CSaveableObject {
private:
CString _key;
CString _value;
+
+ void setValue(const CString &name);
public:
CLASSDEF
@@ -45,7 +47,16 @@ public:
*/
virtual void load(SimpleFile *file);
+ /**
+ * Return the key
+ */
const CString &getString() const { return _key; }
+
+ /**
+ * Checks whether a file for the given key exists,
+ * and returns it's filename if it does
+ */
+ CString exists();
};
} // End of namespace Titanic
diff --git a/engines/titanic/core/view_item.cpp b/engines/titanic/core/view_item.cpp
index 5253f24749..7038e94538 100644
--- a/engines/titanic/core/view_item.cpp
+++ b/engines/titanic/core/view_item.cpp
@@ -67,4 +67,10 @@ void CViewItem::load(SimpleFile *file) {
CNamedItem::load(file);
}
+bool CViewItem::getResourceKey(CResourceKey *key) {
+ *key = _resourceKey;
+ CString filename = key->exists();
+ return !filename.empty();
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/core/view_item.h b/engines/titanic/core/view_item.h
index 805b7a4f9c..106c795773 100644
--- a/engines/titanic/core/view_item.h
+++ b/engines/titanic/core/view_item.h
@@ -52,6 +52,11 @@ public:
* Load the data for the class from file
*/
virtual void load(SimpleFile *file);
+
+ /**
+ * Get the resource key for the view
+ */
+ bool getResourceKey(CResourceKey *key);
};
} // End of namespace Titanic
diff --git a/engines/titanic/files_manager.cpp b/engines/titanic/files_manager.cpp
index 4dcee2e062..b7562b638a 100644
--- a/engines/titanic/files_manager.cpp
+++ b/engines/titanic/files_manager.cpp
@@ -20,16 +20,18 @@
*
*/
+#include "common/file.h"
#include "titanic/files_manager.h"
#include "titanic/game_manager.h"
namespace Titanic {
CFilesManager::CFilesManager() : _gameManager(nullptr),
- _field0(0), _field14(0), _field18(0), _field1C(0), _field3C(0) {
+ _assetsPath("Assets"), _field0(0), _field14(0),
+ _field18(0), _field1C(0), _field3C(0) {
}
-int CFilesManager::fn1(const CString &name) {
+bool CFilesManager::fn1(const CString &name) {
if (name.empty())
return 0;
@@ -50,7 +52,14 @@ int CFilesManager::fn1(const CString &name) {
str += ".st";
}
- return 0;
+
+
+ return true;
+}
+
+bool CFilesManager::fileExists(const CString &name) {
+ Common::File f;
+ return f.exists(name);
}
} // End of namespace Titanic
diff --git a/engines/titanic/files_manager.h b/engines/titanic/files_manager.h
index 29a67e6605..63eda5ec1e 100644
--- a/engines/titanic/files_manager.h
+++ b/engines/titanic/files_manager.h
@@ -43,6 +43,7 @@ private:
int _field18;
int _field1C;
int _field3C;
+ const CString _assetsPath;
public:
CFilesManager();
@@ -53,7 +54,12 @@ public:
_gameManager = gameManager;
}
- int fn1(const CString &name);
+ bool fn1(const CString &name);
+
+ /**
+ * Returns true if a file of the given name exists
+ */
+ static bool fileExists(const CString &name);
};
} // End of namespace Titanic
diff --git a/engines/titanic/game_manager.cpp b/engines/titanic/game_manager.cpp
index 2f718626e9..5d5dc164ed 100644
--- a/engines/titanic/game_manager.cpp
+++ b/engines/titanic/game_manager.cpp
@@ -92,4 +92,8 @@ void CGameManager::initBounds() {
_bounds = Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}
+void CGameManager::fn2() {
+ warning("TODO");
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/game_manager.h b/engines/titanic/game_manager.h
index 82ab6d1e3b..6a4905239e 100644
--- a/engines/titanic/game_manager.h
+++ b/engines/titanic/game_manager.h
@@ -102,6 +102,8 @@ public:
* Set default screen bounds
*/
void initBounds();
+
+ void fn2();
};
} // End of namespace Titanic
diff --git a/engines/titanic/main_game_window.cpp b/engines/titanic/main_game_window.cpp
index e9fb423bd1..bf5ec6efd1 100644
--- a/engines/titanic/main_game_window.cpp
+++ b/engines/titanic/main_game_window.cpp
@@ -96,8 +96,13 @@ int CMainGameWindow::selectSavegame() {
return -1;
}
-void CMainGameWindow::setActiveView(CViewItem *view) {
- warning("TODO");
+void CMainGameWindow::setActiveView(CViewItem *viewItem) {
+ _gameManager->_gameState._gameLocation.setView(viewItem);
+
+ CResourceKey key;
+ if (viewItem->getResourceKey(&key)) {
+ // TODO
+ }
}
void CMainGameWindow::fn2() {
diff --git a/engines/titanic/main_game_window.h b/engines/titanic/main_game_window.h
index ec8eff3ec6..eedac23ef8 100644
--- a/engines/titanic/main_game_window.h
+++ b/engines/titanic/main_game_window.h
@@ -72,7 +72,7 @@ public:
/**
* Sets the view to be shown
*/
- void setActiveView(CViewItem *view);
+ void setActiveView(CViewItem *viewItem);
void fn2();
};
diff --git a/engines/titanic/string.cpp b/engines/titanic/string.cpp
index f726f78c21..c1afb4ff52 100644
--- a/engines/titanic/string.cpp
+++ b/engines/titanic/string.cpp
@@ -40,9 +40,20 @@ CString CString::mid(uint start, uint count) const {
return CString(c_str() + start, MIN(count, size() - start));
}
+CString CString::mid(uint start) const {
+ uint strSize = size();
+ assert(start <= strSize);
+ return mid(start, strSize - start);
+}
+
int CString::indexOf(char c) {
const char *charP = strchr(c_str(), c);
return charP ? charP - c_str() : -1;
}
+int CString::lastIndexOf(char c) {
+ const char *charP = strrchr(c_str(), c);
+ return charP ? charP - c_str() : -1;
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/string.h b/engines/titanic/string.h
index de442647ca..d70e23d023 100644
--- a/engines/titanic/string.h
+++ b/engines/titanic/string.h
@@ -53,9 +53,19 @@ public:
CString mid(uint start, uint count) const;
/**
+ * Returns a substring from within the string
+ */
+ CString mid(uint start) const;
+
+ /**
* Returns the index of the first occurance of a given character
*/
int indexOf(char c);
+
+ /**
+ * Returns the index of the last occurance of a given character
+ */
+ int lastIndexOf(char c);
};
} // End of namespace Titanic
diff --git a/engines/titanic/titanic.cpp b/engines/titanic/titanic.cpp
index d1d8386228..a9d0cc9421 100644
--- a/engines/titanic/titanic.cpp
+++ b/engines/titanic/titanic.cpp
@@ -21,6 +21,7 @@
*/
#include "common/scummsys.h"
+#include "common/archive.h"
#include "common/config-manager.h"
#include "common/debug-channels.h"
#include "common/events.h"
@@ -55,6 +56,11 @@ TitanicEngine::~TitanicEngine() {
CSaveableObject::freeClassList();
}
+void TitanicEngine::initializePath(const Common::FSNode &gamePath) {
+ Engine::initializePath(gamePath);
+ SearchMan.addSubDirectoryMatching(gamePath, "assets");
+}
+
void TitanicEngine::initialize() {
// Set up debug channels
DebugMan.addDebugChannel(kDebugCore, "core", "Core engine debug level");
diff --git a/engines/titanic/titanic.h b/engines/titanic/titanic.h
index 9513f8d759..112d6d63c1 100644
--- a/engines/titanic/titanic.h
+++ b/engines/titanic/titanic.h
@@ -91,6 +91,7 @@ protected:
int _loadSaveSlot;
// Engine APIs
+ virtual void initializePath(const Common::FSNode &gamePath);
virtual Common::Error run();
virtual bool hasFeature(EngineFeature f) const;
public: