Trait-based units. Any unit/building without sequences will cause a crash when built.
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
<Compile Include="int2.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Tuple.cs" />
|
||||
<Compile Include="TypeDictionary.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
38
OpenRa.DataStructures/TypeDictionary.cs
Executable file
38
OpenRa.DataStructures/TypeDictionary.cs
Executable file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenRa
|
||||
{
|
||||
public class TypeDictionary
|
||||
{
|
||||
Dictionary<Type, object> inner = new Dictionary<Type, object>();
|
||||
|
||||
public void Add<T>( T val )
|
||||
{
|
||||
inner.Add( typeof( T ), val );
|
||||
}
|
||||
|
||||
public void Remove<T>()
|
||||
{
|
||||
inner.Remove( typeof( T ) );
|
||||
}
|
||||
|
||||
public bool Contains<T>()
|
||||
{
|
||||
return inner.ContainsKey( typeof( T ) );
|
||||
}
|
||||
|
||||
public T Get<T>()
|
||||
{
|
||||
return (T)inner[ typeof( T ) ];
|
||||
}
|
||||
|
||||
public IEnumerable<T> WithInterface<T>()
|
||||
{
|
||||
foreach( var i in inner )
|
||||
if( i.Value is T )
|
||||
yield return (T)i.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user