Remove TileSet.Palette and PaletteFromCurrentTileset.

This commit is contained in:
Paul Chote
2018-04-08 17:27:58 +00:00
committed by reaperrr
parent 7221c29d9b
commit 4f0aa89c01
22 changed files with 179 additions and 87 deletions

View File

@@ -184,7 +184,6 @@ namespace OpenRA
public readonly string Name;
public readonly string Id;
public readonly int SheetSize = 512;
public readonly string Palette;
public readonly Color[] HeightDebugColors = new[] { Color.Red };
public readonly string[] EditorTemplateOrder;
public readonly bool IgnoreTileSpriteOffsets;
@@ -234,11 +233,10 @@ namespace OpenRA
.Select(y => new TerrainTemplateInfo(this, y)).ToDictionary(t => t.Id).AsReadOnly();
}
public TileSet(string name, string id, string palette, TerrainTypeInfo[] terrainInfo)
public TileSet(string name, string id, TerrainTypeInfo[] terrainInfo)
{
Name = name;
Id = id;
Palette = palette;
TerrainInfo = terrainInfo;
if (TerrainInfo.Length >= byte.MaxValue)

View File

@@ -191,14 +191,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
Console.WriteLine("\tRenderSprites:");
if (useTerrainPalette)
{
if (Game.ModData.DefaultRules.Actors.ContainsKey("world"))
{
var terrainPaletteDefintion = Game.ModData.DefaultRules.Actors["world"].TraitInfos<PaletteFromCurrentTilesetInfo>();
if (terrainPaletteDefintion.Any())
Console.WriteLine("\t\tPalette: " + terrainPaletteDefintion.Last().Name);
}
}
Console.WriteLine("\t\tPalette: terrain");
var image = rulesSection.GetValue("Image", string.Empty);
if (!string.IsNullOrEmpty(image) && image != "none")

View File

@@ -537,7 +537,6 @@
<Compile Include="Traits\World\LoadWidgetAtGameStart.cs" />
<Compile Include="Traits\World\MPStartLocations.cs" />
<Compile Include="Traits\World\MPStartUnits.cs" />
<Compile Include="Traits\World\PaletteFromCurrentTileset.cs" />
<Compile Include="Traits\World\PaletteFromFile.cs" />
<Compile Include="Traits\World\PaletteFromGimpOrJascFile.cs" />
<Compile Include="Traits\World\PaletteFromRGBA.cs" />
@@ -863,6 +862,7 @@
<Compile Include="UpdateRules\Rules\RenameWormSpawner.cs" />
<Compile Include="UpdateRules\Rules\RemoveWithReloadingSpriteTurret.cs" />
<Compile Include="UpdateRules\Rules\AddEditorPlayer.cs" />
<Compile Include="UpdateRules\Rules\RemovePaletteFromCurrentTileset.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">

View File

@@ -1,51 +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.Collections.Generic;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Loads the palette specified in the tileset definition")]
public class PaletteFromCurrentTilesetInfo : ITraitInfo
{
[FieldLoader.Require, PaletteDefinition]
[Desc("internal palette name")]
public readonly string Name = null;
[Desc("Map listed indices to shadow. Ignores previous color.")]
public readonly int[] ShadowIndex = { };
public readonly bool AllowModifiers = true;
public object Create(ActorInitializer init) { return new PaletteFromCurrentTileset(init.World, this); }
}
public class PaletteFromCurrentTileset : ILoadsPalettes, IProvidesAssetBrowserPalettes
{
readonly World world;
readonly PaletteFromCurrentTilesetInfo info;
public PaletteFromCurrentTileset(World world, PaletteFromCurrentTilesetInfo info)
{
this.world = world;
this.info = info;
}
public void LoadPalettes(WorldRenderer wr)
{
wr.AddPalette(info.Name, new ImmutablePalette(wr.World.Map.Open(world.Map.Rules.TileSet.Palette), info.ShadowIndex), info.AllowModifiers);
}
public IEnumerable<string> PaletteNames { get { yield return info.Name; } }
}
}

View File

@@ -0,0 +1,88 @@
#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.Collections.Generic;
using System.Linq;
namespace OpenRA.Mods.Common.UpdateRules.Rules
{
public class RemovePaletteFromCurrentTileset : UpdateRule
{
public override string Name { get { return "Remove PaletteFromCurrentTileset trait"; } }
public override string Description
{
get
{
return "The PaletteFromCurrentTileset trait and Palette field on TileSets have been removed.\n" +
"Terrain palettes are now explicitly defined on the world actor.";
}
}
readonly Dictionary<string, string> tilesetPalettes = new Dictionary<string, string>();
readonly List<Tuple<string, int[]>> paletteTraits = new List<Tuple<string, int[]>>();
string BuildYaml(string palette, int[] shadow, string tileset, string filename)
{
return "PaletteFromFile@{0}:\n Name: {1}\n Tileset: {2}\n Filename: {3}\n ShadowIndex: {4}".F(
palette + '-' + tileset.ToLower(), palette, tileset, filename, FieldSaver.FormatValue(shadow));
}
public override IEnumerable<string> AfterUpdate(ModData modData)
{
if (tilesetPalettes.Any() && paletteTraits.Any())
yield return "You must add the following to your palette definitions:\n"
+ paletteTraits.Select(p => tilesetPalettes.Select(kv =>
BuildYaml(p.Item1, p.Item2, kv.Key, kv.Value)).JoinWith("\n")).JoinWith("\n");
paletteTraits.Clear();
yield break;
}
public override IEnumerable<string> UpdateTilesetNode(ModData modData, MiniYamlNode tilesetNode)
{
if (tilesetNode.Key == "General")
{
var idNode = tilesetNode.LastChildMatching("Id");
if (idNode == null)
yield break;
var paletteNode = tilesetNode.LastChildMatching("Palette");
if (paletteNode != null)
tilesetPalettes[idNode.Value.Value] = paletteNode.Value.Value;
tilesetNode.RemoveNodes("Palette");
}
}
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
{
foreach (var paletteNode in actorNode.ChildrenMatching("PaletteFromCurrentTileset"))
{
var name = "terrain";
var shadow = new int[] { };
var shadowNode = paletteNode.LastChildMatching("ShadowIndex");
if (shadowNode != null)
shadow = shadowNode.NodeValue<int[]>();
var nameNode = paletteNode.LastChildMatching("Name");
if (nameNode != null)
name = nameNode.Value.Value;
paletteTraits.Add(Tuple.Create(name, shadow));
}
actorNode.RemoveNodes("PaletteFromCurrentTileset");
yield break;
}
}
}

View File

@@ -46,7 +46,8 @@ namespace OpenRA.Mods.Common.UpdateRules
new RenameWormSpawner(),
new RemoveWithReloadingSpriteTurret(),
new IgnoreAbstractActors(),
new AddEditorPlayer()
new AddEditorPlayer(),
new RemovePaletteFromCurrentTileset()
})
};

View File

@@ -1,9 +1,53 @@
^Palettes:
PaletteFromCurrentTileset@terrain:
PaletteFromFile@terrain-desert:
Name: terrain
Tileset: DESERT
Filename: desert.pal
ShadowIndex: 4
PaletteFromCurrentTileset@static:
PaletteFromFile@terrain-winter:
Name: terrain
Tileset: WINTER
Filename: winter.pal
ShadowIndex: 4
PaletteFromFile@terrain-snow:
Name: terrain
Tileset: SNOW
Filename: snow.pal
ShadowIndex: 4
PaletteFromFile@terrain-temperat:
Name: terrain
Tileset: TEMPERAT
Filename: temperat.pal
ShadowIndex: 4
PaletteFromFile@terrain-jungle:
Name: terrain
Tileset: JUNGLE
Filename: jungle.pal
ShadowIndex: 4
PaletteFromFile@staticterrain-desert:
Name: staticterrain
Tileset: DESERT
Filename: desert.pal
ShadowIndex: 4
PaletteFromFile@staticterrain-winter:
Name: staticterrain
Tileset: WINTER
Filename: winter.pal
ShadowIndex: 4
PaletteFromFile@staticterrain-snow:
Name: staticterrain
Tileset: SNOW
Filename: snow.pal
ShadowIndex: 4
PaletteFromFile@staticterrain-temperat:
Name: staticterrain
Tileset: TEMPERAT
Filename: temperat.pal
ShadowIndex: 4
PaletteFromFile@staticterrain-jungle:
Name: staticterrain
Tileset: JUNGLE
Filename: jungle.pal
ShadowIndex: 4
PaletteFromFile@chrome:
Name: chrome

View File

@@ -1,7 +1,6 @@
General:
Name: Desert
Id: DESERT
Palette: desert.pal
EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge
HeightDebugColors: 880000

View File

@@ -1,7 +1,6 @@
General:
Name: Jungle
Id: JUNGLE
Palette: jungle.pal
EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge
HeightDebugColors: AA0000

View File

@@ -1,7 +1,6 @@
General:
Name: Snow
Id: SNOW
Palette: snow.pal
EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge
HeightDebugColors: 880000

View File

@@ -1,7 +1,6 @@
General:
Name: Temperate
Id: TEMPERAT
Palette: temperat.pal
EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge
HeightDebugColors: AA0000

View File

@@ -1,7 +1,6 @@
General:
Name: Winter
Id: WINTER
Palette: winter.pal
EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Beach, River, Bridge
HeightDebugColors: 880000

View File

@@ -1,6 +1,7 @@
^Palettes:
PaletteFromCurrentTileset:
PaletteFromFile:
Name: terrain
Filename: PALETTE.BIN
PaletteFromFile@d2k:
Name: d2k
Filename: PALETTE.BIN

View File

@@ -2,7 +2,6 @@ General:
Name: Arrakis
Id: ARRAKIS
SheetSize: 1024
Palette: PALETTE.BIN
EditorTemplateOrder: Basic, Dune, Sand-Detail, Rock-Detail, Ice-Detail, Rock-Sand-Smooth, Sand-Sand-Cliff, Sand-Rock-Cliff, Sand-Ice-Cliff, Rock-Rock-Cliff, Rock-Sand-Cliff, Cliff-Type-Changer, Cliff-Ends, Sand-Platform, Bridge, Rotten-Base, Dead-Worm, Unidentified
IgnoreTileSpriteOffsets: True
HeightDebugColors: 880000

View File

@@ -1,11 +1,28 @@
^Palettes:
PaletteFromFile@terrain-snow:
Name: terrain
Tileset: SNOW
Filename: snow.pal
ShadowIndex: 3, 4
PaletteFromFile@terrain-interior:
Name: terrain
Tileset: INTERIOR
Filename: interior.pal
ShadowIndex: 3, 4
PaletteFromFile@terrain-temperat:
Name: terrain
Tileset: TEMPERAT
Filename: temperat.pal
ShadowIndex: 3, 4
PaletteFromFile@terrain-desert:
Name: terrain
Tileset: DESERT
Filename: desert.pal
ShadowIndex: 3, 4
PaletteFromFile@player:
Name: player
Filename: temperat.pal
ShadowIndex: 4
PaletteFromCurrentTileset:
Name: terrain
ShadowIndex: 3,4
PaletteFromFile@chrome:
Name: chrome
Filename: temperat.pal

View File

@@ -1,7 +1,6 @@
General:
Name: Desert
Id: DESERT
Palette: desert.pal
EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Water Cliffs, Beach, River, Bridge
HeightDebugColors: 880000

View File

@@ -1,7 +1,6 @@
General:
Name: Interior
Id: INTERIOR
Palette: interior.pal
EditorTemplateOrder: Floor, Wall
HeightDebugColors: 880000

View File

@@ -1,7 +1,6 @@
General:
Name: Snow
Id: SNOW
Palette: snow.pal
EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Water Cliffs, Beach, River, Bridge
HeightDebugColors: 880000

View File

@@ -1,7 +1,6 @@
General:
Name: Temperate
Id: TEMPERAT
Palette: temperat.pal
SheetSize: 1024
EditorTemplateOrder: Terrain, Debris, Road, Cliffs, Water Cliffs, Beach, River, Bridge
HeightDebugColors: AA0000

View File

@@ -2,6 +2,24 @@
PaletteFromFile@mouse:
Name: mouse
Filename: mousepal.pal
PaletteFromFile@terraintem:
Name: terrain
Tileset: TEMPERATE
Filename: isotem.pal
PaletteFromFile@terrainsno:
Name: terrain
Tileset: SNOW
Filename: isosno.pal
PaletteFromFile@terraindectem:
Name: terraindecoration
Tileset: TEMPERATE
Filename: isotem.pal
ShadowIndex: 1
PaletteFromFile@terraindecsno:
Name: terraindecoration
Tileset: SNOW
Filename: isosno.pal
ShadowIndex: 1
PaletteFromFile@playersno:
Name: player
Tileset: SNOW
@@ -15,11 +33,6 @@
PaletteFromFile@depth:
Name: depth
Filename: depth.pal
PaletteFromCurrentTileset:
Name: terrain
PaletteFromCurrentTileset@decoration:
Name: terraindecoration
ShadowIndex: 1
PaletteFromFile@chrome:
Name: chrome
Filename: cameo.pal

View File

@@ -1,7 +1,6 @@
General:
Name: Snow
Id: SNOW
Palette: isosno.pal
HeightDebugColors: 00000080, 00004480, 00008880, 0000CC80, 0000FF80, 4400CC80, 88008880, CC004480, FF110080, FF550080, FF990080, FFDD0080, DDFF0080, 99FF0080, 55FF0080, 11FF0080
EditorTemplateOrder: Bendy Dirt Roads, Blank, Bridges, Civilian Buildings, Clear, Clear/Rough LAT, Cliff Pieces, Cliff Set, Cliff/Water pieces, Dead Oil Tanker, Destroyable Cliffs, Dirt Road Junctions, Dirt Road Slopes, DirtTrackTunnel Floor, DirtTunnel Floor, Grey/Clear LAT, House, Ice 01, Ice 02, Ice 03, Ice Flow, Ice Ramps, Ice shore, Misc Buildings, Monorail Slopes, Paved Road Ends, Paved Road Slopes, Paved Roads, Pavement, Pavement (Use for LAT), Pavement/Clear LAT, Ramp edge fixup, Rough ground, Rough lat, Ruins, Shore Pieces, Slope Set Pieces, Straight Dirt Roads, TrackTunnel Floor, TrainBridges, Tunnel Side, Tunnels, Water, Water slopes, Waterfalls, Waterfalls-B, Waterfalls-C, Waterfalls-D
SheetSize: 2048

View File

@@ -1,7 +1,6 @@
General:
Name: Temperate
Id: TEMPERATE
Palette: isotem.pal
HeightDebugColors: 00000080, 00004480, 00008880, 0000CC80, 0000FF80, 4400CC80, 88008880, CC004480, FF110080, FF550080, FF990080, FFDD0080, DDFF0080, 99FF0080, 55FF0080, 11FF0080
EditorTemplateOrder: Misc Buildings, Clear, Cliff Pieces, Ice Flow, House, Blank, Ice Ramps, Cliff Set, Civilian Buildings, Shore Pieces, Rough LAT tile, Clear/Rough LAT, Cliff/Water pieces, Bendy Dirt Roads, Dirt Road Junctions, Straight Dirt Roads, Bridges, Paved Roads, Water, Dirt Road Slopes, Slope Set Pieces, Dead Oil Tanker, Ruins, Waterfalls, Ground 01, Ground 02, Sand, Sand/Clear LAT, Rough ground, Paved Road Ends, TrainBridges, Pavement, Pavement/Clear LAT, Paved road bits, Green, Green/Clear LAT, Ramp edge fixup, Water slopes, Pavement (Use for LAT), Paved Road Slopes, Monorail Slopes, Waterfalls-B, Waterfalls-C, Waterfalls-D, Tunnel Floor, Tunnel Side, TrackTunnel Floor, Destroyable Cliffs, Water Caves, Scrin Wreckage, DirtTrackTunnel Floor, DirtTunnel Floor, Crystal LAT tile, Clear Crystal LAT, Swampy, Swampy LAT, Blue Mold, Blue Mold LAT, Crystal Cliff, Kodiak Crash
SheetSize: 2048