add SDL filesystem implementation

This commit is contained in:
Gered 2013-08-15 18:41:41 -04:00
parent 42a19a4008
commit 42db6d83ae
2 changed files with 40 additions and 0 deletions

View file

@ -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>

View 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; }
}
}
}