Adds utility function to clean up and standardize the remapping handling for keybinds

Adds sanity check so if no remappable binds are found for an actionMap, it isn't listed in the controls menu
Updates ExampleModule's keybinds to use new utility function
This commit is contained in:
Areloch 2022-12-06 00:16:13 -06:00
parent a304198abb
commit 44c894d335
3 changed files with 53 additions and 66 deletions

View file

@ -8,4 +8,23 @@ function getMouseAdjustAmount(%val)
{
// based on a default camera FOV of 90'
return(%val * ($cameraFov / 90) * 0.01) * $pref::Input::LinkMouseSensitivity;
}
function addKeyRemap(%name, %actionMap, %device, %command, %description)
{
if(%name $= "" ||
%actionMap $= "" ||
%device $= "" ||
%command $= "")
{
error("addKeybindRemap() - tried to add a remap entry, but didn't have all the keeded info!");
return;
}
$RemapName[$RemapCount] = %name;
$RemapCmd[$RemapCount] = %command;
$RemapActionMap[$RemapCount] = %actionMap;
$RemapDevice[$RemapCount] = %device;
$RemapDescription[$RemapCount] = %description;
$RemapCount++;
}

View file

@ -1,70 +1,21 @@
$RemapName[$RemapCount] = "Forward";
$RemapCmd[$RemapCount] = "moveforward";
$RemapActionMap[$RemapCount] = "ExampleMoveMap";
$RemapDevice[$RemapCount] = "keyboard";
$RemapDescription[$RemapCount] = "Forward Movement";
$RemapCount++;
$RemapName[$RemapCount] = "Backward";
$RemapCmd[$RemapCount] = "movebackward";
$RemapActionMap[$RemapCount] = "ExampleMoveMap";
$RemapDevice[$RemapCount] = "keyboard";
$RemapDescription[$RemapCount] = "Backward Movement";
$RemapCount++;
$RemapName[$RemapCount] = "Strafe Left";
$RemapCmd[$RemapCount] = "moveleft";
$RemapActionMap[$RemapCount] = "ExampleMoveMap";
$RemapDevice[$RemapCount] = "keyboard";
$RemapDescription[$RemapCount] = "Left Strafing Movement";
$RemapCount++;
$RemapName[$RemapCount] = "Strafe Right";
$RemapCmd[$RemapCount] = "moveright";
$RemapActionMap[$RemapCount] = "ExampleMoveMap";
$RemapDevice[$RemapCount] = "keyboard";
$RemapDescription[$RemapCount] = "Right Strafing Movement";
$RemapCount++;
$RemapName[$RemapCount] = "Ascend";
$RemapCmd[$RemapCount] = "moveup";
$RemapActionMap[$RemapCount] = "ExampleMoveMap";
$RemapDevice[$RemapCount] = "keyboard";
$RemapDescription[$RemapCount] = "Makes the camera ascend";
$RemapCount++;
$RemapName[$RemapCount] = "Descend";
$RemapCmd[$RemapCount] = "movedown";
$RemapActionMap[$RemapCount] = "ExampleMoveMap";
$RemapDevice[$RemapCount] = "keyboard";
$RemapDescription[$RemapCount] = "Makes the camera descend";
$RemapCount++;
$RemapName[$RemapCount] = "Jump";
$RemapCmd[$RemapCount] = "jump";
$RemapActionMap[$RemapCount] = "ExampleMoveMap";
$RemapDevice[$RemapCount] = "keyboard";
$RemapDescription[$RemapCount] = "Jump";
$RemapCount++;
if(!isObject( ExampleMoveMap ) )
{
new ActionMap(ExampleMoveMap)
{
humanReadableName = "Example Movement";
};
}
$RemapName[$RemapCount] = "Ascend";
$RemapCmd[$RemapCount] = "moveup";
$RemapActionMap[$RemapCount] = "ExampleMoveMap";
$RemapDevice[$RemapCount] = "gamepad";
$RemapDescription[$RemapCount] = "Makes the camera ascend";
$RemapCount++;
$RemapName[$RemapCount] = "Descend";
$RemapCmd[$RemapCount] = "movedown";
$RemapActionMap[$RemapCount] = "ExampleMoveMap";
$RemapDevice[$RemapCount] = "gamepad";
$RemapDescription[$RemapCount] = "Makes the camera descend";
$RemapCount++;
$RemapName[$RemapCount] = "Jump";
$RemapCmd[$RemapCount] = "jump";
$RemapActionMap[$RemapCount] = "ExampleMoveMap";
$RemapDevice[$RemapCount] = "gamepad";
$RemapDescription[$RemapCount] = "Jump";
$RemapCount++;
if ( isObject( ExampleMoveMap ) )
ExampleMoveMap.delete();
new ActionMap(ExampleMoveMap);
ExampleMoveMap.humanReadableName = "Example Movement";
//------------------------------------------------------------------------------
// Set up remappable entries
//------------------------------------------------------------------------------
addKeyRemap("Forward", "ExampleMoveMap", "keyboard", "moveForward", "Forward Movement");
addKeyRemap("Backward", "ExampleMoveMap", "keyboard", "movebackward", "Backward Movement");
addKeyRemap("Strafe Left", "ExampleMoveMap", "keyboard", "moveleft", "Left Strafing Movement");
addKeyRemap("Strafe Right", "ExampleMoveMap", "keyboard", "moveright", "Right Strafing Movement");
addKeyRemap("Ascend", "ExampleMoveMap", "keyboard", "moveup", "Makes the camera ascend");
addKeyRemap("Descend", "ExampleMoveMap", "keyboard", "movedown", "Makes the camera descend");
addKeyRemap("Jump", "ExampleMoveMap", "keyboard", "jump", "Jump");
//------------------------------------------------------------------------------
// Non-remapable binds

View file

@ -145,6 +145,23 @@ function fillRemapList()
%actionMapName = %actionMap.humanReadableName $= "" ? %actionMap.getName() : %actionMap.humanReadableName;
//see if we have any actual listed remappable keys for this movemap. if so, drop it from the listing
%hasRemaps = false;
for ( %r = 0; %r < $RemapCount; %r++ )
{
%testMapName = $RemapActionMap[%r].humanReadableName $= "" ? $RemapActionMap[%r].getName() : $RemapActionMap[%r].humanReadableName;
if(%actionMapName $= %testMapName)
{
//got a match to at least one, so we're ok to continue
%hasRemaps = true;
break;
}
}
if(!%hasRemaps)
continue;
if(%actionMapList $= "")
%actionMapList = %actionMapName;
else