TITANIC: Fleshing out resource key and view loading

This commit is contained in:
Paul Gilbert 2016-03-15 23:49:18 -04:00
parent 3c29a10130
commit 6a26539abb
14 changed files with 115 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -102,6 +102,8 @@ public:
* Set default screen bounds
*/
void initBounds();
void fn2();
};
} // End of namespace Titanic

View File

@ -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() {

View File

@ -72,7 +72,7 @@ public:
/**
* Sets the view to be shown
*/
void setActiveView(CViewItem *view);
void setActiveView(CViewItem *viewItem);
void fn2();
};

View File

@ -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

View File

@ -52,10 +52,20 @@ 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

View File

@ -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");

View File

@ -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: