fix syntax

This commit is contained in:
2026-02-17 09:15:15 -06:00
parent f310c18b84
commit 4e1b63fd0e
52 changed files with 2169 additions and 1754 deletions

View File

@@ -17,11 +17,23 @@ gesture.reset = function() {
gesture.on_input = function(action_id, action) {
if (search(action_id, 'gamepad_touchpad_') == null) return
var finger = action.finger || 0
var touchpad = action.touchpad || 0
var fingerId = `${touchpad}_${finger}`
var touchCount = 0
var fingers = null
var currentDist = 0
var d = 0
var gesture_type = null
var touch = null
var dt = 0
var dx = 0
var dy = 0
var absX = 0
var absY = 0
var dir = null
if (action_id == 'gamepad_touchpad_down') {
// Add new touch
this.touches[fingerId] = {
@@ -31,9 +43,9 @@ gesture.on_input = function(action_id, action) {
startY: action.y,
startTime: time.number()
}
var touchCount = length(array(this.touches))
touchCount = length(array(this.touches))
if (touchCount == 1) {
// Single touch started
this.gestureState = 'single'
@@ -41,7 +53,7 @@ gesture.on_input = function(action_id, action) {
} else if (touchCount == 2) {
// Two touches - potential pinch
this.gestureState = 'multi'
var fingers = array(array(this.touches), k => this.touches[k])
fingers = array(array(this.touches), k => this.touches[k])
this.startDist = this.dist(fingers[0], fingers[1])
}
}
@@ -50,17 +62,17 @@ gesture.on_input = function(action_id, action) {
// Update touch position
this.touches[fingerId].x = action.x
this.touches[fingerId].y = action.y
var touchCount = length(array(this.touches))
touchCount = length(array(this.touches))
if (touchCount == 2 && this.gestureState == 'multi') {
// Check for pinch gesture
var fingers = array(array(this.touches), k => this.touches[k])
var currentDist = this.dist(fingers[0], fingers[1])
var d = currentDist - this.startDist
fingers = array(array(this.touches), k => this.touches[k])
currentDist = this.dist(fingers[0], fingers[1])
d = currentDist - this.startDist
if (abs(d) >= this.PINCH_TH) {
var gesture_type = d > 0 ? 'pinch_out' : 'pinch_in'
gesture_type = d > 0 ? 'pinch_out' : 'pinch_in'
// scene.recurse(game.root, 'on_input', [gesture_type, { delta: d }])
this.startDist = currentDist
}
@@ -69,19 +81,20 @@ gesture.on_input = function(action_id, action) {
}
else if (action_id == 'gamepad_touchpad_up') {
if (this.touches[fingerId]) {
var touch = this.touches[fingerId]
var touchCount = length(array(this.touches))
touch = this.touches[fingerId]
touchCount = length(array(this.touches))
// Check for swipe if this was the only/last touch
if (touchCount == 1 && this.gestureState == 'single') {
var dt = time.number() - touch.startTime
var dx = action.x - touch.startX
var dy = action.y - touch.startY
dt = time.number() - touch.startTime
dx = action.x - touch.startX
dy = action.y - touch.startY
if (dt < this.MAX_TIME / 1000) { // Convert to seconds
var absX = abs(dx), absY = abs(dy)
absX = abs(dx)
absY = abs(dy)
if (absX > this.MIN_SWIPE / 100 || absY > this.MIN_SWIPE / 100) { // Normalize for 0-1 range
var dir = absX > absY
dir = absX > absY
? (dx > 0 ? 'swipe_right' : 'swipe_left')
: (dy > 0 ? 'swipe_down' : 'swipe_up')
audio.play('swipe')
@@ -89,10 +102,10 @@ gesture.on_input = function(action_id, action) {
}
}
}
// Remove touch
delete this.touches[fingerId]
// Reset if no touches left
if (length(array(this.touches)) == 0) {
this.gestureState = null