Use IReadOnlyFileSystem in voxel loader.
This commit is contained in:
@@ -13,6 +13,7 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Graphics
|
||||
@@ -37,6 +38,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
readonly List<Vertex[]> vertices = new List<Vertex[]>();
|
||||
readonly Cache<Pair<string, string>, Voxel> voxels;
|
||||
readonly IReadOnlyFileSystem fileSystem;
|
||||
IVertexBuffer<Vertex> vertexBuffer;
|
||||
int totalVertexCount;
|
||||
int cachedVertexCount;
|
||||
@@ -57,8 +59,9 @@ namespace OpenRA.Graphics
|
||||
return new SheetBuilder(SheetType.DualIndexed, allocate);
|
||||
}
|
||||
|
||||
public VoxelLoader()
|
||||
public VoxelLoader(IReadOnlyFileSystem fileSystem)
|
||||
{
|
||||
this.fileSystem = fileSystem;
|
||||
voxels = new Cache<Pair<string, string>, Voxel>(LoadFile);
|
||||
vertices = new List<Vertex[]>();
|
||||
totalVertexCount = 0;
|
||||
@@ -218,9 +221,9 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
VxlReader vxl;
|
||||
HvaReader hva;
|
||||
using (var s = Game.ModData.ModFiles.Open(files.First + ".vxl"))
|
||||
using (var s = fileSystem.Open(files.First + ".vxl"))
|
||||
vxl = new VxlReader(s);
|
||||
using (var s = Game.ModData.ModFiles.Open(files.Second + ".hva"))
|
||||
using (var s = fileSystem.Open(files.Second + ".hva"))
|
||||
hva = new HvaReader(s, files.Second + ".hva");
|
||||
return new Voxel(this, vxl, hva);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.FileSystem;
|
||||
|
||||
namespace OpenRA.Graphics
|
||||
{
|
||||
@@ -19,20 +20,20 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
static Dictionary<string, Dictionary<string, Voxel>> units;
|
||||
|
||||
public static void Initialize(ModData modData, string[] voxelFiles, List<MiniYamlNode> voxelNodes)
|
||||
public static void Initialize(VoxelLoader loader, IReadOnlyFileSystem fileSystem, string[] voxelFiles, List<MiniYamlNode> voxelNodes)
|
||||
{
|
||||
units = new Dictionary<string, Dictionary<string, Voxel>>();
|
||||
|
||||
var sequences = MiniYaml.Merge(voxelFiles.Select(
|
||||
s => MiniYaml.FromStream(modData.ModFiles.Open(s))));
|
||||
s => MiniYaml.FromStream(fileSystem.Open(s))));
|
||||
|
||||
foreach (var s in sequences)
|
||||
LoadVoxelsForUnit(s.Key, s.Value);
|
||||
LoadVoxelsForUnit(loader, s.Key, s.Value);
|
||||
|
||||
Game.ModData.VoxelLoader.RefreshBuffer();
|
||||
loader.RefreshBuffer();
|
||||
}
|
||||
|
||||
static Voxel LoadVoxel(string unit, MiniYaml info)
|
||||
static Voxel LoadVoxel(VoxelLoader voxelLoader, string unit, MiniYaml info)
|
||||
{
|
||||
var vxl = unit;
|
||||
var hva = unit;
|
||||
@@ -46,15 +47,15 @@ namespace OpenRA.Graphics
|
||||
hva = fields[1].Trim();
|
||||
}
|
||||
|
||||
return Game.ModData.VoxelLoader.Load(vxl, hva);
|
||||
return voxelLoader.Load(vxl, hva);
|
||||
}
|
||||
|
||||
static void LoadVoxelsForUnit(string unit, MiniYaml sequences)
|
||||
static void LoadVoxelsForUnit(VoxelLoader loader, string unit, MiniYaml sequences)
|
||||
{
|
||||
Game.ModData.LoadScreen.Display();
|
||||
try
|
||||
{
|
||||
var seq = sequences.ToDictionary(my => LoadVoxel(unit, my));
|
||||
var seq = sequences.ToDictionary(my => LoadVoxel(loader, unit, my));
|
||||
units.Add(unit, seq);
|
||||
}
|
||||
catch (FileNotFoundException) { } // Do nothing; we can crash later if we actually wanted art
|
||||
|
||||
Reference in New Issue
Block a user