add SDL filesystem implementation
This commit is contained in:
parent
42a19a4008
commit
42db6d83ae
|
@ -46,6 +46,7 @@
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Input\SDLKeyboard.cs" />
|
<Compile Include="Input\SDLKeyboard.cs" />
|
||||||
<Compile Include="Input\SDLMouse.cs" />
|
<Compile Include="Input\SDLMouse.cs" />
|
||||||
|
<Compile Include="IO\SDLFileSystem.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -56,5 +57,6 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Input\" />
|
<Folder Include="Input\" />
|
||||||
|
<Folder Include="IO\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
38
Blarg.GameFramework.SDL2/IO/SDLFileSystem.cs
Normal file
38
Blarg.GameFramework.SDL2/IO/SDLFileSystem.cs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using SDL2;
|
||||||
|
|
||||||
|
namespace Blarg.GameFramework.IO
|
||||||
|
{
|
||||||
|
public class SDLFileSystem : IFileSystem
|
||||||
|
{
|
||||||
|
string _assetsPath;
|
||||||
|
|
||||||
|
public SDLFileSystem()
|
||||||
|
{
|
||||||
|
string executablePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||||
|
_assetsPath = Path.Combine(executablePath, "assets");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream Open(string filename)
|
||||||
|
{
|
||||||
|
string realPath = TranslateFilePath(filename);
|
||||||
|
return new FileStream(realPath, FileMode.Open);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string TranslateFilePath(string path)
|
||||||
|
{
|
||||||
|
if (path.StartsWith("assets://"))
|
||||||
|
return Path.Combine(_assetsPath, path.Substring(9));
|
||||||
|
else
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string AssetsPath
|
||||||
|
{
|
||||||
|
get { return _assetsPath; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Reference in a new issue