|
|
- using Raylib_cs;
-
- namespace Smoll.Ex2
- {
- class RaylibAssetManagerModule : IEngineModule {
- string path;
-
- Dictionary<string, Image> images;
- Dictionary<string, Texture2D> textures;
- Dictionary<string, Sound> sounds;
- Dictionary<string, string> scripts;
-
- public RaylibAssetManagerModule(string path = "./assets") {
- this.path = path;
- images = new Dictionary<string, Image>();
- textures = new Dictionary<string, Texture2D>();
- sounds = new Dictionary<string, Sound>();
- scripts = new Dictionary<string, string>();
- }
-
- public Image GetImage(string name) {
- Image image;
- if(! images.TryGetValue(name, out image)) {
- image = Raylib.LoadImage(path+"/"+name);
- images.Add(name, image);
- }
- return image;
- }
-
- public Texture2D GetTexture(string name) {
- Texture2D texture;
- if(! textures.TryGetValue(name, out texture)) {
- Image image = GetImage(name);
- texture = Raylib.LoadTextureFromImage(image);
- textures.Add(name, texture);
- }
- return texture;
- }
-
- public Sound GetSound(string name) {
- Sound sound;
- if(! sounds.TryGetValue(name, out sound)) {
- sound = Raylib.LoadSound(path+"/"+name);
- sounds.Add(name, sound);
- }
- return sound;
- }
-
- public string GetScript(string name) {
- string script;
- if(! scripts.TryGetValue(name, out script)) {
- script = File.ReadAllText(path+"/"+name);
- scripts.Add(name, script);
- }
- return script;
- }
- }
- }
|