using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
namespace SCJMapper_V2
{
///
/// Maintain actionmap Modifiers
///
class Modifiers : List
{
///
/// Returns a properly formatted Modifier entry
///
///
public String toXML()
{
string r = "";
r += string.Format( "\t\n" );
foreach ( string s in this ) {
r += string.Format( "\t\t\n", s );
}
r += string.Format( "\t\n" );
return r;
}
///
/// Read an Modifier entry from XML - do some sanity check
///
/// the XML action fragment
/// True if an action was decoded
private Boolean Instance_fromXML( XmlReader reader )
{
reader.Read( );
while ( !reader.EOF ) {
if ( reader.Name.ToLowerInvariant() == "mod" ) {
String input = reader["input"];
if ( !String.IsNullOrWhiteSpace( input ) ) {
this.Add( input );
}
}
reader.Read( );
if ( reader.NodeType == XmlNodeType.EndElement ) break; // expect end of here
}//while
return true;
}
///
/// Reads the Modifier entry from an action map file
///
public Boolean fromXML( String xml )
{
/*
*/
this.Clear( );
XmlReaderSettings settings = new XmlReaderSettings( );
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.IgnoreWhitespace = true;
settings.IgnoreComments = true;
XmlReader reader = XmlReader.Create( new StringReader( xml ), settings );
reader.Read( );
// try to disassemble the items
while ( !reader.EOF ) {
if ( reader.Name.ToLowerInvariant( ) == "modifiers" ) {
Instance_fromXML( reader );
}
reader.Read( );
if ( reader.NodeType == XmlNodeType.EndElement ) break; // expect end of here
}
return true;
}
}
}