Skip to content

Commit

Permalink
Move exactMoveDelay into SuspendableContext
Browse files Browse the repository at this point in the history
  • Loading branch information
GregHib committed Jan 23, 2025
1 parent a22de59 commit b07c014
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@ fun Character.exactMove(delta: Delta, delay: Int = tile.distanceTo(tile.add(delt
setExactMovement(Delta.EMPTY, delay, start.delta(tile), direction = direction)
}

context(SuspendableContext<*>) suspend fun Character.exactMoveDelay(delta: Delta, delay: Int = tile.distanceTo(tile.add(delta)) * 30, direction: Direction = Direction.NONE) {
character.exactMove(delta, delay, direction)
delay(delay / 30)
}

fun Character.exactMove(target: Tile, delay: Int = tile.distanceTo(target) * 30, direction: Direction = Direction.NONE, startDelay: Int = 0) {
val start = tile
tele(target)
Expand All @@ -200,11 +195,6 @@ fun Character.exactMove(target: Tile, delay: Int = tile.distanceTo(target) * 30,
setExactMovement(Delta.EMPTY, delay, start.delta(tile), startDelay, direction = direction)
}

context(SuspendableContext<*>) suspend fun Character.exactMoveDelay(target: Tile, delay: Int = tile.distanceTo(target) * 30, direction: Direction = Direction.NONE, startDelay: Int = 0) {
character.exactMove(target, delay, direction, startDelay)
delay((startDelay + delay) / 30)
}

val Character.turn: Delta
get() = Tile(visuals.turn.targetX, visuals.turn.targetY, tile.level).delta(tile)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package world.gregs.voidps.engine.suspend

import kotlinx.coroutines.suspendCancellableCoroutine
import world.gregs.voidps.engine.entity.character.Character
import world.gregs.voidps.engine.entity.character.exactMove
import world.gregs.voidps.engine.event.Context
import world.gregs.voidps.type.Delta
import world.gregs.voidps.type.Direction
import world.gregs.voidps.type.Tile

interface SuspendableContext<C : Character> : Context<C> {
/**
Expand All @@ -25,4 +29,17 @@ interface SuspendableContext<C : Character> : Context<C> {
character.delay = it
}
}

suspend fun Character.exactMoveDelay(delta: Delta, delay: Int = tile.distanceTo(tile.add(delta)) * 30, direction: Direction = Direction.NONE) {
character.exactMove(delta, delay, direction)
delay(delay / 30)
}

/**
* Gradually move the characters appeared location over time
*/
suspend fun Character.exactMoveDelay(target: Tile, delay: Int = tile.distanceTo(target) * 30, direction: Direction = Direction.NONE, startDelay: Int = 0) {
character.exactMove(target, delay, direction, startDelay)
delay((startDelay + delay) / 30)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package world.gregs.voidps.world.activity.skill.agility.course

import world.gregs.voidps.engine.entity.character.exactMoveDelay
import world.gregs.voidps.engine.entity.character.exactMove
import world.gregs.voidps.engine.entity.character.face
import world.gregs.voidps.engine.entity.character.move.tele
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package world.gregs.voidps.world.activity.skill.agility.course

import world.gregs.voidps.engine.client.message
import world.gregs.voidps.engine.data.Settings
import world.gregs.voidps.engine.entity.character.exactMoveDelay
import world.gregs.voidps.engine.entity.character.exactMove
import world.gregs.voidps.engine.entity.character.face
import world.gregs.voidps.engine.entity.character.move.tele
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package world.gregs.voidps.world.activity.skill.agility.course

import world.gregs.voidps.engine.client.message
import world.gregs.voidps.engine.entity.character.exactMoveDelay
import world.gregs.voidps.engine.entity.character.face
import world.gregs.voidps.engine.entity.character.move.tele
import world.gregs.voidps.engine.entity.character.move.walkOver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package world.gregs.voidps.world.activity.skill.agility.course

import world.gregs.voidps.engine.client.message
import world.gregs.voidps.engine.data.Settings
import world.gregs.voidps.engine.entity.character.exactMoveDelay
import world.gregs.voidps.engine.entity.character.face
import world.gregs.voidps.engine.entity.character.move.tele
import world.gregs.voidps.engine.entity.character.move.walkOver
Expand Down

0 comments on commit b07c014

Please sign in to comment.