Load unit data from ra.yaml
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRa.FileFormats;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenRa.Game.GameRules
|
||||
{
|
||||
@@ -15,6 +16,39 @@ namespace OpenRa.Game.GameRules
|
||||
}
|
||||
}
|
||||
|
||||
public static void CheckYaml( object self, Dictionary<string, MiniYaml> d )
|
||||
{
|
||||
//foreach( var x in d )
|
||||
//{
|
||||
// if( x.Key == "Tab" ) continue;
|
||||
// if( x.Key == "Description" ) continue;
|
||||
// if( x.Key == "LongDesc" ) continue;
|
||||
|
||||
// var key = x.Key;
|
||||
// if( key == "Prerequisites" ) key = "Prerequisite";
|
||||
// if( key == "HP" ) key = "Strength";
|
||||
// if( key == "Priority" ) key = "SelectionPriority";
|
||||
// if( key == "Bounds" ) key = "SelectionSize";
|
||||
// var field = self.GetType().GetField( key );
|
||||
// var old = field.GetValue( self );
|
||||
// var neww = GetValue( field.FieldType, x.Value.Value.Trim() );
|
||||
// if( old.ToString() != neww.ToString() )
|
||||
// throw new NotImplementedException();
|
||||
//}
|
||||
foreach( var x in d )
|
||||
{
|
||||
var key = x.Key;
|
||||
if( key == "Tab" )
|
||||
continue;
|
||||
if( key == "Prerequisites" ) key = "Prerequisite";
|
||||
if( key == "HP" ) key = "Strength";
|
||||
if( key == "Priority" ) key = "SelectionPriority";
|
||||
if( key == "Bounds" ) key = "SelectionSize";
|
||||
var field = self.GetType().GetField( key.Trim() );
|
||||
field.SetValue( self, GetValue( field.FieldType, x.Value.Value.Trim() ) );
|
||||
}
|
||||
}
|
||||
|
||||
static object GetValue( Type fieldType, string x )
|
||||
{
|
||||
if( fieldType == typeof( int ) )
|
||||
|
||||
24
OpenRa.Game/GameRules/NewUnitInfo.cs
Executable file
24
OpenRa.Game/GameRules/NewUnitInfo.cs
Executable file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRa.FileFormats;
|
||||
|
||||
namespace OpenRa.Game.GameRules
|
||||
{
|
||||
class NewUnitInfo
|
||||
{
|
||||
public readonly string Parent;
|
||||
public readonly Dictionary<string, MiniYaml> Traits = new Dictionary<string, MiniYaml>();
|
||||
|
||||
public NewUnitInfo( MiniYaml node )
|
||||
{
|
||||
MiniYaml inherit;
|
||||
if( node.Nodes.TryGetValue( "Inherits", out inherit ) )
|
||||
{
|
||||
Parent = inherit.Value;
|
||||
node.Nodes.Remove( "Inherits" );
|
||||
}
|
||||
Traits = node.Nodes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ namespace OpenRa.Game
|
||||
public static Map Map;
|
||||
public static TileSet TileSet;
|
||||
|
||||
public static Dictionary<string, NewUnitInfo> NewUnitInfo;
|
||||
|
||||
public static void LoadRules(string mapFileName, bool useAftermath)
|
||||
{
|
||||
if( useAftermath )
|
||||
@@ -91,6 +93,14 @@ namespace OpenRa.Game
|
||||
Map = new Map( AllRules );
|
||||
FileSystem.MountTemporary( new Package( Rules.Map.Theater + ".mix" ) );
|
||||
TileSet = new TileSet( Map.TileSuffix );
|
||||
|
||||
NewUnitInfo = new Dictionary<string, NewUnitInfo>();
|
||||
foreach( var kv in MiniYaml.FromFile( "ra.yaml" ) )
|
||||
NewUnitInfo.Add( kv.Key.ToLowerInvariant(), new NewUnitInfo( kv.Value ) );
|
||||
|
||||
foreach( var unit in NewUnitInfo )
|
||||
foreach( var trait in unit.Value.Traits.Values )
|
||||
FieldLoader.CheckYaml( UnitInfo[ unit.Key.ToLowerInvariant() ], trait.Nodes );
|
||||
}
|
||||
|
||||
static void LoadCategories(params string[] types)
|
||||
|
||||
Reference in New Issue
Block a user