Mercurial > games > semicongine
annotate semiconginev2/old/input.nim @ 1218:56781cc0fc7c compiletime-tests
did: renamge main package
author | sam <sam@basx.dev> |
---|---|
date | Wed, 17 Jul 2024 21:01:37 +0700 |
parents | semicongine/old/input.nim@a3eb305bcac2 |
children |
rev | line source |
---|---|
1021 | 1 # Linux joystick: https://www.kernel.org/doc/Documentation/input/joystick-api.txt |
2 # Windows joystick: https://learn.microsoft.com/en-us/windows/win32/xinput/getting-started-with-xinput | |
1022
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
3 |
1021 | 4 |
1022
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
5 import std/tables |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
6 import std/strutils |
1021 | 7 |
8 import ./core/vector | |
9 import ./events | |
1022
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
10 import ./storage |
1021 | 11 |
12 type | |
13 Input = object | |
14 keyIsDown: set[Key] | |
15 keyWasPressed: set[Key] | |
16 keyWasReleased: set[Key] | |
17 mouseIsDown: set[MouseButton] | |
18 mouseWasPressed: set[MouseButton] | |
19 mouseWasReleased: set[MouseButton] | |
20 mousePosition: Vec2f | |
21 mouseMove: Vec2f | |
22 mouseWheel: float32 | |
23 windowWasResized: bool = true | |
1157
dd757eb5ca86
fix: minimizing window on windows breaks everything, also: do not try to acquire next frame for inifinity
sam@sambook-windows.localdomain
parents:
1138
diff
changeset
|
24 windowIsMinimized: bool = false |
1021 | 25 |
1022
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
26 # warning, shit is not thread safe |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
27 var input: Input |
1021 | 28 |
1022
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
29 proc UpdateInputs*(events: seq[Event]): bool = |
1021 | 30 # reset input states |
31 input.keyWasPressed = {} | |
32 input.keyWasReleased = {} | |
33 input.mouseWasPressed = {} | |
34 input.mouseWasReleased = {} | |
35 input.mouseWheel = 0 | |
1136 | 36 input.mouseMove = NewVec2f() |
1021 | 37 input.windowWasResized = false |
38 | |
39 var killed = false | |
40 for event in events: | |
41 case event.eventType: | |
42 of Quit: | |
43 killed = true | |
44 of ResizedWindow: | |
45 input.windowWasResized = true | |
46 of KeyPressed: | |
47 input.keyWasPressed.incl event.key | |
48 input.keyIsDown.incl event.key | |
49 of KeyReleased: | |
50 input.keyWasReleased.incl event.key | |
51 input.keyIsDown.excl event.key | |
52 of MousePressed: | |
53 input.mouseWasPressed.incl event.button | |
54 input.mouseIsDown.incl event.button | |
55 of MouseReleased: | |
56 input.mouseWasReleased.incl event.button | |
57 input.mouseIsDown.excl event.button | |
58 of MouseMoved: | |
1136 | 59 let newPos = NewVec2(float32(event.x), float32(event.y)) |
1021 | 60 input.mouseMove = newPos - input.mousePosition |
61 input.mousePosition = newPos | |
62 of MouseWheel: | |
63 input.mouseWheel = event.amount | |
1157
dd757eb5ca86
fix: minimizing window on windows breaks everything, also: do not try to acquire next frame for inifinity
sam@sambook-windows.localdomain
parents:
1138
diff
changeset
|
64 of MinimizedWindow: |
dd757eb5ca86
fix: minimizing window on windows breaks everything, also: do not try to acquire next frame for inifinity
sam@sambook-windows.localdomain
parents:
1138
diff
changeset
|
65 input.windowIsMinimized = true |
dd757eb5ca86
fix: minimizing window on windows breaks everything, also: do not try to acquire next frame for inifinity
sam@sambook-windows.localdomain
parents:
1138
diff
changeset
|
66 of RestoredWindow: |
dd757eb5ca86
fix: minimizing window on windows breaks everything, also: do not try to acquire next frame for inifinity
sam@sambook-windows.localdomain
parents:
1138
diff
changeset
|
67 input.windowIsMinimized = false |
dd757eb5ca86
fix: minimizing window on windows breaks everything, also: do not try to acquire next frame for inifinity
sam@sambook-windows.localdomain
parents:
1138
diff
changeset
|
68 |
1021 | 69 return not killed |
70 | |
1022
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
71 proc KeyIsDown*(key: Key): bool = key in input.keyIsDown |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
72 proc KeyWasPressed*(key: Key): bool = key in input.keyWasPressed |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
73 proc KeyWasPressed*(): bool = input.keyWasPressed.len > 0 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
74 proc KeyWasReleased*(key: Key): bool = key in input.keyWasReleased |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
75 proc MouseIsDown*(button: MouseButton): bool = button in input.mouseIsDown |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
76 proc MouseWasPressed*(): bool = input.mouseWasPressed.len > 0 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
77 proc MouseWasPressed*(button: MouseButton): bool = button in input.mouseWasPressed |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
78 proc MousePressedButtons*(): set[MouseButton] = input.mouseWasPressed |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
79 proc MouseWasReleased*(): bool = input.mouseWasReleased.len > 0 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
80 proc MouseWasReleased*(button: MouseButton): bool = button in input.mouseWasReleased |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
81 proc MouseReleasedButtons*(): set[MouseButton] = input.mouseWasReleased |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
82 proc MousePosition*(): Vec2f = input.mousePosition |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
83 proc MousePositionNormalized*(size: (int, int)): Vec2f = |
1021 | 84 result.x = (input.mousePosition.x / float32(size[0])) * 2.0 - 1.0 |
85 result.y = (input.mousePosition.y / float32(size[1])) * 2.0 - 1.0 | |
1022
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
86 proc MouseMove*(): auto = input.mouseMove |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
87 proc MouseWheel*(): auto = input.mouseWheel |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
88 proc WindowWasResized*(): auto = input.windowWasResized |
1157
dd757eb5ca86
fix: minimizing window on windows breaks everything, also: do not try to acquire next frame for inifinity
sam@sambook-windows.localdomain
parents:
1138
diff
changeset
|
89 proc WindowIsMinimized*(): auto = input.windowIsMinimized |
1022
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
90 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
91 # actions as a slight abstraction over raw input |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
92 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
93 type |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
94 ActionMap = object |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
95 keyActions: Table[string, set[Key]] |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
96 mouseActions: Table[string, set[MouseButton]] |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
97 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
98 # warning, shit is not thread safe |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
99 var actionMap: ActionMap |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
100 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
101 proc MapAction*[T: enum](action: T, key: Key) = |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
102 if not actionMap.keyActions.contains($action): |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
103 actionMap.keyActions[$action] = {} |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
104 actionMap.keyActions[$action].incl key |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
105 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
106 proc MapAction*[T: enum](action: T, button: MouseButton) = |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
107 if not actionMap.mouseActions.contains($action): |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
108 actionMap.mouseActions[$action] = {} |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
109 actionMap.mouseActions[$action].incl button |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
110 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
111 proc MapAction*[T: enum](action: T, keys: openArray[Key|MouseButton]) = |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
112 for key in keys: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
113 MapAction(action, key) |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
114 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
115 proc UnmapAction*[T: enum](action: T, key: Key) = |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
116 if actionMap.keyActions.contains($action): |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
117 actionMap.keyActions[$action].excl(key) |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
118 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
119 proc UnmapAction*[T: enum](action: T, button: MouseButton) = |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
120 if actionMap.mouseActions.contains($action): |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
121 actionMap.mouseActions[$action].excl(button) |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
122 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
123 proc UnmapAction*[T: enum](action: T) = |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
124 if actionMap.keyActions.contains($action): |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
125 actionMap.keyActions[$action] = {} |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
126 if actionMap.mouseActions.contains($action): |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
127 actionMap.mouseActions[$action] = {} |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
128 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
129 proc SaveCurrentActionMapping*() = |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
130 for name, keys in actionMap.keyActions.pairs: |
1138 | 131 SystemStorage.Store(name, keys, table = "input_mapping_key") |
1022
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
132 for name, buttons in actionMap.mouseActions.pairs: |
1138 | 133 SystemStorage.Store(name, buttons, table = "input_mapping_mouse") |
1022
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
134 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
135 proc LoadActionMapping*[T]() = |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
136 reset(actionMap) |
1138 | 137 for name in SystemStorage.List(table = "input_mapping_key"): |
1022
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
138 let action = parseEnum[T](name) |
1138 | 139 let keys = SystemStorage.Load(name, set[Key](), table = "input_mapping_key") |
1022
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
140 for key in keys: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
141 MapAction(action, key) |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
142 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
143 proc ActionDown*[T](action: T): bool = |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
144 if actionMap.keyActions.contains($action): |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
145 for key in actionMap.keyActions[$action]: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
146 if key in input.keyIsDown: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
147 return true |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
148 return false |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
149 if actionMap.mouseActions.contains($action): |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
150 for button in actionMap.mouseActions[$action]: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
151 if button in input.mouseIsDown: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
152 return true |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
153 return false |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
154 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
155 proc ActionPressed*[T](action: T): bool = |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
156 if actionMap.keyActions.contains($action): |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
157 for key in actionMap.keyActions[$action]: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
158 if key in input.keyWasPressed: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
159 return true |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
160 elif actionMap.mouseActions.contains($action): |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
161 for button in actionMap.mouseActions[$action]: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
162 if button in input.mouseWasPressed: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
163 return true |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
164 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
165 proc ActionReleased*[T](action: T): bool = |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
166 if actionMap.keyActions.contains($action): |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
167 for key in actionMap.keyActions[$action]: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
168 if key in input.keyWasReleased: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
169 return true |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
170 elif actionMap.mouseActions.contains($action): |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
171 for button in actionMap.mouseActions[$action]: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
172 if button in input.mouseWasReleased: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
173 return true |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
174 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
175 proc ActionValue*[T](action: T): float32 = |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
176 if actionMap.keyActions.contains($action): |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
177 for key in actionMap.keyActions[$action]: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
178 if key in input.keyIsDown: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
179 return 1 |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
180 elif actionMap.mouseActions.contains($action): |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
181 for button in actionMap.mouseActions[$action]: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
182 if button in input.mouseIsDown: |
f888ac4825b8
did: refactor input system, did some renaming, add quering of keys in key-value-store
sam <sam@basx.dev>
parents:
1021
diff
changeset
|
183 return 1 |