Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using SFML.Audio;
- using SFML.Graphics;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace BlockBreaker.App.Main
- {
- public class IAssestHandler
- {
- private static IAssestHandler instance;
- public String audioDir = "Resources/audio/";
- public String textureDir = "Resources/textures/";
- public String fontDir = "Resources/fonts/";
- SortedDictionary<String, Texture> textures = new SortedDictionary<string, Texture> { };
- SortedDictionary<String, Font> fonts = new SortedDictionary<string, Font> { };
- SortedDictionary<String, SoundBuffer> audioBuffer = new SortedDictionary<string, SoundBuffer> { };
- private IAssestHandler()
- {
- }
- public static IAssestHandler Instance
- {
- get
- {
- if (instance == null)
- {
- instance = new IAssestHandler();
- }
- return instance;
- }
- }
- public Texture getTexture(String name)
- {
- Texture texture;
- if (name == "")
- {
- if (textures.TryGetValue("pixel.png", out texture))
- {
- return texture;
- }
- else
- {
- Image image = new Image(1, 1);
- textures["pixel.png"] = new Texture(image);
- return textures["pixel.png"];
- }
- }
- else
- {
- if (textures.TryGetValue(name, out texture))
- {
- return texture;
- }
- else
- {
- try
- {
- textures[name] = new Texture("../" + textureDir + name);
- }catch (Exception ex)
- {
- Console.Write(ex.StackTrace);
- return getTexture("");
- }
- return textures[name];
- }
- }
- }
- public Font getFont(String name)
- {
- Font font;
- if (fonts.TryGetValue(name, out font))
- {
- return font;
- }
- else
- {
- try
- {
- fonts[name] = new Font("../" + fontDir + name);
- }
- catch (Exception ex)
- {
- Console.Write(ex.StackTrace);
- }
- }
- return fonts[name];
- }
- public Sound getSound(String name)
- {
- SoundBuffer buffer;
- if (audioBuffer.TryGetValue(name, out buffer))
- {
- return new Sound(buffer);
- }
- else
- {
- try
- {
- audioBuffer[name] = new SoundBuffer("../" + fontDir + name);
- }
- catch (Exception ex)
- {
- Console.Write(ex.StackTrace);
- }
- return new Sound(audioBuffer[name]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement