Clean up some trait info loading code
Remove some methods that traits define to load their YAML values on their own.
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
@@ -20,7 +19,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("This actor's experience increases when it has killed a GivesExperience actor.")]
|
||||
public class GainsExperienceInfo : ITraitInfo, Requires<ValuedInfo>, Requires<UpgradeManagerInfo>
|
||||
{
|
||||
[FieldLoader.LoadUsing("LoadUpgrades", true)]
|
||||
[FieldLoader.Require]
|
||||
[Desc("Upgrades to grant at each level.",
|
||||
"Key is the XP requirements for each level as a percentage of our own value.",
|
||||
"Value is a list of the upgrade types to grant")]
|
||||
@@ -33,15 +32,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public readonly bool SuppressLevelupAnimation = true;
|
||||
|
||||
public object Create(ActorInitializer init) { return new GainsExperience(init, this); }
|
||||
|
||||
static object LoadUpgrades(MiniYaml y)
|
||||
{
|
||||
MiniYaml upgrades = y.ToDictionary()["Upgrades"];
|
||||
|
||||
return upgrades.Nodes.ToDictionary(
|
||||
kv => FieldLoader.GetValue<int>("(key)", kv.Key),
|
||||
kv => FieldLoader.GetValue<string[]>("(value)", kv.Value.Value));
|
||||
}
|
||||
}
|
||||
|
||||
public class GainsExperience : ISync, IResolveOrder
|
||||
|
||||
@@ -28,7 +28,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Damage types that trigger prone state. Defined on the warheads.")]
|
||||
public readonly string[] DamageTriggers = null;
|
||||
|
||||
[FieldLoader.LoadUsing("LoadModifiers")]
|
||||
[Desc("Damage modifiers for each damage type (defined on the warheads) while the unit is prone.")]
|
||||
public readonly Dictionary<string, int> DamageModifiers = new Dictionary<string, int>();
|
||||
|
||||
@@ -37,15 +36,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[SequenceReference(null, true)] public readonly string ProneSequencePrefix = "prone-";
|
||||
|
||||
public override object Create(ActorInitializer init) { return new TakeCover(init, this); }
|
||||
|
||||
public static object LoadModifiers(MiniYaml yaml)
|
||||
{
|
||||
var md = yaml.ToDictionary();
|
||||
|
||||
return md.ContainsKey("DamageModifiers")
|
||||
? md["DamageModifiers"].ToDictionary(my => FieldLoader.GetValue<int>("(value)", my.Value))
|
||||
: new Dictionary<string, int>();
|
||||
}
|
||||
}
|
||||
|
||||
public class TakeCover : Turreted, INotifyDamage, IDamageModifier, ISpeedModifier, ISync, IRenderInfantrySequenceModifier
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Warheads;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -17,7 +16,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class TerrainModifiesDamageInfo : ITraitInfo
|
||||
{
|
||||
[FieldLoader.LoadUsing("LoadPercents", true)]
|
||||
[FieldLoader.Require]
|
||||
[Desc("Damage percentage for specific terrain types. 120 = 120%, 80 = 80%, etc.")]
|
||||
public readonly Dictionary<string, int> TerrainModifier = null;
|
||||
|
||||
@@ -25,13 +24,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public readonly bool ModifyHealing = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new TerrainModifiesDamage(init.Self, this); }
|
||||
|
||||
static object LoadPercents(MiniYaml y)
|
||||
{
|
||||
return y.ToDictionary()["TerrainModifier"].Nodes.ToDictionary(
|
||||
kv => FieldLoader.GetValue<string>("(key)", kv.Key),
|
||||
kv => FieldLoader.GetValue<int>("(value)", kv.Value.Value));
|
||||
}
|
||||
}
|
||||
|
||||
public class TerrainModifiesDamage : IDamageModifier
|
||||
|
||||
@@ -29,7 +29,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("The sequence name that defines the actor sprites. Defaults to the actor name.")]
|
||||
public readonly string Image = null;
|
||||
|
||||
[FieldLoader.LoadUsing("LoadFactionImages")]
|
||||
[Desc("A dictionary of faction-specific image overrides.")]
|
||||
public readonly Dictionary<string, string> FactionImages = null;
|
||||
|
||||
@@ -42,16 +41,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Change the sprite image size.")]
|
||||
public readonly float Scale = 1f;
|
||||
|
||||
protected static object LoadFactionImages(MiniYaml y)
|
||||
{
|
||||
MiniYaml images;
|
||||
|
||||
if (!y.ToDictionary().TryGetValue("FactionImages", out images))
|
||||
return null;
|
||||
|
||||
return images.Nodes.ToDictionary(kv => kv.Key, kv => kv.Value.Value);
|
||||
}
|
||||
|
||||
public virtual object Create(ActorInitializer init) { return new RenderSprites(init, this); }
|
||||
|
||||
public IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init)
|
||||
|
||||
Reference in New Issue
Block a user