Created
December 15, 2016 10:31
-
-
Save jezzye13/7b0eba0d6e43176618411119201ec24a to your computer and use it in GitHub Desktop.
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
using System.Collections.Generic; | |
using System.IO; | |
using System; | |
namespace GameEngine | |
{ | |
/// <summary> | |
/// Loads all *.png`s use GetBitmap(string key) | |
/// </summary> | |
public class Visuals | |
{ | |
private string _path; | |
private Dictionary<string, Bitmap> _bitmaps; | |
public Visuals() | |
{ | |
_bitmaps = new Dictionary<string, Bitmap>(); | |
//as last | |
LoadFolder(); | |
} | |
public Visuals(string folderToLoadForm) | |
{ | |
_path = folderToLoadForm; | |
_bitmaps = new Dictionary<string, Bitmap>(); | |
//as last | |
LoadFolder(); | |
} | |
private void LoadFolder() | |
{ | |
Console.WriteLine("[{0}] Loading Files", this.ToString()); | |
DirectoryInfo dinfo; | |
#if DEBUG | |
dinfo = new DirectoryInfo("../../Assets/"); | |
#else | |
dinfo = new DirectoryInfo("./Assets/"); | |
#endif | |
FileInfo[] Files = dinfo.GetFiles("*.png"); | |
//loop trow files | |
foreach (FileInfo file in Files) | |
{ | |
_bitmaps.Add(file.Name, new Bitmap(file.Name)); | |
Console.WriteLine("{0} {1}", file.CreationTime.Date.ToString("yyyy-MM-dd h:mm tt"), file.Name); | |
} | |
Console.WriteLine("[{0}] Loading Done", this.ToString()); | |
} | |
public Bitmap GetBitmap(string key) | |
{ | |
return _bitmaps[key + ".png"]; | |
} | |
public Bitmap GetBitmapFull(string fullName) | |
{ | |
return _bitmaps[fullName]; | |
} | |
public void Dispose() | |
{ | |
_bitmaps.Clear(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment