annotate semiconginev2/old/input.nim @ 1219:c61658d2d227 compiletime-tests

del: old test file
author sam <sam@basx.dev>
date Wed, 17 Jul 2024 21:03:30 +0700
parents 56781cc0fc7c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1021
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
1 # Linux joystick: https://www.kernel.org/doc/Documentation/input/joystick-api.txt
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
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
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
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
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
7
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
8 import ./core/vector
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
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
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
11
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
12 type
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
13 Input = object
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
14 keyIsDown: set[Key]
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
15 keyWasPressed: set[Key]
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
16 keyWasReleased: set[Key]
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
17 mouseIsDown: set[MouseButton]
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
18 mouseWasPressed: set[MouseButton]
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
19 mouseWasReleased: set[MouseButton]
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
20 mousePosition: Vec2f
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
21 mouseMove: Vec2f
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
22 mouseWheel: float32
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
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
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
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
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
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
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
30 # reset input states
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
31 input.keyWasPressed = {}
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
32 input.keyWasReleased = {}
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
33 input.mouseWasPressed = {}
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
34 input.mouseWasReleased = {}
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
35 input.mouseWheel = 0
1136
71315636ba82 did: refactor naming in tons of places
sam <sam@basx.dev>
parents: 1022
diff changeset
36 input.mouseMove = NewVec2f()
1021
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
37 input.windowWasResized = false
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
38
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
39 var killed = false
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
40 for event in events:
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
41 case event.eventType:
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
42 of Quit:
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
43 killed = true
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
44 of ResizedWindow:
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
45 input.windowWasResized = true
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
46 of KeyPressed:
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
47 input.keyWasPressed.incl event.key
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
48 input.keyIsDown.incl event.key
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
49 of KeyReleased:
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
50 input.keyWasReleased.incl event.key
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
51 input.keyIsDown.excl event.key
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
52 of MousePressed:
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
53 input.mouseWasPressed.incl event.button
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
54 input.mouseIsDown.incl event.button
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
55 of MouseReleased:
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
56 input.mouseWasReleased.incl event.button
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
57 input.mouseIsDown.excl event.button
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
58 of MouseMoved:
1136
71315636ba82 did: refactor naming in tons of places
sam <sam@basx.dev>
parents: 1022
diff changeset
59 let newPos = NewVec2(float32(event.x), float32(event.y))
1021
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
60 input.mouseMove = newPos - input.mousePosition
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
61 input.mousePosition = newPos
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
62 of MouseWheel:
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
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
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
69 return not killed
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
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
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
84 result.x = (input.mousePosition.x / float32(size[0])) * 2.0 - 1.0
73b572f82a1f add: bases for a better input-system
sam <sam@basx.dev>
parents:
diff changeset
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
02e1d2658ff5 did: more renaming
sam <sam@basx.dev>
parents: 1136
diff changeset
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
02e1d2658ff5 did: more renaming
sam <sam@basx.dev>
parents: 1136
diff changeset
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
02e1d2658ff5 did: more renaming
sam <sam@basx.dev>
parents: 1136
diff changeset
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
02e1d2658ff5 did: more renaming
sam <sam@basx.dev>
parents: 1136
diff changeset
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