Skip to content

Commit

Permalink
#5231: Map and prefab paths can be retrieved through the GameManager …
Browse files Browse the repository at this point in the history
…interface.
  • Loading branch information
codereader committed Apr 27, 2020
1 parent 01e6915 commit 1ce60d2
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 26 deletions.
6 changes: 6 additions & 0 deletions include/igame.h
Expand Up @@ -92,6 +92,12 @@ class IGameManager :

typedef std::vector<IGamePtr> GameList;
virtual const GameList& getSortedGameList() = 0;

// Returns the absolute path where maps are going to be saved to
virtual const std::string& getMapPath() = 0;

// Returns the absolute path where prefabs are going to be saved to
virtual const std::string& getPrefabPath() = 0;
};
typedef std::shared_ptr<IGameManager> IGameManagerPtr;

Expand Down
6 changes: 0 additions & 6 deletions include/imodule.h
Expand Up @@ -18,12 +18,6 @@
* \defgroup module Module system
*/

/** greebo: These registry keys can be used application-wide during runtime
* to retrieve the various paths.
*/
const char* const RKEY_MAP_PATH = "user/paths/mapPath";
const char* const RKEY_PREFAB_PATH = "user/paths/prefabPath";

/**
* greebo: Compatibility level: a number inlined into all the modules and returned
* by their RegisterableModule::getCompatibilityLevel() method.
Expand Down
3 changes: 2 additions & 1 deletion radiant/map/AutoSaver.cpp
Expand Up @@ -7,6 +7,7 @@
#include "itextstream.h"
#include "iscenegraph.h"
#include "iradiant.h"
#include "igame.h"
#include "imainframe.h"
#include "ipreferencesystem.h"

Expand Down Expand Up @@ -284,7 +285,7 @@ void AutoMapSaver::checkSave()
if (GlobalMap().isUnnamed())
{
// Get the maps path (within the mod path)
std::string autoSaveFilename = GlobalRegistry().get(RKEY_MAP_PATH);
std::string autoSaveFilename = GlobalGameManager().getMapPath();

// Try to create the map folder, in case there doesn't exist one
os::makeDirectory(autoSaveFilename);
Expand Down
7 changes: 4 additions & 3 deletions radiant/map/MapFileManager.cpp
Expand Up @@ -2,6 +2,7 @@

#include "i18n.h"
#include "iregistry.h"
#include "igame.h"
#include "ifiletypes.h"
#include "imainframe.h"
#include "modulesystem/ApplicationContextImpl.h"
Expand All @@ -15,8 +16,8 @@ namespace map
MapFileManager::MapFileManager()
{
// Load the default values
_lastDirs[filetype::TYPE_MAP] = GlobalRegistry().get(RKEY_MAP_PATH);
_lastDirs[filetype::TYPE_PREFAB] = GlobalRegistry().get(RKEY_PREFAB_PATH);
_lastDirs[filetype::TYPE_MAP] = GlobalGameManager().getMapPath();
_lastDirs[filetype::TYPE_PREFAB] = GlobalGameManager().getPrefabPath();
}

// Instance owner method
Expand Down Expand Up @@ -50,7 +51,7 @@ MapFileSelection MapFileManager::selectFile(bool open,
if (_lastDirs.find(type) == _lastDirs.end())
{
// Default to the map path, if the type is not yet associated
_lastDirs[type] = GlobalRegistry().get(RKEY_MAP_PATH);
_lastDirs[type] = GlobalGameManager().getMapPath();
}

// Get the first extension from the list of possible patterns (e.g. *.pfb or *.map)
Expand Down
3 changes: 2 additions & 1 deletion radiant/map/StartupMapLoader.cpp
Expand Up @@ -4,6 +4,7 @@
#include "igl.h"
#include "irender.h"
#include "iregistry.h"
#include "igame.h"
#include "iradiant.h"
#include "Map.h"
#include "ui/mru/MRU.h"
Expand Down Expand Up @@ -46,7 +47,7 @@ void StartupMapLoader::onRadiantStartup()
break;
}

fs::path mapsPath = GlobalRegistry().get(RKEY_MAP_PATH);
fs::path mapsPath = GlobalGameManager().getMapPath();

fs::path fullMapPath = mapsPath / candidate;

Expand Down
35 changes: 20 additions & 15 deletions radiant/settings/GameManager.cpp
Expand Up @@ -252,42 +252,37 @@ void Manager::showGameSetupDialog()
void Manager::setMapAndPrefabPaths(const std::string& baseGamePath)
{
// Construct the map path and make sure the folder exists
std::string mapPath;

// Get the maps folder (e.g. "maps/")
std::string mapFolder = currentGame()->getLocalXPath(GKEY_MAPS_FOLDER)[0].getAttributeValue("value");
if (mapFolder.empty()) {
if (mapFolder.empty())
{
mapFolder = "maps/";
}

if (_config.modPath.empty() && _config.modBasePath.empty())
{
mapPath = baseGamePath + mapFolder;
_mapPath = baseGamePath + mapFolder;
}
else if (!_config.modPath.empty())
{
mapPath = _config.modPath + mapFolder;
_mapPath = _config.modPath + mapFolder;
}
else // _config.modBasePath is not empty
{
mapPath = _config.modBasePath + mapFolder;
_mapPath = _config.modBasePath + mapFolder;
}

rMessage() << "GameManager: Map path set to " << mapPath << std::endl;
os::makeDirectory(mapPath);

// Save the map path to the registry
registry::setValue(RKEY_MAP_PATH, mapPath);
rMessage() << "GameManager: Map path set to " << _mapPath << std::endl;
os::makeDirectory(_mapPath);

// Setup the prefab path
std::string prefabPath = mapPath;
_prefabPath = _mapPath;
std::string pfbFolder = currentGame()->getLocalXPath(GKEY_PREFAB_FOLDER)[0].getAttributeValue("value");

// Replace the "maps/" with "prefabs/"
string::replace_last(prefabPath, mapFolder, pfbFolder);
string::replace_last(_prefabPath, mapFolder, pfbFolder);
// Store the path into the registry
rMessage() << "GameManager: Prefab path set to " << prefabPath << std::endl;
registry::setValue(RKEY_PREFAB_PATH, prefabPath);
rMessage() << "GameManager: Prefab path set to " << _prefabPath << std::endl;
}

void Manager::initialiseVfs()
Expand Down Expand Up @@ -356,6 +351,16 @@ const Manager::PathList& Manager::getVFSSearchPaths() const
return GlobalFileSystem().getVfsSearchPaths();
}

const std::string& Manager::getMapPath()
{
return _mapPath;
}

const std::string& Manager::getPrefabPath()
{
return _prefabPath;
}

const std::string& Manager::getEnginePath() const
{
return _config.enginePath;
Expand Down
6 changes: 6 additions & 0 deletions radiant/settings/GameManager.h
Expand Up @@ -33,6 +33,9 @@ class Manager :
// The currently active game configuration
GameConfiguration _config;

std::string _mapPath;
std::string _prefabPath;

public:
Manager();

Expand Down Expand Up @@ -63,6 +66,9 @@ class Manager :
// Returns the sorted game path list
const PathList& getVFSSearchPaths() const override;

const std::string& getMapPath() override;
const std::string& getPrefabPath() override;

// RegisterableModule implementation
const std::string& getName() const override;
const StringSet& getDependencies() const override;
Expand Down

0 comments on commit 1ce60d2

Please sign in to comment.