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

View File

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

View File

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

View File

@@ -18,21 +18,21 @@ namespace OpenRA.GameRules
{ {
public class WarheadInfo 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" )] [FieldLoader.LoadUsing( "LoadVersus" )]
public readonly Dictionary<string, float> Versus; // damage vs each armortype public readonly Dictionary<string, float> Versus; // damage vs each armortype
[FieldLoader.Load] public readonly bool Ore = false; // can this damage ore? public readonly bool Ore = false; // can this damage ore?
[FieldLoader.Load] public readonly string Explosion = null; // explosion effect to use public readonly string Explosion = null; // explosion effect to use
[FieldLoader.Load] public readonly string WaterExplosion = null; // explosion effect on hitting water (usually a splash) 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 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) 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 public readonly int InfDeath = 0; // infantry death animation to use
[FieldLoader.Load] public readonly string ImpactSound = null; // sound to play on impact public readonly string ImpactSound = null; // sound to play on impact
[FieldLoader.Load] public readonly string WaterImpactSound = null; // sound to play on impact with water 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 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) 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 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 PreventProne = false; // whether we should prevent prone response in infantry.
public float EffectivenessAgainst(Actor self) public float EffectivenessAgainst(Actor self)
{ {
@@ -85,15 +85,15 @@ namespace OpenRA.GameRules
public class WeaponInfo public class WeaponInfo
{ {
[FieldLoader.Load] public readonly float Range = 0; public readonly float Range = 0;
[FieldLoader.Load] public readonly string Report = null; public readonly string Report = null;
[FieldLoader.Load] public readonly int ROF = 1; public readonly int ROF = 1;
[FieldLoader.Load] public readonly int Burst = 1; public readonly int Burst = 1;
[FieldLoader.Load] public readonly bool Charges = false; public readonly bool Charges = false;
[FieldLoader.Load] public readonly bool Underwater = false; public readonly bool Underwater = false;
[FieldLoader.Load] public readonly string[] ValidTargets = { "Ground" }; public readonly string[] ValidTargets = { "Ground" };
[FieldLoader.Load] public readonly int BurstDelay = 5; public readonly int BurstDelay = 5;
[FieldLoader.Load] public readonly float MinRange = 0; public readonly float MinRange = 0;
[FieldLoader.LoadUsing( "LoadProjectile" )] public IProjectileInfo Projectile; [FieldLoader.LoadUsing( "LoadProjectile" )] public IProjectileInfo Projectile;
[FieldLoader.LoadUsing( "LoadWarheads" )] public List<WarheadInfo> Warheads; [FieldLoader.LoadUsing( "LoadWarheads" )] public List<WarheadInfo> Warheads;

View File

@@ -22,53 +22,52 @@ namespace OpenRA
{ {
public class Map public class Map
{ {
protected IFolder Container; [FieldLoader.Ignore] protected IFolder Container;
public string Path {get; protected set;} public string Path {get; protected set;}
// Yaml map data // Yaml map data
public string Uid { get; protected set; } public string Uid { get; protected set; }
[FieldLoader.Load] public int MapFormat; public int MapFormat;
[FieldLoader.Load] public bool Selectable; public bool Selectable;
[FieldLoader.Load] public bool UseAsShellmap; public bool UseAsShellmap;
[FieldLoader.Load] public string RequiresMod; public string RequiresMod;
[FieldLoader.Load] public string Title; public string Title;
[FieldLoader.Load] public string Type = "Conquest"; public string Type = "Conquest";
[FieldLoader.Load] public string Description; public string Description;
[FieldLoader.Load] public string Author; public string Author;
[FieldLoader.Load] public string Tileset; 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 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); } } 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 // Yaml map data
public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>(); [FieldLoader.Ignore] public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>();
public Lazy<List<SmudgeReference>> Smudges; [FieldLoader.Ignore] public Lazy<List<SmudgeReference>> Smudges;
// Rules overrides // Rules overrides
public List<MiniYamlNode> Rules = new List<MiniYamlNode>(); [FieldLoader.Ignore] public List<MiniYamlNode> Rules = new List<MiniYamlNode>();
// Sequences overrides // Sequences overrides
public List<MiniYamlNode> Sequences = new List<MiniYamlNode>(); [FieldLoader.Ignore] public List<MiniYamlNode> Sequences = new List<MiniYamlNode>();
// Weapon overrides // Weapon overrides
public List<MiniYamlNode> Weapons = new List<MiniYamlNode>(); [FieldLoader.Ignore] public List<MiniYamlNode> Weapons = new List<MiniYamlNode>();
// Voices overrides // Voices overrides
public List<MiniYamlNode> Voices = new List<MiniYamlNode>(); [FieldLoader.Ignore] public List<MiniYamlNode> Voices = new List<MiniYamlNode>();
// Binary map data // Binary map data
public byte TileFormat = 1; [FieldLoader.Ignore] public byte TileFormat = 1;
[FieldLoader.Load] public int2 MapSize; public int2 MapSize;
public Lazy<TileReference<ushort, byte>[,]> MapTiles; [FieldLoader.Ignore] public Lazy<TileReference<ushort, byte>[,]> MapTiles;
public Lazy<TileReference<byte, byte>[,]> MapResources; [FieldLoader.Ignore] public Lazy<TileReference<byte, byte>[,]> MapResources;
public string [,] CustomTerrain; [FieldLoader.Ignore] public string [,] CustomTerrain;
public Map() public Map()
{ {

View File

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

View File

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

View File

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