RenderBuildingWall -> WithWallSpriteBody

This commit is contained in:
reaperrr
2015-07-15 07:25:43 +02:00
parent 21186c10b6
commit bf51e0600d
13 changed files with 71 additions and 40 deletions

View File

@@ -411,7 +411,7 @@
<Compile Include="Traits\Render\RenderNameTag.cs" /> <Compile Include="Traits\Render\RenderNameTag.cs" />
<Compile Include="Traits\Render\RenderSimple.cs" /> <Compile Include="Traits\Render\RenderSimple.cs" />
<Compile Include="Traits\Render\RenderSprites.cs" /> <Compile Include="Traits\Render\RenderSprites.cs" />
<Compile Include="Traits\Render\RenderBuildingWall.cs" /> <Compile Include="Traits\Render\WithWallSpriteBody.cs" />
<Compile Include="Traits\Render\RenderDetectionCircle.cs" /> <Compile Include="Traits\Render\RenderDetectionCircle.cs" />
<Compile Include="Traits\Render\RenderRangeCircle.cs" /> <Compile Include="Traits\Render\RenderRangeCircle.cs" />
<Compile Include="Traits\Render\RenderVoxels.cs" /> <Compile Include="Traits\Render\RenderVoxels.cs" />

View File

@@ -17,11 +17,11 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Render trait for actors that change sprites if neighbors with the same trait are present.")] [Desc("Render trait for actors that change sprites if neighbors with the same trait are present.")]
class RenderBuildingWallInfo : RenderBuildingInfo class WithWallSpriteBodyInfo : WithSpriteBodyInfo
{ {
public readonly string Type = "wall"; public readonly string Type = "wall";
public override object Create(ActorInitializer init) { return new RenderBuildingWall(init, this); } public override object Create(ActorInitializer init) { return new WithWallSpriteBody(init, this); }
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p) public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
{ {
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
var haveNeighbour = false; var haveNeighbour = false;
foreach (var n in kv.Value) foreach (var n in kv.Value)
{ {
var rb = init.World.Map.Rules.Actors[n].Traits.GetOrDefault<RenderBuildingWallInfo>(); var rb = init.World.Map.Rules.Actors[n].Traits.GetOrDefault<WithWallSpriteBodyInfo>();
if (rb != null && rb.Type == Type) if (rb != null && rb.Type == Type)
{ {
haveNeighbour = true; haveNeighbour = true;
@@ -68,33 +68,26 @@ namespace OpenRA.Mods.Common.Traits
} }
} }
class RenderBuildingWall : RenderBuilding, INotifyAddedToWorld, INotifyRemovedFromWorld class WithWallSpriteBody : WithSpriteBody, INotifyAddedToWorld, INotifyRemovedFromWorld, ITick
{ {
readonly RenderBuildingWallInfo info; readonly WithWallSpriteBodyInfo wallInfo;
int adjacent = 0; int adjacent = 0;
bool dirty = true; bool dirty = true;
public RenderBuildingWall(ActorInitializer init, RenderBuildingWallInfo info) public WithWallSpriteBody(ActorInitializer init, WithWallSpriteBodyInfo info)
: base(init, info) : base(init, info, () => 0)
{ {
this.info = info; wallInfo = info;
} DefaultAnimation.PlayFetchIndex(NormalizeSequence(init.Self, Info.Sequence), () => adjacent);
public override void BuildingComplete(Actor self)
{
DefaultAnimation.PlayFetchIndex(info.Sequence, () => adjacent);
UpdateNeighbours(self);
} }
public override void DamageStateChanged(Actor self, AttackInfo e) public override void DamageStateChanged(Actor self, AttackInfo e)
{ {
DefaultAnimation.PlayFetchIndex(NormalizeSequence(DefaultAnimation, e.DamageState, info.Sequence), () => adjacent); DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), () => adjacent);
} }
public override void Tick(Actor self) public void Tick(Actor self)
{ {
base.Tick(self);
if (!dirty) if (!dirty)
return; return;
@@ -105,8 +98,8 @@ namespace OpenRA.Mods.Common.Traits
adjacent = 0; adjacent = 0;
foreach (var a in adjacentActors) foreach (var a in adjacentActors)
{ {
var rb = a.TraitOrDefault<RenderBuildingWall>(); var rb = a.TraitOrDefault<WithWallSpriteBody>();
if (rb == null || rb.info.Type != info.Type) if (rb == null || rb.wallInfo.Type != wallInfo.Type)
continue; continue;
var location = self.Location; var location = self.Location;
@@ -129,7 +122,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
var adjacentActors = CVec.Directions.SelectMany(dir => var adjacentActors = CVec.Directions.SelectMany(dir =>
self.World.ActorMap.GetUnitsAt(self.Location + dir)) self.World.ActorMap.GetUnitsAt(self.Location + dir))
.Select(a => a.TraitOrDefault<RenderBuildingWall>()) .Select(a => a.TraitOrDefault<WithWallSpriteBody>())
.Where(a => a != null); .Where(a => a != null);
foreach (var rb in adjacentActors) foreach (var rb in adjacentActors)
@@ -138,6 +131,7 @@ namespace OpenRA.Mods.Common.Traits
public void AddedToWorld(Actor self) public void AddedToWorld(Actor self)
{ {
DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), () => adjacent);
UpdateNeighbours(self); UpdateNeighbours(self);
} }

View File

@@ -1902,6 +1902,33 @@ namespace OpenRA.Mods.Common.UtilityCommands
if (rrb != null) if (rrb != null)
rrb.Key = "-WithTurretedSpriteBody"; rrb.Key = "-WithTurretedSpriteBody";
} }
// Replaced RenderBuildingWall with RenderSprites + WithWallSpriteBody (+AutoSelectionSize)
if (depth == 0)
{
var childKeysExcludeFromRS = new[] { "Sequence", "Type" };
var rb = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("RenderBuildingWall"));
if (rb != null)
{
rb.Key = "WithWallSpriteBody";
var rsNodes = rb.Value.Nodes.Where(n => !childKeysExcludeFromRS.Contains(n.Key)).ToList();
if (rsNodes.Any())
node.Value.Nodes.Add(new MiniYamlNode("RenderSprites", new MiniYaml("", rsNodes)));
else
node.Value.Nodes.Add(new MiniYamlNode("RenderSprites", ""));
node.Value.Nodes.Add(new MiniYamlNode("AutoSelectionSize", ""));
rb.Value.Nodes.RemoveAll(n => rsNodes.Contains(n));
}
var rrb = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("-RenderBuildingWall"));
if (rrb != null)
rrb.Key = "-WithWallSpriteBody";
}
} }
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);

View File

@@ -287,7 +287,7 @@ BARB:
NodeTypes: barbwire NodeTypes: barbwire
LineBuildNode: LineBuildNode:
Types: barbwire Types: barbwire
RenderBuildingWall: WithWallSpriteBody:
Type: barbwire Type: barbwire
WOOD: WOOD:
@@ -303,7 +303,7 @@ WOOD:
NodeTypes: woodfence NodeTypes: woodfence
LineBuildNode: LineBuildNode:
Types: woodfence Types: woodfence
RenderBuildingWall: WithWallSpriteBody:
Type: woodfence Type: woodfence
BRIDGE1: BRIDGE1:

View File

@@ -560,8 +560,10 @@
Types: wall Types: wall
BodyOrientation: BodyOrientation:
QuantizedFacings: 1 QuantizedFacings: 1
RenderBuildingWall: RenderSprites:
Palette: staticterrain Palette: staticterrain
WithWallSpriteBody:
AutoSelectionSize:
GivesExperience: GivesExperience:
AutoTargetIgnore: AutoTargetIgnore:
Sellable: Sellable:

View File

@@ -862,7 +862,7 @@ SBAG:
NodeTypes: sandbag NodeTypes: sandbag
LineBuildNode: LineBuildNode:
Types: sandbag Types: sandbag
RenderBuildingWall: WithWallSpriteBody:
Type: sandbag Type: sandbag
CYCL: CYCL:
@@ -887,7 +887,7 @@ CYCL:
NodeTypes: chain NodeTypes: chain
LineBuildNode: LineBuildNode:
Types: chain Types: chain
RenderBuildingWall: WithWallSpriteBody:
Type: chain Type: chain
BRIK: BRIK:
@@ -917,7 +917,7 @@ BRIK:
NodeTypes: concrete NodeTypes: concrete
LineBuildNode: LineBuildNode:
Types: concrete Types: concrete
RenderBuildingWall: WithWallSpriteBody:
Type: concrete Type: concrete
BARRACKS: BARRACKS:

View File

@@ -312,7 +312,9 @@
-WithCrumbleOverlay: -WithCrumbleOverlay:
-WithMakeAnimation: -WithMakeAnimation:
-RenderBuilding: -RenderBuilding:
RenderBuildingWall: RenderSprites:
WithWallSpriteBody:
AutoSelectionSize:
LineBuildNode: LineBuildNode:
Types: turret Types: turret
MustBeDestroyed: MustBeDestroyed:

View File

@@ -513,7 +513,9 @@ wall:
Types: wall Types: wall
TargetableBuilding: TargetableBuilding:
TargetTypes: Ground, Wall TargetTypes: Ground, Wall
RenderBuildingWall: RenderSprites:
WithWallSpriteBody:
AutoSelectionSize:
AutoTargetIgnore: AutoTargetIgnore:
Sellable: Sellable:
SellSounds: CHUNG.WAV SellSounds: CHUNG.WAV

View File

@@ -462,8 +462,9 @@
Types: wall Types: wall
TargetableBuilding: TargetableBuilding:
TargetTypes: Ground, DetonateAttack, Wall TargetTypes: Ground, DetonateAttack, Wall
RenderBuildingWall: RenderSprites:
Palette: effect Palette: effect
WithWallSpriteBody:
GivesExperience: GivesExperience:
AutoTargetIgnore: AutoTargetIgnore:
ProximityCaptor: ProximityCaptor:

View File

@@ -1514,7 +1514,7 @@ SBAG:
NodeTypes: sandbag NodeTypes: sandbag
LineBuildNode: LineBuildNode:
Types: sandbag Types: sandbag
RenderBuildingWall: WithWallSpriteBody:
Type: sandbag Type: sandbag
FENC: FENC:
@@ -1539,7 +1539,7 @@ FENC:
NodeTypes: fence NodeTypes: fence
LineBuildNode: LineBuildNode:
Types: fence Types: fence
RenderBuildingWall: WithWallSpriteBody:
Type: fence Type: fence
BRIK: BRIK:
@@ -1569,7 +1569,7 @@ BRIK:
NodeTypes: concrete NodeTypes: concrete
LineBuildNode: LineBuildNode:
Types: concrete Types: concrete
RenderBuildingWall: WithWallSpriteBody:
Type: concrete Type: concrete
CYCL: CYCL:
@@ -1584,7 +1584,7 @@ CYCL:
NodeTypes: chain NodeTypes: chain
LineBuildNode: LineBuildNode:
Types: chain Types: chain
RenderBuildingWall: WithWallSpriteBody:
Type: chain Type: chain
BARB: BARB:
@@ -1599,7 +1599,7 @@ BARB:
NodeTypes: barbwire NodeTypes: barbwire
LineBuildNode: LineBuildNode:
Types: barbwire Types: barbwire
RenderBuildingWall: WithWallSpriteBody:
Type: barbwire Type: barbwire
WOOD: WOOD:
@@ -1614,7 +1614,7 @@ WOOD:
NodeTypes: woodfence NodeTypes: woodfence
LineBuildNode: LineBuildNode:
Types: woodfence Types: woodfence
RenderBuildingWall: WithWallSpriteBody:
Type: woodfence Type: woodfence
BARRACKS: BARRACKS:

View File

@@ -1237,7 +1237,7 @@ GASAND:
NodeTypes: sandbags NodeTypes: sandbags
LineBuildNode: LineBuildNode:
Types: sandbags Types: sandbags
RenderBuildingWall: WithWallSpriteBody:
Type: sandbags Type: sandbags
GASPOT: GASPOT:

View File

@@ -166,7 +166,9 @@
Types: wall Types: wall
TargetableBuilding: TargetableBuilding:
TargetTypes: Ground, Wall, C4 TargetTypes: Ground, Wall, C4
RenderBuildingWall: RenderSprites:
AutoSelectionSize:
WithWallSpriteBody:
Type: wall Type: wall
GivesExperience: GivesExperience:
AutoTargetIgnore: AutoTargetIgnore:

View File

@@ -103,7 +103,8 @@ GACTWR:
LineBuildNode: LineBuildNode:
Types: turret Types: turret
-RenderBuilding: -RenderBuilding:
RenderBuildingWall: RenderSprites:
WithWallSpriteBody:
Type: wall Type: wall
Power@base: Power@base:
Amount: -10 Amount: -10