recrownedgtk/RecrownedGTK/AssetsSystem/AssetLoader.cs

31 lines
1.2 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using RecrownedGTK.AssetsSystem.Information;
using RecrownedGTK.AssetsSystem.Loaders;
namespace RecrownedGTK.AssetsSystem {
public class AssetLoader {
private readonly Dictionary<Type, ILoader> typeLoaders;
public AssetLoader() {
typeLoaders = new Dictionary<Type, ILoader>();
}
public void AddLoaderResolver(Type type, ILoader loader) {
if (typeLoaders.ContainsKey(type)) {
throw new InvalidOperationException(String.Format("The type {0} already exists in this resolver.", type));
}
typeLoaders.Add(type, loader);
}
public void RemoveLoaderResolver(Type type) {
if (!typeLoaders.ContainsKey(type)) {
throw new InvalidOperationException(String.Format("The type {0} doesn't exist in this resolver.", type));
}
typeLoaders.Remove(type);
}
public IInfo Load(string path, Type type) {
if (!typeLoaders.ContainsKey(type)) {
throw new InvalidOperationException(String.Format("The type {0} doesn't exist in this resolver.", type));
}
return typeLoaders[type].load(path);
}
}
}