From 42db6d83ae02fc046aa4229c8c90e9fd793d5849 Mon Sep 17 00:00:00 2001 From: gered Date: Thu, 15 Aug 2013 18:41:41 -0400 Subject: [PATCH] add SDL filesystem implementation --- .../Blarg.GameFramework.SDL2.csproj | 2 + Blarg.GameFramework.SDL2/IO/SDLFileSystem.cs | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 Blarg.GameFramework.SDL2/IO/SDLFileSystem.cs diff --git a/Blarg.GameFramework.SDL2/Blarg.GameFramework.SDL2.csproj b/Blarg.GameFramework.SDL2/Blarg.GameFramework.SDL2.csproj index 5996778..030733d 100644 --- a/Blarg.GameFramework.SDL2/Blarg.GameFramework.SDL2.csproj +++ b/Blarg.GameFramework.SDL2/Blarg.GameFramework.SDL2.csproj @@ -46,6 +46,7 @@ + @@ -56,5 +57,6 @@ + \ No newline at end of file diff --git a/Blarg.GameFramework.SDL2/IO/SDLFileSystem.cs b/Blarg.GameFramework.SDL2/IO/SDLFileSystem.cs new file mode 100644 index 0000000..bd9dd06 --- /dev/null +++ b/Blarg.GameFramework.SDL2/IO/SDLFileSystem.cs @@ -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; } + } + } +} +