Skip to content

Commit

Permalink
io visibility and activation events
Browse files Browse the repository at this point in the history
  • Loading branch information
jjppof committed Sep 5, 2023
1 parent ac3d609 commit b70e972
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 1 deletion.
1 change: 1 addition & 0 deletions base/field_abilities/FrostFieldPsynergy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export class FrostFieldPsynergy extends FieldAbilities {
/*Plays the pillar's growing animation*/
grow_pillar() {
this.data.audio.play_se("psynergy/7");
this.target_object.sprite.visible = true;
this.target_object.play("pillar");
this.target_object.sprite.animations.currentAnim.onComplete.addOnce(() => {
FrostFieldPsynergy.set_permanent_blink(this.game, this.target_object);
Expand Down
2 changes: 2 additions & 0 deletions base/game_events/GameEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export enum event_types {
LAYER_TWEEN = "layer_tween",
LAYER_VISIBILITY = "layer_visibility",
MAIN_CHARS_JOIN_SPLIT = "main_chars_join_split",
SET_IO_VISIBILITY = "set_io_visibility",
SET_IO_ACTIVATION = "set_io_activation",
}

export enum game_event_misc_origin {
Expand Down
22 changes: 22 additions & 0 deletions base/game_events/GameEventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ import {InteractableObjects} from "interactable_objects/InteractableObjects";
import {LayerTweenEvent} from "./LayerTweenEvent";
import {LayerVisibilityEvent} from "./LayerVisibilityEvent";
import {MainCharsJoinSplitEvent} from "./MainCharsJoinSplitEvent";
import {SetIoVisibilityEvent} from "./SetIoVisibilityEvent";
import {SetIoActivationEvent} from "./SetIoActivationEvent";

export enum interaction_patterns {
NO_INTERACTION = "no_interaction",
Expand Down Expand Up @@ -1090,6 +1092,26 @@ export class GameEventManager {
info.keep_npc_collision_disable,
info.dash
);
case event_types.SET_IO_VISIBILITY:
return new SetIoVisibilityEvent(
this.game,
this.data,
info.active,
info.key_name,
info.keep_reveal,
info.io_label,
info.visible
);
case event_types.SET_IO_ACTIVATION:
return new SetIoActivationEvent(
this.game,
this.data,
info.active,
info.key_name,
info.keep_reveal,
info.io_label,
info.io_active
);
default:
const origin = `Event origin: ${event_origin}. ${
entity_origin?.label
Expand Down
4 changes: 4 additions & 0 deletions base/game_events/IOAnimPlayEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export class IOAnimPlayEvent extends GameEvent {

async _fire() {
const interactable_object = this.data.map.interactable_objects_label_map[this.io_label];
if (!(this.io_label in this.data.map.interactable_objects_label_map)) {
this.data.logger.log_message(`Game Event [${this.type}]: IO with label "${this.io_label}" doesn't exist.`);
return;
}
if (this.stop_animation) {
interactable_object.sprite.animations.currentAnim.stop(this.reset_frame_on_stop);
} else {
Expand Down
23 changes: 23 additions & 0 deletions base/game_events/SetIoActivationEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {GameEvent, event_types} from "./GameEvent";

export class SetIoActivationEvent extends GameEvent {
private io_label: string;
private io_active: boolean;

constructor(game, data, active, key_name, keep_reveal, io_label, io_active) {
super(game, data, event_types.SET_IO_ACTIVATION, active, key_name, keep_reveal);
this.io_label = io_label;
this.io_active = io_active ?? true;
}

_fire() {
if (!(this.io_label in this.data.map.interactable_objects_label_map)) {
this.data.logger.log_message(`Game Event [${this.type}]: IO with label "${this.io_label}" doesn't exist.`);
return;
}
const interactable_object = this.data.map.interactable_objects_label_map[this.io_label];
interactable_object.toggle_active(this.io_active);
}

_destroy() {}
}
5 changes: 4 additions & 1 deletion base/game_events/SetIoCollisionEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export class SetIoCollisionEvent extends GameEvent {

_fire() {
const interactable_object = this.data.map.interactable_objects_label_map[this.io_label];

if (!(this.io_label in this.data.map.interactable_objects_label_map)) {
this.data.logger.log_message(`Game Event [${this.type}]: IO with label "${this.io_label}" doesn't exist.`);
return;
}
switch (this.control_type) {
case control_types.REMOVE:
interactable_object.destroy_body(true);
Expand Down
25 changes: 25 additions & 0 deletions base/game_events/SetIoVisibilityEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {GameEvent, event_types} from "./GameEvent";

export class SetIoVisibilityEvent extends GameEvent {
private io_label: string;
private visible: boolean;

constructor(game, data, active, key_name, keep_reveal, io_label, visible) {
super(game, data, event_types.SET_IO_VISIBILITY, active, key_name, keep_reveal);
this.io_label = io_label;
this.visible = visible ?? true;
}

_fire() {
if (!(this.io_label in this.data.map.interactable_objects_label_map)) {
this.data.logger.log_message(`Game Event [${this.type}]: IO with label "${this.io_label}" doesn't exist.`);
return;
}
const interactable_object = this.data.map.interactable_objects_label_map[this.io_label];
if (interactable_object.sprite) {
interactable_object.sprite.visible = this.visible;
}
}

_destroy() {}
}

0 comments on commit b70e972

Please sign in to comment.