~melchizedek6809/WolkenWelten

ref: 19a5ae3cc7ddc83c7cd41598efcaf8af9dfff1f7 WolkenWelten/client/src/nujel/input_keyboard.nuj -rw-r--r-- 5.1 KiB
19a5ae3cBen (X13/Arch) Increased melee range for chars/animals 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
[def input-keyboard-handler [arr-new 256]]
[def input-keyboard-state   [arr-new 256]]

[def key-a  4]
[def key-b  5]
[def key-c  6]
[def key-d  7]
[def key-e  8]
[def key-f  9]
[def key-g 10]
[def key-h 11]
[def key-i 12]
[def key-j 13]
[def key-k 14]
[def key-l 15]
[def key-m 16]
[def key-n 17]
[def key-o 18]
[def key-p 19]
[def key-q 20]
[def key-r 21]
[def key-s 22]
[def key-t 23]
[def key-u 24]
[def key-v 25]
[def key-w 26]
[def key-x 27]
[def key-y 28]
[def key-z 29]

[def key-1 30]
[def key-2 31]
[def key-3 32]
[def key-4 33]
[def key-5 34]
[def key-6 35]
[def key-7 36]
[def key-8 37]
[def key-9 38]
[def key-0 39]

[def key-return       40]
[def key-escape       41]
[def key-backspace    42]
[def key-tab          43]
[def key-space        44]
[def key-minus        45]
[def key-backspace    46]
[def key-leftbracket  47]
[def key-rightbracket 48]
[def key-backslash    49]
[def key-hash         50]
[def key-semicolon    51]
[def key-apostrophe   52]
[def key-grave        53]
[def key-comma        54]
[def key-period       55]
[def key-slash        56]
[def key-capslock     57]

[def key-f1    58]
[def key-f2    59]
[def key-f3    60]
[def key-f4    61]
[def key-f5    62]
[def key-f6    63]
[def key-f7    64]
[def key-f8    65]
[def key-f9    66]
[def key-f10   67]
[def key-f11   68]

[def key-f12   69]
[def key-print 70]

[def key-lshift 225]

[def input-keyboard-handler-default [λ [code value]
	"Default handler to be used for continuously firing actions"

	[arr-set! input-keyboard-state code [> value 0]]
]]

[def toggle-chat! [λ
	"Toggle the chat visibility"
	[chat-open! [not [chat-open]]]
]]

[arr-set! input-keyboard-handler key-r      input-keyboard-handler-default]
[arr-set! input-keyboard-handler key-q      input-keyboard-handler-default]
[arr-set! input-keyboard-handler key-space  input-keyboard-handler-default]
[arr-set! input-keyboard-handler key-w      input-keyboard-handler-default]
[arr-set! input-keyboard-handler key-a      input-keyboard-handler-default]
[arr-set! input-keyboard-handler key-s      input-keyboard-handler-default]
[arr-set! input-keyboard-handler key-d      input-keyboard-handler-default]
[arr-set! input-keyboard-handler key-v      input-keyboard-handler-default]
[arr-set! input-keyboard-handler key-lshift input-keyboard-handler-default]

[arr-set! input-keyboard-handler key-c   [λ [code value] [when value [cons-mode!  [not [cons-mode!]]]]]]
[arr-set! input-keyboard-handler key-e   [λ [code value] [when value [fire-hook]]]]
[arr-set! input-keyboard-handler key-m   [λ [code value] [when value [debug-info! [not [debug-info!]]]]]]
[arr-set! input-keyboard-handler key-n   [λ [code value] [when value [no-clip!    [not [no-clip!]]]]]]

[arr-set! input-keyboard-handler key-f1  [λ [code value] [when value [third-person! #f] [save-options]]]]
[arr-set! input-keyboard-handler key-f2  [λ [code value] [when value [s [debug-stuff!]]]]]
[arr-set! input-keyboard-handler key-f3  [λ [code value] [when value [third-person! #t] [save-options]]]]
[arr-set! input-keyboard-handler key-f8  [λ [code value] [when value [player-hp 12]]]]
[arr-set! input-keyboard-handler key-f9  [λ [code value] [when value [draw-boundaries! [wrap-value [++ [draw-boundaries]] 0 3]]]]
[arr-set! input-keyboard-handler key-f10 [λ [code value] [when value [wire-frame! [not [wire-frame?]]]]]]
[arr-set! input-keyboard-handler key-print [λ [code value] [when value [screenshot]]]]
[arr-set! input-keyboard-handler key-tab [λ [code value] [when value [toggle-inventory!]]]]
[arr-set! input-keyboard-handler key-t [λ [code value] [when value [toggle-chat!]]]]

[unless [eq? OS "Emscripten"]
	[arr-set! input-keyboard-handler key-f11 [λ [code value]
		[when value
			[fullscreen! [not [fullscreen?]]]
			[save-options]
		]
	]]
]

[def inv-active-kh [λ [code value]
	"Sets the players active item depending on the keycode passed"

	[when value
		[player-active-slot! [- code 30]]
		[stop-anim]
	]
]]

[arr-set! input-keyboard-handler key-1 inv-active-kh]
[arr-set! input-keyboard-handler key-2 inv-active-kh]
[arr-set! input-keyboard-handler key-3 inv-active-kh]
[arr-set! input-keyboard-handler key-4 inv-active-kh]
[arr-set! input-keyboard-handler key-5 inv-active-kh]
[arr-set! input-keyboard-handler key-6 inv-active-kh]
[arr-set! input-keyboard-handler key-7 inv-active-kh]
[arr-set! input-keyboard-handler key-8 inv-active-kh]
[arr-set! input-keyboard-handler key-9 inv-active-kh]
[arr-set! input-keyboard-handler key-0 inv-active-kh]

[def input-keyboard-tick [λ []
	"Keyboard input handler"

	[when [widget-focus-on-game?]
		[when [input-keyboard-state key-w]     [player-walk!   -1.0]]
		[when [input-keyboard-state key-s]     [player-walk!    1.0]]
		[when [input-keyboard-state key-a]     [player-strafe! -1.0]]
		[when [input-keyboard-state key-d]     [player-strafe!  1.0]]
		[when [input-keyboard-state key-space] [player-jump!    1.0]]
		[when [input-keyboard-state key-r]     [player-tertiary!]]
		[when [input-keyboard-state key-q]     [player-throw!]]
		[player-sneak! [input-keyboard-state key-v]]
		[player-boost! [input-keyboard-state key-lshift]]
	]
]]

[test-add #t [int? key-1]]
[test-add #t [array? input-keyboard-handler]]
[test-add 58 key-f1]
[test-add #t [bool? [widget-focus-on-game?]]]