Skip to content

Commit

Permalink
exit sand event, teleport fade bug fix, support color on camera fade …
Browse files Browse the repository at this point in the history
…event
  • Loading branch information
jjppof committed Nov 23, 2023
1 parent b76f93d commit 375b7ef
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 7 deletions.
13 changes: 8 additions & 5 deletions base/game_events/CameraFadeEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ export class CameraFadeEvent extends GameEvent {
private finish_events: GameEvent[];
private fade_type: fade_types;
private duration: number;
private color: string;

constructor(game, data, active, key_name, keep_reveal, fade_type, duration, finish_events) {
constructor(game, data, active, key_name, keep_reveal, fade_type, duration, color, finish_events) {
super(game, data, event_types.CAMERA_FADE, active, key_name, keep_reveal);
this.fade_type = fade_type;
this.duration = duration ?? 500;
this.color = color;

this.finish_events = [];
if (finish_events !== undefined) {
Expand All @@ -29,11 +31,12 @@ export class CameraFadeEvent extends GameEvent {

let promise_resolve;
const promise = new Promise(resolve => (promise_resolve = resolve));
if (this.fade_type === fade_types.IN) {
this.game.camera.fade(undefined, this.duration, true);
let color = this.color ? parseInt(this.color, 16) : undefined;
if (this.fade_type === fade_types.OUT) {
this.game.camera.fade(color, this.duration, true);
this.game.camera.onFadeComplete.addOnce(promise_resolve);
} else if (this.fade_type === fade_types.OUT) {
this.game.camera.flash(0x0, this.duration, true);
} else if (this.fade_type === fade_types.IN) {
this.game.camera.flash(color ?? 0x0, this.duration, true);
this.game.camera.onFlashComplete.addOnce(promise_resolve);
}
await promise;
Expand Down
31 changes: 31 additions & 0 deletions base/game_events/ExitSandModeEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {SandFieldPsynergy} from "../field_abilities/SandFieldPsynergy";
import {GameEvent, event_types} from "./GameEvent";

export class ExitSandModeEvent extends GameEvent {
private finish_events: GameEvent[];

constructor(game, data, active, key_name, keep_reveal, finish_events) {
super(game, data, event_types.EXIT_SAND_MODE, active, key_name, keep_reveal);
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);
});
}
}

_fire() {
if (this.data.hero.sand_mode) {
++this.data.game_event_manager.events_running_count;
(this.data.info.field_abilities_list.sand as SandFieldPsynergy).return_to_normal(() => {
--this.data.game_event_manager.events_running_count;
this.finish_events.forEach(event => event.fire(this.origin_npc));
});
}
}

_destroy() {
this.finish_events.forEach(event => event?.destroy());
}
}
1 change: 1 addition & 0 deletions base/game_events/GameEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export enum event_types {
CHAR_TWEEN_POSITION = "char_tween_position",
CHAR_SHADOW_VISIBILITY = "char_shadow_visibility",
IO_TWEEN_POSITION = "io_tween_position",
EXIT_SAND_MODE = "exit_sand_mode",
}

export enum game_event_misc_origin {
Expand Down
11 changes: 11 additions & 0 deletions base/game_events/GameEventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import {CharRotationEvent} from "./CharRotationEvent";
import {CharTweenPositionEvent} from "./CharTweenPositionEvent";
import {CharShadowVisibilityEvent} from "./CharShadowVisibilityEvent";
import {IOTweenPositionEvent} from "./IOTweenPositionEvent";
import {ExitSandModeEvent} from "./ExitSandModeEvent";

export enum interaction_patterns {
NO_INTERACTION = "no_interaction",
Expand Down Expand Up @@ -749,6 +750,7 @@ export class GameEventManager {
info.keep_reveal,
info.fade_type,
info.duration,
info.color,
info.finish_events
);
case event_types.COLORIZE_MAP:
Expand Down Expand Up @@ -1214,6 +1216,15 @@ export class GameEventManager {
info.dest_collision_layer,
info.change_collision_layer_on_init
);
case event_types.EXIT_SAND_MODE:
return new ExitSandModeEvent(
this.game,
this.data,
info.active,
info.key_name,
info.key_name,
info.finish_events
);
default:
const origin = `Event origin: ${event_origin}. ${
entity_origin?.label
Expand Down
16 changes: 14 additions & 2 deletions base/tile_events/TeleportEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,20 @@ export class TeleportEvent extends TileEvent {
};

if (this.fade_camera) {
this.game.camera.fade(undefined, this.fade_duration, true);
this.game.camera.onFadeComplete.addOnce(on_camera_fade_in);
if (
this.game.camera.fxType === Phaser.Camera.FADE_OUT &&
this.game.camera.fx.graphicsData[0]?.fillColor === 0x0
) {
const timer = this.game.time.create(true);
timer.add(this.fade_duration, () => {
timer.destroy();
on_camera_fade_in();
});
timer.start();
} else {
this.game.camera.fade(undefined, this.fade_duration, true);
this.game.camera.onFadeComplete.addOnce(on_camera_fade_in);
}
} else {
on_camera_fade_in();
}
Expand Down
3 changes: 3 additions & 0 deletions static/phaser.js
Original file line number Diff line number Diff line change
Expand Up @@ -29141,6 +29141,9 @@ Phaser.Camera.FADE_OUT = 1;
Phaser.Camera.FADE_IN = 2;

Phaser.Camera.prototype = {
get fxType() {
return this._fxType;
},

/**
* Called automatically by Phaser.World.
Expand Down
5 changes: 5 additions & 0 deletions types/phaser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,9 @@ declare module Phaser {
static SHAKE_HORIZONTAL: number;
static SHAKE_VERTICAL: number;
static ENABLE_FX: number;
static FLASH: number;
static FADE_OUT: number;
static FADE_IN: number;

atLimit: { x: boolean; y: boolean; };
bounds: Phaser.Rectangle;
Expand All @@ -689,6 +692,7 @@ declare module Phaser {
id: number;
fixedView: Phaser.Rectangle;
fx: Phaser.Graphics;
fxType: number;
game: Phaser.Game;
height: number;
lerp: Phaser.Point;
Expand Down Expand Up @@ -1864,6 +1868,7 @@ declare module Phaser {
fixedToCamera: boolean;
fresh: boolean;
game: Phaser.Game;
graphicsData: Phaser.GraphicsData[];
height: number;
inCamera: boolean;
inWorld: boolean;
Expand Down

0 comments on commit 375b7ef

Please sign in to comment.