2020-04-18 03:09:13 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using RecrownedGTK.AssetsSystem.Information;
|
|
|
|
using RecrownedGTK.AssetsSystem.Loaders;
|
|
|
|
|
2020-02-20 21:34:00 +00:00
|
|
|
namespace RecrownedGTK.AssetsSystem {
|
|
|
|
public class AssetLoader {
|
2020-04-18 03:09:13 +00:00
|
|
|
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);
|
2020-02-20 21:34:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|