A Smoll game engine
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

57 rindas
1.8 KiB

  1. using Raylib_cs;
  2. namespace Smoll.Ex2
  3. {
  4. class RaylibAssetManagerModule : IEngineModule {
  5. string path;
  6. Dictionary<string, Image> images;
  7. Dictionary<string, Texture2D> textures;
  8. Dictionary<string, Sound> sounds;
  9. Dictionary<string, string> scripts;
  10. public RaylibAssetManagerModule(string path = "./assets") {
  11. this.path = path;
  12. images = new Dictionary<string, Image>();
  13. textures = new Dictionary<string, Texture2D>();
  14. sounds = new Dictionary<string, Sound>();
  15. scripts = new Dictionary<string, string>();
  16. }
  17. public Image GetImage(string name) {
  18. Image image;
  19. if(! images.TryGetValue(name, out image)) {
  20. image = Raylib.LoadImage(path+"/"+name);
  21. images.Add(name, image);
  22. }
  23. return image;
  24. }
  25. public Texture2D GetTexture(string name) {
  26. Texture2D texture;
  27. if(! textures.TryGetValue(name, out texture)) {
  28. Image image = GetImage(name);
  29. texture = Raylib.LoadTextureFromImage(image);
  30. textures.Add(name, texture);
  31. }
  32. return texture;
  33. }
  34. public Sound GetSound(string name) {
  35. Sound sound;
  36. if(! sounds.TryGetValue(name, out sound)) {
  37. sound = Raylib.LoadSound(path+"/"+name);
  38. sounds.Add(name, sound);
  39. }
  40. return sound;
  41. }
  42. public string GetScript(string name) {
  43. string script;
  44. if(! scripts.TryGetValue(name, out script)) {
  45. script = File.ReadAllText(path+"/"+name);
  46. scripts.Add(name, script);
  47. }
  48. return script;
  49. }
  50. }
  51. }