add mechanism for traits to export the *Inits they can use

This commit is contained in:
Chris Forbes
2011-11-05 12:29:55 +13:00
parent bd90666c07
commit 564fdd650d
5 changed files with 19 additions and 13 deletions

View File

@@ -118,5 +118,20 @@ namespace OpenRA
.Select( t => t.GetGenericArguments()[ 0 ] )
.ToList();
}
public IEnumerable<Pair<string, Type>> GetInitKeys()
{
var inits = Traits.WithInterface<ITraitInfo>().SelectMany(
t => t.GetType().GetInterfaces()
.Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(UsesInit<>))
.Select(i => i.GetGenericArguments()[0])).ToList();
inits.Add( typeof(OwnerInit) ); /* not exposed by a trait; this is used by the Actor itself */
return inits.Select(
i => Pair.New(
i.GetType().Name.Replace( "Init", "" ),
i.GetType().GetInterfaces()[0].GetGenericArguments()[0] ) );
}
}
}

View File

@@ -102,14 +102,6 @@ namespace OpenRA
return map;
}
class Format2ActorReference
{
public string Id = null;
public string Type = null;
public int2 Location = int2.Zero;
public string Owner = null;
}
void AssertExists(string filename)
{
using(var s = Container.GetContent(filename))

View File

@@ -46,10 +46,7 @@ namespace OpenRA.Server
public Map Map;
volatile bool shutdown = false;
public void Shutdown()
{
shutdown = true;
}
public void Shutdown() { shutdown = true; }
public Server(IPEndPoint endpoint, string[] mods, ServerSettings settings, ModData modData)
{

View File

@@ -7,6 +7,7 @@
* see COPYING.
*/
#endregion
using System;
using OpenRA.Network;

View File

@@ -184,6 +184,7 @@ namespace OpenRA.Traits
public class TraitInfo<T> : ITraitInfo where T : new() { public virtual object Create(ActorInitializer init) { return new T(); } }
public interface Requires<T> where T : class { }
public interface UsesInit<T> where T : IActorInit { }
public interface INotifySelection { void SelectionChanged(); }
public interface IWorldLoaded { void WorldLoaded(World w); }