-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
124 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import {GameEvent, event_types} from "./GameEvent"; | ||
import * as _ from "lodash"; | ||
|
||
export class LayerTweenEvent extends GameEvent { | ||
private map_layer_name: string; | ||
private finish_events: GameEvent[]; | ||
private duration: number; | ||
private destination_offset: { | ||
x?: number; | ||
y?: number; | ||
}; | ||
private easing: string; | ||
|
||
constructor( | ||
game, | ||
data, | ||
active, | ||
key_name, | ||
keep_reveal, | ||
map_layer_name, | ||
finish_events, | ||
destination_offset, | ||
duration, | ||
easing | ||
) { | ||
super(game, data, event_types.LAYER_TWEEN, active, key_name, keep_reveal); | ||
this.map_layer_name = map_layer_name; | ||
this.finish_events = []; | ||
if (finish_events !== undefined) { | ||
finish_events.forEach(event_info => { | ||
const event = this.data.game_event_manager.get_event_instance(event_info, this.type, this.origin_npc); | ||
this.finish_events.push(event); | ||
}); | ||
} | ||
this.destination_offset = destination_offset ?? {}; | ||
this.duration = duration ?? 0; | ||
this.easing = easing ?? "Linear.None"; | ||
} | ||
|
||
_fire() { | ||
const map_layer = this.data.map.get_layer(this.map_layer_name); | ||
|
||
if (!map_layer || !map_layer.sprite) { | ||
return; | ||
} | ||
|
||
++this.data.game_event_manager.events_running_count; | ||
|
||
const finish = () => { | ||
--this.data.game_event_manager.events_running_count; | ||
this.finish_events.forEach(event => event.fire(this.origin_npc)); | ||
}; | ||
|
||
if (this.duration > 30) { | ||
const easing = _.get(Phaser.Easing, this.easing); | ||
this.game.add | ||
.tween(map_layer.sprite.tileOffset) | ||
.to(_.pick(this.destination_offset, "x", "y"), this.duration, easing, true) | ||
.onComplete.addOnce(finish); | ||
} else { | ||
map_layer.sprite.tileOffset.x = this.destination_offset.x ?? map_layer.sprite.tileOffset.x; | ||
map_layer.sprite.tileOffset.y = this.destination_offset.y ?? map_layer.sprite.tileOffset.y; | ||
finish(); | ||
} | ||
} | ||
|
||
_destroy() { | ||
this.finish_events.forEach(event => event?.destroy()); | ||
} | ||
} |
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,24 @@ | ||
import {GameEvent, event_types} from "./GameEvent"; | ||
|
||
export class LayerVisibilityEvent extends GameEvent { | ||
private map_layer_name: string; | ||
private visible: boolean; | ||
|
||
constructor(game, data, active, key_name, keep_reveal, map_layer_name, visible) { | ||
super(game, data, event_types.LAYER_VISIBILITY, active, key_name, keep_reveal); | ||
this.map_layer_name = map_layer_name; | ||
this.visible = visible ?? true; | ||
} | ||
|
||
_fire() { | ||
const map_layer = this.data.map.get_layer(this.map_layer_name); | ||
|
||
if (!map_layer || !map_layer.sprite) { | ||
return; | ||
} | ||
|
||
map_layer.sprite.visible = this.visible; | ||
} | ||
|
||
_destroy() {} | ||
} |
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