Add AppearsOnMapPreview
Allows preplaced actors to be rendered on map preview when saving the map. Also removes requirements for ResourceLayer in OpenRA.Game and moves it to OpenRA.Mods.Common.
This commit is contained in:
committed by
reaperrr
parent
ea4f24d0b7
commit
9fef2c01ec
@@ -646,8 +646,24 @@ namespace OpenRA
|
||||
public byte[] SavePreview()
|
||||
{
|
||||
var tileset = Rules.TileSet;
|
||||
var resources = Rules.Actors["world"].TraitInfos<ResourceTypeInfo>()
|
||||
.ToDictionary(r => r.ResourceType, r => r.TerrainType);
|
||||
var actorTypes = Rules.Actors.Values.Where(a => a.HasTraitInfo<IMapPreviewSignatureInfo>());
|
||||
var actors = ActorDefinitions.Where(a => actorTypes.Where(ai => ai.Name == a.Value.Value).Any());
|
||||
var positions = new List<Pair<MPos, Color>>();
|
||||
foreach (var actor in actors)
|
||||
{
|
||||
var s = new ActorReference(actor.Value.Value, actor.Value.ToDictionary());
|
||||
|
||||
var ai = Rules.Actors[actor.Value.Value];
|
||||
var impsis = ai.TraitInfos<IMapPreviewSignatureInfo>();
|
||||
foreach (var impsi in impsis)
|
||||
impsi.PopulateMapPreviewSignatureCells(this, ai, s, positions);
|
||||
}
|
||||
|
||||
// ResourceLayer is on world actor, which isn't caught above, so an extra check for it.
|
||||
var worldActorInfo = Rules.Actors["world"];
|
||||
var worldimpsis = worldActorInfo.TraitInfos<IMapPreviewSignatureInfo>();
|
||||
foreach (var worldimpsi in worldimpsis)
|
||||
worldimpsi.PopulateMapPreviewSignatureCells(this, worldActorInfo, null, positions);
|
||||
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
@@ -672,15 +688,10 @@ namespace OpenRA
|
||||
for (var x = 0; x < width; x++)
|
||||
{
|
||||
var uv = new MPos(x + Bounds.Left, y + Bounds.Top);
|
||||
var resourceType = Resources[uv].Type;
|
||||
if (resourceType != 0)
|
||||
var actorsThere = positions.Where(ap => ap.First == uv);
|
||||
if (actorsThere.Any())
|
||||
{
|
||||
// Cell contains resources
|
||||
string res;
|
||||
if (!resources.TryGetValue(resourceType, out res))
|
||||
continue;
|
||||
|
||||
leftColor = rightColor = tileset[tileset.GetTerrainIndex(res)].Color;
|
||||
leftColor = rightColor = actorsThere.First().Second;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -181,7 +181,6 @@
|
||||
<Compile Include="Traits\Target.cs" />
|
||||
<Compile Include="Traits\TraitsInterfaces.cs" />
|
||||
<Compile Include="Traits\World\Faction.cs" />
|
||||
<Compile Include="Traits\World\ResourceType.cs" />
|
||||
<Compile Include="Traits\World\ScreenShaker.cs" />
|
||||
<Compile Include="Traits\World\DebugVisualizations.cs" />
|
||||
<Compile Include="World.cs" />
|
||||
|
||||
@@ -287,6 +287,11 @@ namespace OpenRA.Traits
|
||||
|
||||
public interface ISelectionDecorations { void DrawRollover(Actor self, WorldRenderer worldRenderer); }
|
||||
|
||||
public interface IMapPreviewSignatureInfo : ITraitInfoInterface
|
||||
{
|
||||
void PopulateMapPreviewSignatureCells(Map map, ActorInfo ai, ActorReference s, List<Pair<MPos, Color>> destinationBuffer);
|
||||
}
|
||||
|
||||
public interface IOccupySpaceInfo : ITraitInfoInterface
|
||||
{
|
||||
IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any);
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2019 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;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
public class ResourceTypeInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Sequence image that holds the different variants.")]
|
||||
public readonly string Image = "resources";
|
||||
|
||||
[FieldLoader.Require]
|
||||
[SequenceReference("Image")]
|
||||
[Desc("Randomly chosen image sequences.")]
|
||||
public readonly string[] Sequences = { };
|
||||
|
||||
[PaletteReference]
|
||||
[Desc("Palette used for rendering the resource sprites.")]
|
||||
public readonly string Palette = TileSet.TerrainPaletteInternalName;
|
||||
|
||||
[Desc("Resource index used in the binary map data.")]
|
||||
public readonly int ResourceType = 1;
|
||||
|
||||
[Desc("Credit value of a single resource unit.")]
|
||||
public readonly int ValuePerUnit = 0;
|
||||
|
||||
[Desc("Maximum number of resource units allowed in a single cell.")]
|
||||
public readonly int MaxDensity = 10;
|
||||
|
||||
[FieldLoader.Require]
|
||||
[Desc("Resource identifier used by other traits.")]
|
||||
public readonly string Type = null;
|
||||
|
||||
[FieldLoader.Require]
|
||||
[Desc("Resource name used by tooltips.")]
|
||||
public readonly string Name = null;
|
||||
|
||||
[FieldLoader.Require]
|
||||
[Desc("Terrain type used to determine unit movement and minimap colors.")]
|
||||
public readonly string TerrainType = null;
|
||||
|
||||
[Desc("Terrain types that this resource can spawn on.")]
|
||||
public readonly HashSet<string> AllowedTerrainTypes = new HashSet<string>();
|
||||
|
||||
[Desc("Allow resource to spawn under Mobile actors.")]
|
||||
public readonly bool AllowUnderActors = false;
|
||||
|
||||
[Desc("Allow resource to spawn under Buildings.")]
|
||||
public readonly bool AllowUnderBuildings = false;
|
||||
|
||||
[Desc("Allow resource to spawn on ramp tiles.")]
|
||||
public readonly bool AllowOnRamps = false;
|
||||
|
||||
[Desc("Harvester content pip color.")]
|
||||
public PipType PipColor = PipType.Yellow;
|
||||
|
||||
public object Create(ActorInitializer init) { return new ResourceType(this, init.World); }
|
||||
}
|
||||
|
||||
public class ResourceType : IWorldLoaded
|
||||
{
|
||||
public readonly ResourceTypeInfo Info;
|
||||
public PaletteReference Palette { get; private set; }
|
||||
public readonly Dictionary<string, Sprite[]> Variants;
|
||||
|
||||
public ResourceType(ResourceTypeInfo info, World world)
|
||||
{
|
||||
Info = info;
|
||||
Variants = new Dictionary<string, Sprite[]>();
|
||||
foreach (var v in info.Sequences)
|
||||
{
|
||||
var seq = world.Map.Rules.Sequences.GetSequence(Info.Image, v);
|
||||
var sprites = Exts.MakeArray(seq.Length, x => seq.GetSprite(x));
|
||||
Variants.Add(v, sprites);
|
||||
}
|
||||
}
|
||||
|
||||
public void WorldLoaded(World w, WorldRenderer wr)
|
||||
{
|
||||
Palette = wr.Palette(Info.Palette);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user