Streamline resource anim traits

- Replaces WithSiloAnimation with
  WithResourceLevelSpriteBody.

PlayFetchIndex on a With*Animation trait conflicts
with the animation concept, as it's bound to conflict
with pretty much all 'normal' animation traits and
blocks progress on the animation priority system.

We also already have multiple similar SpriteBody traits,
like WithGateSpriteBody and WithWallSpriteBody.

- Rename WithResources to WithResourceLevelOverlay

Make name more accurate and consistent with sprite body
equivalent.
Also fix TS silo yaml setup (bleed setup stems from times
before WithResources was introduced).
This commit is contained in:
reaperrr
2018-12-14 00:18:16 +01:00
committed by Paul Chote
parent 305d82f887
commit be310ab6a6
10 changed files with 173 additions and 77 deletions

View File

@@ -465,7 +465,7 @@
<Compile Include="Traits\Render\WithAimAnimation.cs" />
<Compile Include="Traits\Render\WithAttackOverlay.cs" />
<Compile Include="Traits\Render\WithMoveAnimation.cs" />
<Compile Include="Traits\Render\WithSiloAnimation.cs" />
<Compile Include="Traits\Render\WithResourceLevelSpriteBody.cs" />
<Compile Include="Traits\Render\WithBuildingPlacedAnimation.cs" />
<Compile Include="Traits\Render\WithMakeAnimation.cs" />
<Compile Include="Traits\Render\WithCrateBody.cs" />
@@ -485,7 +485,7 @@
<Compile Include="Traits\Render\WithRangeCircle.cs" />
<Compile Include="Traits\Render\WithResupplyAnimation.cs" />
<Compile Include="Traits\Render\WithRepairOverlay.cs" />
<Compile Include="Traits\Render\WithResources.cs" />
<Compile Include="Traits\Render\WithResourceLevelOverlay.cs" />
<Compile Include="Traits\Render\WithShadow.cs" />
<Compile Include="Traits\Render\WithSpriteBody.cs" />
<Compile Include="Traits\Render\WithSpriteTurret.cs" />
@@ -949,6 +949,7 @@
<Compile Include="UpdateRules\Rules\20180923\DefineLevelUpImageDefault.cs" />
<Compile Include="UpdateRules\Rules\20180923\RemovedAutoCarryallCircleTurnSpeed.cs" />
<Compile Include="UpdateRules\Rules\20180923\ReplacedWithChargeAnimation.cs" />
<Compile Include="UpdateRules\Rules\20180923\RefactorResourceLevelAnimating.cs" />
<Compile Include="Traits\Player\PlayerResources.cs" />
<Compile Include="UtilityCommands\DumpSequenceSheetsCommand.cs" />
<Compile Include="Traits\Render\WithBuildingRepairDecoration.cs" />

View File

@@ -15,16 +15,15 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[Desc("Displays the fill status of PlayerResources with an extra sprite overlay on the actor.")]
class WithResourcesInfo : ConditionalTraitInfo, Requires<WithSpriteBodyInfo>, Requires<RenderSpritesInfo>
class WithResourceLevelOverlayInfo : ConditionalTraitInfo, Requires<WithSpriteBodyInfo>, Requires<RenderSpritesInfo>
{
[Desc("Sequence name to use")]
[SequenceReference] public readonly string Sequence = "resources";
public override object Create(ActorInitializer init) { return new WithResources(init.Self, this); }
public override object Create(ActorInitializer init) { return new WithResourceLevelOverlay(init.Self, this); }
}
// TODO: Rename to WithResourcesOverlay to conform with our naming conventions
class WithResources : ConditionalTrait<WithResourcesInfo>, INotifyOwnerChanged, INotifyDamageStateChanged
class WithResourceLevelOverlay : ConditionalTrait<WithResourceLevelOverlayInfo>, INotifyOwnerChanged, INotifyDamageStateChanged
{
readonly AnimationWithOffset anim;
readonly RenderSprites rs;
@@ -32,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits.Render
PlayerResources playerResources;
public WithResources(Actor self, WithResourcesInfo info)
public WithResourceLevelOverlay(Actor self, WithResourceLevelOverlayInfo info)
: base(info)
{
rs = self.Trait<RenderSprites>();

View File

@@ -0,0 +1,76 @@
#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 System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[Desc("Render trait for buildings that change the sprite according to the remaining resource storage capacity across all depots.")]
public class WithResourceLevelSpriteBodyInfo : WithSpriteBodyInfo
{
[Desc("Internal resource stages. Does not have to match number of sequence frames.")]
public readonly int Stages = 10;
public override object Create(ActorInitializer init) { return new WithResourceLevelSpriteBody(init, this); }
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
{
if (!EnabledByDefault)
yield break;
var anim = new Animation(init.World, image);
anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => 0);
yield return new SpriteActorPreview(anim, () => WVec.Zero, () => 0, p, rs.Scale);
}
}
public class WithResourceLevelSpriteBody : WithSpriteBody, INotifyOwnerChanged
{
readonly WithResourceLevelSpriteBodyInfo info;
PlayerResources playerResources;
public WithResourceLevelSpriteBody(ActorInitializer init, WithResourceLevelSpriteBodyInfo info)
: base(init, info, () => 0)
{
this.info = info;
playerResources = init.Self.Owner.PlayerActor.Trait<PlayerResources>();
ConfigureAnimation(init.Self);
}
void ConfigureAnimation(Actor self)
{
DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence),
() => playerResources.ResourceCapacity != 0
? ((info.Stages * DefaultAnimation.CurrentSequence.Length - 1) * playerResources.Resources) / (info.Stages * playerResources.ResourceCapacity)
: 0);
}
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
{
playerResources = newOwner.PlayerActor.Trait<PlayerResources>();
}
protected override void TraitEnabled(Actor self)
{
// Do nothing - we just want to disable the default WithSpriteBody implementation
}
public override void CancelCustomAnimation(Actor self)
{
ConfigureAnimation(self);
}
}
}

View File

@@ -1,60 +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.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[Desc("Render trait for buildings that change the sprite according to the remaining resource storage capacity across all depots.")]
class WithSiloAnimationInfo : ConditionalTraitInfo, Requires<WithSpriteBodyInfo>, Requires<RenderSpritesInfo>
{
[Desc("Sequence to use for resources-dependent 'stages'."), SequenceReference]
public readonly string Sequence = "stages";
[Desc("Internal resource stages. Does not have to match number of sequence frames.")]
public readonly int Stages = 10;
[Desc("Which sprite body to play the animation on.")]
public readonly string Body = "body";
public override object Create(ActorInitializer init) { return new WithSiloAnimation(init, this); }
}
class WithSiloAnimation : ConditionalTrait<WithSiloAnimationInfo>, INotifyOwnerChanged
{
readonly WithSpriteBody wsb;
PlayerResources playerResources;
public WithSiloAnimation(ActorInitializer init, WithSiloAnimationInfo info)
: base(info)
{
wsb = init.Self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
playerResources = init.Self.Owner.PlayerActor.Trait<PlayerResources>();
}
void PlayAnimation(Actor self)
{
wsb.DefaultAnimation.PlayFetchIndex(wsb.NormalizeSequence(self, Info.Sequence),
() => playerResources.ResourceCapacity != 0
? ((Info.Stages * wsb.DefaultAnimation.CurrentSequence.Length - 1) * playerResources.Resources) / (Info.Stages * playerResources.ResourceCapacity)
: 0);
}
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
{
playerResources = newOwner.PlayerActor.Trait<PlayerResources>();
PlayAnimation(self);
}
protected override void TraitEnabled(Actor self) { PlayAnimation(self); }
}
}

View File

@@ -0,0 +1,76 @@
#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 System.Linq;
namespace OpenRA.Mods.Common.UpdateRules.Rules
{
public class RefactorResourceLevelAnimating : UpdateRule
{
public override string Name { get { return "Streamlined traits animating player resource level"; } }
public override string Description
{
get
{
return "Replaced WithSiloAnimation with WithResourceLevelSpriteBody and\n" +
"renamed WithResources to WithResourceLevelOverlay.";
}
}
readonly List<string> locations = new List<string>();
public override IEnumerable<string> AfterUpdate(ModData modData)
{
if (locations.Any())
yield return "WithSiloAnimation has been replaced by WithResourceLevelSpriteBody.\n" +
"You may need to disable/remove any previous (including inherited) *SpriteBody traits\n" +
"on the following actors:\n" +
UpdateUtils.FormatMessageList(locations);
locations.Clear();
}
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
{
foreach (var wr in actorNode.ChildrenMatching("WithResources"))
wr.RenameKey("WithResourceLevelOverlay");
var siloAnims = actorNode.ChildrenMatching("WithSiloAnimation");
foreach (var sa in siloAnims)
{
// If it's a trait removal, we only rename it.
if (sa.IsRemoval())
{
sa.RenameKey("WithResourceLevelSpriteBody");
continue;
}
var sequence = sa.LastChildMatching("Sequence");
var body = sa.LastChildMatching("Body");
if (sequence == null)
{
var newSequenceNode = new MiniYamlNode("Sequence", "stages");
sa.AddNode(newSequenceNode);
}
if (body != null)
sa.RemoveNode(body);
sa.RenameKey("WithResourceLevelSpriteBody");
locations.Add("{0} ({1})".F(actorNode.Key, sa.Location.Filename));
}
yield break;
}
}
}

View File

@@ -112,6 +112,7 @@ namespace OpenRA.Mods.Common.UpdateRules
new RemovedAutoCarryallCircleTurnSpeed(),
new RemoveAttackIgnoresVisibility(),
new ReplacedWithChargeAnimation(),
new RefactorResourceLevelAnimating(),
})
};

View File

@@ -228,7 +228,7 @@ PROC:
SpawnOffset: 1,2
Facing: 64
WithBuildingBib:
WithResources:
WithResourceLevelOverlay:
RequiresCondition: !build-incomplete
Power:
Amount: -40
@@ -257,8 +257,9 @@ SILO:
Range: 4c0
WithBuildingBib:
HasMinibib: Yes
WithSiloAnimation:
RequiresCondition: !build-incomplete
-WithSpriteBody:
WithResourceLevelSpriteBody:
Sequence: stages
StoresResources:
PipCount: 10
PipColor: Green

View File

@@ -353,8 +353,9 @@ silo:
fremen: silo.atreides
harkonnen: silo.harkonnen
corrino: silo.harkonnen
WithSiloAnimation:
RequiresCondition: !build-incomplete
-WithSpriteBody:
WithResourceLevelSpriteBody:
Sequence: stages
StoresResources:
PipColor: green
PipCount: 5

View File

@@ -1273,8 +1273,9 @@ SILO:
Notification: CreditsStolen
WithBuildingBib:
HasMinibib: Yes
WithSiloAnimation:
RequiresCondition: !build-incomplete
-WithSpriteBody:
WithResourceLevelSpriteBody:
Sequence: stages
StoresResources:
PipCount: 5
Capacity: 3000

View File

@@ -160,10 +160,10 @@ GASILO:
FactionImages:
gdi: gasilo.gdi
nod: gasilo.nod
WithSiloAnimation:
RequiresCondition: !build-incomplete
WithIdleOverlay@UNDERLAY:
WithResourceLevelOverlay@FILLSTAGE:
RequiresCondition: !build-incomplete
Sequence: stages
WithSpriteBody:
Sequence: idle-underlay
WithIdleOverlay@LIGHTS:
RequiresCondition: !build-incomplete