bot: added support for loading from custom folders (ref #498)
This commit is contained in:
parent
835c9fc4ed
commit
a904f49231
7 changed files with 59 additions and 19 deletions
|
|
@ -621,13 +621,15 @@ void BotConfig::loadDifficultyConfig () {
|
|||
}
|
||||
|
||||
void BotConfig::loadMapSpecificConfig () {
|
||||
auto mapSpecificConfig = strings.joinPath (folders.addons, folders.bot, folders.config, "maps", strings.format ("%s.%s", game.getMapName (), kConfigExtension));
|
||||
auto mapSpecificConfig = strings.joinPath (folders.config, "maps", strings.format ("%s.%s", game.getMapName (), kConfigExtension));
|
||||
|
||||
// check existence of file
|
||||
if (plat.fileExists (strings.joinPath (game.getRunningModName (), mapSpecificConfig).chars ())) {
|
||||
game.serverCommand ("exec %s", mapSpecificConfig);
|
||||
if (plat.fileExists (strings.joinPath (bstor.getRunningPath (), mapSpecificConfig).chars ())) {
|
||||
auto mapSpecificConfigForExec = strings.joinPath (bstor.getRunningPathVFS (), mapSpecificConfig);
|
||||
mapSpecificConfigForExec.replace ("\\", "/");
|
||||
|
||||
ctrl.msg ("Executed map-specific config: %s", mapSpecificConfig);
|
||||
game.serverCommand ("exec %s", mapSpecificConfigForExec);
|
||||
ctrl.msg ("Executed map-specific config: %s", mapSpecificConfigForExec);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -837,7 +839,7 @@ bool BotConfig::openConfig (StringRef fileName, StringRef errorIfNotExists, MemF
|
|||
}
|
||||
|
||||
// save config dir
|
||||
auto configDir = strings.joinPath (folders.addons, folders.bot, folders.config);
|
||||
auto configDir = strings.joinPath (bstor.getRunningPathVFS (), folders.config);
|
||||
|
||||
if (languageDependant) {
|
||||
if (fileName.startsWith ("lang") && cv_language.str () == "en") {
|
||||
|
|
|
|||
|
|
@ -206,10 +206,10 @@ int BotControl::cmdCvars () {
|
|||
|
||||
// if save requested, dump cvars to main config
|
||||
if (isSave) {
|
||||
auto cfgPath = strings.joinPath (game.getRunningModName (), folders.addons, folders.bot, folders.config, strings.format ("%s.%s", product.nameLower, kConfigExtension));
|
||||
auto cfgPath = strings.joinPath (bstor.getRunningPath (), folders.config, strings.format ("%s.%s", product.nameLower, kConfigExtension));
|
||||
|
||||
if (isSaveMap) {
|
||||
cfgPath = strings.joinPath (game.getRunningModName (), folders.addons, folders.bot, folders.config, "maps", strings.format ("%s.%s", game.getMapName (), kConfigExtension));
|
||||
cfgPath = strings.joinPath (bstor.getRunningPath (), folders.config, "maps", strings.format ("%s.%s", game.getMapName (), kConfigExtension));
|
||||
}
|
||||
cfg.open (cfgPath, "wt");
|
||||
cfg.puts ("// Configuration file for %s\n\n", product.name);
|
||||
|
|
|
|||
|
|
@ -807,8 +807,8 @@ bool Game::postload () {
|
|||
game.print (msg);
|
||||
});
|
||||
|
||||
auto ensureBotPathExists = [this] (StringRef dir1, StringRef dir2) {
|
||||
File::makePath (strings.joinPath (getRunningModName (), folders.addons, folders.bot, dir1, dir2).chars ());
|
||||
auto ensureBotPathExists = [] (StringRef dir1, StringRef dir2) {
|
||||
File::makePath (strings.joinPath (bstor.getRunningPath (), dir1, dir2).chars ());
|
||||
};
|
||||
|
||||
// ensure we're have all needed directories
|
||||
|
|
|
|||
|
|
@ -318,13 +318,12 @@ String BotStorage::buildPath (int32_t file, bool isMemoryLoad) {
|
|||
path.clear ();
|
||||
|
||||
// if not memory file we're don't need game dir
|
||||
if (!isMemoryLoad) {
|
||||
path.emplace (game.getRunningModName ());
|
||||
if (isMemoryLoad) {
|
||||
path.emplace (getRunningPathVFS ());
|
||||
}
|
||||
else {
|
||||
path.emplace (getRunningPath ());
|
||||
}
|
||||
|
||||
// always append addons/product
|
||||
path.emplace (folders.addons);
|
||||
path.emplace (folders.bot);
|
||||
|
||||
// the datadir
|
||||
path.emplace (folders.data);
|
||||
|
|
@ -341,7 +340,7 @@ String BotStorage::buildPath (int32_t file, bool isMemoryLoad) {
|
|||
auto timebuf = strings.chars ();
|
||||
|
||||
strftime (timebuf, StringBuffer::StaticBufferSize, "L%d%m%Y", &timeinfo);
|
||||
path.emplace (strings.format ("%s_%s.%s", folders.bot, timebuf, paths[file].second));
|
||||
path.emplace (strings.format ("%s_%s.%s", product.nameLower, timebuf, paths[file].second));
|
||||
}
|
||||
else {
|
||||
String mapName = game.getMapName ();
|
||||
|
|
@ -394,4 +393,39 @@ void BotStorage::unlinkFromDisk () {
|
|||
graph.reset (); // re-initialize points
|
||||
}
|
||||
|
||||
String BotStorage::getRunningPath () {
|
||||
// this function get's relative path against bot library (bot library should reside in bin dir)
|
||||
|
||||
static String path;
|
||||
|
||||
// compute the full path to the our folder
|
||||
if (path.empty ()) {
|
||||
path = SharedLibrary::path (&bstor);
|
||||
|
||||
if (path.startsWith ("<unk")) {
|
||||
logger.fatal ("Unable to detect library path. Giving up...");
|
||||
}
|
||||
auto parts = path.substr (1).split (kPathSeparator);
|
||||
|
||||
parts.pop (); // remove library name
|
||||
parts.pop (); // remove bin directory
|
||||
|
||||
path = path.substr (0, 1) + String::join (parts, kPathSeparator);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
String BotStorage::getRunningPathVFS () {
|
||||
static String path;
|
||||
|
||||
if (path.empty ()) {
|
||||
path = getRunningPath ();
|
||||
|
||||
path = path.substr (path.find (game.getRunningModName ())); // skip to the game dir
|
||||
path = path.substr (path.find (kPathSeparator) + 1); // skip the game dir
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
#endif // BOT_STORAGE_EXPLICIT_INSTANTIATIONS
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue