@ -5,6 +5,12 @@ using System.Xml;
using System.IO ;
using SCJMapper_V2.Actions ;
using System.Xml.Linq ;
using System.Linq ;
using SCJMapper_V2.Devices.Joystick ;
using SCJMapper_V2.Devices.Keyboard ;
using SCJMapper_V2.Devices.Mouse ;
using SCJMapper_V2.Devices.Gamepad ;
namespace SCJMapper_V2.SC
{
@ -19,40 +25,30 @@ namespace SCJMapper_V2.SC
public bool ValidContent { get ; set ; }
private Stack < string > m_nodeNameStack = null ; // element name stack - keeping track where we are
// state for the parser
enum EState
{
idle = 0 ,
inActionMap ,
}
private EState m_state = EState . idle ;
// an action map and its actions
class ProfileAction
{
public string n ame { get ; set ; } // the action name
public string d evID { get ; set ; } // the input method K,J,X,P
public string Name { get ; set ; } // the action name
public string DevID { get ; set ; } // the input method K,J,X,P
private string m_defBinding = "" ; // NOTE: this is AC1 style in the Profile - need to conver later when dumping out
public string d efBinding { get { return m_defBinding ; } set { m_defBinding = value ; } } // DONT! need to clean this one, found spaces...
public string DefBinding { get { return m_defBinding ; } set { m_defBinding = value ; } } // DONT! need to clean this one, found spaces...
private ActivationMode m_defActivationMode = ActivationMode . Default ;
public ActivationMode d efActivationMode { get { return m_defActivationMode ; } set { m_defActivationMode = value ; } }
public ActivationMode DefActivationMode { get { return m_defActivationMode ; } set { m_defActivationMode = value ; } }
public string k eyName
{ get { return devID + n ame; } } // prep for TreView usage - create a key from input+name
public string K eyName
{ get { return DevID + N ame; } } // prep for TreView usage - create a key from input+name
}
class ActionMap : List < ProfileAction > // carries the action list
{
public string n ame { get ; set ; } // the map name
public string N ame { get ; set ; } // the map name
static int ContainsLoop ( List < ProfileAction > list , string value )
{
for ( int i = 0 ; i < list . Count ; i + + ) {
if ( list [ i ] . k eyName = = value ) {
if ( list [ i ] . K eyName = = value ) {
return i ;
}
}
@ -61,12 +57,12 @@ namespace SCJMapper_V2.SC
public new int IndexOf ( ProfileAction pact )
{
return ContainsLoop ( this , pact . k eyName ) ;
return ContainsLoop ( this , pact . K eyName ) ;
}
public new bool Contains ( ProfileAction pact )
{
return ( ContainsLoop ( this , pact . k eyName ) > = 0 ) ;
return ( ContainsLoop ( this , pact . K eyName ) > = 0 ) ;
}
public new void Add ( ProfileAction pact )
@ -78,6 +74,8 @@ namespace SCJMapper_V2.SC
base . Add ( pact ) ;
}
} ;
Dictionary < string , ActionMap > m_aMap = null ; // key would be the actionmap name
ActionMap m_currentMap = null ;
@ -105,9 +103,9 @@ namespace SCJMapper_V2.SC
string buf = "" ;
foreach ( ActionMap am in m_aMap . Values ) {
buf + = am . n ame + ";" ;
buf + = am . N ame + ";" ;
foreach ( ProfileAction a in am ) {
buf + = a . keyName + ";" + a . defBinding + ";" + a . d efActivationMode. Name + ";" + a . d efActivationMode. MultiTap . ToString ( ) + ";" ; // add default binding + activation mode to the CSV
buf + = a . KeyName + ";" + a . DefBinding + ";" + a . D efActivationMode. Name + ";" + a . D efActivationMode. MultiTap . ToString ( ) + ";" ; // add default binding + activation mode to the CSV
}
buf + = string . Format ( "\n" ) ;
}
@ -116,413 +114,233 @@ namespace SCJMapper_V2.SC
}
/// <summary>
/// Assumes to be in an action element
/// retrieves the attributes and collects the various control=binding pairs
/// </summary>
/// <param name="xr">An XML reader @ StartElement</param>
private void CollectActions ( Dictionary < string , string > attr )
// INPUT processing of the xml nodes
private void ActModeInput ( ref ProfileAction pa , XElement xml )
{
//first find an ActivationMode if there is - applies to all actions
string actModeName = ActivationMode . Default . Name ;
string multiTap = "0" ;
// this can be an Activation Mode OR a multitap
// if there is an activationMode the multiTap remains 0
// if no ActivationMode is given, multitap is 1 or may be 2...
if ( attr . ContainsKey ( "ActivationMode" ) ) {
actModeName = attr [ "ActivationMode" ] ;
multiTap = ActivationModes . Instance . MultiTapFor ( actModeName ) . ToString ( ) ; // given by the already collected items
string actModeName = ( string ) xml . Attribute ( "ActivationMode" ) ;
string multiTap = ( string ) xml . Attribute ( "multiTap" ) ;
if ( string . IsNullOrEmpty ( actModeName ) ) {
actModeName = pa . DefActivationMode . Name ; // from store
}
else {
// name remains default - we handle multiTaps only here
multiTap = "1" ; // default if not changed in the action to may be 2 or so..
if ( attr . ContainsKey ( "multiTap" ) ) {
multiTap = attr [ "multiTap" ] ;
}
}
ActivationMode actMode = new ActivationMode ( actModeName , int . Parse ( multiTap ) ) ; // should be a valid ActivationMode for this action
// we collect actions for each input ie for K,J,X and M
if ( attr . ContainsKey ( "joystick" ) ) {
ProfileAction ac = new ProfileAction ( ) ;
ac . name = attr [ "name" ] ;
ac . devID = "J" ;
ac . defBinding = attr [ "joystick" ] ;
ac . defActivationMode = actMode ;
if ( ac . defBinding = = " " ) {
ac . defBinding = Devices . Joystick . JoystickCls . BlendedInput ;
m_currentMap . Add ( ac ) ; // finally add it to the current map if it was bound
}
else if ( ! string . IsNullOrEmpty ( ac . defBinding ) ) {
ac . defBinding = "js1_" + ac . defBinding ;
m_currentMap . Add ( ac ) ; // finally add it to the current map if it was bound
}
if ( string . IsNullOrEmpty ( multiTap ) ) {
multiTap = ActivationModes . Instance . MultiTapFor ( actModeName ) . ToString ( ) ; // given by the already collected items
}
pa . DefActivationMode = new ActivationMode ( actModeName , int . Parse ( multiTap ) ) ; // renew
}
if ( attr . ContainsKey ( "keyboard" ) ) {
ProfileAction ac = new ProfileAction ( ) ;
ac . name = attr [ "name" ] ;
ac . devID = "K" ;
ac . defBinding = attr [ "keyboard" ] ;
ac . defActivationMode = actMode ;
if ( ac . defBinding = = " " ) {
ac . defBinding = Devices . Keyboard . KeyboardCls . BlendedInput ;
m_currentMap . Add ( ac ) ; // finally add it to the current map if it was bound
}
else if ( ! string . IsNullOrEmpty ( ac . defBinding ) ) {
ac . defBinding = "kb1_" + ac . defBinding ;
m_currentMap . Add ( ac ) ; // finally add it to the current map if it was bound
}
private void JInput ( ref ProfileAction pa , XElement xml , string input )
{
ActModeInput ( ref pa , xml ) ;
if ( ! string . IsNullOrEmpty ( input ) ) {
pa . DefBinding = input ;
if ( pa . DefBinding = = " " )
pa . DefBinding = JoystickCls . DisabledInput ;
else if ( ! string . IsNullOrEmpty ( pa . DefBinding ) )
pa . DefBinding = "js1_" + pa . DefBinding ; // extend with device for mapping use
}
}
if ( attr . ContainsKey ( "mouse" ) ) { // 20151220BM: add mouse device (from AC 2.0 defaultProfile usage)
ProfileAction ac = new ProfileAction ( ) ;
ac . name = attr [ "name" ] ;
ac . devID = "M" ;
ac . defBinding = attr [ "mouse" ] ;
ac . defActivationMode = actMode ;
if ( ac . defBinding = = " " ) {
ac . defBinding = Devices . Mouse . MouseCls . BlendedInput ;
m_currentMap . Add ( ac ) ; // finally add it to the current map if it was bound
}
else if ( ! string . IsNullOrEmpty ( ac . defBinding ) ) {
ac . defBinding = "mo1_" + ac . defBinding ;
m_currentMap . Add ( ac ) ; // finally add it to the current map if it was bound
}
private void KInput ( ref ProfileAction pa , XElement xml , string input )
{
ActModeInput ( ref pa , xml ) ;
if ( ! string . IsNullOrEmpty ( input ) ) {
pa . DefBinding = input ;
if ( pa . DefBinding = = " " )
pa . DefBinding = KeyboardCls . DisabledInput ;
else if ( ! string . IsNullOrEmpty ( pa . DefBinding ) )
pa . DefBinding = "kb1_" + pa . DefBinding ; // extend with device for mapping use
}
}
if ( attr . ContainsKey ( "xboxpad" ) ) {
ProfileAction ac = new ProfileAction ( ) ;
ac . name = attr [ "name" ] ;
ac . devID = "X" ;
ac . defBinding = attr [ "xboxpad" ] ;
ac . defActivationMode = actMode ;
if ( ac . defBinding = = " " ) {
ac . defBinding = Devices . Gamepad . GamepadCls . BlendedInput ;
m_currentMap . Add ( ac ) ; // finally add it to the current map if it was bound
}
else if ( ! string . IsNullOrEmpty ( ac . defBinding ) ) {
ac . defBinding = "xi1_" + ac . defBinding ;
m_currentMap . Add ( ac ) ; // finally add it to the current map if it was bound
}
}
if ( attr . ContainsKey ( "ps3pad" ) ) {
// ignore
private void MInput ( ref ProfileAction pa , XElement xml , string input )
{
ActModeInput ( ref pa , xml ) ;
if ( ! string . IsNullOrEmpty ( input ) ) {
pa . DefBinding = input ;
if ( pa . DefBinding = = " " )
pa . DefBinding = MouseCls . DisabledInput ;
else if ( ! string . IsNullOrEmpty ( pa . DefBinding ) )
pa . DefBinding = "mo1_" + pa . DefBinding ; // extend with device for mapping use
}
}
/// <summary>
/// Read one 'empty' XML element
///
/// <name [attr="" ..] />
///
/// </summary>
/// <param name="xr">An XML reader @ StartElement</param>
/// <returns>True if reading can continue</returns>
private bool ReadEmptyElement ( XmlReader xr )
private void XInput ( ref ProfileAction pa , XElement xml , string input )
{
Dictionary < string , string > attr = new Dictionary < string , string > ( ) ;
string eName = xr . Name ;
switch ( xr . NodeType ) {
case XmlNodeType . Element :
//Console.Write( "<{0}", xr.Name );
while ( xr . MoveToNextAttribute ( ) ) {
attr . Add ( xr . Name , xr . Value ) ; // save the attributes
//Console.Write( " {0}='{1}'", xr.Name, xr.Value );
}
if ( m_state = = EState . inActionMap ) {
// processing a valid action map - collect actions
if ( eName . ToLower ( ) = = "action" ) {
// this is an action.. - collect it
CollectActions ( attr ) ;
}
} // if inmap
//Console.Write( ">\n" );
break ;
case XmlNodeType . Text :
//Console.Write( xr.Value );
break ;
case XmlNodeType . EndElement :
//Console.Write( "</{0}>\n", xr.Name );
break ;
ActModeInput ( ref pa , xml ) ;
if ( ! string . IsNullOrEmpty ( input ) ) {
pa . DefBinding = input ;
if ( pa . DefBinding = = " " )
pa . DefBinding = GamepadCls . DisabledInput ;
else if ( ! string . IsNullOrEmpty ( pa . DefBinding ) )
pa . DefBinding = "xi1_" + pa . DefBinding ; // extend with device for mapping use
}
return true ;
}
/// <summary>
/// Read s an action sub e lement
/// Read all from an Action XElement
/// </summary>
/// <param name="xr">An XML reader @ StartElement</param>
private void ReadActionSub ( XmlReader xr , string actionName , string device )
/// <param name="action">The action XElement</param>
/// <returns>True if successfull</returns>
private bool ReadAction ( XElement action )
{
/ * A variety exists here . . .
< action name = "v_eject_cinematic" onPress = "0" onHold = "1" onRelease = "1" keyboard = "ralt+l" xboxpad = "shoulderl+shoulderr+y" joystick = " " / >
< action name = "v_exit" onPress = "1" onHold = "0" onRelease = "1" multiTap = "1" multiTapBlock = "1" pressTriggerThreshold = "1.0" releaseTriggerThreshold = "-1" releaseTriggerDelay = "0" keyboard = "f" xboxpad = "y" UILabel = "@ui_CIExit" UIDescription = "@ui_CIExitDesc" >
< joystick ActivationMode = "press" input = " " / >
< / action >
< action name = "v_throttle_100" onPress = "1" xboxpad = " " joystick = " " UILabel = "@ui_CIThrottleMax" UIDescription = "@ui_CIThrottleMaxDesc" >
< xboxpad multiTap = "2" input = "thumbl_up" / >
< keyboard multiTap = "2" input = " " / >
< / action >
< action name = "v_target_deselect_component" ActivationMode = "delayed_press" pressTriggerThreshold = "0.75" joystick = "" >
< keyboard >
< inputdata input = "lbracket" / >
< inputdata input = "rbracket" / >
< / keyboard >
< / action >
* /
log . Debug ( "DProfileReader.ReadAction - Entry" ) ;
// a complete actionmap arrives here
bool retVal = true ;
/ *
< action name = "v_throttle_100" onPress = "1" xboxpad = " " joystick = " " UILabel = "@ui_CIThrottleMax" UIDescription = "@ui_CIThrottleMaxDesc" >
< keyboard multiTap = "2" input = "w" / >
< / action >
or
< action name = "v_brake" onPress = "1" onHold = "1" onRelease = "1" keyboard = "space" xboxpad = "xi_shoulderl+xi_shoulderr" >
< joystick input = "js2_button7" / >
< joystick input = "js2_button8" / >
< / action >
or
< action name = "v_hud_confirm" onPress = "1" onRelease = "1" xboxpad = "xi_triggerL_btn+xi_a" joystick = "js1_button19" >
< keyboard >
< inputdata input = "enter" / >
< / keyboard >
< / action >
or
< action name = "ui_up" onPress = "1" onHold = "1" holdTriggerDelay = "0.15" holdRepeatDelay = "0.15" >
< keyboard >
< inputdata input = "up" / >
< / keyboard >
< xboxpad >
< inputdata input = "dpad_up" / >
< inputdata input = "thumbly" useAnalogCompare = "1" analogCompareVal = "0.5" analogCompareOp = "GREATERTHAN" / >
< inputdata input = "thumbry" useAnalogCompare = "1" analogCompareVal = "0.5" analogCompareOp = "GREATERTHAN" / >
< / xboxpad >
< / action >
* /
bool done = false ;
do {
xr . Read ( ) ; // get next element
Dictionary < string , string > attr = new Dictionary < string , string > ( ) ;
// add what is not contained in the structure we are about to parse
attr . Add ( "name" , actionName ) ; // actionName is in the outer element
string eName = xr . Name ; // this is either the device or inputdata if there are multiple entries
// read attributes if any
while ( xr . MoveToNextAttribute ( ) ) {
attr . Add ( xr . Name , xr . Value ) ; // save the attributes
//Console.Write( " {0}='{1}'", xr.Name, xr.Value );
}
xr . MoveToElement ( ) ; // backup
// Have to add the device, otherwise the following does not work..
if ( attr . ContainsKey ( "input" ) ) {
if ( ! string . IsNullOrEmpty ( device ) ) {
// device is given i.e. enclosing the input statements
// 20170512 - some keyboard entries are listed with mouse input ... ?!?
// we substitute and add such mouse entries - don't know what the game does later...
string ip = attr [ "input" ] ;
if ( ! string . IsNullOrEmpty ( ip ) ) {
if ( ip . StartsWith ( "mouse" ) ) {
attr . Add ( "mouse" , attr [ "input" ] ) ; // override the device given
}
else {
attr . Add ( device , attr [ "input" ] ) ; // if the device is given, use it
string name = ( string ) action . Attribute ( "name" ) ;
// prep all kinds
var jAC = new ProfileAction ( ) { Name = name , DevID = Act . DevTag ( JoystickCls . DeviceClass ) } ;
var kAC = new ProfileAction ( ) { Name = name , DevID = Act . DevTag ( KeyboardCls . DeviceClass ) } ;
var mAC = new ProfileAction ( ) { Name = name , DevID = Act . DevTag ( MouseCls . DeviceClass ) } ;
var xAC = new ProfileAction ( ) { Name = name , DevID = Act . DevTag ( GamepadCls . DeviceClass ) } ;
// process element items
JInput ( ref jAC , action , ( string ) action . Attribute ( JoystickCls . DeviceClass ) ) ;
KInput ( ref kAC , action , ( string ) action . Attribute ( KeyboardCls . DeviceClass ) ) ;
MInput ( ref mAC , action , ( string ) action . Attribute ( MouseCls . DeviceClass ) ) ;
XInput ( ref xAC , action , ( string ) action . Attribute ( GamepadCls . DeviceClass ) ) ;
// then nested ones - they may or may not exist from the initial scan
foreach ( XElement l1action in action . Elements ( ) ) {
// comes with the name of the device class
switch ( l1action . Name . LocalName ) {
case JoystickCls . DeviceClass : {
JInput ( ref jAC , l1action , ( string ) l1action . Attribute ( "input" ) ) ; // may have attributed ones
foreach ( XElement l2action in l1action . Elements ( ) ) {
if ( l2action . Name . LocalName = = "inputdata" ) {
JInput ( ref jAC , l2action , ( string ) l2action . Attribute ( "input" ) ) ; // or in the inputdata nesting
}
}
}
}
else {
string ip = attr [ "input" ] ;
if ( ! string . IsNullOrEmpty ( ip ) ) {
attr . Add ( eName , ip ) ; // else it should be the eName element
}
}
}
// the element name is a control
if ( xr . NodeType = = XmlNodeType . EndElement ) {
done = ( xr . Name = = m_nodeNameStack . Peek ( ) ) ; // EXIT if the end element matches the entry
}
else if ( xr . IsEmptyElement ) {
// an attribute only element
CollectActions ( attr ) ;
}
else {
// one with subelements again
m_nodeNameStack . Push ( xr . Name ) ; // recursive .. push element name to terminate later (this is i.e. keyboard)
ReadActionSub ( xr , actionName , xr . Name ) ;
}
} while ( ! done ) ;
break ;
m_nodeNameStack . Pop ( ) ; // action is finished
}
/// <summary>
/// Read one XML element
///
/// <name attr="">
/// [ Xelement ]
/// </name>
///
/// </summary>
/// <param name="xr">An XML reader @ StartElement</param>
/// <returns>True if reading can continue</returns>
private bool ReadElement ( XmlReader xr )
{
Dictionary < string , string > attr = new Dictionary < string , string > ( ) ;
string eName = xr . Name ;
switch ( xr . NodeType ) {
case XmlNodeType . Element :
//Console.Write( "<{0}", xr.Name );
while ( xr . MoveToNextAttribute ( ) ) {
attr . Add ( xr . Name , xr . Value ) ; // save the attributes
//Console.Write( " {0}='{1}'", xr.Name, xr.Value );
}
// now here we could have an actionmap start
if ( m_state = = EState . idle ) {
if ( m_nodeNameStack . Peek ( ) . ToLower ( ) = = "actionmap" ) {
// check for a valid one
string mapName = attr [ "name" ] ;
string item = Array . Find ( ActionMapsCls . ActionMaps , delegate ( string sstr ) { return sstr = = mapName ; } ) ;
if ( ! string . IsNullOrEmpty ( item ) ) {
// finally.... it is a valid actionmap
m_currentMap = new ActionMap ( ) ;
m_currentMap . name = mapName ;
if ( ! m_aMap . ContainsKey ( mapName ) ) { //20170325 - fix multiple map names - don't add the second, third etc. (CIG bug..)
m_aMap . Add ( mapName , m_currentMap ) ; // add to our inventory
case KeyboardCls . DeviceClass : {
KInput ( ref kAC , l1action , ( string ) l1action . Attribute ( "input" ) ) ; // may have attributed ones
foreach ( XElement l2action in l1action . Elements ( ) ) {
if ( l2action . Name . LocalName = = "inputdata" ) {
KInput ( ref kAC , l2action , ( string ) l2action . Attribute ( "input" ) ) ; // or in the inputdata nesting
}
else {
log . DebugFormat ( "ReadElement: IGNORED duplicate map with name: {0}" , mapName ) ;
}
}
break ;
case MouseCls . DeviceClass : {
MInput ( ref mAC , l1action , ( string ) l1action . Attribute ( "input" ) ) ; // may have attributed ones
foreach ( XElement l2action in l1action . Elements ( ) ) {
if ( l2action . Name . LocalName = = "inputdata" ) {
MInput ( ref mAC , l2action , ( string ) l2action . Attribute ( "input" ) ) ; // or in the inputdata nesting
}
m_state = EState . inActionMap ; // now we are in and processing the map
}
}
}
else if ( m_state = = EState . inActionMap ) {
// processing a valid action map - collect actions
if ( eName . ToLower ( ) = = "action" ) {
// this is an action.. - collect it
CollectActions ( attr ) ;
ReadActionSub ( xr , attr [ "name" ] , "" ) ; // a non empty action element may have a sub element (but no device yet)
break ;
case GamepadCls . DeviceClass : {
XInput ( ref xAC , l1action , ( string ) l1action . Attribute ( "input" ) ) ; // may have attributed ones
foreach ( XElement l2action in l1action . Elements ( ) ) {
if ( l2action . Name . LocalName = = "inputdata" ) {
XInput ( ref xAC , l2action , ( string ) l2action . Attribute ( "input" ) ) ; // or in the inputdata nesting
}
}
}
}
//Console.Write( ">\n" );
break ;
case XmlNodeType . Text :
//Console.Write( xr.Value );
break ;
case XmlNodeType . EndElement :
//Console.Write( "</{0}>\n", xr.Name );
break ;
break ;
default : break ;
}
}
return true ;
if ( ! string . IsNullOrEmpty ( jAC . DefBinding ) ) m_currentMap . Add ( jAC ) ; // finally add it to the current map if it was bound
if ( ! string . IsNullOrEmpty ( kAC . DefBinding ) ) m_currentMap . Add ( kAC ) ; // finally add it to the current map if it was bound
if ( ! string . IsNullOrEmpty ( mAC . DefBinding ) ) m_currentMap . Add ( mAC ) ; // finally add it to the current map if it was bound
if ( ! string . IsNullOrEmpty ( xAC . DefBinding ) ) m_currentMap . Add ( xAC ) ; // finally add it to the current map if it was bound
return retVal ;
}
/// <summary>
/// Read the xml part
/// Read all from an Actionmap XElemen t
/// </summary>
/// <param name=" xr"> </param>
/// <returns> </returns>
private bool Read XML( XmlReader xr )
/// <param name=" actionmap">The Actionmap XElement </param>
/// <returns> True if successfull </returns>
private bool Read Actionmap( XElement actionmap )
{
log . Debug ( "DProfileReader.Read XML - Entry" ) ;
log . Debug ( "DProfileReader.Read Actionmap - Entry" ) ;
// a complete actionmap arrives here
bool retVal = true ;
try {
do {
if ( xr . IsStartElement ( ) ) {
m_nodeNameStack . Push ( xr . Name ) ;
if ( xr . IsEmptyElement ) {
retVal = retVal & & ReadEmptyElement ( xr ) ;
m_nodeNameStack . Pop ( ) ; // empty ones end inline
}
else {
retVal = retVal & & ReadElement ( xr ) ;
}
// check for a valid one
string mapName = ( string ) actionmap . Attribute ( "name" ) ; // mandatory
string item = Array . Find ( ActionMapsCls . ActionMaps , delegate ( string sstr ) { return sstr = = mapName ; } ) ;
if ( ! string . IsNullOrEmpty ( item ) ) {
// finally.... it is a valid actionmap
m_currentMap = new ActionMap ( ) ;
m_currentMap . Name = mapName ;
if ( ! m_aMap . ContainsKey ( mapName ) ) { //20170325 - fix multiple map names - don't add the second, third etc. (CIG bug..)
m_aMap . Add ( mapName , m_currentMap ) ; // add to our inventory
IEnumerable < XElement > actions = from x in actionmap . Elements ( )
where ( x . Name = = "action" )
select x ;
foreach ( XElement action in actions ) {
// one action
retVal & = ReadAction ( action ) ;
}
else if ( xr . NodeType = = XmlNodeType . EndElement ) {
//Console.Write( "</{0}>\n", xr.Name );
string exitElement = m_nodeNameStack . Pop ( ) ;
if ( m_state = = EState . inActionMap )
if ( exitElement . ToLower ( ) = = "actionmap" ) m_state = EState . idle ; // finished
}
} while ( xr . Read ( ) ) ;
if ( m_nodeNameStack . Count = = 0 )
return retVal & & true ;
else
return false ;
}
catch ( Exception ex ) {
// get any exceptions from reading
log . Error ( "DProfileReader.ReadXML - unexpected" , ex ) ;
return false ;
}
}
/ *
//<ActivationModes >
// <ActivationMode name="tap" onPress="0" onHold="0" onRelease="1" multiTap="1" multiTapBlock="1" pressTriggerThreshold="-1" releaseTriggerThreshold="0.25" releaseTriggerDelay="0" />
. . .
//</ActivationModes>
* /
private bool ReadActivationModes ( XmlReader xr )
{
log . Debug ( "DProfileReader.ReadActivationModes - Entry" ) ;
try {
xr . ReadToFollowing ( "ActivationModes" ) ;
xr . ReadToDescendant ( "ActivationMode" ) ;
do {
if ( xr . NodeType = = XmlNodeType . EndElement ) {
xr . Read ( ) ;
break ; // finished
}
string name = xr [ "name" ] ;
string mTap = xr [ "multiTap" ] ;
if ( ! string . IsNullOrEmpty ( name ) ) ActivationModes . Instance . Add ( new ActivationMode ( name , int . Parse ( mTap ) ) ) ;
} while ( xr . Read ( ) ) ;
}
else {
log . DebugFormat ( "ReadActionmap: IGNORED duplicate map with name: {0}" , mapName ) ;
}
return true ;
}
catch ( Exception ex ) {
// get any exceptions from reading
log . Error ( "DProfileReader.ReadXML - unexpected" , ex ) ;
return false ;
}
return retVal ;
}
// Read modifiers
//<modifiers>
// <mod input = "xi_shoulderl" />
// <mod input ="xi_triggerl_btn" />
// <mod input = "xi_dpad_down" />
// <mod input ="xi_y" />
// <mod input = "kb_z" />
// <mod input ="kb_f3" />
// <mod input = "kb_lalt" />
// <mod input = "kb_lalt" />
// <mod input = "kb_f4" />
// <mod input = "kb_mouse2" />
// <mod input = "xi_dpad_down" />
// <mod input = "xi_shoulderl" />
// <mod input = "xi_triggerl_btn" />
//</ modifiers >
private bool ReadModifiers ( XmlReader xr )
/// <summary>
/// Read all from ActivationMode XElement
/// </summary>
/// <param name="actmodes">The Activatiomodes XElement</param>
/// <returns>True if successfull</returns>
private bool ReadActivationModes ( XElement actmodes )
{
log . Debug ( "DProfileReader.ReadModifiers - Entry" ) ;
/ *
//<ActivationModes >
// <ActivationMode name="tap" onPress="0" onHold="0" onRelease="1" multiTap="1" multiTapBlock="1" pressTriggerThreshold="-1" releaseTriggerThreshold="0.25" releaseTriggerDelay="0" />
. . .
//</ActivationModes>
* /
log . Debug ( "DProfileReader.ReadActivationModes - Entry" ) ;
try {
xr . ReadToFollowing ( "modifiers" ) ;
return Modifiers . Instance . FromXML ( xr . ReadOuterXml ( ) , true ) ;
}
catch ( Exception ex ) {
// get any exceptions from reading
log . Error ( "DProfileReader.ReadXML - unexpected" , ex ) ;
return false ;
IEnumerable < XElement > activationmodes = from x in actmodes . Elements ( )
where ( x . Name = = "ActivationMode" )
select x ;
foreach ( XElement activationmode in activationmodes ) {
string name = ( string ) activationmode . Attribute ( "name" ) ;
string mTap = ( string ) activationmode . Attribute ( "multiTap" ) ;
if ( ! string . IsNullOrEmpty ( name ) ) ActivationModes . Instance . Add ( new ActivationMode ( name , int . Parse ( mTap ) ) ) ;
}
return true ;
}
/// <summary>
/// Read the defaultProfile.xml - do some sanity check
/// </summary>
@ -532,32 +350,52 @@ namespace SCJMapper_V2.SC
{
log . Debug ( "DProfileReader.fromXML - Entry" ) ;
if ( ActionMapsCls . ActionMaps . Length = = 0 ) ActionMapsCls . LoadSupportedActionMaps ( ActionMapList ( xml ) ) ; // make sure we have them loaded ( refactoring to get a singleton or so...)
// make sure we have them loaded ( refactoring to get a singleton or so...)
if ( ActionMapsCls . ActionMaps . Length = = 0 ) ActionMapsCls . LoadSupportedActionMaps ( ActionMapList ( xml ) ) ;
XmlReaderSettings settings = new XmlReaderSettings ( ) ;
settings . ConformanceLevel = ConformanceLevel . Fragment ;
settings . IgnoreWhitespace = true ;
settings . IgnoreComments = true ;
XmlReader reader = XmlReader . Create ( new StringReader ( xml ) , settings ) ;
// read the content of the xml
XmlReaderSettings settings = new XmlReaderSettings {
ConformanceLevel = ConformanceLevel . Fragment ,
IgnoreWhitespace = true ,
IgnoreComments = true
} ;
using ( XmlReader reader = XmlReader . Create ( new StringReader ( xml ) , settings ) ) {
m_aMap = new Dictionary < string , ActionMap > ( ) ;
// init the activation modes singleton
ActivationModes . Instance . Clear ( ) ;
ActivationModes . Instance . Add ( ActivationMode . Default ) ;
m_nodeNameStack = new Stack < string > ( ) ;
m_aMap = new Dictionary < string , ActionMap > ( ) ;
// init the activation modes singleton
ActivationModes . Instance . Clear ( ) ;
ActivationModes . Instance . Add ( ActivationMode . Default ) ;
ValidContent = true ; // init
ValidContent = true ; // init
reader . Read ( ) ;
ValidContent & = ReadActivationModes ( reader ) ;
reader . MoveToContent ( ) ;
if ( XNode . ReadFrom ( reader ) is XElement el ) {
IEnumerable < XElement > activationModes = from x in el . Elements ( )
where ( x . Name = = "ActivationModes" )
select x ;
foreach ( XElement activationMode in activationModes ) {
ValidContent & = ReadActivationModes ( activationMode ) ;
}
Modifiers . Instance . Clear ( ) ;
ValidContent & = ReadModifiers ( reader ) ;
m_nodeNameStack . Push ( "profile" ) ; // we are already in the XML now
Modifiers . Instance . Clear ( ) ;
IEnumerable < XElement > modifiers = from x in el . Elements ( )
where ( x . Name = = "modifiers" )
select x ;
foreach ( XElement modifier in modifiers ) {
ValidContent & = Modifiers . Instance . FromXML ( modifier ) ;
}
ValidContent & = ReadXML ( reader ) ;
IEnumerable < XElement > actionmaps = from x in el . Elements ( )
where ( x . Name = = "actionmap" )
select x ;
foreach ( XElement actionmap in actionmaps ) {
ValidContent & = ReadActionmap ( actionmap ) ;
}
}
}
return ValidContent ;
}
@ -568,24 +406,25 @@ namespace SCJMapper_V2.SC
/// <returns>A filled SCActionMapList object</returns>
public SCActionMapList ActionMapList ( string xml )
{
SCActionMapList aml = new SCActionMapList ( ) ;
log . Debug ( "DProfileReader.ActionMapList - Entry" ) ;
XmlReaderSettings settings = new XmlReaderSettings ( ) ;
settings . ConformanceLevel = ConformanceLevel . Fragment ;
settings . IgnoreWhitespace = true ;
settings . IgnoreComments = true ;
XmlReader reader = XmlReader . Create ( new StringReader ( xml ) , settings ) ;
reader . Read ( ) ;
if ( ! reader . ReadToFollowing ( "actionmap" ) ) return aml ; // ERROR empty one..
do {
string attr = reader [ "name" ] ;
if ( ! string . IsNullOrEmpty ( attr ) )
aml . AddActionMap ( attr ) ;
} while ( reader . ReadToFollowing ( "actionmap" ) ) ;
SCActionMapList aml = new SCActionMapList ( ) ;
XmlReaderSettings settings = new XmlReaderSettings {
ConformanceLevel = ConformanceLevel . Fragment ,
IgnoreWhitespace = true ,
IgnoreComments = true
} ;
using ( XmlReader reader = XmlReader . Create ( new StringReader ( xml ) , settings ) ) {
reader . MoveToContent ( ) ;
if ( XNode . ReadFrom ( reader ) is XElement el ) {
IEnumerable < XElement > actionmaps = from x in el . Elements ( )
where ( x . Name = = "actionmap" )
select x ;
foreach ( XElement actionmap in actionmaps ) {
aml . AddActionMap ( ( string ) actionmap . Attribute ( "name" ) ) ;
}
}
}
return aml ;
}