Skip to content

Commit

Permalink
Bug fix with touching not returning the correct value in the web plat…
Browse files Browse the repository at this point in the history
…form.
  • Loading branch information
dwursteisen committed Mar 19, 2024
1 parent dece52e commit 784a5dc
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 62 deletions.
Binary file modified tiny-cli/src/jvmMain/resources/sfx/tiny-export.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion tiny-doc/src/docs/asciidoc/sample/tiny-engine.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,12 @@ class TouchManager(lastKeyCode: KeyCode) {
private fun processTouchEvent(event: InternalTouchEvent) {
when (event.way) {
InternalTouchEventWay.DOWN -> {
justTouch[event.touchSignal.ordinal] = event.position
touch[event.touchSignal.ordinal] = event.position
justTouch[event.touchSignal.ordinal] = event.position.copy()
touch[event.touchSignal.ordinal] = event.position.copy()
lastTouch.set(event.position)
}

InternalTouchEventWay.MOVE -> {
touch[event.touchSignal.ordinal]?.run {
x = event.position.x
y = event.position.y
}
lastTouch.set(event.position)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class CtrlLib(
"- 1: right click or two fingers\n" +
"- 2: middle click or three fingers\n\n",
example = CTRL_TOUCHING_EXAMPLE,
name = "touching"
)
inner class touching : OneArgFunction() {
@TinyCall("Is the screen is still touched or mouse button is still pressed?")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,34 @@ end
const val CTRL_TOUCHING_EXAMPLE = """
function _draw()
gfx.cls()
local p = ctrl.touch()
shape.circlef(p.x, p.y, 4, 8)
local start = ctrl.touching(0)
if start ~= nil then
local pos = ctrl.touch()
shape.line(start.x, start.y, pos.x, pos.y, 9)
shape.line(start.x, start.y, pos.x, pos.y, 1)
print("("..start.x .. ", "..start.y..")", start.x, start.y)
print("("..pos.x .. ", "..pos.y..")", pos.x, pos.y)
end
end
"""

const val CTRL_TOUCHED_EXAMPLE = """
function _draw()
local circles = {}
function _update()
local pos = ctrl.touched(0)
if pos ~= nil then
table.insert(circles, pos)
end
end
function _draw()
gfx.cls()
local p = ctrl.touch()
shape.circlef(p.x, p.y, 4, 8)
for pos in all(circles) do
shape.circlef(pos.x, pos.y, 4, 9)
print("("..pos.x .. ", "..pos.y..")", pos.x + 3, pos.y + 3)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.minigdx.tiny.input

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertNull
Expand Down Expand Up @@ -30,7 +31,7 @@ class TouchManagerTest {
}

@Test
fun key_just_presset() {
fun key_just_pressed() {
// push key
val touchManager = TouchManager(10)
touchManager.onKeyPressed(1)
Expand All @@ -54,7 +55,7 @@ class TouchManagerTest {
}

@Test
fun key_presset_without_released() {
fun key_pressed_without_released() {
// push key
val touchManager = TouchManager(10)
touchManager.onKeyPressed(1)
Expand All @@ -77,4 +78,18 @@ class TouchManagerTest {
assertFalse(touchManager.isAnyKeyPressed)
assertFalse(touchManager.isKeyPressed(1))
}

@Test
fun touching() {
// push key
val touchManager = TouchManager(10)
touchManager.onTouchDown(TouchSignal.TOUCH1, 0f, 0f)
touchManager.processReceivedEvent()
touchManager.onTouchMove(TouchSignal.TOUCH1, 10f, 0f)
touchManager.processReceivedEvent()

val pos = touchManager.isTouched(TouchSignal.TOUCH1)
assertEquals(0f, pos?.x)
}

}
51 changes: 0 additions & 51 deletions tiny-engine/src/jvmMain/kotlin/com/DeleteMe.kt

This file was deleted.

0 comments on commit 784a5dc

Please sign in to comment.