1,079
edits
(→Example: engines/quux/quux.cpp: quux.cpp was badly outdated and broken -- fixed it) |
|||
Line 151: | Line 151: | ||
#include "base/game.h" | #include "base/game.h" | ||
#include "base/plugins.h" | #include "base/plugins.h" | ||
#include "engines/metaengine.h" | |||
#include "quux/quux.h" | #include "quux/quux.h" | ||
Line 161: | Line 163: | ||
}; | }; | ||
class QuuxMetaEngine : public MetaEngine { | |||
public: | |||
const | virtual const char *getName() const { | ||
return "Quux the Example Module"; | |||
} | |||
virtual const char *getCopyright() const { | |||
return "Copyright (C) Quux Entertainment Ltd."; | |||
} | } | ||
virtual GameList getSupportedGames() const { | |||
GameList games; | |||
const PlainGameDescriptor *g = quux_setting; | |||
while (g->gameid) { | |||
games.push_back(*g); | |||
g++; | |||
} | |||
return games; | |||
} | } | ||
if (0 == scumm_stricmp( | virtual GameDescriptor findGame(const char *gameid) const { | ||
const PlainGameDescriptor *g = quux_setting; | |||
while (g->gameid) { | |||
if (0 == scumm_stricmp(gameid, g->gameid)) | |||
break; | break; | ||
g++; | |||
} | } | ||
return GameDescriptor(g->gameid, g->description); | |||
} | } | ||
virtual GameList detectGames(const FSList &fslist) const { | |||
GameList detectedGames; | |||
// Iterate over all files in the given directory | |||
for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { | |||
if (!file->isDirectory()) { | |||
const char *gameName = file->getName().c_str(); | |||
if ( | |||
return | if (0 == scumm_stricmp("README", gameName)) { | ||
// You could check the contents of the file now if you need to. | |||
detectedGames.push_back(quux_setting[0]); | |||
break; | |||
} | |||
} | |||
} | |||
return detectedGames; | |||
} | } | ||
// Invoke the detector | virtual PluginError createInstance(OSystem *syst, Engine **engine) const { | ||
assert(syst); | |||
assert(engine); | |||
// Scan the target directory for files (error out if it does not exist) | |||
FSList fslist; | |||
FilesystemNode dir(ConfMan.get("path")); | |||
if (!dir.getChildren(fslist, FilesystemNode::kListAll)) { | |||
return kInvalidPathError; | |||
} | |||
// Invoke the detector | |||
Common::String gameid = ConfMan.get("gameid"); | |||
GameList detectedGames = detectGames(fslist); | |||
for (uint i = 0; i < detectedGames.size(); i++) { | |||
if (detectedGames[i].gameid() == gameid) { | |||
// At this point you may want to perform additional sanity checks. | |||
*engine = new Quux::QuuxEngine(syst); | |||
return kNoError; | |||
} | |||
} | } | ||
// Failed to find any game data | |||
return kNoGameDataFoundError; | |||
} | } | ||
}; | |||
REGISTER_PLUGIN(QUUX, | REGISTER_PLUGIN(QUUX, QuuxMetaEngine); | ||
edits