swipe detector
Initial commit
| -rw-r--r-- | .gitattributes | 4 | ||||
| -rw-r--r-- | .github/FUNDING.yml | 1 | ||||
| -rw-r--r-- | .github/workflows/export.yml | 80 | ||||
| -rw-r--r-- | .gitignore | 9 | ||||
| -rw-r--r-- | LICENSE | 21 | ||||
| -rw-r--r-- | README.md | 18 | ||||
| -rw-r--r-- | Test.gd | 10 | ||||
| -rw-r--r-- | Test.tscn | 6 | ||||
| -rw-r--r-- | addons/swipe-detector/InputEventSwipe.gd | 7 | ||||
| -rw-r--r-- | addons/swipe-detector/LICENSE | 21 | ||||
| -rw-r--r-- | addons/swipe-detector/README.md | 14 | ||||
| -rw-r--r-- | addons/swipe-detector/SwipeDetector.gd | 33 | ||||
| -rw-r--r-- | addons/swipe-detector/package.json | 24 | ||||
| -rw-r--r-- | export_presets.cfg | 24 | ||||
| -rw-r--r-- | project.godot | 38 |
15 files changed, 310 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a05dc57 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +*.png filter=lfs diff=lfs merge=lfs -text +*.ogg filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.svg filter=lfs diff=lfs merge=lfs -text diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..1bfbcab --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +ko_fi: bendn diff --git a/.github/workflows/export.yml b/.github/workflows/export.yml new file mode 100644 index 0000000..80bc4ec --- /dev/null +++ b/.github/workflows/export.yml @@ -0,0 +1,80 @@ +name: "export" +on: + workflow_dispatch: + push: + paths: + - "**.gd" + - "**.tscn" + - "**.import" + - "**.tres" + - "**.ttf" + - "**.yml" + branches: + - main + +env: + GODOT_VERSION: 3.5 + NAME: ${{ github.event.repository.name }} + +jobs: + export: + runs-on: ubuntu-latest + container: + image: ghcr.io/bend-n/godot-2d:3.5 + name: ${{ matrix.name }} + strategy: + matrix: + include: + - name: Windows export + platform: windows + + - name: Linux export + platform: linux + + - name: Mac export + platform: mac + + - name: Web export + platform: web + + - name: Android export + platform: android + + steps: + - name: Build (Windows) + if: matrix.platform == 'windows' + uses: bend-n/godot-actions/.github/actions/export-windows@main + + - name: Build (Linux) + if: matrix.platform == 'linux' + uses: bend-n/godot-actions/.github/actions/export-linux@main + + - name: Build (Mac) + if: matrix.platform == 'mac' + uses: bend-n/godot-actions/.github/actions/export-mac@main + + - name: Build (Web) + if: matrix.platform == 'web' + uses: bend-n/godot-actions/.github/actions/export-web@main + + - name: Build (Android) + if: matrix.platform == 'android' + uses: bend-n/godot-actions/.github/actions/export-android@main + with: + android-keystore-base64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }} + android-password: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }} + + push-itch: + needs: [export] + name: Push to itch.io + runs-on: ubuntu-20.04 + steps: + - name: Check for api key + id: secret + run: echo '::set-output name=secret::${{ secrets.BUTLER_CREDENTIALS }}' + + - name: Push + if: steps.secret.outputs.secret + uses: bend-n/godot-actions/.github/actions/itch-push@main + with: + api-key: ${{ secrets.BUTLER_CREDENTIALS }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d851401 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.import/ +logs/ +*.sh +*.py +*.pgn +.vscode/ +exports/ +*.x86_64 +addons/gdcli @@ -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/README.md b/README.md new file mode 100644 index 0000000..64d2cb0 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# godot swipe detector + +[](https://godotengine.org "Made with godot") +[](https://www.npmjs.com/package/@bendn/swipe-detector) +<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> + +A script to detect directional swipes on the screen. + +## Usage example + +```gdscript +func _ready(): + add_child(SwipeDetector.new()) + +func _input(event): + if event is InputEventSwipe: + print(event.direction) +``` @@ -0,0 +1,10 @@ +extends Node + + +func _ready(): + add_child(SwipeDetector.new()) + + +func _input(event): + if event is InputEventSwipe: + print(event.direction) diff --git a/Test.tscn b/Test.tscn new file mode 100644 index 0000000..a65812c --- /dev/null +++ b/Test.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Test.gd" type="Script" id=1] + +[node name="Test" type="Node"] +script = ExtResource( 1 ) diff --git a/addons/swipe-detector/InputEventSwipe.gd b/addons/swipe-detector/InputEventSwipe.gd new file mode 100644 index 0000000..9e4f26c --- /dev/null +++ b/addons/swipe-detector/InputEventSwipe.gd @@ -0,0 +1,7 @@ +class_name InputEventSwipe +extends InputEventAction + +var direction := Vector2.ZERO + +func _init(dir: Vector2) -> void: + direction = dir.snapped(Vector2(.1, .1))
\ No newline at end of file diff --git a/addons/swipe-detector/LICENSE b/addons/swipe-detector/LICENSE new file mode 100644 index 0000000..9a9763e --- /dev/null +++ b/addons/swipe-detector/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/swipe-detector/README.md b/addons/swipe-detector/README.md new file mode 100644 index 0000000..eff4445 --- /dev/null +++ b/addons/swipe-detector/README.md @@ -0,0 +1,14 @@ +# godot swipe detector + +A script to detect directional swipes on the screen. + +## Usage example + +```gdscript +func _ready(): + add_child(SwipeDetector.new()) + +func _input(event): + if event is InputEventSwipe: + print(event.direction) +``` diff --git a/addons/swipe-detector/SwipeDetector.gd b/addons/swipe-detector/SwipeDetector.gd new file mode 100644 index 0000000..916a658 --- /dev/null +++ b/addons/swipe-detector/SwipeDetector.gd @@ -0,0 +1,33 @@ +extends Node +class_name SwipeDetector + +export(float) var swipe_timeout := .5 # only set this before `_ready` is called + +onready var timer := Timer.new() +var swipe_start_position := Vector2() setget set_swipe_start_position + + +func _ready(): + add_child(timer) + timer.wait_time = swipe_timeout + timer.one_shot = true + + +func _unhandled_input(event: InputEvent) -> void: + if not event is InputEventScreenTouch: + return + if event.pressed: # press + set_swipe_start_position(event.position) + elif not timer.is_stopped(): # let go. + _end_detection(event.position) + + +func set_swipe_start_position(position: Vector2) -> void: + swipe_start_position = position + timer.start() + + +func _end_detection(position: Vector2) -> void: + timer.stop() + var direction := (position - swipe_start_position).normalized() + Input.parse_input_event(InputEventSwipe.new(direction)) diff --git a/addons/swipe-detector/package.json b/addons/swipe-detector/package.json new file mode 100644 index 0000000..5570164 --- /dev/null +++ b/addons/swipe-detector/package.json @@ -0,0 +1,24 @@ +{ + "name": "@bendn/swipe-detector", + "version": "1.0.0", + "description": "godot swipe detector", + "main": "SwipeDetector.gd", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/bend-n/swipe-detector.git" + }, + "keywords": [ + "godot", + "godot-engine", + "swipe" + ], + "author": "bendn", + "license": "MIT", + "bugs": { + "url": "https://github.com/bend-n/swipe-detector/issues" + }, + "homepage": "https://github.com/bend-n/swipe-detector#readme" +}
\ No newline at end of file diff --git a/export_presets.cfg b/export_presets.cfg new file mode 100644 index 0000000..fb88f7e --- /dev/null +++ b/export_presets.cfg @@ -0,0 +1,24 @@ +[preset.0] + +name="Linux" +platform="Linux/X11" +runnable=true +custom_features="" +export_filter="all_resources" +include_filter="" +exclude_filter="" +export_path="" +script_export_mode=1 +script_encryption_key="" + +[preset.0.options] + +custom_template/debug="" +custom_template/release="" +binary_format/64_bits=true +binary_format/embed_pck=true +texture_format/bptc=false +texture_format/s3tc=true +texture_format/etc=false +texture_format/etc2=false +texture_format/no_bptc_fallbacks=true diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..e8384b4 --- /dev/null +++ b/project.godot @@ -0,0 +1,38 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=4 + +_global_script_classes=[ { +"base": "InputEventAction", +"class": "InputEventSwipe", +"language": "GDScript", +"path": "res://addons/swipe-detector/InputEventSwipe.gd" +}, { +"base": "Node", +"class": "SwipeDetector", +"language": "GDScript", +"path": "res://addons/swipe-detector/SwipeDetector.gd" +} ] +_global_script_class_icons={ +"InputEventSwipe": "", +"SwipeDetector": "" +} + +[application] + +config/name="swipe detector" +run/main_scene="res://Test.tscn" + +[input_devices] + +pointing/emulate_touch_from_mouse=true + +[rendering] + +quality/driver/driver_name="GLES2" |