Skip to content

Commit 606a46e

Browse files
author
Roberto De Ioris
committed
added lot of movements api
1 parent 673f800 commit 606a46e

5 files changed

Lines changed: 419 additions & 0 deletions

File tree

‎Source/UnrealEnginePython/Private/UEPyInput.cpp‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,114 @@ PyObject *py_ue_is_input_key_down(ue_PyUObject *self, PyObject * args) {
2525
return Py_False;
2626
}
2727

28+
PyObject *py_ue_was_input_key_just_pressed(ue_PyUObject *self, PyObject * args) {
29+
30+
ue_py_check(self);
31+
32+
char *key;
33+
if (!PyArg_ParseTuple(args, "s:was_input_key_just_pressed", &key)) {
34+
return NULL;
35+
}
36+
37+
UWorld *world = ue_get_uworld(self);
38+
if (!world)
39+
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
40+
41+
APlayerController *controller = world->GetFirstPlayerController();
42+
43+
if (controller->WasInputKeyJustPressed(key)) {
44+
Py_INCREF(Py_True);
45+
return Py_True;
46+
}
47+
48+
Py_INCREF(Py_False);
49+
return Py_False;
50+
}
51+
52+
PyObject *py_ue_is_action_pressed(ue_PyUObject *self, PyObject * args) {
53+
54+
ue_py_check(self);
55+
56+
char *key;
57+
if (!PyArg_ParseTuple(args, "s:is_action_pressed", &key)) {
58+
return NULL;
59+
}
60+
61+
UWorld *world = ue_get_uworld(self);
62+
if (!world)
63+
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
64+
65+
APlayerController *controller = world->GetFirstPlayerController();
66+
UPlayerInput *input = controller->PlayerInput;
67+
if (!input)
68+
goto end;
69+
70+
for (FInputActionKeyMapping mapping : input->GetKeysForAction(key)) {
71+
if (controller->WasInputKeyJustPressed(mapping.Key)) {
72+
Py_INCREF(Py_True);
73+
return Py_True;
74+
}
75+
}
76+
77+
end:
78+
Py_INCREF(Py_False);
79+
return Py_False;
80+
}
81+
82+
PyObject *py_ue_was_input_key_just_released(ue_PyUObject *self, PyObject * args) {
83+
84+
ue_py_check(self);
85+
86+
char *key;
87+
if (!PyArg_ParseTuple(args, "s:was_input_key_just_released", &key)) {
88+
return NULL;
89+
}
90+
91+
UWorld *world = ue_get_uworld(self);
92+
if (!world)
93+
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
94+
95+
APlayerController *controller = world->GetFirstPlayerController();
96+
97+
if (controller->WasInputKeyJustReleased(key)) {
98+
Py_INCREF(Py_True);
99+
return Py_True;
100+
}
101+
102+
Py_INCREF(Py_False);
103+
return Py_False;
104+
}
105+
106+
PyObject *py_ue_is_action_released(ue_PyUObject *self, PyObject * args) {
107+
108+
ue_py_check(self);
109+
110+
char *key;
111+
if (!PyArg_ParseTuple(args, "s:is_action_released", &key)) {
112+
return NULL;
113+
}
114+
115+
UWorld *world = ue_get_uworld(self);
116+
if (!world)
117+
return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");
118+
119+
APlayerController *controller = world->GetFirstPlayerController();
120+
UPlayerInput *input = controller->PlayerInput;
121+
if (!input)
122+
goto end;
123+
124+
for (FInputActionKeyMapping mapping : input->GetKeysForAction(key)) {
125+
if (controller->WasInputKeyJustReleased(mapping.Key)) {
126+
Py_INCREF(Py_True);
127+
return Py_True;
128+
}
129+
}
130+
131+
end:
132+
Py_INCREF(Py_False);
133+
return Py_False;
134+
}
135+
28136
PyObject *py_ue_enable_input(ue_PyUObject *self, PyObject * args) {
29137

30138
ue_py_check(self);

‎Source/UnrealEnginePython/Private/UEPyInput.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77

88
PyObject *py_ue_is_input_key_down(ue_PyUObject *, PyObject *);
9+
PyObject *py_ue_was_input_key_just_pressed(ue_PyUObject *, PyObject *);
10+
PyObject *py_ue_was_input_key_just_released(ue_PyUObject *, PyObject *);
11+
PyObject *py_ue_is_action_pressed(ue_PyUObject *, PyObject *);
12+
PyObject *py_ue_is_action_released(ue_PyUObject *, PyObject *);
913
PyObject *py_ue_enable_input(ue_PyUObject *, PyObject *);
1014
PyObject *py_ue_get_input_axis(ue_PyUObject *, PyObject *);
1115
PyObject *py_ue_bind_input_axis(ue_PyUObject *, PyObject *);

‎Source/UnrealEnginePython/Private/UEPyModule.cpp‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,11 @@ static PyMethodDef ue_PyUObject_methods[] = {
10101010
{ "show_mouse_cursor", (PyCFunction)py_ue_show_mouse_cursor, METH_VARARGS, "" },
10111011
{ "enable_click_events", (PyCFunction)py_ue_enable_click_events, METH_VARARGS, "" },
10121012
{ "enable_mouse_over_events", (PyCFunction)py_ue_enable_mouse_over_events, METH_VARARGS, "" },
1013+
{ "was_input_key_just_pressed", (PyCFunction)py_ue_was_input_key_just_pressed, METH_VARARGS, "" },
1014+
{ "was_input_key_just_released", (PyCFunction)py_ue_was_input_key_just_released, METH_VARARGS, "" },
1015+
{ "is_action_pressed", (PyCFunction)py_ue_is_action_pressed, METH_VARARGS, "" },
1016+
{ "is_action_released", (PyCFunction)py_ue_is_action_released, METH_VARARGS, "" },
1017+
10131018

10141019
// Movements
10151020

@@ -1018,6 +1023,16 @@ static PyMethodDef ue_PyUObject_methods[] = {
10181023
{ "get_control_rotation", (PyCFunction)py_ue_get_control_rotation, METH_VARARGS, "" },
10191024
{ "add_movement_input", (PyCFunction)py_ue_add_movement_input, METH_VARARGS, "" },
10201025

1026+
{ "jump", (PyCFunction)py_ue_jump, METH_VARARGS, "" },
1027+
{ "stop_jumping", (PyCFunction)py_ue_stop_jumping, METH_VARARGS, "" },
1028+
{ "crouch", (PyCFunction)py_ue_crouch, METH_VARARGS, "" },
1029+
{ "uncrouch", (PyCFunction)py_ue_uncrouch, METH_VARARGS, "" },
1030+
{ "launch", (PyCFunction)py_ue_launch, METH_VARARGS, "" },
1031+
{ "is_jumping", (PyCFunction)py_ue_is_jumping, METH_VARARGS, "" },
1032+
{ "is_crouched", (PyCFunction)py_ue_is_crouched, METH_VARARGS, "" },
1033+
{ "can_jump", (PyCFunction)py_ue_can_jump, METH_VARARGS, "" },
1034+
{ "can_crouch", (PyCFunction)py_ue_can_crouch, METH_VARARGS, "" },
1035+
10211036

10221037
{ "get_class", (PyCFunction)py_ue_get_class, METH_VARARGS, "" },
10231038
{ "actor_components", (PyCFunction)py_ue_actor_components, METH_VARARGS, "" },

0 commit comments

Comments
 (0)