mirror of https://github.com/OpenMW/openmw.git
Lua package 'openmw.input'
parent
ee1ec53cd9
commit
0e6fbbc126
@ -0,0 +1,150 @@
|
||||
#include "luabindings.hpp"
|
||||
|
||||
#include <SDL_events.h>
|
||||
#include <SDL_gamecontroller.h>
|
||||
|
||||
#include "../mwbase/inputmanager.hpp"
|
||||
#include "../mwinput/actions.hpp"
|
||||
|
||||
namespace sol
|
||||
{
|
||||
template <>
|
||||
struct is_automagical<SDL_Keysym> : std::false_type {};
|
||||
}
|
||||
|
||||
namespace MWLua
|
||||
{
|
||||
|
||||
sol::table initInputPackage(const Context& context)
|
||||
{
|
||||
sol::usertype<SDL_Keysym> keyEvent = context.mLua->sol().new_usertype<SDL_Keysym>("KeyEvent");
|
||||
keyEvent["symbol"] = sol::readonly_property([](const SDL_Keysym& e) { return std::string(1, static_cast<char>(e.sym)); });
|
||||
keyEvent["code"] = sol::readonly_property([](const SDL_Keysym& e) -> int { return e.sym; });
|
||||
keyEvent["modifiers"] = sol::readonly_property([](const SDL_Keysym& e) -> int { return e.mod; });
|
||||
keyEvent["withShift"] = sol::readonly_property([](const SDL_Keysym& e) -> bool { return e.mod & KMOD_SHIFT; });
|
||||
keyEvent["withCtrl"] = sol::readonly_property([](const SDL_Keysym& e) -> bool { return e.mod & KMOD_CTRL; });
|
||||
keyEvent["withAlt"] = sol::readonly_property([](const SDL_Keysym& e) -> bool { return e.mod & KMOD_ALT; });
|
||||
keyEvent["withSuper"] = sol::readonly_property([](const SDL_Keysym& e) -> bool { return e.mod & KMOD_GUI; });
|
||||
|
||||
MWBase::InputManager* input = MWBase::Environment::get().getInputManager();
|
||||
sol::table api(context.mLua->sol(), sol::create);
|
||||
|
||||
api["isIdle"] = [input]() { return input->isIdle(); };
|
||||
api["isActionPressed"] = [input](int action) { return input->actionIsActive(action); };
|
||||
api["isMouseButtonPressed"] = [input](int button) -> bool
|
||||
{
|
||||
return input->getMouseButtonsState() & (1 << (button - 1));
|
||||
};
|
||||
api["getMouseMoveX"] = [input]() { return input->getMouseMoveX(); };
|
||||
api["getMouseMoveY"] = [input]() { return input->getMouseMoveY(); };
|
||||
api["getAxisValue"] = [input](int axis)
|
||||
{
|
||||
if (axis < SDL_CONTROLLER_AXIS_MAX)
|
||||
return input->getControllerAxisValue(static_cast<SDL_GameControllerAxis>(axis));
|
||||
else
|
||||
return input->getActionValue(axis - SDL_CONTROLLER_AXIS_MAX) * 2 - 1;
|
||||
};
|
||||
|
||||
api["getControlSwitch"] = [input](const std::string& key) { return input->getControlSwitch(key); };
|
||||
api["setControlSwitch"] = [input](const std::string& key, bool v) { input->toggleControlSwitch(key, v); };
|
||||
|
||||
api["ACTION"] = context.mLua->makeReadOnly(context.mLua->sol().create_table_with(
|
||||
"GameMenu", MWInput::A_GameMenu,
|
||||
"Screenshot", MWInput::A_Screenshot,
|
||||
"Inventory", MWInput::A_Inventory,
|
||||
"Console", MWInput::A_Console,
|
||||
|
||||
"MoveLeft", MWInput::A_MoveLeft,
|
||||
"MoveRight", MWInput::A_MoveRight,
|
||||
"MoveForward", MWInput::A_MoveForward,
|
||||
"MoveBackward", MWInput::A_MoveBackward,
|
||||
|
||||
"Activate", MWInput::A_Activate,
|
||||
"Use", MWInput::A_Use,
|
||||
"Jump", MWInput::A_Jump,
|
||||
"AutoMove", MWInput::A_AutoMove,
|
||||
"Rest", MWInput::A_Rest,
|
||||
"Journal", MWInput::A_Journal,
|
||||
"Weapon", MWInput::A_Weapon,
|
||||
"Spell", MWInput::A_Spell,
|
||||
"Run", MWInput::A_Run,
|
||||
"CycleSpellLeft", MWInput::A_CycleSpellLeft,
|
||||
"CycleSpellRight", MWInput::A_CycleSpellRight,
|
||||
"CycleWeaponLeft", MWInput::A_CycleWeaponLeft,
|
||||
"CycleWeaponRight", MWInput::A_CycleWeaponRight,
|
||||
"ToggleSneak", MWInput::A_ToggleSneak,
|
||||
"AlwaysRun", MWInput::A_AlwaysRun,
|
||||
"Sneak", MWInput::A_Sneak,
|
||||
|
||||
"QuickSave", MWInput::A_QuickSave,
|
||||
"QuickLoad", MWInput::A_QuickLoad,
|
||||
"QuickMenu", MWInput::A_QuickMenu,
|
||||
"ToggleWeapon", MWInput::A_ToggleWeapon,
|
||||
"ToggleSpell", MWInput::A_ToggleSpell,
|
||||
"TogglePOV", MWInput::A_TogglePOV,
|
||||
|
||||
"QuickKey1", MWInput::A_QuickKey1,
|
||||
"QuickKey2", MWInput::A_QuickKey2,
|
||||
"QuickKey3", MWInput::A_QuickKey3,
|
||||
"QuickKey4", MWInput::A_QuickKey4,
|
||||
"QuickKey5", MWInput::A_QuickKey5,
|
||||
"QuickKey6", MWInput::A_QuickKey6,
|
||||
"QuickKey7", MWInput::A_QuickKey7,
|
||||
"QuickKey8", MWInput::A_QuickKey8,
|
||||
"QuickKey9", MWInput::A_QuickKey9,
|
||||
"QuickKey10", MWInput::A_QuickKey10,
|
||||
"QuickKeysMenu", MWInput::A_QuickKeysMenu,
|
||||
|
||||
"ToggleHUD", MWInput::A_ToggleHUD,
|
||||
"ToggleDebug", MWInput::A_ToggleDebug,
|
||||
|
||||
"ZoomIn", MWInput::A_ZoomIn,
|
||||
"ZoomOut", MWInput::A_ZoomOut
|
||||
));
|
||||
|
||||
api["CONTROL_SWITCH"] = context.mLua->makeReadOnly(context.mLua->sol().create_table_with(
|
||||
"Controls", "playercontrols",
|
||||
"Fighting", "playerfighting",
|
||||
"Jumping", "playerjumping",
|
||||
"Looking", "playerlooking",
|
||||
"Magic", "playermagic",
|
||||
"ViewMode", "playerviewswitch",
|
||||
"VanityMode", "vanitymode"
|
||||
));
|
||||
|
||||
api["CONTROLLER_BUTTON"] = context.mLua->makeReadOnly(context.mLua->sol().create_table_with(
|
||||
"A", SDL_CONTROLLER_BUTTON_A,
|
||||
"B", SDL_CONTROLLER_BUTTON_B,
|
||||
"X", SDL_CONTROLLER_BUTTON_X,
|
||||
"Y", SDL_CONTROLLER_BUTTON_Y,
|
||||
"Back", SDL_CONTROLLER_BUTTON_BACK,
|
||||
"Guide", SDL_CONTROLLER_BUTTON_GUIDE,
|
||||
"Start", SDL_CONTROLLER_BUTTON_START,
|
||||
"LeftStick", SDL_CONTROLLER_BUTTON_LEFTSTICK,
|
||||
"RightStick", SDL_CONTROLLER_BUTTON_RIGHTSTICK,
|
||||
"LeftShoulder", SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
|
||||
"RightShoulder", SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
|
||||
"DPadUp", SDL_CONTROLLER_BUTTON_DPAD_UP,
|
||||
"DPadDown", SDL_CONTROLLER_BUTTON_DPAD_DOWN,
|
||||
"DPadLeft", SDL_CONTROLLER_BUTTON_DPAD_LEFT,
|
||||
"DPadRight", SDL_CONTROLLER_BUTTON_DPAD_RIGHT
|
||||
));
|
||||
|
||||
api["CONTROLLER_AXIS"] = context.mLua->makeReadOnly(context.mLua->sol().create_table_with(
|
||||
"LeftX", SDL_CONTROLLER_AXIS_LEFTX,
|
||||
"LeftY", SDL_CONTROLLER_AXIS_LEFTY,
|
||||
"RightX", SDL_CONTROLLER_AXIS_RIGHTX,
|
||||
"RightY", SDL_CONTROLLER_AXIS_RIGHTY,
|
||||
"TriggerLeft", SDL_CONTROLLER_AXIS_TRIGGERLEFT,
|
||||
"TriggerRight", SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
|
||||
|
||||
"LookUpDown", SDL_CONTROLLER_AXIS_MAX + MWInput::A_LookUpDown,
|
||||
"LookLeftRight", SDL_CONTROLLER_AXIS_MAX + MWInput::A_LookLeftRight,
|
||||
"MoveForwardBackward", SDL_CONTROLLER_AXIS_MAX + MWInput::A_MoveForwardBackward,
|
||||
"MoveLeftRight", SDL_CONTROLLER_AXIS_MAX + MWInput::A_MoveLeftRight
|
||||
));
|
||||
|
||||
return context.mLua->makeReadOnly(api);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
Package openmw.input
|
||||
====================
|
||||
|
||||
.. raw:: html
|
||||
:file: generated_html/openmw_input.html
|
||||
|
@ -0,0 +1,170 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- `openmw.input` can be used only in scripts attached to a player.
|
||||
-- @module input
|
||||
-- @usage local input = require('openmw.input')
|
||||
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Is player idle.
|
||||
-- @function [parent=#input] isIdle
|
||||
-- @return #boolean
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Is a specific control currently pressed.
|
||||
-- Input bindings can be changed ingame using Options/Controls menu.
|
||||
-- @function [parent=#input] isActionPressed
|
||||
-- @param #number actionId One of @{openmw.input#ACTION}
|
||||
-- @return #boolean
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Is a mouse button currently pressed.
|
||||
-- @function [parent=#input] isMouseButtonPressed
|
||||
-- @param #number buttonId Button index (1 - left, 2 - middle, 3 - right, 4 - X1, 5 - X2)
|
||||
-- @return #boolean
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Horizontal mouse movement during the last frame.
|
||||
-- @function [parent=#input] getMouseMoveX
|
||||
-- @return #number
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Vertical mouse movement during the last frame.
|
||||
-- @function [parent=#input] getMouseMoveY
|
||||
-- @return #number
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Get value of an axis of a game controller.
|
||||
-- @function [parent=#input] getAxisValue
|
||||
-- @param #number axisId Index of a controller axis, one of @{openmw.input#CONTROLLER_AXIS}.
|
||||
-- @return #number Value in range [-1, 1].
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Get state of a control switch. I.e. is player able to move/fight/jump/etc.
|
||||
-- @function [parent=#input] getControlSwitch
|
||||
-- @param #string key Control type (see @{openmw.input#CONTROL_SWITCH})
|
||||
-- @return #boolean
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Set state of a control switch. I.e. forbid or allow player to move/fight/jump/etc.
|
||||
-- @function [parent=#input] setControlSwitch
|
||||
-- @param #string key Control type (see @{openmw.input#CONTROL_SWITCH})
|
||||
-- @param #boolean value
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- @type CONTROL_SWITCH
|
||||
-- @field [parent=#CONTROL_SWITCH] #string Controls Ability to move
|
||||
-- @field [parent=#CONTROL_SWITCH] #string Fighting Ability to attack
|
||||
-- @field [parent=#CONTROL_SWITCH] #string Jumping Ability to jump
|
||||
-- @field [parent=#CONTROL_SWITCH] #string Looking Ability to change view direction
|
||||
-- @field [parent=#CONTROL_SWITCH] #string Magic Ability to use magic
|
||||
-- @field [parent=#CONTROL_SWITCH] #string ViewMode Ability to toggle 1st/3rd person view
|
||||
-- @field [parent=#CONTROL_SWITCH] #string VanityMode Vanity view if player doesn't touch controls for a long time
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Values that can be used with getControlSwitch/setControlSwitch.
|
||||
-- @field [parent=#input] #CONTROL_SWITCH CONTROL_SWITCH
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- @type ACTION
|
||||
-- @field [parent=#ACTION] #number GameMenu
|
||||
-- @field [parent=#ACTION] #number Screenshot
|
||||
-- @field [parent=#ACTION] #number Inventory
|
||||
-- @field [parent=#ACTION] #number Console
|
||||
-- @field [parent=#ACTION] #number MoveLeft
|
||||
-- @field [parent=#ACTION] #number MoveRight
|
||||
-- @field [parent=#ACTION] #number MoveForward
|
||||
-- @field [parent=#ACTION] #number MoveBackward
|
||||
-- @field [parent=#ACTION] #number Activate
|
||||
-- @field [parent=#ACTION] #number Use
|
||||
-- @field [parent=#ACTION] #number Jump
|
||||
-- @field [parent=#ACTION] #number AutoMove
|
||||
-- @field [parent=#ACTION] #number Journal
|
||||
-- @field [parent=#ACTION] #number Weapon
|
||||
-- @field [parent=#ACTION] #number Spell
|
||||
-- @field [parent=#ACTION] #number Run
|
||||
-- @field [parent=#ACTION] #number CycleSpellLeft
|
||||
-- @field [parent=#ACTION] #number CycleSpellRight
|
||||
-- @field [parent=#ACTION] #number CycleWeaponLeft
|
||||
-- @field [parent=#ACTION] #number CycleWeaponRight
|
||||
-- @field [parent=#ACTION] #number ToggleSneak
|
||||
-- @field [parent=#ACTION] #number AlwaysRun
|
||||
-- @field [parent=#ACTION] #number Sneak
|
||||
-- @field [parent=#ACTION] #number QuickSave
|
||||
-- @field [parent=#ACTION] #number QuickLoad
|
||||
-- @field [parent=#ACTION] #number QuickMenu
|
||||
-- @field [parent=#ACTION] #number ToggleWeapon
|
||||
-- @field [parent=#ACTION] #number ToggleSpell
|
||||
-- @field [parent=#ACTION] #number TogglePOV
|
||||
-- @field [parent=#ACTION] #number QuickKey1
|
||||
-- @field [parent=#ACTION] #number QuickKey2
|
||||
-- @field [parent=#ACTION] #number QuickKey3
|
||||
-- @field [parent=#ACTION] #number QuickKey4
|
||||
-- @field [parent=#ACTION] #number QuickKey5
|
||||
-- @field [parent=#ACTION] #number QuickKey6
|
||||
-- @field [parent=#ACTION] #number QuickKey7
|
||||
-- @field [parent=#ACTION] #number QuickKey8
|
||||
-- @field [parent=#ACTION] #number QuickKey9
|
||||
-- @field [parent=#ACTION] #number QuickKey10
|
||||
-- @field [parent=#ACTION] #number QuickKeysMenu
|
||||
-- @field [parent=#ACTION] #number ToggleHUD
|
||||
-- @field [parent=#ACTION] #number ToggleDebug
|
||||
-- @field [parent=#ACTION] #number ZoomIn
|
||||
-- @field [parent=#ACTION] #number ZoomOut
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Values that can be used with isActionPressed.
|
||||
-- @field [parent=#input] #ACTION ACTION
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- @type CONTROLLER_BUTTON
|
||||
-- @field [parent=#CONTROLLER_BUTTON] #number A
|
||||
-- @field [parent=#CONTROLLER_BUTTON] #number B
|
||||
-- @field [parent=#CONTROLLER_BUTTON] #number X
|
||||
-- @field [parent=#CONTROLLER_BUTTON] #number Y
|
||||
-- @field [parent=#CONTROLLER_BUTTON] #number Back
|
||||
-- @field [parent=#CONTROLLER_BUTTON] #number Guide
|
||||
-- @field [parent=#CONTROLLER_BUTTON] #number Start
|
||||
-- @field [parent=#CONTROLLER_BUTTON] #number LeftStick
|
||||
-- @field [parent=#CONTROLLER_BUTTON] #number RightStick
|
||||
-- @field [parent=#CONTROLLER_BUTTON] #number LeftShoulder
|
||||
-- @field [parent=#CONTROLLER_BUTTON] #number RightShoulder
|
||||
-- @field [parent=#CONTROLLER_BUTTON] #number DPadUp
|
||||
-- @field [parent=#CONTROLLER_BUTTON] #number DPadDown
|
||||
-- @field [parent=#CONTROLLER_BUTTON] #number DPadLeft
|
||||
-- @field [parent=#CONTROLLER_BUTTON] #number DPadRight
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Values that can be passed to onControllerButtonPress/onControllerButtonRelease engine handlers.
|
||||
-- @field [parent=#input] #CONTROLLER_BUTTON CONTROLLER_BUTTON
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Ids of game controller axises. Used as an argument in getAxisValue.
|
||||
-- @type CONTROLLER_AXIS
|
||||
-- @field [parent=#CONTROLLER_AXIS] #number LeftX Left stick horizontal axis (from -1 to 1)
|
||||
-- @field [parent=#CONTROLLER_AXIS] #number LeftY Left stick vertical axis (from -1 to 1)
|
||||
-- @field [parent=#CONTROLLER_AXIS] #number RightX Right stick horizontal axis (from -1 to 1)
|
||||
-- @field [parent=#CONTROLLER_AXIS] #number RightY Right stick vertical axis (from -1 to 1)
|
||||
-- @field [parent=#CONTROLLER_AXIS] #number TriggerLeft Left trigger (from 0 to 1)
|
||||
-- @field [parent=#CONTROLLER_AXIS] #number TriggerRight Right trigger (from 0 to 1)
|
||||
-- @field [parent=#CONTROLLER_AXIS] #number LookUpDown View direction vertical axis (RightY by default, can be mapped to another axis in Options/Controls menu)
|
||||
-- @field [parent=#CONTROLLER_AXIS] #number LookLeftRight View direction horizontal axis (RightX by default, can be mapped to another axis in Options/Controls menu)
|
||||
-- @field [parent=#CONTROLLER_AXIS] #number MoveForwardBackward Movement forward/backward (LeftY by default, can be mapped to another axis in Options/Controls menu)
|
||||
-- @field [parent=#CONTROLLER_AXIS] #number MoveLeftRight Side movement (LeftX by default, can be mapped to another axis in Options/Controls menu)
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Values that can be used with getAxisValue.
|
||||
-- @field [parent=#input] #CONTROLLER_AXIS CONTROLLER_AXIS
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- The argument of `onKeyPress`/`onKeyRelease` engine handlers.
|
||||
-- @type KeyboardEvent
|
||||
-- @field [parent=#KeyboardEvent] #string symbol The pressed symbol (1-symbol string).
|
||||
-- @field [parent=#KeyboardEvent] #string code Key code.
|
||||
-- @field [parent=#KeyboardEvent] #boolean withShift Is `Shift` key pressed.
|
||||
-- @field [parent=#KeyboardEvent] #boolean withCtrl Is `Control` key pressed.
|
||||
-- @field [parent=#KeyboardEvent] #boolean withAlt Is `Alt` key pressed.
|
||||
-- @field [parent=#KeyboardEvent] #boolean withSuper Is `Super`/`Win` key pressed.
|
||||
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue