Browse Source

small fix

Ethosa 3 years ago
parent
commit
5bfb9ea8dd
2 changed files with 12 additions and 13 deletions
  1. 4 4
      src/nodesnim/core/input.nim
  2. 8 9
      tests/test3.nim

+ 4 - 4
src/nodesnim/core/input.nim

@@ -89,13 +89,13 @@ proc isInputEventText*(a: InputEvent): bool =
   a.kind == TEXT
 
 
-proc addButtonAction*(a: type Input, name: string, button: cint) =
+proc addButtonAction*(a: type Input, name: string, button: uint8 | cint) =
   ## Adds a new action on button.
   ##
   ## Arguments:
   ## - `name` - action name.
   ## - `button` - button index, e.g.: BUTTON_LEFT, BUTTON_RIGHT or BUTTON_MIDDLE.
-  actionlist.add(InputAction(kind: MOUSE, name: name, button_index: button))
+  actionlist.add(InputAction(kind: MOUSE, name: name, button_index: button.cint))
 
 proc addKeyAction*(a: type Input, name, key: string) =
   ## Adds a new action on keyboard.
@@ -103,7 +103,7 @@ proc addKeyAction*(a: type Input, name, key: string) =
   ## Arguments:
   ## - `name` - action name.
   ## - `key` - key, e.g.: "w", "1", etc.
-  actionlist.add(InputAction(kind: KEYBOARD, name: name, key: key))
+  actionlist.add(InputAction(kind: KEYBOARD, name: name, key: key, key_int: ord(key[0]).cint))
 
 proc addKeyAction*(a: type Input, name: string, key: cint) =
   ## Adds a new action on keyboard.
@@ -156,7 +156,7 @@ proc isActionPressed*(a: type Input, name: string): bool =
         if press_state > 0:
           result = true
       elif action.kind == KEYBOARD and last_event.kind == KEYBOARD:
-        if action.key in pressed_keys or action.key_int in pressed_keys_ints:
+        if action.key_int in pressed_keys_ints:
           if press_state > 0:
             result = true
 

+ 8 - 9
tests/test3.nim

@@ -22,15 +22,6 @@ Input.addButtonAction("release", BUTTON_RIGHT)
 
 node.on_process =
   proc(self: NodeRef) =  # This called every frame.
-    if Input.isActionPressed("forward"):  # returns true, when user press "w"
-      echo "forward"
-    if Input.isActionPressed("backward"):  # returns true, when user press "s"
-      echo "backward"
-    if Input.isActionPressed("left"):  # returns true, when user press "a"
-      echo "left"
-    if Input.isActionPressed("right"):  # returns true, when user press "d"
-      echo "right"
-
     if Input.isActionJustPressed("click"):  # returns true, when the user clicks the left button one time.
       echo "clicked!"
 
@@ -41,6 +32,14 @@ node.on_input =
   proc(self: NodeRef, event: InputEvent) =  # This called only on user input.
     if event.isInputEventMouseButton() and event.pressed:
       echo "hi"
+    if Input.isActionPressed("forward"):  # returns true, when user press "w"
+      echo "forward"
+    if Input.isActionPressed("backward"):  # returns true, when user press "s"
+      echo "backward"
+    if Input.isActionPressed("left"):  # returns true, when user press "a"
+      echo "left"
+    if Input.isActionPressed("right"):  # returns true, when user press "d"
+      echo "right"
 
 
 addScene(main)