-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
And move PrefixByFullness there. Also put it into Mods.Cnc, as RA is the only shipping mod using this.
- Loading branch information
Showing
8 changed files
with
139 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#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.Activities; | ||
using OpenRA.Graphics; | ||
using OpenRA.Mods.Common.Graphics; | ||
using OpenRA.Mods.Common.Traits; | ||
using OpenRA.Mods.Common.Traits.Render; | ||
using OpenRA.Traits; | ||
|
||
namespace OpenRA.Mods.Cnc.Traits.Render | ||
{ | ||
public class WithHarvesterSpriteBodyInfo : WithFacingSpriteBodyInfo, Requires<HarvesterInfo> | ||
{ | ||
[Desc("Images switched between depending on fullness of harvester. Overrides RenderSprites.Image.")] | ||
public readonly string[] ImageByFullness = { }; | ||
|
||
public override object Create(ActorInitializer init) { return new WithHarvesterSpriteBody(init, this); } | ||
} | ||
|
||
public class WithHarvesterSpriteBody : WithFacingSpriteBody, ITick | ||
{ | ||
readonly WithHarvesterSpriteBodyInfo info; | ||
readonly Harvester harv; | ||
|
||
public WithHarvesterSpriteBody(ActorInitializer init, WithHarvesterSpriteBodyInfo info) | ||
: base(init, info) | ||
{ | ||
this.info = info; | ||
harv = init.Self.Trait<Harvester>(); | ||
} | ||
|
||
void ITick.Tick(Actor self) | ||
{ | ||
if (harv == null || info.ImageByFullness.Length == 0) | ||
return; | ||
|
||
var desiredState = harv.Fullness * (info.ImageByFullness.Length - 1) / 100; | ||
var desiredImage = info.ImageByFullness[desiredState]; | ||
|
||
DefaultAnimation.ChangeImage(desiredImage, DefaultAnimation.CurrentSequence.Name); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
OpenRA.Mods.Common/UpdateRules/Rules/20190314/SplitHarvesterSpriteBody.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#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; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace OpenRA.Mods.Common.UpdateRules.Rules | ||
{ | ||
public class SplitHarvesterSpriteBody : UpdateRule | ||
{ | ||
public override string Name { get { return "Split fullness display from WithHarvestAnimation to new WithHarvesterSpriteBody"; } } | ||
public override string Description | ||
{ | ||
get | ||
{ | ||
return "WithHarvestAnimation.PrefixByFullness logic was moved to a dedicated WithHarvesterSpriteBody."; | ||
} | ||
} | ||
|
||
readonly List<Tuple<string, string>> fullnessPrefixes = new List<Tuple<string, string>>(); | ||
|
||
public override IEnumerable<string> AfterUpdate(ModData modData) | ||
{ | ||
var message = "PrefixByFullness has been removed from WithHarvestAnimation.\n" | ||
+ "To display fullness levels, use the new WithHarvesterSpriteBody\n" | ||
+ "to switch between separate image sprites instead (see RA mod harvester for reference).\n" | ||
+ "The following places most likely need manual changes:\n" | ||
+ UpdateUtils.FormatMessageList(fullnessPrefixes.Select(n => n.Item1 + " (" + n.Item2 + ")")); | ||
|
||
if (fullnessPrefixes.Any()) | ||
yield return message; | ||
|
||
fullnessPrefixes.Clear(); | ||
} | ||
|
||
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode) | ||
{ | ||
var harvAnim = actorNode.LastChildMatching("WithHarvestAnimation"); | ||
if (harvAnim != null) | ||
{ | ||
var fullnessPrefix = harvAnim.LastChildMatching("PrefixByFullness"); | ||
|
||
// If PrefixByFullness is empty, no changes are needed. | ||
if (fullnessPrefix == null) | ||
yield break; | ||
|
||
harvAnim.RemoveNode(fullnessPrefix); | ||
|
||
fullnessPrefixes.Add(Tuple.Create(actorNode.Key, actorNode.Location.Filename)); | ||
} | ||
|
||
yield break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters