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) static IFolder OpenPackage(string filename)
{ {
if (filename.EndsWith(".mix")) if (filename.EndsWith(".mix"))
return new Package(filename, order++); return new MixFile(filename, order++);
else if (filename.EndsWith(".zip")) else if (filename.EndsWith(".zip"))
return new CompressedPackage(filename, order++); return new CompressedPackage(filename, order++);
else else

View File

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

View File

@@ -17,7 +17,7 @@ namespace OpenRA.FileFormats
{ {
public class MapStub public class MapStub
{ {
public IFolder Package { get; protected set; } public IFolder Container { get; protected set; }
// Yaml map data // Yaml map data
public string Uid { get; protected set; } public string Uid { get; protected set; }
@@ -39,13 +39,13 @@ namespace OpenRA.FileFormats
public int Height { get { return BottomRight.Y - TopLeft.Y; } } public int Height { get { return BottomRight.Y - TopLeft.Y; } }
public MapStub() {} // Hack for the editor - not used for anything important public MapStub() {} // Hack for the editor - not used for anything important
public MapStub(IFolder package) public MapStub(IFolder container)
{ {
Package = package; Container = container;
var yaml = MiniYaml.FromStream(Package.GetContent("map.yaml")); var yaml = MiniYaml.FromStream(Container.GetContent("map.yaml"));
FieldLoader.Load( this, new MiniYaml( null, 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 ) 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"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -59,8 +59,6 @@
<Compile Include="Evaluator.cs" /> <Compile Include="Evaluator.cs" />
<Compile Include="Exts.cs" /> <Compile Include="Exts.cs" />
<Compile Include="FieldLoader.cs" /> <Compile Include="FieldLoader.cs" />
<Compile Include="FileSystem.cs" />
<Compile Include="Folder.cs" />
<Compile Include="Graphics\IGraphicsDevice.cs" /> <Compile Include="Graphics\IGraphicsDevice.cs" />
<Compile Include="Graphics\IInputHandler.cs" /> <Compile Include="Graphics\IInputHandler.cs" />
<Compile Include="Graphics\Vertex.cs" /> <Compile Include="Graphics\Vertex.cs" />
@@ -68,8 +66,6 @@
<Compile Include="MiniYaml.cs" /> <Compile Include="MiniYaml.cs" />
<Compile Include="Mod.cs" /> <Compile Include="Mod.cs" />
<Compile Include="PackageEntry.cs" /> <Compile Include="PackageEntry.cs" />
<Compile Include="Package.cs" />
<Compile Include="PackageWriter.cs" />
<Compile Include="Palette.cs" /> <Compile Include="Palette.cs" />
<Compile Include="PlayerColorRemap.cs" /> <Compile Include="PlayerColorRemap.cs" />
<Compile Include="Primitives\DisposableAction.cs" /> <Compile Include="Primitives\DisposableAction.cs" />
@@ -101,8 +97,12 @@
<Compile Include="Map\MapStub.cs" /> <Compile Include="Map\MapStub.cs" />
<Compile Include="Map\SmudgeReference.cs" /> <Compile Include="Map\SmudgeReference.cs" />
<Compile Include="Map\PlayerReference.cs" /> <Compile Include="Map\PlayerReference.cs" />
<Compile Include="CompressedPackage.cs" />
<Compile Include="Graphics\VqaReader.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> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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 Name="AfterBuild">
</Target> </Target>
--> -->
<ItemGroup>
<Folder Include="Filesystem\" />
</ItemGroup>
</Project> </Project>

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

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

View File

@@ -60,7 +60,7 @@ namespace OpenRA
if (!AvailableMaps.ContainsKey(uid)) if (!AvailableMaps.ContainsKey(uid))
throw new InvalidDataException("Invalid map uid: {0}".F(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); Rules.LoadRules(Manifest, map);
if (map.Theater != cachedTheatre) if (map.Theater != cachedTheatre)

View File

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

View File

@@ -183,7 +183,7 @@ namespace OpenRA.Widgets.Delegates
{ {
if (MapUid == orderManager.LobbyInfo.GlobalSettings.Map) return; if (MapUid == orderManager.LobbyInfo.GlobalSettings.Map) return;
MapUid = orderManager.LobbyInfo.GlobalSettings.Map; 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"); var title = Widget.RootWidget.GetWidget<LabelWidget>("LOBBY_TITLE");
title.Text = "OpenRA Multiplayer Lobby - " + orderManager.LobbyInfo.GlobalSettings.ServerName; title.Text = "OpenRA Multiplayer Lobby - " + orderManager.LobbyInfo.GlobalSettings.ServerName;

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Widgets
public Func<MapStub> Map = () => null; public Func<MapStub> Map = () => null;
public Action<int> OnSpawnClick = spawn => {}; public Action<int> OnSpawnClick = spawn => {};
public Func<Dictionary<int2, Color>> SpawnColors = () => new Dictionary<int2, Color>(); 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() { } public MapPreviewWidget() : base() { }
protected MapPreviewWidget(MapPreviewWidget other) protected MapPreviewWidget(MapPreviewWidget other)