File tree 5 files changed +43
-53
lines changed
TypescriptServer/src/cmd/handlers
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 })
8
8
name = ""
9
9
10
10
// 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 ,
15
16
16
- kjump = false
17
- kjump_rel = false
18
- kjump_press = false
17
+ kjump : false ,
18
+ kjump_rel : false ,
19
+ kjump_press : false ,
19
20
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 1
1
// / @description platformer inputs logic
2
2
3
3
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)
8
9
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)
12
13
13
- move_x = kright - kleft
14
- move_y = kdown - kup
14
+ move.x = kright - kleft
15
+ move.y = kdown - kup
16
+ }
15
17
16
18
17
- sendPlayerControls ()
19
+ sendPlayerControls (inputs )
18
20
}
19
21
20
22
if (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)
17
12
}
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 })
3
4
}
4
5
5
6
function sendPartyLeave () {
Original file line number Diff line number Diff line change @@ -2,23 +2,11 @@ import { addHandler } from "#cmd/handlePacket";
2
2
import Point from "#types/point" ;
3
3
import { clamp } from "#util/maths" ;
4
4
5
-
6
5
addHandler ( 'player controls' , ( c , data ) => {
7
6
if ( ! c . entity ) return ;
8
7
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 ] ;
19
11
}
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