-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from JerryImMouse/resource-manager
Resource Manager impl
- Loading branch information
Showing
18 changed files
with
565 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
namespace Hypercube.Client.Graphics.Texturing; | ||
using Hypercube.Shared.Resources; | ||
|
||
namespace Hypercube.Client.Graphics.Texturing; | ||
|
||
public interface ITextureManager | ||
{ | ||
ITexture Create(string path); | ||
ITexture Create(ResourcePath path); | ||
/// <summary> | ||
/// Creates ITexture, allows to set flipping mode | ||
/// </summary> | ||
/// <param name="path">Path to image</param> | ||
/// <param name="doFlip"><a href="https://www.youtube.com/watch?v=WQuL95_ckDo">DO FLIP</a></param> | ||
/// <returns>ITexture</returns> | ||
ITexture Create(string path, bool doFlip); | ||
ITexture Create(ResourcePath path, bool doFlip); | ||
|
||
ITextureHandle CreateHandler(string path); | ||
ITextureHandle CreateHandler(ResourcePath path); | ||
ITextureHandle CreateHandler(ITexture texture); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Hypercube.Shared.Logging; | ||
using Hypercube.Shared.Utilities.Helpers; | ||
|
||
namespace Hypercube.Shared.Resources.DirRoot; | ||
|
||
public class DirContentRoot : IContentRoot | ||
{ | ||
private readonly DirectoryInfo _directory; | ||
private Logger _logger; | ||
|
||
public DirContentRoot(DirectoryInfo directory, Logger logger) | ||
{ | ||
_directory = directory; | ||
_logger = logger; | ||
} | ||
|
||
public bool TryGetFile(ResourcePath path, [NotNullWhen(true)] out Stream? stream) | ||
{ | ||
if (!FileExists(path)) | ||
{ | ||
stream = null; | ||
return false; | ||
} | ||
|
||
try | ||
{ | ||
stream = File.Open(GetPath(path), FileMode.Open, FileAccess.Read); | ||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.Error(ex.Message); | ||
stream = null; | ||
} | ||
return false; | ||
} | ||
|
||
private bool FileExists(ResourcePath relPath) | ||
{ | ||
var path = GetPath(relPath); | ||
return File.Exists(path); | ||
} | ||
|
||
private string GetPath(ResourcePath path) | ||
{ | ||
return Path.GetFullPath(Path.Combine(_directory.FullName, path)); | ||
} | ||
|
||
public IEnumerable<ResourcePath> FindFiles(ResourcePath path) | ||
{ | ||
var fullPath = GetPath(path); | ||
if (!Directory.Exists(fullPath)) | ||
yield break; | ||
|
||
var paths = PathHelpers.GetFiles(fullPath); | ||
|
||
foreach (var filePath in paths) | ||
{ | ||
var relPath = filePath.Substring(_directory.FullName.Length); | ||
yield return ResourcePath.FromRelativeSystemPath(relPath, OperatingSystem.IsWindows() ? '\\' : '/'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Hypercube.Shared.Resources; | ||
|
||
public interface IContentRoot | ||
{ | ||
bool TryGetFile(ResourcePath path, [NotNullWhen(true)] out Stream? stream); | ||
IEnumerable<ResourcePath> FindFiles(ResourcePath path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Hypercube.Shared.Resources.Manager; | ||
|
||
public interface IResourceManager | ||
{ | ||
StreamReader WrapStream(Stream stream); | ||
void AddRoot(ResourcePath prefix, IContentRoot root); | ||
void MountContentFolder(string file, ResourcePath? prefix = null); | ||
Stream? ReadFileContent(ResourcePath path); | ||
bool TryReadFileContent(ResourcePath path, [NotNullWhen(true)] out Stream? fileStream); | ||
IEnumerable<ResourcePath> FindContentFiles(ResourcePath? path); | ||
string ReadFileContentAllText(ResourcePath path); | ||
} |
Oops, something went wrong.