Skip to content

Commit 61cb5ba

Browse files
committed
make sending inputs less obnoxious
1 parent 6c4c13f commit 61cb5ba

File tree

5 files changed

+43
-53
lines changed

5 files changed

+43
-53
lines changed

Client/objects/oPlayer/Create_0.gml

+13-9
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ use_states({ idle: 0, walk: 1 })
88
name = ""
99

1010
// controls
11-
kright = false
12-
kleft = false
13-
kup = false
14-
kdown = false
11+
inputs = {
12+
kright : false,
13+
kleft : false,
14+
kup : false,
15+
kdown : false,
1516

16-
kjump = false
17-
kjump_rel = false
18-
kjump_press = false
17+
kjump : false,
18+
kjump_rel : false,
19+
kjump_press : false,
1920

20-
move_x = 0
21-
move_y = 0
21+
move: {
22+
x: 0,
23+
y: 0
24+
}
25+
}

Client/objects/oPlayer/Step_0.gml

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
/// @description platformer inputs logic
22

33
if (!remote) {
4-
kup = keyboard_check(ord("W")) || keyboard_check(vk_up)
5-
kleft = keyboard_check(ord("A")) || keyboard_check(vk_left)
6-
kdown = keyboard_check(ord("S")) || keyboard_check(vk_down)
7-
kright = keyboard_check(ord("D")) || keyboard_check(vk_right)
4+
with (inputs) {
5+
kup = keyboard_check(ord("W")) || keyboard_check(vk_up)
6+
kleft = keyboard_check(ord("A")) || keyboard_check(vk_left)
7+
kdown = keyboard_check(ord("S")) || keyboard_check(vk_down)
8+
kright = keyboard_check(ord("D")) || keyboard_check(vk_right)
89

9-
kjump = keyboard_check(vk_space)
10-
kjump_press = keyboard_check_pressed(vk_space)
11-
kjump_rel = keyboard_check_released(vk_space)
10+
kjump = keyboard_check(vk_space)
11+
kjump_press = keyboard_check_pressed(vk_space)
12+
kjump_rel = keyboard_check_released(vk_space)
1213

13-
move_x = kright - kleft
14-
move_y = kdown - kup
14+
move.x = kright - kleft
15+
move.y = kdown - kup
16+
}
1517

1618

17-
sendPlayerControls()
19+
sendPlayerControls(inputs)
1820
}
1921

2022
if (state == states.walk) {
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
function sendPlayerControls() {
2-
send({
3-
cmd: "player controls",
4-
move: {
5-
x: move_x,
6-
y: move_y
7-
},
8-
kright: kright,
9-
kleft: kleft,
10-
kup: kup,
11-
kdown: kdown,
12-
13-
kjump: kjump,
14-
kjump_rel: kjump_rel,
15-
kjump_press: kjump_press
16-
})
1+
function sendPlayerControls(inputs) {
2+
var data = { cmd: "player controls" }
3+
4+
var input_names = variable_struct_get_names(inputs)
5+
for(var i = 0; i < variable_struct_names_count(inputs); i++) {
6+
var input_name = input_names[i]
7+
data[$ input_name] = self.inputs[input_name]
8+
}
9+
10+
11+
send(data)
1712
}

Client/scripts/partySenders/partySenders.gml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
function sendPartyInvite(uname = "", profile_id = "") {
2-
send({ cmd: "party invite", profile_id, uname })
1+
// invite either via username or via profile_id
2+
function sendPartyInvite(username = "", profile_id = "") {
3+
send({ cmd: "party invite", profile_id, username })
34
}
45

56
function sendPartyLeave() {

TypescriptServer/src/cmd/handlers/custom.ts

+4-16
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,11 @@ import { addHandler } from "#cmd/handlePacket";
22
import Point from "#types/point";
33
import { clamp } from "#util/maths";
44

5-
65
addHandler('player controls', (c, data) => {
76
if (!c.entity) return;
87

9-
c.entity.inputs = {
10-
move: data.move as Point,
11-
kright: data.kright,
12-
kleft: data.kleft,
13-
kup: data.kup,
14-
kdown: data.kdown,
15-
16-
kjump: data.kjump,
17-
kjump_rel: data.kjump_rel,
18-
kjump_press: data.kjump_press
8+
for(let input_name in c.entity.inputs) {
9+
if (data[input_name] !== undefined)
10+
c.entity.inputs[input_name] = data[input_name];
1911
}
20-
21-
c.entity.inputs.move.x = clamp(c.entity.inputs.move.x, -1, 1);
22-
c.entity.inputs.move.y = clamp(c.entity.inputs.move.y, -1, 1);
23-
});
24-
12+
});

0 commit comments

Comments
 (0)