1
0
Fork 0

warthog: add js overlay support

This allows to have generic axis/button definitions with aircraft
specific or aircraft class specific modification overlays. These
are also found in $FG_HOME, where they override global files. This
mechanism is desirable, because the Warthog is an A-10 replica, and
it should be possible to have an automatically loaded (1:1 mapped)
A-10 joystick config when flying the A-10, while using generic layouts
otherwise, or a specific helicopter overlay for helicopters etc.

Overlay files look exactly like joystick config files, except they
have no <name> and only specify actually differing elements. Axes
with <number> *need* a property index (e.g. <axis n="2">), which
usually corresponds to the <unix> value (i.e. n'th axis def in file).
Overlay files can contain a <nasal> block which is executed on
load. The files are to be named {$FG_ROOT,$FG_HOME}/Input/Joysticks/\
ThrustMaster/Warthog/{Joystick,Throttle}/{generic,helicopter,<aircraft>}\
.xml.
This commit is contained in:
Melchior FRANZ 2011-09-10 00:03:11 +02:00
parent ea0c72494d
commit 820323e854
2 changed files with 60 additions and 8 deletions

View file

@ -8,11 +8,35 @@
<name>Thustmaster Joystick - HOTAS Warthog</name>
<nasal>
<command>nasal</command>
<script>
var this = cmdarg().getParent();
var popup = func gui.popupTip(call(sprintf, arg));
var is_dir = func(path) {(var stat = io.stat(path)) != nil and stat[11] == "dir"};
var is_helicopter = (var _ = props.globals.getNode("rotors", 0)) != nil and _.getAttribute("children");
var dir = "/Input/Joysticks/ThrustMaster/Warthog/Joystick/";
var trimstep = 0.75;
var overlay = {};
foreach (var base; [getprop("/sim/fg-root"), getprop("/sim/fg-home")])
if (is_dir(base ~ dir))
foreach (var file; directory(base ~ dir))
overlay[file] = base ~ dir ~ file;
var load_overlay = func(name) {
var file = name ~ ".xml";
if (contains(overlay, file)) {
printlog("info", "WARTHOG: loading overlay " ~ overlay[file]);
cmdarg().getNode("script").setValue("");
io.read_properties(overlay[file], this);
props.runBinding(cmdarg());
}
}
load_overlay("generic");
if (is_helicopter)
load_overlay("helicopter");
load_overlay(getprop("/sim/aircraft"));
overlay = nil;
foreach (var b; this.getChildren("button")) {
if (b.getAttribute("children") == 1) {
@ -20,6 +44,8 @@
b.setValues({binding: {command: "nasal", script: 'popup("' ~ name ~ '")'}});
}
}
var trimstep = 0.75;
</script>
</nasal>

View file

@ -8,9 +8,42 @@
<name>Thrustmaster Throttle - HOTAS Warthog</name>
<nasal>
<command>nasal</command>
<script>
var this = cmdarg().getParent();
var popup = func gui.popupTip(call(sprintf, arg));
var is_dir = func(path) {(var stat = io.stat(path)) != nil and stat[11] == "dir"}
var is_helicopter = (var _ = props.globals.getNode("rotors", 0)) != nil and _.getAttribute("children");
var dir = "/Input/Joysticks/ThrustMaster/Warthog/Throttle/";
var overlay = {};
foreach (var base; [getprop("/sim/fg-root"), getprop("/sim/fg-home")])
if (is_dir(base ~ dir))
foreach (var file; directory(base ~ dir))
overlay[file] = base ~ dir ~ file;
var load_overlay = func(name) {
var file = name ~ ".xml";
if (contains(overlay, file)) {
printlog("info", "WARTHOG: loading overlay " ~ overlay[file]);
cmdarg().getNode("script").setValue("");
io.read_properties(overlay[file], this);
props.runBinding(cmdarg());
}
}
load_overlay("generic");
if (is_helicopter)
load_overlay("helicopter");
load_overlay(getprop("/sim/aircraft"));
overlay = nil;
foreach (var b; this.getChildren("button")) {
if (b.getAttribute("children") == 1) {
var name = b.getNode("name", 1).getValue() or "??";
b.setValues({binding: {command: "nasal", script: 'popup("' ~ name ~ '")'}});
}
}
var even_engines = [0, 2, 4, 6, 8, 10];
var odd_engines = [1, 3, 5, 7, 9, 11];
@ -20,13 +53,6 @@
var t = viewdir[i].getNode("type");
viewdir[i] = t != nil and t.getValue() == "lookat" ? 1 : -1;
}
foreach (var b; this.getChildren("button")) {
if (b.getAttribute("children") == 1) {
var name = b.getNode("name", 1).getValue() or "??";
b.setValues({binding: {command: "nasal", script: 'popup("' ~ name ~ '")'}});
}
}
</script>
</nasal>