1
0
Fork 0

Restore named JS/input configs (overrides)

Thanks to jano for pointing out I'd broken this feature!
This commit is contained in:
James Turner 2012-09-25 14:20:18 +01:00
parent 8050f39089
commit ae6218ff10
4 changed files with 31 additions and 4 deletions

View file

@ -40,8 +40,17 @@
using simgear::PropertyList;
using std::string;
FGDeviceConfigurationMap::FGDeviceConfigurationMap( const string& relative_path)
FGDeviceConfigurationMap::FGDeviceConfigurationMap( const string& relative_path,
SGPropertyNode* nodePath,
const std::string& nodeName)
{
// scan for over-ride configurations, loaded via joysticks.xml, etc
BOOST_FOREACH(SGPropertyNode_ptr preloaded, nodePath->getChildren(nodeName)) {
BOOST_FOREACH(SGPropertyNode* nameProp, preloaded->getChildren("name")) {
overrideDict[nameProp->getStringValue()] = preloaded;
} // of names iteration
} // of defined overrides iteration
scan_dir( SGPath(globals->get_fg_home(), relative_path));
scan_dir( SGPath(globals->get_fg_root(), relative_path));
}
@ -53,6 +62,12 @@ FGDeviceConfigurationMap::~FGDeviceConfigurationMap()
SGPropertyNode_ptr
FGDeviceConfigurationMap::configurationForDeviceName(const std::string& name)
{
NameNodeMap::iterator j = overrideDict.find(name);
if (j != overrideDict.end()) {
return j->second;
}
// no override, check out list of config files
NamePathMap::iterator it = namePathMap.find(name);
if (it == namePathMap.end()) {
return SGPropertyNode_ptr();
@ -71,6 +86,11 @@ FGDeviceConfigurationMap::configurationForDeviceName(const std::string& name)
bool FGDeviceConfigurationMap::hasConfiguration(const std::string& name) const
{
NameNodeMap::const_iterator j = overrideDict.find(name);
if (j != overrideDict.end()) {
return true;
}
return namePathMap.find(name) != namePathMap.end();
}

View file

@ -37,7 +37,9 @@
class FGDeviceConfigurationMap
{
public:
FGDeviceConfigurationMap ( const std::string& relative_path);
FGDeviceConfigurationMap ( const std::string& relative_path,
SGPropertyNode* nodePath,
const std::string& nodeName);
virtual ~FGDeviceConfigurationMap();
SGPropertyNode_ptr configurationForDeviceName(const std::string& name);
@ -49,6 +51,11 @@ private:
void readCachedData(const SGPath& path);
void refreshCacheForFile(const SGPath& path);
typedef std::map<std::string, SGPropertyNode_ptr> NameNodeMap;
// dictionary of over-ridden configurations, where the config data
// was explicitly loaded and shoudl be picked over a file search
NameNodeMap overrideDict;
typedef std::map<std::string, SGPath> NamePathMap;
// mapping from joystick name to XML configuration file path
NamePathMap namePathMap;

View file

@ -294,7 +294,7 @@ void FGInputDevice::SetName( string name )
const char * FGEventInput::PROPERTY_ROOT = "/input/event";
FGEventInput::FGEventInput() :
configMap( "Input/Event")
configMap( "Input/Event", fgGetNode(PROPERTY_ROOT, true), "device-named")
{
}

View file

@ -106,7 +106,7 @@ void FGJoystickInput::init()
SGPropertyNode_ptr js_nodes = fgGetNode("/input/joysticks", true);
status_node = fgGetNode("/devices/status/joysticks", true);
FGDeviceConfigurationMap configMap("Input/Joysticks");
FGDeviceConfigurationMap configMap("Input/Joysticks",js_nodes, "js-named");
for (int i = 0; i < MAX_JOYSTICKS; i++) {
jsJoystick * js = new jsJoystick(i);