File tree Expand file tree Collapse file tree 5 files changed +43
-53
lines changed
TypescriptServer/src/cmd/handlers Expand file tree Collapse file tree 5 files changed +43
-53
lines changed Original file line number Diff line number Diff line change @@ -8,14 +8,18 @@ use_states({ idle: 0, walk: 1 })
88name = ""
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+ }
Original file line number Diff line number Diff line change 11// / @description platformer inputs logic
22
33if (!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
2022if (state == states.walk) {
Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff line change 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
56function sendPartyLeave () {
Original file line number Diff line number Diff line change @@ -2,23 +2,11 @@ import { addHandler } from "#cmd/handlePacket";
22import Point from "#types/point" ;
33import { clamp } from "#util/maths" ;
44
5-
65addHandler ( '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+ } ) ;
You can’t perform that action at this time.
0 commit comments