Skip to content

Commit

Permalink
improving log msgs for dup sprite keys
Browse files Browse the repository at this point in the history
  • Loading branch information
jjppof committed Oct 24, 2023
1 parent 65e4a47 commit d39bb08
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
7 changes: 7 additions & 0 deletions base/SpriteBase.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {GoldenSun} from "GoldenSun";
import {msg_types} from "./Logger";

/**
* This class holds all the info related to spritesheet data, animations, actions
Expand Down Expand Up @@ -93,6 +94,12 @@ export class SpriteBase {
for (let action in this.actions) {
const spritesheet = this.actions[action].spritesheet;
const action_key = this.getSpriteKey(action);
if (game.cache.checkImageKey(action_key)) {
this.data.logger.log_message(
`Sprite key '<key_name>/<action>' '${action_key} is already registered in the engine. Please consider renaming it.'`,
msg_types.ERROR
);
}
const loader = game.load.atlasJSONHash(action_key, spritesheet.image, spritesheet.json);
if (force_load) {
loader.onLoadComplete.addOnce(on_load_complete, this);
Expand Down
12 changes: 6 additions & 6 deletions base/initializers/initialize_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ export async function initialize_game_data(game: Phaser.Game, data: GoldenSun) {
},
};

// Initializes all NPCS data
let load_npcs_promise_resolve;
const load_npcs_promise = new Promise(resolve => (load_npcs_promise_resolve = resolve));
data.info.npcs_sprite_base_list = initialize_npcs_data(game, data, data.dbs.npc_db, load_npcs_promise_resolve);
await load_npcs_promise;

// Initializes MAIN CHARS
let load_chars_promise_resolve;
const load_chars_promise = new Promise(resolve => (load_chars_promise_resolve = resolve));
Expand Down Expand Up @@ -168,12 +174,6 @@ export async function initialize_game_data(game: Phaser.Game, data: GoldenSun) {
);
await load_iter_objs_promise;

// Initializes all NPCS data
let load_npcs_promise_resolve;
const load_npcs_promise = new Promise(resolve => (load_npcs_promise_resolve = resolve));
data.info.npcs_sprite_base_list = initialize_npcs_data(game, data, data.dbs.npc_db, load_npcs_promise_resolve);
await load_npcs_promise;

// Initializes SHOPS
data.info.shops_list = initialize_shops(data, data.dbs.shops_db);

Expand Down
12 changes: 1 addition & 11 deletions base/initializers/main_chars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function initialize_main_chars(
continue;
}
const char_db = npc_db[char_data.key_name];
const sprite_base = new SpriteBase(data, char_data.key_name, Object.keys(char_db.actions));
const sprite_base = data.info.npcs_sprite_base_list[char_data.key_name];
const char_snapshot_data = snapshot?.main_chars.find(
member_info => member_info.key_name === char_data.key_name
);
Expand Down Expand Up @@ -124,16 +124,6 @@ export function initialize_main_chars(
main_char.current_hp = char_snapshot_data?.current_hp ?? main_char.current_hp;
main_char.current_pp = char_snapshot_data?.current_pp ?? main_char.current_pp;

for (let action_key in char_db.actions) {
const action = char_db.actions[action_key];
sprite_base.setActionSpritesheet(action_key, action.spritesheet.image, action.spritesheet.json);
sprite_base.setActionAnimations(action_key, action.animations, action.frames_count);
sprite_base.setActionFrameRate(action_key, action.frame_rate);
sprite_base.setActionLoop(action_key, action.loop);
}
sprite_base.generateAllFrames();
sprite_base.loadSpritesheets(game, false);

if (Object.keys(char_data.weapons_sprites).length && base_actions.BATTLE in char_db.actions) {
const action = char_db.actions[base_actions.BATTLE];
for (let weapon_type in char_data.weapons_sprites) {
Expand Down

0 comments on commit d39bb08

Please sign in to comment.