STARK: Revert the console changes that were merged by mistake

This commit is contained in:
Bastien Bouclet 2018-06-24 16:12:26 +02:00
parent 056761c3e9
commit ddb866d5e6
3 changed files with 16 additions and 158 deletions

View file

@ -116,55 +116,32 @@ bool Console::Cmd_DumpArchive(int argc, const char **argv) {
} }
bool Console::Cmd_DumpRoot(int argc, const char **argv) { bool Console::Cmd_DumpRoot(int argc, const char **argv) {
Resources::Root *root = StarkGlobal->getRoot(); StarkGlobal->getRoot()->print();
if (root) {
root->print();
} else {
debugPrintf("The global root has not been loaded\n");
}
return true; return true;
} }
bool Console::Cmd_DumpGlobal(int argc, const char **argv) { bool Console::Cmd_DumpGlobal(int argc, const char **argv) {
Resources::Level *level = StarkGlobal->getLevel(); StarkGlobal->getLevel()->print();
if (level) {
level->print();
} else {
debugPrintf("The global level has not been loaded\n");
}
return true; return true;
} }
bool Console::Cmd_DumpStatic(int argc, const char **argv) { bool Console::Cmd_DumpStatic(int argc, const char **argv) {
// Static resources are initialized in the beginning of the running
StarkStaticProvider->getLevel()->print(); StarkStaticProvider->getLevel()->print();
return true; return true;
} }
bool Console::Cmd_DumpLevel(int argc, const char **argv) { bool Console::Cmd_DumpLevel(int argc, const char **argv) {
Current *current = StarkGlobal->getCurrent(); StarkGlobal->getCurrent()->getLevel()->print();
if (current) {
current->getLevel()->print();
} else {
debugPrintf("Game levels have not been loaded\n");
}
return true; return true;
} }
bool Console::Cmd_DumpKnowledge(int argc, const char **argv) { bool Console::Cmd_DumpKnowledge(int argc, const char **argv) {
Current *current = StarkGlobal->getCurrent(); Resources::Level *level = StarkGlobal->getCurrent()->getLevel();
Resources::Location *location = StarkGlobal->getCurrent()->getLocation();
if (!current) {
debugPrintf("Game levels have not been loaded\n");
return true;
}
Resources::Level *level = current->getLevel();
Resources::Location *location = current->getLocation();
Common::Array<Resources::Knowledge *> knowledge = level->listChildrenRecursive<Resources::Knowledge>(); Common::Array<Resources::Knowledge *> knowledge = level->listChildrenRecursive<Resources::Knowledge>();
knowledge.insert_at(knowledge.size(), location->listChildrenRecursive<Resources::Knowledge>()); knowledge.insert_at(knowledge.size(), location->listChildrenRecursive<Resources::Knowledge>());
Common::Array<Resources::Knowledge *>::iterator it; Common::Array<Resources::Knowledge *>::iterator it;
@ -175,13 +152,6 @@ bool Console::Cmd_DumpKnowledge(int argc, const char **argv) {
} }
bool Console::Cmd_ChangeKnowledge(int argc, const char **argv) { bool Console::Cmd_ChangeKnowledge(int argc, const char **argv) {
Current *current = StarkGlobal->getCurrent();
if (!current) {
debugPrintf("Game levels have not been loaded\n");
return true;
}
uint index = 0; uint index = 0;
char type = 0; char type = 0;
@ -189,8 +159,8 @@ bool Console::Cmd_ChangeKnowledge(int argc, const char **argv) {
index = atoi(argv[1]); index = atoi(argv[1]);
type = argv[2][0]; type = argv[2][0];
if (type == 'b' || type == 'i') { if (type == 'b' || type == 'i') {
Resources::Level *level = current->getLevel(); Resources::Level *level = StarkGlobal->getCurrent()->getLevel();
Resources::Location *location = current->getLocation(); Resources::Location *location = StarkGlobal->getCurrent()->getLocation();
Common::Array<Resources::Knowledge *> knowledgeArr = level->listChildrenRecursive<Resources::Knowledge>(); Common::Array<Resources::Knowledge *> knowledgeArr = level->listChildrenRecursive<Resources::Knowledge>();
knowledgeArr.insert_at(knowledgeArr.size(), location->listChildrenRecursive<Resources::Knowledge>()); knowledgeArr.insert_at(knowledgeArr.size(), location->listChildrenRecursive<Resources::Knowledge>());
if (index < knowledgeArr.size() ) { if (index < knowledgeArr.size() ) {
@ -230,12 +200,6 @@ Common::Array<Resources::Script *> Console::listAllLocationScripts() const {
} }
bool Console::Cmd_ListScripts(int argc, const char **argv) { bool Console::Cmd_ListScripts(int argc, const char **argv) {
Current *current = StarkGlobal->getCurrent();
if (!current) {
debugPrintf("Game levels have not been loaded\n");
return true;
}
Common::Array<Resources::Script *> scripts = listAllLocationScripts(); Common::Array<Resources::Script *> scripts = listAllLocationScripts();
for (uint i = 0; i < scripts.size(); i++) { for (uint i = 0; i < scripts.size(); i++) {
@ -260,12 +224,6 @@ bool Console::Cmd_ListScripts(int argc, const char **argv) {
} }
bool Console::Cmd_EnableScript(int argc, const char **argv) { bool Console::Cmd_EnableScript(int argc, const char **argv) {
Current *current = StarkGlobal->getCurrent();
if (!current) {
debugPrintf("Game levels have not been loaded\n");
return true;
}
uint index = 0; uint index = 0;
if (argc >= 2) { if (argc >= 2) {
@ -295,12 +253,6 @@ bool Console::Cmd_EnableScript(int argc, const char **argv) {
} }
bool Console::Cmd_ForceScript(int argc, const char **argv) { bool Console::Cmd_ForceScript(int argc, const char **argv) {
Current *current = StarkGlobal->getCurrent();
if (!current) {
debugPrintf("Game levels have not been loaded\n");
return true;
}
uint index = 0; uint index = 0;
if (argc >= 2) { if (argc >= 2) {
@ -327,12 +279,6 @@ bool Console::Cmd_ForceScript(int argc, const char **argv) {
} }
bool Console::Cmd_DecompileScript(int argc, const char **argv) { bool Console::Cmd_DecompileScript(int argc, const char **argv) {
Current *current = StarkGlobal->getCurrent();
if (!current) {
debugPrintf("Game levels have not been loaded\n");
return true;
}
if (argc >= 2) { if (argc >= 2) {
uint index = atoi(argv[1]); uint index = atoi(argv[1]);
@ -454,44 +400,27 @@ void Console::decompileScriptChildren(Resources::Object *level) {
bool Console::Cmd_DumpLocation(int argc, const char **argv) { bool Console::Cmd_DumpLocation(int argc, const char **argv) {
if (StarkStaticProvider->isStaticLocation()) { if (StarkStaticProvider->isStaticLocation()) {
StarkStaticProvider->getLocation()->print(); StarkStaticProvider->getLocation()->print();
return true;
}
Current *current = StarkGlobal->getCurrent();
if (current) {
current->getLocation()->print();
} else { } else {
debugPrintf("Locations have not been loaded\n"); StarkGlobal->getCurrent()->getLocation()->print();
} }
return true; return true;
} }
bool Console::Cmd_ListInventory(int argc, const char **argv) { bool Console::Cmd_ListInventory(int argc, const char **argv) {
if (StarkGlobal->getInventory()) { StarkGlobal->printInventory(argc != 2);
StarkGlobal->printInventory(argc != 2);
} else {
debugPrintf("The inventory has not been loaded\n");
}
return true; return true;
} }
bool Console::Cmd_EnableInventoryItem(int argc, const char **argv) { bool Console::Cmd_EnableInventoryItem(int argc, const char **argv) {
if (!StarkGlobal->getInventory()) {
debugPrintf("The inventory has not been loaded\n");
return true;
}
if (argc != 2) { if (argc != 2) {
debugPrintf("Enable a specific inventory item. Use listInventory to get an id\n"); debugPrintf("Enable a specific inventory item. Use listInventory to get an id\n");
debugPrintf("Usage :\n"); debugPrintf("Usage :\n");
debugPrintf("enableInventoryItem [id]\n"); debugPrintf("enableInventoryItem [id]\n");
return true; return true;
} }
StarkGlobal->enableInventoryItem(atoi(argv[1])); StarkGlobal->enableInventoryItem(atoi(argv[1]));
return true; return true;
} }
@ -542,11 +471,6 @@ bool Console::Cmd_ListLocations(int argc, const char **argv) {
} }
bool Console::Cmd_ChangeLocation(int argc, const char **argv) { bool Console::Cmd_ChangeLocation(int argc, const char **argv) {
if (!StarkGlobal->getRoot()) {
debugPrintf("The global root has not been loaded\n");
return true;
}
if (argc != 3) { if (argc != 3) {
debugPrintf("Change the current location. Use listLocations to get ids\n"); debugPrintf("Change the current location. Use listLocations to get ids\n");
debugPrintf("Usage :\n"); debugPrintf("Usage :\n");
@ -557,57 +481,12 @@ bool Console::Cmd_ChangeLocation(int argc, const char **argv) {
uint levelIndex = strtol(argv[1] , nullptr, 16); uint levelIndex = strtol(argv[1] , nullptr, 16);
uint locationIndex = strtol(argv[2] , nullptr, 16); uint locationIndex = strtol(argv[2] , nullptr, 16);
bool isIndicesValid = true; StarkResourceProvider->requestLocationChange(levelIndex, locationIndex);
// Temporarily replace the global archive loader return false;
ArchiveLoader *archiveLoader = new ArchiveLoader();
ArchiveLoader *gameArchiveLoader = StarkArchiveLoader;
StarkArchiveLoader = archiveLoader;
archiveLoader->load("x.xarc");
Resources::Root *root = archiveLoader->useRoot<Resources::Root>("x.xarc");
// Assert the level index
Resources::Level *level = root->findChildWithIndex<Resources::Level>(levelIndex);
if (!level) {
debugPrintf("Invalid level index %d, only %d indices available\n", levelIndex,
root->listChildren<Resources::Level>().size());
isIndicesValid = false;
}
// Load locations archives
Common::String levelArchive = archiveLoader->buildArchiveName(level);
archiveLoader->load(levelArchive);
level = archiveLoader->useRoot<Resources::Level>(levelArchive);
// Assert the location index
Resources::Location *location = level->findChildWithIndex<Resources::Location>(locationIndex);
if (!location) {
debugPrintf("Invalid location index %d, only %d indices available\n", locationIndex,
level->listChildren<Resources::Location>().size());
isIndicesValid = false;
}
// Restore the global archive loader
archiveLoader->returnRoot(levelArchive);
archiveLoader->unloadUnused();
StarkArchiveLoader = gameArchiveLoader;
delete archiveLoader;
if (isIndicesValid) {
StarkResourceProvider->requestLocationChange(levelIndex, locationIndex);
return false;
}
return true;
} }
bool Console::Cmd_ChangeChapter(int argc, const char **argv) { bool Console::Cmd_ChangeChapter(int argc, const char **argv) {
if (!StarkGlobal->getLevel()) {
debugPrintf("The global level has not been loaded\n");
return true;
}
if (argc != 2) { if (argc != 2) {
debugPrintf("Change the current chapter\n"); debugPrintf("Change the current chapter\n");
debugPrintf("Usage :\n"); debugPrintf("Usage :\n");
@ -623,13 +502,6 @@ bool Console::Cmd_ChangeChapter(int argc, const char **argv) {
} }
bool Console::Cmd_Location(int argc, const char **argv) { bool Console::Cmd_Location(int argc, const char **argv) {
Current *current = StarkGlobal->getCurrent();
if (!current) {
debugPrintf("Game levels have not been loaded\n");
return true;
}
if (argc != 1) { if (argc != 1) {
debugPrintf("Display the current location\n"); debugPrintf("Display the current location\n");
debugPrintf("Usage :\n"); debugPrintf("Usage :\n");
@ -637,17 +509,14 @@ bool Console::Cmd_Location(int argc, const char **argv) {
return true; return true;
} }
Current *current = StarkGlobal->getCurrent();
debugPrintf("location: %02x %02x\n", current->getLevel()->getIndex(), current->getLocation()->getIndex()); debugPrintf("location: %02x %02x\n", current->getLevel()->getIndex(), current->getLocation()->getIndex());
return true; return true;
} }
bool Console::Cmd_Chapter(int argc, const char **argv) { bool Console::Cmd_Chapter(int argc, const char **argv) {
if (!StarkGlobal->getLevel()) {
debugPrintf("The global level has not been loaded\n");
return true;
}
if (argc != 1) { if (argc != 1) {
debugPrintf("Display the current chapter\n"); debugPrintf("Display the current chapter\n");
debugPrintf("Usage :\n"); debugPrintf("Usage :\n");

View file

@ -27,9 +27,6 @@
#include "engines/stark/resources/knowledge.h" #include "engines/stark/resources/knowledge.h"
#include "engines/stark/resources/knowledgeset.h" #include "engines/stark/resources/knowledgeset.h"
#include "gui/debugger.h"
#include "engines/engine.h"
namespace Stark { namespace Stark {
Global::Global() : Global::Global() :
@ -55,24 +52,18 @@ void Global::setCurrentChapter(int32 value) {
} }
void Global::printInventory(bool printAll) { void Global::printInventory(bool printAll) {
// Assume that this function is only called by the debug console
Common::Array<Resources::Item*> inventoryItems = _inventory->listChildren<Resources::Item>(Resources::Item::kItemInventory); Common::Array<Resources::Item*> inventoryItems = _inventory->listChildren<Resources::Item>(Resources::Item::kItemInventory);
Common::Array<Resources::Item*>::iterator it = inventoryItems.begin(); Common::Array<Resources::Item*>::iterator it = inventoryItems.begin();
for (int i = 0; it != inventoryItems.end(); ++it, i++) { for (int i = 0; it != inventoryItems.end(); ++it, i++) {
if (printAll || (*it)->isEnabled()) { if (printAll || (*it)->isEnabled()) {
g_engine->getDebugger()->debugPrintf("Item %d: %s\n", i, (*it)->getName().c_str()); warning("Item %d: %s", i, (*it)->getName().c_str());
} }
} }
} }
void Global::enableInventoryItem(int32 num) { void Global::enableInventoryItem(int32 num) {
Common::Array<Resources::Item*> inventoryItems = _inventory->listChildren<Resources::Item>(Resources::Item::kItemInventory); Common::Array<Resources::Item*> inventoryItems = _inventory->listChildren<Resources::Item>(Resources::Item::kItemInventory);
if (num >= 0 && num <= inventoryItems.size()) { inventoryItems[num]->setEnabled(true);
inventoryItems[num]->setEnabled(true);
} else {
// Assume that only being called by the debug console will cause the cheking failed
g_engine->getDebugger()->debugPrintf("Invalid index %d, only %d indices available\n", num, inventoryItems.size());
}
} }
Common::String Global::getCharacterName(int32 id) { Common::String Global::getCharacterName(int32 id) {

View file

@ -61,12 +61,10 @@ public:
/** Build a save file name for the specified target and slot */ /** Build a save file name for the specified target and slot */
static Common::String formatSaveName(const char *target, int slot); static Common::String formatSaveName(const char *target, int slot);
// Engine API
GUI::Debugger *getDebugger() override { return (GUI::Debugger *)_console; }
protected: protected:
// Engine APIs // Engine APIs
Common::Error run() override; Common::Error run() override;
GUI::Debugger *getDebugger() override { return (GUI::Debugger *)_console; }
bool hasFeature(EngineFeature f) const override; bool hasFeature(EngineFeature f) const override;
bool canLoadGameStateCurrently() override; bool canLoadGameStateCurrently() override;
bool canSaveGameStateCurrently() override; bool canSaveGameStateCurrently() override;