remove FieldLoader.LoadAttribute; replace with FieldLoader.IgnoreAttribute

This commit is contained in:
Chris Forbes
2011-06-30 20:01:22 +12:00
committed by Paul Chote
parent a4648cfbcc
commit cd63da85d8
8 changed files with 64 additions and 82 deletions

View File

@@ -219,26 +219,22 @@ namespace OpenRA.FileFormats
foreach( var ff in type.GetFields() )
{
var field = ff;
var load = field.GetCustomAttributes<LoadAttribute>( false );
var ignore = field.GetCustomAttributes<IgnoreAttribute>( false );
var loadUsing = field.GetCustomAttributes<LoadUsingAttribute>( false );
var fromYamlKey = field.GetCustomAttributes<FieldFromYamlKeyAttribute>( false );
if( loadUsing.Length != 0 )
ret[ field ] = ( _1, fieldType, yaml ) => loadUsing[ 0 ].LoaderFunc( field )( yaml );
else if( fromYamlKey.Length != 0 )
ret[ field ] = ( f, ft, yaml ) => GetValue( f, ft, yaml.Value );
else if( load.Length != 0 )
else if( ignore.Length == 0 )
ret[ field ] = null;
}
if( ret.Count == 0 )
foreach( var f in type.GetFields() )
ret.Add( f, null );
return ret;
}
[AttributeUsage( AttributeTargets.Field )]
public class LoadAttribute : Attribute { }
public class IgnoreAttribute : Attribute { }
[AttributeUsage( AttributeTargets.Field )]
public class LoadUsingAttribute : Attribute

View File

@@ -31,10 +31,10 @@ namespace OpenRA.FileFormats
public class TileTemplate
{
[FieldLoader.Load] public ushort Id;
[FieldLoader.Load] public string Image;
[FieldLoader.Load] public int2 Size;
[FieldLoader.Load] public bool PickAny;
public ushort Id;
public string Image;
public int2 Size;
public bool PickAny;
[FieldLoader.LoadUsing( "LoadTiles" )]
public Dictionary<byte, string> Tiles = new Dictionary<byte, string>();

View File

@@ -8,19 +8,19 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.FileFormats;
using System;
namespace OpenRA.GameRules
{
public class VoiceInfo
{
public readonly Dictionary<string,string[]> Variants;
public readonly Dictionary<string,string[]> Voices;
[FieldLoader.Ignore] public readonly Dictionary<string,string[]> Variants;
[FieldLoader.Ignore] public readonly Dictionary<string,string[]> Voices;
public readonly string DefaultVariant = ".aud" ;
[FieldLoader.Load] public readonly string[] DisableVariants = { };
public readonly string[] DisableVariants = { };
static Dictionary<string, string[]> Load( MiniYaml y, string name )
{

View File

@@ -18,21 +18,21 @@ namespace OpenRA.GameRules
{
public class WarheadInfo
{
[FieldLoader.Load] public readonly int Spread = 1; // distance (in pixels) from the explosion center at which damage is 1/2.
public readonly int Spread = 1; // distance (in pixels) from the explosion center at which damage is 1/2.
[FieldLoader.LoadUsing( "LoadVersus" )]
public readonly Dictionary<string, float> Versus; // damage vs each armortype
[FieldLoader.Load] public readonly bool Ore = false; // can this damage ore?
[FieldLoader.Load] public readonly string Explosion = null; // explosion effect to use
[FieldLoader.Load] public readonly string WaterExplosion = null; // explosion effect on hitting water (usually a splash)
[FieldLoader.Load] public readonly string SmudgeType = null; // type of smudge to apply
[FieldLoader.Load] public readonly int[] Size = { 0, 0 }; // size of the explosion. provide 2 values for a ring effect (outer/inner)
[FieldLoader.Load] public readonly int InfDeath = 0; // infantry death animation to use
[FieldLoader.Load] public readonly string ImpactSound = null; // sound to play on impact
[FieldLoader.Load] public readonly string WaterImpactSound = null; // sound to play on impact with water
[FieldLoader.Load] public readonly int Damage = 0; // how much (raw) damage to deal
[FieldLoader.Load] public readonly int Delay = 0; // delay in ticks before dealing the damage. 0=instant (old model)
[FieldLoader.Load] public readonly DamageModel DamageModel = DamageModel.Normal; // which damage model to use
[FieldLoader.Load] public readonly bool PreventProne = false; // whether we should prevent prone response in infantry.
public readonly bool Ore = false; // can this damage ore?
public readonly string Explosion = null; // explosion effect to use
public readonly string WaterExplosion = null; // explosion effect on hitting water (usually a splash)
public readonly string SmudgeType = null; // type of smudge to apply
public readonly int[] Size = { 0, 0 }; // size of the explosion. provide 2 values for a ring effect (outer/inner)
public readonly int InfDeath = 0; // infantry death animation to use
public readonly string ImpactSound = null; // sound to play on impact
public readonly string WaterImpactSound = null; // sound to play on impact with water
public readonly int Damage = 0; // how much (raw) damage to deal
public readonly int Delay = 0; // delay in ticks before dealing the damage. 0=instant (old model)
public readonly DamageModel DamageModel = DamageModel.Normal; // which damage model to use
public readonly bool PreventProne = false; // whether we should prevent prone response in infantry.
public float EffectivenessAgainst(Actor self)
{
@@ -85,15 +85,15 @@ namespace OpenRA.GameRules
public class WeaponInfo
{
[FieldLoader.Load] public readonly float Range = 0;
[FieldLoader.Load] public readonly string Report = null;
[FieldLoader.Load] public readonly int ROF = 1;
[FieldLoader.Load] public readonly int Burst = 1;
[FieldLoader.Load] public readonly bool Charges = false;
[FieldLoader.Load] public readonly bool Underwater = false;
[FieldLoader.Load] public readonly string[] ValidTargets = { "Ground" };
[FieldLoader.Load] public readonly int BurstDelay = 5;
[FieldLoader.Load] public readonly float MinRange = 0;
public readonly float Range = 0;
public readonly string Report = null;
public readonly int ROF = 1;
public readonly int Burst = 1;
public readonly bool Charges = false;
public readonly bool Underwater = false;
public readonly string[] ValidTargets = { "Ground" };
public readonly int BurstDelay = 5;
public readonly float MinRange = 0;
[FieldLoader.LoadUsing( "LoadProjectile" )] public IProjectileInfo Projectile;
[FieldLoader.LoadUsing( "LoadWarheads" )] public List<WarheadInfo> Warheads;

View File

@@ -22,53 +22,52 @@ namespace OpenRA
{
public class Map
{
protected IFolder Container;
[FieldLoader.Ignore] protected IFolder Container;
public string Path {get; protected set;}
// Yaml map data
public string Uid { get; protected set; }
[FieldLoader.Load] public int MapFormat;
[FieldLoader.Load] public bool Selectable;
[FieldLoader.Load] public bool UseAsShellmap;
[FieldLoader.Load] public string RequiresMod;
public int MapFormat;
public bool Selectable;
public bool UseAsShellmap;
public string RequiresMod;
[FieldLoader.Load] public string Title;
[FieldLoader.Load] public string Type = "Conquest";
[FieldLoader.Load] public string Description;
[FieldLoader.Load] public string Author;
[FieldLoader.Load] public string Tileset;
public string Title;
public string Type = "Conquest";
public string Description;
public string Author;
public string Tileset;
public Lazy<Dictionary<string, ActorReference>> Actors;
[FieldLoader.Ignore] public Lazy<Dictionary<string, ActorReference>> Actors;
public int PlayerCount { get { return Players.Count(p => p.Value.Playable); } }
public IEnumerable<int2> SpawnPoints { get { return Actors.Value.Values.Where(a => a.Type == "mpspawn").Select(a => a.InitDict.Get<LocationInit>().value); } }
[FieldLoader.Load] public Rectangle Bounds;
public Rectangle Bounds;
// Yaml map data
public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>();
public Lazy<List<SmudgeReference>> Smudges;
[FieldLoader.Ignore] public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>();
[FieldLoader.Ignore] public Lazy<List<SmudgeReference>> Smudges;
// Rules overrides
public List<MiniYamlNode> Rules = new List<MiniYamlNode>();
[FieldLoader.Ignore] public List<MiniYamlNode> Rules = new List<MiniYamlNode>();
// Sequences overrides
public List<MiniYamlNode> Sequences = new List<MiniYamlNode>();
[FieldLoader.Ignore] public List<MiniYamlNode> Sequences = new List<MiniYamlNode>();
// Weapon overrides
public List<MiniYamlNode> Weapons = new List<MiniYamlNode>();
[FieldLoader.Ignore] public List<MiniYamlNode> Weapons = new List<MiniYamlNode>();
// Voices overrides
public List<MiniYamlNode> Voices = new List<MiniYamlNode>();
[FieldLoader.Ignore] public List<MiniYamlNode> Voices = new List<MiniYamlNode>();
// Binary map data
public byte TileFormat = 1;
[FieldLoader.Load] public int2 MapSize;
[FieldLoader.Ignore] public byte TileFormat = 1;
public int2 MapSize;
public Lazy<TileReference<ushort, byte>[,]> MapTiles;
public Lazy<TileReference<byte, byte>[,]> MapResources;
public string [,] CustomTerrain;
[FieldLoader.Ignore] public Lazy<TileReference<ushort, byte>[,]> MapTiles;
[FieldLoader.Ignore] public Lazy<TileReference<byte, byte>[,]> MapResources;
[FieldLoader.Ignore] public string [,] CustomTerrain;
public Map()
{

View File

@@ -17,8 +17,8 @@ namespace OpenRA.Network
{
public class HandshakeRequest
{
[FieldLoader.Load] public string[] Mods;
[FieldLoader.Load] public string Map;
public string[] Mods;
public string Map;
public string Serialize()
{
@@ -37,9 +37,9 @@ namespace OpenRA.Network
public class HandshakeResponse
{
[FieldLoader.Load] public string[] Mods;
[FieldLoader.Load] public string Password;
public Session.Client Client;
public string[] Mods;
public string Password;
[FieldLoader.Ignore] public Session.Client Client;
public string Serialize()
{

View File

@@ -35,11 +35,9 @@ namespace OpenRA.Mods.RA
{
class HackyAIInfo : IBotInfo, ITraitInfo
{
[FieldLoader.Load]
public readonly string Name = "Unnamed Bot";
[FieldLoader.Load]
public readonly int SquadSize = 8;
public readonly int AssignRolesInterval = 20;
string IBotInfo.Name { get { return this.Name; } }
@@ -65,9 +63,6 @@ namespace OpenRA.Mods.RA
return ret;
}
[FieldLoader.Load]
public readonly int AssignRolesInterval = 20;
public object Create(ActorInitializer init) { return new HackyAI(this); }
}

View File

@@ -23,21 +23,13 @@ namespace OpenRA.Mods.RA.Move
{
[FieldLoader.LoadUsing("LoadSpeeds")]
public readonly Dictionary<string, TerrainInfo> TerrainSpeeds;
[FieldLoader.Load]
public readonly string[] Crushes;
[FieldLoader.Load]
public readonly int WaitAverage = 60;
[FieldLoader.Load]
public readonly int WaitSpread = 20;
[FieldLoader.Load]
public readonly int InitialFacing = 128;
[FieldLoader.Load]
public readonly int ROT = 255;
[FieldLoader.Load]
public readonly int Speed = 1;
[FieldLoader.Load]
public readonly bool OnRails = false;
[FieldLoader.Load]
public readonly bool SharesCell = false;
public virtual object Create(ActorInitializer init) { return new Mobile(init, this); }