2018-11-22 22:53:05 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using OpenDiablo2.Common.Interfaces;
|
|
|
|
|
using OpenDiablo2.Common.Models;
|
|
|
|
|
|
|
|
|
|
namespace OpenDiablo2.Core
|
|
|
|
|
{
|
|
|
|
|
public sealed class ResourceManager : IResourceManager
|
|
|
|
|
{
|
|
|
|
|
private readonly IMPQProvider mpqProvider;
|
2018-11-24 03:07:41 -05:00
|
|
|
|
private readonly IEngineDataManager engineDataManager;
|
|
|
|
|
|
2018-11-22 22:53:05 -05:00
|
|
|
|
private Dictionary<string, ImageSet> ImageSets = new Dictionary<string, ImageSet>();
|
|
|
|
|
private Dictionary<string, MPQFont> MPQFonts = new Dictionary<string, MPQFont>();
|
|
|
|
|
private Dictionary<string, Palette> Palettes = new Dictionary<string, Palette>();
|
2018-11-24 03:07:41 -05:00
|
|
|
|
private Dictionary<string, MPQDT1> DTs = new Dictionary<string, MPQDT1>();
|
2018-11-22 22:53:05 -05:00
|
|
|
|
|
2018-11-24 03:07:41 -05:00
|
|
|
|
public ResourceManager(IMPQProvider mpqProvider, IEngineDataManager engineDataManager)
|
2018-11-22 22:53:05 -05:00
|
|
|
|
{
|
|
|
|
|
this.mpqProvider = mpqProvider;
|
2018-11-24 03:07:41 -05:00
|
|
|
|
this.engineDataManager = engineDataManager;
|
2018-11-22 22:53:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ImageSet GetImageSet(string resourcePath)
|
|
|
|
|
{
|
|
|
|
|
if (!ImageSets.ContainsKey(resourcePath))
|
|
|
|
|
ImageSets[resourcePath] = ImageSet.LoadFromStream(mpqProvider.GetStream(resourcePath));
|
|
|
|
|
|
|
|
|
|
return ImageSets[resourcePath];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MPQFont GetMPQFont(string resourcePath)
|
|
|
|
|
{
|
|
|
|
|
if (!MPQFonts.ContainsKey(resourcePath))
|
|
|
|
|
MPQFonts[resourcePath] = MPQFont.LoadFromStream(mpqProvider.GetStream($"{resourcePath}.DC6"), mpqProvider.GetStream($"{resourcePath}.tbl"));
|
|
|
|
|
|
|
|
|
|
return MPQFonts[resourcePath];
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-25 01:51:21 -05:00
|
|
|
|
public MPQDS1 GetMPQDS1(string resourcePath, LevelPreset level, LevelDetail levelDetail, LevelType levelType)
|
2018-11-24 03:07:41 -05:00
|
|
|
|
{
|
|
|
|
|
var mapName = resourcePath.Replace("data\\global\\tiles\\", "").Replace("\\", "/");
|
2018-11-28 21:20:01 -05:00
|
|
|
|
return new MPQDS1(mpqProvider.GetStream(resourcePath), level, levelDetail, levelType, engineDataManager, this)
|
|
|
|
|
{
|
|
|
|
|
MapFile = resourcePath
|
|
|
|
|
};
|
2018-11-24 03:07:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-22 22:53:05 -05:00
|
|
|
|
public Palette GetPalette(string paletteFile)
|
|
|
|
|
{
|
|
|
|
|
if (!Palettes.ContainsKey(paletteFile))
|
|
|
|
|
{
|
|
|
|
|
var paletteNameParts = paletteFile.Split('\\');
|
|
|
|
|
var paletteName = paletteNameParts[paletteNameParts.Count() - 2];
|
|
|
|
|
Palettes[paletteFile] = Palette.LoadFromStream(mpqProvider.GetStream(paletteFile), paletteName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Palettes[paletteFile];
|
|
|
|
|
|
2018-11-24 03:07:41 -05:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MPQDT1 GetMPQDT1(string resourcePath)
|
|
|
|
|
{
|
|
|
|
|
if (!DTs.ContainsKey(resourcePath))
|
|
|
|
|
DTs[resourcePath] = new MPQDT1(mpqProvider.GetStream(resourcePath));
|
|
|
|
|
|
|
|
|
|
return DTs[resourcePath];
|
2018-11-22 22:53:05 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|