extend methods by which the correct assets path is "discovered"
This commit is contained in:
parent
c72838c7fd
commit
b28498fae6
|
@ -9,10 +9,30 @@ namespace Blarg.GameFramework.IO
|
||||||
{
|
{
|
||||||
string _assetsPath;
|
string _assetsPath;
|
||||||
|
|
||||||
public SDLFileSystem()
|
public SDLFileSystem(ILogger logger)
|
||||||
{
|
{
|
||||||
string executablePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
string envAssetsPath = Environment.GetEnvironmentVariable("ASSETS_DIR");
|
||||||
_assetsPath = Path.Combine(executablePath, "assets");
|
string workingDirPath = Path.Combine(Environment.CurrentDirectory, "assets");
|
||||||
|
|
||||||
|
if (!String.IsNullOrEmpty(envAssetsPath))
|
||||||
|
{
|
||||||
|
logger.Info("SDL_FILESYSTEM", "Environment variable ASSETS_DIR value found.");
|
||||||
|
_assetsPath = envAssetsPath;
|
||||||
|
}
|
||||||
|
else if (Directory.Exists(workingDirPath))
|
||||||
|
{
|
||||||
|
logger.Info("SDL_FILESYSTEM", "'Assets' found under the current working directory.");
|
||||||
|
_assetsPath = workingDirPath;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// fallback to the default otherwise
|
||||||
|
logger.Info("SDL_FILESYSTEM", "Assuming 'Assets' directory located next to application executable.");
|
||||||
|
_assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "assets");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Directory.Exists(_assetsPath))
|
||||||
|
logger.Warn("SDL_FILESYSTEM", "Attempting to use assets directory {0} which doesn't exist.", _assetsPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream Open(string filename)
|
public Stream Open(string filename)
|
||||||
|
|
|
@ -315,8 +315,9 @@ namespace Blarg.GameFramework
|
||||||
Logger.Warn(LOG_TAG, "\tMore information could not be obtained.");
|
Logger.Warn(LOG_TAG, "\tMore information could not be obtained.");
|
||||||
}
|
}
|
||||||
|
|
||||||
_filesystem = new SDLFileSystem();
|
_filesystem = new SDLFileSystem(Logger);
|
||||||
Logger.Info(LOG_TAG, "Filesystem access initialized.");
|
Logger.Info(LOG_TAG, "Filesystem access initialized.");
|
||||||
|
Logger.Info(LOG_TAG, "Using assets path: {0}", _filesystem.AssetsPath);
|
||||||
|
|
||||||
int numVideoDrivers = SDL.SDL_GetNumVideoDrivers();
|
int numVideoDrivers = SDL.SDL_GetNumVideoDrivers();
|
||||||
Logger.Info(LOG_TAG, "Video drivers present: {0}.", numVideoDrivers);
|
Logger.Info(LOG_TAG, "Video drivers present: {0}.", numVideoDrivers);
|
||||||
|
|
Reference in a new issue