using Raylib_cs; namespace Smoll.Ex2 { class RaylibAssetManagerModule : IEngineModule { string path; Dictionary images; Dictionary textures; Dictionary sounds; Dictionary scripts; public RaylibAssetManagerModule(string path = "./assets") { this.path = path; images = new Dictionary(); textures = new Dictionary(); sounds = new Dictionary(); scripts = new Dictionary(); } 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; } } }