Skip to content

Commit

Permalink
Merge pull request #1 from endlessm/github-actions
Browse files Browse the repository at this point in the history
Set up GitHub actions to run pre-commit, and fix linter issues
  • Loading branch information
manuq authored Sep 24, 2024
2 parents cce194f + dfbe3b8 commit 09c786b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 21 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
# Set update schedule for GitHub Actions

version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
24 changes: 24 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Checks

on:
pull_request:
push:
branches:
- main

jobs:
pre-commit:
name: Linting and Formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: set PY
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- uses: pre-commit/[email protected]
5 changes: 4 additions & 1 deletion addons/DampedOscillator/DampedOscillator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ extends EditorPlugin


func _enter_tree():
add_autoload_singleton("DampedOscillator", "res://addons/DampedOscillator/scripts/damped_oscillator.tscn")
add_autoload_singleton(
"DampedOscillator", "res://addons/DampedOscillator/scripts/damped_oscillator.tscn"
)


func _exit_tree():
remove_autoload_singleton("DampedOscillator")
26 changes: 15 additions & 11 deletions addons/DampedOscillator/scripts/AnimationInstance.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extends Node

signal started
signal ended

# node values
var node
Expand All @@ -16,41 +18,43 @@ var scale_factor = 1.0

var active = true

signal started
signal ended

func _physics_process(delta):
# Do the math
var force = -spring_force * displacement - damp * velocity
velocity += force * delta
displacement += velocity * delta

# Check if node is gone
var wr = weakref(node)

if !wr.get_ref():
set_physics_process(false)
queue_free()
return

# Apply the math

match typeof(node.get(propertie)):
TYPE_FLOAT:
node.set(propertie, original_value + displacement*scale_factor)
node.set(propertie, original_value + displacement * scale_factor)
TYPE_INT:
node.set(propertie, original_value + int(displacement*scale_factor))
node.set(propertie, original_value + int(displacement * scale_factor))
TYPE_VECTOR2:
node.set(propertie, original_value + Vector2(displacement,-displacement)*scale_factor )

node.set(
propertie, original_value + Vector2(displacement, -displacement) * scale_factor
)

if abs(velocity - 0) < 0.001:
end() # Bye bye
end() # Bye bye


func start():
set_physics_process(true)
active = true
emit_signal("started")


func end():
emit_signal("ended")
node.set(propertie, original_value)
Expand Down
19 changes: 10 additions & 9 deletions addons/DampedOscillator/scripts/DampedOscillator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ extends Node
var animation_instance = preload("res://addons/DampedOscillator/scripts/animation_instance.tscn")
var queue_sysem_enabled = false

func animate(node, propertie: String, string: float, damp: float, velocity: float, scale_factor: float):

func animate(
node, propertie: String, string: float, damp: float, velocity: float, scale_factor: float
):
# Spawn new animation instance
var i = animation_instance.instantiate()

# Update node values
i.node = node
i.propertie = propertie
i.original_value = node.get(propertie)

# Update oscillator values
i.spring_force = string
i.damp = damp
i.velocity = velocity
i.scale_factor = scale_factor



# Queue system
for animation in get_children():
if animation.node == node and animation.propertie == propertie:
Expand All @@ -29,13 +31,12 @@ func animate(node, propertie: String, string: float, damp: float, velocity: floa
add_child(i)
return
i.active = false
animation.ended.connect(Callable(i,"start"))

animation.ended.connect(Callable(i, "start"))
i.original_value = animation.original_value
i.set_physics_process(false)
add_child(i)
return

# Yayy finally
add_child(i)

0 comments on commit 09c786b

Please sign in to comment.