2009-04-19 18:07:22 +00:00
#region = = = = = = = = = = = = = = = = = = Namespaces
using System ;
using System.Collections.Generic ;
#endregion
namespace CodeImp.DoomBuilder.Map
{
2009-05-21 08:18:34 +00:00
/// <summary>
/// List of universal fields and their values.
/// </summary>
2009-04-19 18:07:22 +00:00
public class UniFields : SortedList < string , UniValue >
{
2009-06-11 21:21:20 +00:00
// Owner of this list
protected MapElement owner ;
public MapElement Owner { get { return owner ; } internal set { owner = value ; } }
2009-04-19 18:07:22 +00:00
// New constructor
2009-05-21 08:18:34 +00:00
///<summary></summary>
2009-04-19 18:07:22 +00:00
public UniFields ( ) : base ( 2 )
{
}
// New constructor
2009-05-21 08:18:34 +00:00
///<summary></summary>
2009-04-19 18:07:22 +00:00
public UniFields ( int capacity ) : base ( capacity )
{
}
2010-08-15 13:45:43 +00:00
// Copy constructor (makes a deep copy)
2009-05-21 08:18:34 +00:00
///<summary></summary>
2010-08-15 13:45:43 +00:00
public UniFields ( UniFields copyfrom ) : base ( copyfrom . Count )
2009-04-19 18:07:22 +00:00
{
2010-08-15 13:45:43 +00:00
foreach ( KeyValuePair < string , UniValue > v in copyfrom )
this . Add ( v . Key , new UniValue ( v . Value ) ) ;
2009-04-19 18:07:22 +00:00
}
2009-06-11 21:21:20 +00:00
// New constructor
///<summary></summary>
public UniFields ( MapElement owner ) : base ( 2 )
{
this . owner = owner ;
}
// New constructor
///<summary></summary>
public UniFields ( MapElement owner , int capacity ) : base ( capacity )
{
this . owner = owner ;
}
// Copy constructor
///<summary></summary>
2013-09-05 13:03:17 +00:00
public UniFields ( MapElement owner , UniFields copyfrom ) : base ( copyfrom . Count )
2009-06-11 21:21:20 +00:00
{
this . owner = owner ;
2013-09-05 13:03:17 +00:00
foreach ( KeyValuePair < string , UniValue > v in copyfrom ) //mxd. No-no-no, David Blaine, I don't want to copy these by reference!
this . Add ( v . Key , new UniValue ( v . Value ) ) ;
2009-06-11 21:21:20 +00:00
}
/// <summary>Call this before making changes to the fields, or they may not be updated correctly with undo/redo!</summary>
public void BeforeFieldsChange ( )
{
if ( owner ! = null )
owner . BeforeFieldsChange ( ) ;
}
2010-09-15 20:29:40 +00:00
/// <summary>This returns the value of a field by name, or returns the specified value when no such field exists or the field value fails to convert to the same datatype.</summary>
public T GetValue < T > ( string fieldname , T defaultvalue )
{
if ( ! this . ContainsKey ( fieldname ) )
return defaultvalue ;
try
{
T val = ( T ) this [ fieldname ] . Value ;
return val ;
}
catch ( InvalidCastException )
{
return defaultvalue ;
}
}
2009-04-19 18:07:22 +00:00
}
}