addon for remapping inputs
add npm package
bendn 2022-08-20
parent af1c6c7 · commit 72a3f68
-rw-r--r--README.md55
-rw-r--r--Test.gd7
-rw-r--r--Test.tscn13
-rw-r--r--addons/remap/KeyPromptLabel.gd6
-rw-r--r--addons/remap/KeySelector.tscn2
-rw-r--r--addons/remap/LICENSE21
-rw-r--r--addons/remap/README.md12
-rw-r--r--addons/remap/RemapUtilities.gd9
-rw-r--r--addons/remap/SaveLoadUtils.gd2
-rw-r--r--addons/remap/package.json23
10 files changed, 86 insertions, 64 deletions
diff --git a/README.md b/README.md
index c6dbb07..08d8bb3 100644
--- a/README.md
+++ b/README.md
@@ -1,51 +1,16 @@
-# godot-template
+# godot cli parser
[![version](https://img.shields.io/badge/3.x-blue?logo=godot-engine&logoColor=white&label=godot&style=for-the-badge)](https://godotengine.org "Made with godot")
+[![package](https://img.shields.io/npm/v/@bendn/remap?label=version&style=for-the-badge)](https://www.npmjs.com/package/@bendn/remap)
<a href='https://ko-fi.com/bendn' title='Buy me a coffee' target='_blank'><img height='28' src='https://storage.ko-fi.com/cdn/brandasset/kofi_button_red.png' alt='Buy me a coffee'> </a>
-Godot template repository for my programs
+A utility for parsing command line arguments for godot.
----
+## Usage
-## How to use
-
-> **Note** This template uses the [gpm](https://github.com/you-win/godot-package-manager).
-
-- Click use this template button
-- Clone your new repository
-- Run install_addons.sh
-- Add your files & change `FUNDING.yml`
-- Commit & push
-
-<details>
-<summary>For itch.io depoloyment</summary>
-<br>
-
-Add a secret called `BUTLER_CREDENTIALS` with your [butler api key](https://itch.io/user/settings/api-keys).
-
-</details>
-
-<details>
-<summary>For android builds</summary>
-<br>
-
-> **Note**
->
-> The keystore user/alias is found automatically.
-
-Add two secrets:
-
-- `ANDROID_KEYSTORE_BASE64`
-- `ANDROID_KEYSTORE_PASSWORD`
-
-</details>
-
----
-
-### CI Availability
-
-| windows | ios | linux | android | mac | html | |
-| :----------------: | :-: | :----------------: | :----------------: | :----------------: | :----------------: | :-----------: |
-| :x: | :x: | :x: | :x: | :x: | :heavy_check_mark: | github pages |
-| :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | itch.io |
-| :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | godot exports |
+```gdscript
+var label = InteractiveActionLabel.new()
+label.action = "ui_left"
+label._name = "left"
+add_child(label)
+```
diff --git a/Test.gd b/Test.gd
new file mode 100644
index 0000000..f1973dc
--- /dev/null
+++ b/Test.gd
@@ -0,0 +1,7 @@
+extends Control
+
+func _ready():
+ var label = InteractiveActionLabel.new()
+ label.action = "ui_left"
+ label._name = "left"
+ add_child(label) \ No newline at end of file
diff --git a/Test.tscn b/Test.tscn
index c2ecd59..4538ec0 100644
--- a/Test.tscn
+++ b/Test.tscn
@@ -1,17 +1,14 @@
-[gd_scene load_steps=3 format=2]
+[gd_scene load_steps=4 format=2]
-[ext_resource path="res://addons/remap/ActionLabel.gd" type="Script" id=1]
+[ext_resource path="res://addons/remap/main.theme" type="Theme" id=1]
[ext_resource path="res://addons/remap/InteractiveActionLabel.gd" type="Script" id=2]
+[ext_resource path="res://Test.gd" type="Script" id=3]
[node name="Test" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
-
-[node name="ActionLabel" type="HBoxContainer" parent="."]
-anchor_right = 1.0
-script = ExtResource( 1 )
-_name = "lef"
-action = "ui_left"
+theme = ExtResource( 1 )
+script = ExtResource( 3 )
[node name="InteractiveActionLabel" type="HBoxContainer" parent="."]
anchor_top = 0.5
diff --git a/addons/remap/KeyPromptLabel.gd b/addons/remap/KeyPromptLabel.gd
index 9dbb499..47aa19f 100644
--- a/addons/remap/KeyPromptLabel.gd
+++ b/addons/remap/KeyPromptLabel.gd
@@ -4,8 +4,10 @@ var selected: InputEvent
func _input(event: InputEvent) -> void:
- if !RemapUtilities.is_valid_action(event):
+ if !RemapUtilities.is_valid_action(event) or event is InputEventMouseButton:
return
- $"%ok".disabled = false
+ if event is InputEventJoypadMotion:
+ event.axis_value = sign(event.axis_value)
selected = event
text = IconMap.get_icon(event)
+ $"%ok".disabled = false
diff --git a/addons/remap/KeySelector.tscn b/addons/remap/KeySelector.tscn
index 801bd1a..f46fa55 100644
--- a/addons/remap/KeySelector.tscn
+++ b/addons/remap/KeySelector.tscn
@@ -47,6 +47,7 @@ margin_bottom = 78.0
unique_name_in_owner = true
margin_right = 119.0
margin_bottom = 25.0
+rect_min_size = Vector2( 50, 0 )
size_flags_horizontal = 3
disabled = true
text = "ok"
@@ -56,5 +57,6 @@ unique_name_in_owner = true
margin_left = 130.0
margin_right = 250.0
margin_bottom = 25.0
+rect_min_size = Vector2( 100, 0 )
size_flags_horizontal = 3
text = "cancel"
diff --git a/addons/remap/LICENSE b/addons/remap/LICENSE
new file mode 100644
index 0000000..9a9763e
--- /dev/null
+++ b/addons/remap/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2022 bendn
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/addons/remap/README.md b/addons/remap/README.md
new file mode 100644
index 0000000..a29ce5e
--- /dev/null
+++ b/addons/remap/README.md
@@ -0,0 +1,12 @@
+# godot cli parser
+
+A utility for parsing command line arguments for godot.
+
+## Usage
+
+```gdscript
+var label = InteractiveActionLabel.new()
+label.action = "ui_left"
+label._name = "left"
+add_child(label)
+```
diff --git a/addons/remap/RemapUtilities.gd b/addons/remap/RemapUtilities.gd
index dce3e84..bacadbf 100644
--- a/addons/remap/RemapUtilities.gd
+++ b/addons/remap/RemapUtilities.gd
@@ -1,14 +1,7 @@
extends Reference
class_name RemapUtilities
-const invalid_actions = [
- InputEventMouseMotion,
- InputEventJoypadMotion,
- InputEventScreenDrag,
- InputEventScreenTouch,
- InputEventMIDI,
- InputEventMouseButton
-]
+const invalid_actions = [InputEventMouseMotion, InputEventScreenDrag, InputEventScreenTouch, InputEventMIDI]
static func clear_mappings(action: String) -> void:
diff --git a/addons/remap/SaveLoadUtils.gd b/addons/remap/SaveLoadUtils.gd
index 869305a..fb92310 100644
--- a/addons/remap/SaveLoadUtils.gd
+++ b/addons/remap/SaveLoadUtils.gd
@@ -45,8 +45,8 @@ static func load2inputmap(action: String) -> void:
for e in data.actions: # validate
if e is InputEvent and RemapUtilities.is_valid_action(e):
continue
+ push_error("Invalid action: %s" % e)
inputmap2file(action) # reset if invalid
- push_error("Invalid action: %s" % action)
return
RemapUtilities.clear_mappings(action)
for e in data.actions:
diff --git a/addons/remap/package.json b/addons/remap/package.json
new file mode 100644
index 0000000..8c6f7a6
--- /dev/null
+++ b/addons/remap/package.json
@@ -0,0 +1,23 @@
+{
+ "name": "@bendn/remap",
+ "version": "1.0.0",
+ "description": "godot input remapping",
+ "main": "InteractiveActionLabel.gd",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/bend-n/remap.git"
+ },
+ "keywords": [
+ "godot",
+ "godot-engine"
+ ],
+ "author": "bendn",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/bend-n/remap/issues"
+ },
+ "homepage": "https://github.com/bend-n/remap#readme"
+} \ No newline at end of file