mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 20:58:38 +02:00
unified two ways to do the mapping in a single JS
This commit is contained in:
parent
f9ebbea585
commit
715b183a3c
2 changed files with 39 additions and 39 deletions
|
@ -4,68 +4,74 @@
|
||||||
// examples
|
// examples
|
||||||
//
|
//
|
||||||
// Created by Sam Gondelman on 6/2/15
|
// Created by Sam Gondelman on 6/2/15
|
||||||
|
// Rewritten by Alessandro Signa on 11/05/15
|
||||||
// Copyright 2015 High Fidelity, Inc.
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
//
|
//
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
// This allows to change the input mapping making a sense of how the new mapping works
|
// This allows to change the input mapping to easly understand of how the new mapping works.
|
||||||
|
// Two different ways are presented: the first one uses a JSON file to create the mapping, the second one declares the new routes explicitly one at a time.
|
||||||
|
// You shuold prefer the first method if you have a lot of new routes, the second one if you want to express the action as a function.
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This function returns a JSON body. It's in charge to modify the mouse/keyboard mapping. The keyboard inputs are mapped directly to actions.
|
This function returns a JSON body. It's in charge to modify the standard controller and the mouse/keyboard mapping.
|
||||||
|
|
||||||
|
The Standard controller is an abstraction: all the actual controllers are mapped to it. (i.e. Hydra --mapped to-> Standard --mapped to-> Action)
|
||||||
|
This example will overwrite the mapping of the left axis (Standard.LY, Standard.LX).
|
||||||
|
It's possible to find all the standard inputs (and their mapping) into standard.json
|
||||||
|
To try these changes you need a controller, not the keyboard.
|
||||||
|
|
||||||
|
The keyboard/mouse inputs are mapped directly to actions since the keyboard doesn't have its default mapping passing through the Standard controller.
|
||||||
If this new mapping contains inputs which are defined in the standard mapping, these will overwrite the old ones(Keyboard.W, Keyboard.RightMouseButton).
|
If this new mapping contains inputs which are defined in the standard mapping, these will overwrite the old ones(Keyboard.W, Keyboard.RightMouseButton).
|
||||||
If this new mapping contains inputs which are not defined in the standard, these will be added to the mapping(Keyboard.M).
|
If this new mapping contains inputs which are not defined in the standard, these will be added to the mapping(Keyboard.M).
|
||||||
*/
|
*/
|
||||||
myFirstMapping = function() {
|
myFirstMapping = function() {
|
||||||
return {
|
return {
|
||||||
"name": "example",
|
"name": "controllerMapping_First",
|
||||||
"channels": [
|
"channels": [
|
||||||
{ "from": "Keyboard.W", "to": "Actions.YAW_LEFT" },
|
|
||||||
{ "from": "Keyboard.M", "to": "Actions.YAW_LEFT" },
|
|
||||||
|
|
||||||
{ "from": "Keyboard.RightMouseButton", "to": "Actions.YAW_RIGHT" }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
This JSON is in charge to modify the Standard controller mapping.
|
|
||||||
The standard controller is an abstraction: all the actual controllers are mapped to it. (i.e. Hydra --mapped to-> Standard --mapped to-> Action)
|
|
||||||
These new inputs will overwrite the standard ones.
|
|
||||||
It's possible to find all the standard inputs (and their mapping) into standard.json
|
|
||||||
To try the mySecondMapping effect you need a controller, not the keyboard.
|
|
||||||
*/
|
|
||||||
mySecondMapping = function() {
|
|
||||||
return {
|
|
||||||
"name": "example2",
|
|
||||||
"channels": [
|
|
||||||
{ "from": "Standard.LY", "to": "Actions.Yaw" },
|
{ "from": "Standard.LY", "to": "Actions.Yaw" },
|
||||||
{ "from": "Standard.LX", "to": "Actions.Yaw" },
|
{ "from": "Standard.LX", "to": "Actions.Yaw" },
|
||||||
|
|
||||||
|
{ "from": "Keyboard.W", "to": "Actions.YAW_LEFT" },
|
||||||
|
{ "from": "Keyboard.M", "to": "Actions.YAW_RIGHT" },
|
||||||
|
|
||||||
|
{ "from": "Keyboard.LeftMouseButton", "to": "Actions.Up" }
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var tryFirst = true;
|
|
||||||
|
var firstWay = true;
|
||||||
var mapping;
|
var mapping;
|
||||||
if(tryFirst){
|
var MAPPING_NAME;
|
||||||
|
|
||||||
|
|
||||||
|
if(firstWay){
|
||||||
var myFirstMappingJSON = myFirstMapping();
|
var myFirstMappingJSON = myFirstMapping();
|
||||||
print('myfirstMappingJSON' + JSON.stringify(myFirstMappingJSON));
|
print('myfirstMappingJSON' + JSON.stringify(myFirstMappingJSON));
|
||||||
mapping = Controller.parseMapping(JSON.stringify(myFirstMappingJSON));
|
mapping = Controller.parseMapping(JSON.stringify(myFirstMappingJSON));
|
||||||
|
mapping.enable();
|
||||||
}else{
|
}else{
|
||||||
var mySecondMappingJSON = mySecondMapping();
|
MAPPING_NAME = "controllerMapping_Second";
|
||||||
print('mySecondMappingJSON' + JSON.stringify(mySecondMappingJSON));
|
var mapping2 = Controller.newMapping(MAPPING_NAME);
|
||||||
mapping = Controller.parseMapping(JSON.stringify(mySecondMappingJSON));
|
mapping2.from(Controller.Hardware.Keyboard.RightMouseClicked).to(function (value) {
|
||||||
|
print("Keyboard.RightMouseClicked");
|
||||||
|
});
|
||||||
|
mapping2.from(Controller.Standard.LX).to(Controller.Actions.Yaw);
|
||||||
|
Controller.enableMapping(MAPPING_NAME);
|
||||||
}
|
}
|
||||||
mapping.enable();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
//-----------------some info prints-----------------------
|
//-----------------some info prints that you would like to enable-----------------------
|
||||||
Object.keys(Controller.Standard).forEach(function (input) {
|
Object.keys(Controller.Standard).forEach(function (input) {
|
||||||
print("Controller.Standard." + input + ":" + Controller.Standard[input]);
|
print("Controller.Standard." + input + ":" + Controller.Standard[input]);
|
||||||
});
|
});
|
||||||
|
@ -94,5 +100,9 @@ Controller.hardwareChanged.connect(function () {
|
||||||
|
|
||||||
|
|
||||||
Script.scriptEnding.connect(function () {
|
Script.scriptEnding.connect(function () {
|
||||||
mapping.disable();
|
if(firstWay){
|
||||||
|
mapping.disable();
|
||||||
|
} else {
|
||||||
|
Controller.disableMapping(MAPPING_NAME);
|
||||||
|
}
|
||||||
});
|
});
|
|
@ -1,10 +0,0 @@
|
||||||
var MAPPING_NAME = "com.highfidelity.rightClickExample";
|
|
||||||
var mapping = Controller.newMapping(MAPPING_NAME);
|
|
||||||
mapping.from(Controller.Hardware.Keyboard.RightMouseClicked).to(function (value) {
|
|
||||||
print("Keyboard.RightMouseClicked");
|
|
||||||
});
|
|
||||||
Controller.enableMapping(MAPPING_NAME);
|
|
||||||
|
|
||||||
Script.scriptEnding.connect(function () {
|
|
||||||
Controller.disableMapping(MAPPING_NAME);
|
|
||||||
});
|
|
Loading…
Reference in a new issue