Refactor Package -> MixFile; group filesystem related classes in FileFormats.

This commit is contained in:
Paul Chote
2010-11-09 11:00:55 +13:00
parent 26cbb9d9c6
commit 356c750b23
12 changed files with 28 additions and 24 deletions

View File

@@ -39,7 +39,7 @@ namespace OpenRA.FileFormats
static IFolder OpenPackage(string filename)
{
if (filename.EndsWith(".mix"))
return new Package(filename, order++);
return new MixFile(filename, order++);
else if (filename.EndsWith(".zip"))
return new CompressedPackage(filename, order++);
else

View File

@@ -23,7 +23,7 @@ namespace OpenRA.FileFormats
int Priority { get; }
}
public class Package : IFolder
public class MixFile : IFolder
{
readonly Dictionary<uint, PackageEntry> index;
readonly bool isRmix, isEncrypted;
@@ -31,7 +31,7 @@ namespace OpenRA.FileFormats
readonly Stream s;
int priority;
public Package(string filename, int priority)
public MixFile(string filename, int priority)
{
this.priority = priority;
s = FileSystem.Open(filename);

View File

@@ -17,7 +17,7 @@ namespace OpenRA.FileFormats
{
public class MapStub
{
public IFolder Package { get; protected set; }
public IFolder Container { get; protected set; }
// Yaml map data
public string Uid { get; protected set; }
@@ -39,13 +39,13 @@ namespace OpenRA.FileFormats
public int Height { get { return BottomRight.Y - TopLeft.Y; } }
public MapStub() {} // Hack for the editor - not used for anything important
public MapStub(IFolder package)
public MapStub(IFolder container)
{
Package = package;
var yaml = MiniYaml.FromStream(Package.GetContent("map.yaml"));
Container = container;
var yaml = MiniYaml.FromStream(Container.GetContent("map.yaml"));
FieldLoader.Load( this, new MiniYaml( null, yaml ) );
Uid = Package.GetContent("map.uid").ReadAllText();
Uid = Container.GetContent("map.uid").ReadAllText();
}
static object LoadWaypoints( MiniYaml y )

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -59,8 +59,6 @@
<Compile Include="Evaluator.cs" />
<Compile Include="Exts.cs" />
<Compile Include="FieldLoader.cs" />
<Compile Include="FileSystem.cs" />
<Compile Include="Folder.cs" />
<Compile Include="Graphics\IGraphicsDevice.cs" />
<Compile Include="Graphics\IInputHandler.cs" />
<Compile Include="Graphics\Vertex.cs" />
@@ -68,8 +66,6 @@
<Compile Include="MiniYaml.cs" />
<Compile Include="Mod.cs" />
<Compile Include="PackageEntry.cs" />
<Compile Include="Package.cs" />
<Compile Include="PackageWriter.cs" />
<Compile Include="Palette.cs" />
<Compile Include="PlayerColorRemap.cs" />
<Compile Include="Primitives\DisposableAction.cs" />
@@ -101,8 +97,12 @@
<Compile Include="Map\MapStub.cs" />
<Compile Include="Map\SmudgeReference.cs" />
<Compile Include="Map\PlayerReference.cs" />
<Compile Include="CompressedPackage.cs" />
<Compile Include="Graphics\VqaReader.cs" />
<Compile Include="Filesystem\MixFile.cs" />
<Compile Include="Filesystem\FileSystem.cs" />
<Compile Include="Filesystem\Folder.cs" />
<Compile Include="Filesystem\PackageWriter.cs" />
<Compile Include="Filesystem\CompressedPackage.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
@@ -112,4 +112,7 @@
<Target Name="AfterBuild">
</Target>
-->
<ItemGroup>
<Folder Include="Filesystem\" />
</ItemGroup>
</Project>

13
OpenRA.Game/Map.cs Executable file → Normal file
View File

@@ -80,11 +80,12 @@ namespace OpenRA
public int2 Location = int2.Zero;
public string Owner = null;
}
public Map(MapStub stub) : this(stub.Container) {}
public Map(IFolder package)
: base(package)
{
var yaml = new MiniYaml( null, MiniYaml.FromStream( Package.GetContent( "map.yaml" ) ) );
var yaml = new MiniYaml( null, MiniYaml.FromStream( Container.GetContent( "map.yaml" ) ) );
// 'Simple' metadata
FieldLoader.Load( this, yaml );
@@ -184,7 +185,7 @@ namespace OpenRA
public void Save(string filepath)
{
// Todo: save to a zip file in the support dir by default
Package = new Folder(filepath, 0);
Container = new Folder(filepath, 0);
MapFormat = 3;
var root = new List<MiniYamlNode>();
@@ -232,7 +233,7 @@ namespace OpenRA
public void LoadBinaryData()
{
using (var dataStream = Package.GetContent("map.bin"))
using (var dataStream = Container.GetContent("map.bin"))
{
if (ReadByte(dataStream) != 1)
throw new InvalidDataException("Unknown binary map format");
@@ -298,8 +299,8 @@ namespace OpenRA
{
// UID is calculated by taking an SHA1 of the yaml and binary data
// Read the relevant data into a buffer
var data = Package.GetContent("map.yaml").ReadAllBytes()
.Concat(Package.GetContent("map.bin").ReadAllBytes()).ToArray();
var data = Container.GetContent("map.yaml").ReadAllBytes()
.Concat(Container.GetContent("map.bin").ReadAllBytes()).ToArray();
// Take the SHA1
using (var csp = SHA1.Create())

View File

@@ -60,7 +60,7 @@ namespace OpenRA
if (!AvailableMaps.ContainsKey(uid))
throw new InvalidDataException("Invalid map uid: {0}".F(uid));
var map = new Map(AvailableMaps[uid].Package);
var map = new Map(AvailableMaps[uid]);
Rules.LoadRules(Manifest, map);
if (map.Theater != cachedTheatre)

View File

@@ -162,7 +162,7 @@ namespace OpenRA.Server
static void LoadMap()
{
Map = new Map(ModData.AvailableMaps[lobbyInfo.GlobalSettings.Map].Package);
Map = new Map(ModData.AvailableMaps[lobbyInfo.GlobalSettings.Map]);
lobbyInfo.Slots = Map.Players
.Select(p => MakeSlotFromPlayerReference(p.Value))
.Where(s => s != null)

View File

@@ -183,7 +183,7 @@ namespace OpenRA.Widgets.Delegates
{
if (MapUid == orderManager.LobbyInfo.GlobalSettings.Map) return;
MapUid = orderManager.LobbyInfo.GlobalSettings.Map;
Map = new Map(Game.modData.AvailableMaps[MapUid].Package);
Map = new Map(Game.modData.AvailableMaps[MapUid]);
var title = Widget.RootWidget.GetWidget<LabelWidget>("LOBBY_TITLE");
title.Text = "OpenRA Multiplayer Lobby - " + orderManager.LobbyInfo.GlobalSettings.ServerName;

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Widgets
public Func<MapStub> Map = () => null;
public Action<int> OnSpawnClick = spawn => {};
public Func<Dictionary<int2, Color>> SpawnColors = () => new Dictionary<int2, Color>();
static Cache<MapStub,Bitmap> PreviewCache = new Cache<MapStub, Bitmap>(stub => Minimap.RenderMapPreview( new Map( stub.Package )));
static Cache<MapStub,Bitmap> PreviewCache = new Cache<MapStub, Bitmap>(stub => Minimap.RenderMapPreview( new Map( stub )));
public MapPreviewWidget() : base() { }
protected MapPreviewWidget(MapPreviewWidget other)