Remove unused tileset update/save code.
This commit is contained in:
committed by
Oliver Brakmann
parent
0fca984463
commit
ad4b4dc7f8
@@ -30,36 +30,10 @@ namespace OpenRA
|
||||
|
||||
public readonly float ZOffset = 0.0f;
|
||||
public readonly float ZRamp = 1.0f;
|
||||
|
||||
public MiniYaml Save(TileSet tileSet)
|
||||
{
|
||||
var root = new List<MiniYamlNode>();
|
||||
if (Height != 0)
|
||||
root.Add(FieldSaver.SaveField(this, "Height"));
|
||||
|
||||
if (RampType != 0)
|
||||
root.Add(FieldSaver.SaveField(this, "RampType"));
|
||||
|
||||
if (LeftColor != tileSet.TerrainInfo[TerrainType].Color)
|
||||
root.Add(FieldSaver.SaveField(this, "LeftColor"));
|
||||
|
||||
if (RightColor != tileSet.TerrainInfo[TerrainType].Color)
|
||||
root.Add(FieldSaver.SaveField(this, "RightColor"));
|
||||
|
||||
if (ZOffset != 0.0f)
|
||||
root.Add(FieldSaver.SaveField(this, "ZOffset"));
|
||||
|
||||
if (ZRamp != 1.0f)
|
||||
root.Add(FieldSaver.SaveField(this, "ZRamp"));
|
||||
|
||||
return new MiniYaml(tileSet.TerrainInfo[TerrainType].Type, root);
|
||||
}
|
||||
}
|
||||
|
||||
public class TerrainTypeInfo
|
||||
{
|
||||
static readonly TerrainTypeInfo Default = new TerrainTypeInfo();
|
||||
|
||||
public readonly string Type;
|
||||
public readonly BitSet<TargetableType> TargetTypes;
|
||||
public readonly HashSet<string> AcceptsSmudgeType = new HashSet<string>();
|
||||
@@ -67,18 +41,11 @@ namespace OpenRA
|
||||
public readonly bool RestrictPlayerColor = false;
|
||||
public readonly string CustomCursor;
|
||||
|
||||
// Private default ctor for serialization comparison
|
||||
TerrainTypeInfo() { }
|
||||
|
||||
public TerrainTypeInfo(MiniYaml my) { FieldLoader.Load(this, my); }
|
||||
|
||||
public MiniYaml Save() { return FieldSaver.SaveDifferences(this, Default); }
|
||||
}
|
||||
|
||||
public class TerrainTemplateInfo
|
||||
{
|
||||
static readonly TerrainTemplateInfo Default = new TerrainTemplateInfo(0, new string[] { null }, int2.Zero, null);
|
||||
|
||||
public readonly ushort Id;
|
||||
public readonly string[] Images;
|
||||
public readonly int[] Frames;
|
||||
@@ -160,21 +127,6 @@ namespace OpenRA
|
||||
{
|
||||
get { return tileInfo.Length; }
|
||||
}
|
||||
|
||||
public MiniYaml Save(TileSet tileSet)
|
||||
{
|
||||
var root = FieldSaver.SaveDifferences(this, Default);
|
||||
|
||||
var tileYaml = tileInfo
|
||||
.Select((ti, i) => Pair.New(i.ToString(), ti))
|
||||
.Where(t => t.Second != null)
|
||||
.Select(t => new MiniYamlNode(t.First, t.Second.Save(tileSet)))
|
||||
.ToList();
|
||||
|
||||
root.Nodes.Add(new MiniYamlNode("Tiles", null, tileYaml));
|
||||
|
||||
return root;
|
||||
}
|
||||
}
|
||||
|
||||
public class TileSet
|
||||
@@ -197,9 +149,6 @@ namespace OpenRA
|
||||
readonly Dictionary<string, byte> terrainIndexByType = new Dictionary<string, byte>();
|
||||
readonly byte defaultWalkableTerrainIndex;
|
||||
|
||||
// Private default ctor for serialization comparison
|
||||
TileSet() { }
|
||||
|
||||
public TileSet(IReadOnlyFileSystem fileSystem, string filepath)
|
||||
{
|
||||
var yaml = MiniYaml.FromStream(fileSystem.Open(filepath), filepath)
|
||||
@@ -298,18 +247,5 @@ namespace OpenRA
|
||||
|
||||
return tpl.Contains(r.Index) ? tpl[r.Index] : null;
|
||||
}
|
||||
|
||||
public void Save(string filepath)
|
||||
{
|
||||
var root = new List<MiniYamlNode>();
|
||||
root.Add(new MiniYamlNode("General", FieldSaver.SaveDifferences(this, new TileSet())));
|
||||
|
||||
root.Add(new MiniYamlNode("Terrain", null,
|
||||
TerrainInfo.Select(t => new MiniYamlNode("TerrainType@{0}".F(t.Type), t.Save())).ToList()));
|
||||
|
||||
root.Add(new MiniYamlNode("Templates", null,
|
||||
Templates.Select(t => new MiniYamlNode("Template@{0}".F(t.Value.Id), t.Value.Save(this))).ToList()));
|
||||
root.WriteToFile(filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -749,7 +749,6 @@
|
||||
<Compile Include="Widgets\VqaPlayerWidget.cs" />
|
||||
<Compile Include="Traits\Render\WithInfantryBody.cs" />
|
||||
<Compile Include="UtilityCommands\CheckSequenceSprites.cs" />
|
||||
<Compile Include="UtilityCommands\FixClassicTilesets.cs" />
|
||||
<Compile Include="Graphics\TilesetSpecificSpriteSequence.cs" />
|
||||
<Compile Include="Traits\Pluggable.cs" />
|
||||
<Compile Include="Traits\Plug.cs" />
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2018 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Mods.Common.UtilityCommands
|
||||
{
|
||||
class FixClassicTilesets : IUtilityCommand
|
||||
{
|
||||
string IUtilityCommand.Name { get { return "--fix-classic-tilesets"; } }
|
||||
|
||||
bool IUtilityCommand.ValidateArguments(string[] args)
|
||||
{
|
||||
return args.Length >= 2;
|
||||
}
|
||||
|
||||
[Desc("EXTENSIONS", "Fixes missing template tile definitions and adds filename extensions.")]
|
||||
void IUtilityCommand.Run(Utility utility, string[] args)
|
||||
{
|
||||
// HACK: The engine code assumes that Game.modData is set.
|
||||
var modData = Game.ModData = utility.ModData;
|
||||
|
||||
var imageField = typeof(TerrainTemplateInfo).GetField("Image");
|
||||
var pickAnyField = typeof(TerrainTemplateInfo).GetField("PickAny");
|
||||
var tileInfoField = typeof(TerrainTemplateInfo).GetField("tileInfo", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var terrainTypeField = typeof(TerrainTileInfo).GetField("TerrainType");
|
||||
var terrainLeftColorField = typeof(TerrainTileInfo).GetField("LeftColor");
|
||||
var terrainRightColorField = typeof(TerrainTileInfo).GetField("RightColor");
|
||||
var empty = new Size(0, 0);
|
||||
var single = new int2(1, 1);
|
||||
var exts = new[] { "" }.Concat(args[1].Split(','));
|
||||
|
||||
foreach (var t in modData.Manifest.TileSets)
|
||||
{
|
||||
var ts = new TileSet(modData.DefaultFileSystem, t);
|
||||
var frameCache = new FrameCache(modData.DefaultFileSystem, modData.SpriteLoaders);
|
||||
|
||||
Console.WriteLine("Tileset: " + ts.Name);
|
||||
foreach (var template in ts.Templates.Values)
|
||||
{
|
||||
// Find the sprite associated with this template
|
||||
foreach (var ext in exts)
|
||||
{
|
||||
Stream s;
|
||||
if (modData.DefaultFileSystem.TryOpen(template.Images[0] + ext, out s))
|
||||
s.Dispose();
|
||||
else
|
||||
continue;
|
||||
|
||||
// Rewrite the template image (normally readonly) using reflection
|
||||
imageField.SetValue(template, template.Images[0] + ext);
|
||||
|
||||
// Fetch the private tileInfo array so that we can write new entries
|
||||
var tileInfo = (TerrainTileInfo[])tileInfoField.GetValue(template);
|
||||
|
||||
// Open the file and search for any implicit frames
|
||||
var allFrames = frameCache[template.Images[0]];
|
||||
var frames = template.Frames != null ? template.Frames.Select(f => allFrames[f]).ToArray() : allFrames;
|
||||
|
||||
// Resize array for new entries
|
||||
if (frames.Length > template.TilesCount)
|
||||
{
|
||||
var ti = new TerrainTileInfo[frames.Length];
|
||||
Array.Copy(tileInfo, ti, template.TilesCount);
|
||||
tileInfoField.SetValue(template, ti);
|
||||
tileInfo = ti;
|
||||
}
|
||||
|
||||
for (var i = 0; i < template.TilesCount; i++)
|
||||
{
|
||||
if (template[i] == null && frames[i] != null && frames[i].Size != empty)
|
||||
{
|
||||
tileInfo[i] = new TerrainTileInfo();
|
||||
var ti = ts.GetTerrainIndex("Clear");
|
||||
terrainTypeField.SetValue(tileInfo[i], ti);
|
||||
terrainLeftColorField.SetValue(tileInfo[i], ts[ti].Color);
|
||||
terrainRightColorField.SetValue(tileInfo[i], ts[ti].Color);
|
||||
Console.WriteLine("Fixing entry for {0}:{1}", template.Images[0], i);
|
||||
}
|
||||
}
|
||||
|
||||
if (template.TilesCount > 1 && template.Size == single)
|
||||
pickAnyField.SetValue(template, true);
|
||||
}
|
||||
}
|
||||
|
||||
ts.Save(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user