Replace custom factpdox sprite with dynamically rendered vortex.

This commit is contained in:
Paul Chote
2023-10-27 00:13:37 +01:00
committed by Gustas
parent 44d7903a4b
commit 37ce5e447f
7 changed files with 102 additions and 25 deletions

View File

@@ -0,0 +1,63 @@
#region Copyright & License Information
/*
* Copyright (c) The OpenRA Developers and Contributors
* 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 OpenRA.Effects;
using OpenRA.Graphics;
using OpenRA.Mods.Cnc.Graphics;
using OpenRA.Mods.Cnc.Traits;
using OpenRA.Primitives;
namespace OpenRA.Mods.Cnc.Effects
{
sealed class ConyardChronoVortex : IEffect, ISpatiallyPartitionable
{
static readonly Size Size = new(64, 64);
static readonly WVec Offset = new(171, 0, 0);
readonly ChronoVortexRenderer renderer;
readonly WPos center;
readonly Action onCompletion;
WPos pos;
WAngle angle;
int loops = 3;
int frame;
public ConyardChronoVortex(Actor launcher, Action onCompletion)
{
this.onCompletion = onCompletion;
renderer = launcher.World.WorldActor.Trait<ChronoVortexRenderer>();
center = launcher.CenterPosition;
pos = center + Offset.Rotate(WRot.FromYaw(angle));
launcher.World.ScreenMap.Add(this, pos, Size);
}
public void Tick(World world)
{
// First 16 frames are the vortex opening
// Next 16 frames are loopable
// Final 16 frames are the vortex closing
if (++frame == 32 && --loops > 0)
frame = 16;
angle += new WAngle(42);
pos = center + Offset.Rotate(WRot.FromYaw(angle));
world.ScreenMap.Update(this, pos, Size);
if (frame == 48)
world.AddFrameEndTask(w => { w.Remove(this); w.ScreenMap.Remove(this); onCompletion(); });
}
public IEnumerable<IRenderable> Render(WorldRenderer wr)
{
yield return new ChronoVortexRenderable(renderer, pos, frame);
}
}
}

View File

@@ -10,7 +10,7 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using OpenRA.Mods.Cnc.Effects;
using OpenRA.Mods.Common; using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.Common.Traits.Render; using OpenRA.Mods.Common.Traits.Render;
@@ -25,13 +25,6 @@ namespace OpenRA.Mods.Cnc.Traits
"Otherwise, a vortex animation is played and damage is dealt each tick, ignoring modifiers.")] "Otherwise, a vortex animation is played and damage is dealt each tick, ignoring modifiers.")]
public class ConyardChronoReturnInfo : TraitInfo, Requires<HealthInfo>, Requires<WithSpriteBodyInfo>, IObservesVariablesInfo public class ConyardChronoReturnInfo : TraitInfo, Requires<HealthInfo>, Requires<WithSpriteBodyInfo>, IObservesVariablesInfo
{ {
[SequenceReference]
[Desc("Sequence name with the baked-in vortex animation")]
public readonly string Sequence = "pdox";
[Desc("Sprite body to play the vortex animation on.")]
public readonly string Body = "body";
[GrantedConditionReference] [GrantedConditionReference]
[Desc("Condition to grant while the vortex animation plays.")] [Desc("Condition to grant while the vortex animation plays.")]
public readonly string Condition = null; public readonly string Condition = null;
@@ -65,7 +58,6 @@ namespace OpenRA.Mods.Cnc.Traits
IDeathActorInitModifier, ITransformActorInitModifier IDeathActorInitModifier, ITransformActorInitModifier
{ {
readonly ConyardChronoReturnInfo info; readonly ConyardChronoReturnInfo info;
readonly WithSpriteBody wsb;
readonly Health health; readonly Health health;
readonly Actor self; readonly Actor self;
readonly string faction; readonly string faction;
@@ -92,8 +84,6 @@ namespace OpenRA.Mods.Cnc.Traits
self = init.Self; self = init.Self;
health = self.Trait<Health>(); health = self.Trait<Health>();
wsb = self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
faction = init.GetValue<FactionInit, string>(self.Owner.Faction.InternalName); faction = init.GetValue<FactionInit, string>(self.Owner.Faction.InternalName);
var returnInit = init.GetOrDefault<ChronoshiftReturnInit>(); var returnInit = init.GetOrDefault<ChronoshiftReturnInit>();
@@ -127,16 +117,12 @@ namespace OpenRA.Mods.Cnc.Traits
triggered = true; triggered = true;
// Don't override the selling animation self.World.AddFrameEndTask(w => w.Add(new ConyardChronoVortex(self, () =>
if (selling)
return;
wsb.PlayCustomAnimation(self, info.Sequence, () =>
{ {
triggered = false; triggered = false;
if (conditionToken != Actor.InvalidConditionToken) if (conditionToken != Actor.InvalidConditionToken && !self.Disposed)
conditionToken = self.RevokeCondition(conditionToken); conditionToken = self.RevokeCondition(conditionToken);
}); })));
} }
CPos? ChooseBestDestinationCell(MobileInfo mobileInfo, CPos destination) CPos? ChooseBestDestinationCell(MobileInfo mobileInfo, CPos destination)

View File

@@ -0,0 +1,33 @@
#region Copyright & License Information
/*
* Copyright (c) The OpenRA Developers and Contributors
* 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;
namespace OpenRA.Mods.Common.UpdateRules.Rules
{
public class RemoveConyardChronoReturnAnimation : UpdateRule
{
public override string Name => "Remove Sequence and Body properties from ConyardChronoReturn.";
public override string Description => "These properties have been replaced with a dynamic vortex renderable.";
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNodeBuilder actorNode)
{
foreach (var trait in actorNode.ChildrenMatching("ConyardChronoReturn"))
{
trait.RemoveNodes("Sequence");
trait.RemoveNodes("Body");
}
yield break;
}
}
}

View File

@@ -111,6 +111,7 @@ namespace OpenRA.Mods.Common.UpdateRules
new RemoveValidRelationsFromCapturable(), new RemoveValidRelationsFromCapturable(),
new ExtractResourceStorageFromHarvester(), new ExtractResourceStorageFromHarvester(),
new ReplacePaletteModifiers(), new ReplacePaletteModifiers(),
new RemoveConyardChronoReturnAnimation(),
// Execute these rules last to avoid premature yaml merge crashes. // Execute these rules last to avoid premature yaml merge crashes.
new AbstractDocking(), new AbstractDocking(),

Binary file not shown.

View File

@@ -92,6 +92,7 @@
Name: immobile Name: immobile
TerrainSpeeds: TerrainSpeeds:
TerrainRenderer: TerrainRenderer:
ChronoVortexRenderer:
ShroudRenderer: ShroudRenderer:
FogVariants: shroud FogVariants: shroud
Index: 255, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 20, 40, 56, 65, 97, 130, 148, 194, 24, 33, 66, 132, 28, 41, 67, 134, 1, 2, 4, 8, 3, 6, 12, 9, 7, 14, 13, 11, 5, 10, 15, 255 Index: 255, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 20, 40, 56, 65, 97, 130, 148, 194, 24, 33, 66, 132, 28, 41, 67, 134, 1, 2, 4, 8, 3, 6, 12, 9, 7, 14, 13, 11, 5, 10, 15, 255

View File

@@ -79,18 +79,11 @@ fact:
build: build:
Start: 1 Start: 1
Length: 25 Length: 25
pdox:
Filename: factpdox.shp
Length: 80
damaged-idle: damaged-idle:
Start: 26 Start: 26
damaged-build: damaged-build:
Start: 27 Start: 27
Length: 25 Length: 25
damaged-pdox:
Filename: factpdox.shp
Start: 80
Length: 80
dead: dead:
Filename: factdead.shp Filename: factdead.shp
Tick: 800 Tick: 800