-
Notifications
You must be signed in to change notification settings - Fork 37
/
LayerTweenEvent.ts
75 lines (67 loc) · 2.43 KB
/
LayerTweenEvent.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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,
keep_custom_psynergy,
map_layer_name,
finish_events,
destination_offset,
duration,
easing
) {
super(game, data, event_types.LAYER_TWEEN, active, key_name, keep_reveal, keep_custom_psynergy);
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.map.layer_changes[this.map_layer_name].layer_offset = {
x: map_layer.sprite.tileOffset.x,
y: map_layer.sprite.tileOffset.y,
};
--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());
}
}