-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding ActorTeleportTask, teleport method to Actor, and fixing ladders
- Loading branch information
Showing
3 changed files
with
79 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Position } from '@engine/world'; | ||
import { Actor } from '@engine/world/actor'; | ||
import { ActorTask } from '@engine/task/impl/actor-task'; | ||
|
||
/** | ||
* A task for an actor to teleport to a new position. | ||
* | ||
* @author Kat | ||
*/ | ||
export class ActorTeleportTask<TActor extends Actor = Actor> extends ActorTask<TActor> { | ||
private readonly _newPosition: Position; | ||
|
||
/** | ||
* @param actor The actor executing this task. | ||
* @param newPosition The position to teleport the actor to. | ||
*/ | ||
constructor ( | ||
actor: TActor, | ||
newPosition: Position | ||
) { | ||
super(actor, { | ||
repeat: false, | ||
immediate: false | ||
}); | ||
this._newPosition = newPosition; | ||
} | ||
|
||
/** | ||
* Teleports the actor to the new position. | ||
* | ||
* TODO (Kat) unit test this | ||
*/ | ||
public execute() { | ||
if (!this.newPosition) { | ||
return; | ||
} | ||
|
||
this.actor.teleport(this.newPosition); | ||
} | ||
|
||
/** | ||
* Get the position the actor will be teleported to. | ||
* | ||
* @returns The position that the actor will be teleported to. | ||
*/ | ||
protected get newPosition(): Position | null { | ||
if (!this._newPosition) { | ||
return null; | ||
} | ||
|
||
return this._newPosition; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters