Skip to content

Commit

Permalink
Merge pull request #208 from Techbot/207-split-loader-class
Browse files Browse the repository at this point in the history
split loaders
  • Loading branch information
Techbot authored Jun 4, 2024
2 parents 7e5d92d + 353cdd5 commit 3e94bd8
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 72 deletions.
25 changes: 25 additions & 0 deletions client/src/game/loaders/bossLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* -------bossLoader ---------
*/

import { useJigsStore } from '../../stores/jigs';

export default class BossLoader {

jigs: any;

constructor() {
this.jigs = useJigsStore();
}

add(scene) {
console.log("---------------Boss Loader-------------")

if (this.jigs.bossesArray) {
this.jigs.bossesArray.forEach(function loader(boss) {
scene.load.spritesheet('boss_' + boss.boss, '/assets/images/Level Bosses/' + boss.boss + '.png',
{ frameWidth: parseInt(boss.field_frame_width), frameHeight: parseInt(boss.field_frame_height) });
});
}
}
}
96 changes: 24 additions & 72 deletions client/src/game/loaders/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,33 @@ import { createCharacterAnims } from "../entities/anim";
import { createSwitchesAnims } from "../entities/anim";
import { createBossAnims } from "../entities/anim";
import MobLoader from "./mobLoader"

import BossLoader from "./bossLoader"
import NpcLoader from "./npcLoader"
import TilesetLoader from "./tilesetLoader"
import SwitchLoader from "./switchLoader"
import QuestLoader from "./questLoader"

export default class Load {

jigs: any;
npcs: any;
sprite: any;
mobloader: any;
mobLoader: any;
bossLoader: any;
npcLoader: any;
tilesetLoader: any;
switchLoader: any;
questLoader: any;

constructor() {
this.jigs = useJigsStore();
this.mobloader= new MobLoader();
this.mobLoader= new MobLoader();
this.bossLoader = new BossLoader();
this.npcLoader = new NpcLoader();
this.tilesetLoader = new TilesetLoader();
this.switchLoader = new SwitchLoader();
this.questLoader = new QuestLoader();

}

padding(n, p, c) {
Expand All @@ -37,66 +52,12 @@ export default class Load {
scene.load.image('pink', '/assets/images/pink.png');
scene.load.tilemapTiledJSON(this.jigs.city + "_" + this.jigs.tiled, '/assets/cities/json/' + this.jigs.city + this.padding(this.jigs.tiled, 3, '0') + '.json?' + Math.random());

this.jigs.tilesetArray_1.forEach(function loader(image) {
if (!textureManager.exists(image)) {
scene.load.image(image, '/assets/images/System/' + image + '.png');
}
}, this);

this.jigs.tilesetArray_2.forEach(function loader(image) {
if (!textureManager.exists(image)) {
scene.load.image(image, '/assets/images/System/' + image + '.png');
}
}, this);

this.jigs.tilesetArray_3.forEach(function loader(image) {
if (!textureManager.exists(image)) {
scene.load.image(image, '/assets/images/System/' + image + '.png');
}
}, this);

if (this.jigs.tilesetArray_4 !== undefined) {
this.jigs.tilesetArray_4.forEach(function loader(image) {
if (!textureManager.exists(image)) {
scene.load.image(image, '/assets/images/System/' + image + '.png');
}
}, this);
}

if (this.jigs.npcArray) {
this.jigs.npcArray.forEach(function loader(Npc) {
scene.load.spritesheet('npc' + Npc[3], '/assets/images/sprites/' + Npc[3] + '.png', { frameWidth: 64, frameHeight: 64 });
}, this);
}

/* if (this.jigs.mobArray) {
this.jigs.mobArray.forEach(function loader(Mob) {
scene.load.spritesheet('mob' + Mob[4], '/assets/images/sprites/' + Mob[4] + '.png', { frameWidth: 64, frameHeight: 64 });
}, this);
} */
this.mobloader.add(scene);


if (this.jigs.bossesArray) {
this.jigs.bossesArray.forEach(function loader(boss) {
scene.load.spritesheet('boss_' + boss.boss, '/assets/images/Level Bosses/' + boss.boss +'.png',
{ frameWidth: parseInt(boss.field_frame_width), frameHeight: parseInt(boss.field_frame_height) });
});
}

if (this.jigs.switchesArray) {
this.jigs.switchesArray.forEach(function loader(switchItem) {
scene.load.spritesheet('switch_' + switchItem.entity_id, '/assets/images/switches/' + switchItem.field_file_value ,
{ frameWidth: parseInt(switchItem.field_frame_width_value), frameHeight: parseInt(switchItem.field_frame_height_value) });
});
}

if (this.jigs.questsArray) {
this.jigs.questsArray.forEach(function loader(questsItem) {
scene.load.spritesheet('quest_' + questsItem.id, '/assets/images/quest/' + questsItem.file + '.png',
{ frameWidth: questsItem.frameWidth, frameHeight: questsItem.frameHeight });
});
}
this.tilesetLoader.add(scene);
this.npcLoader.add(scene);
this.mobLoader.add(scene);
this.bossLoader.add(scene);
this.switchLoader.add(scene);
this.questLoader.add(scene);

scene.load.once(Phaser.Loader.Events.COMPLETE, () => {
const Layer = new Layers;
Expand All @@ -105,19 +66,13 @@ export default class Load {
createCharacterAnims(scene.anims, 'PsibotF_slash', 'slash_oversize'); */

createCharacterAnims(scene.anims, 'player', null);

createCharacterAnims(scene.anims, 'otherPlayer', null);

if (this.jigs.npcArray) {
this.jigs.npcArray.forEach(function loader(Npc) {
createCharacterAnims(scene.anims, 'npc' , Npc[3]);
});
}
/* if (this.jigs.mobArray) {
this.jigs.mobArray.forEach(function loader(mob) {
createCharacterAnims(scene.anims, 'mob' + mob[4], 'default');
});
} */

if (this.jigs.mobArray) {
this.jigs.mobArray.forEach(function loader(mob) {
Expand All @@ -131,9 +86,6 @@ export default class Load {
});
}




if (this.jigs.switchesArray) {
this.jigs.switchesArray.forEach(function loader(switches) {
createSwitchesAnims(scene.anims,
Expand Down
26 changes: 26 additions & 0 deletions client/src/game/loaders/npcLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


/**
* -------npcLoader ---------
*/

import { useJigsStore } from '../../stores/jigs';

export default class NpcLoader {

jigs: any;

constructor() {
this.jigs = useJigsStore();
}

add(scene) {
console.log("------------NPC Loader---------------")

if (this.jigs.npcArray) {
this.jigs.npcArray.forEach(function loader(Npc) {
scene.load.spritesheet('npc' + Npc[3], '/assets/images/sprites/' + Npc[3] + '.png', { frameWidth: 64, frameHeight: 64 });
}, this);
}
}
}
28 changes: 28 additions & 0 deletions client/src/game/loaders/questLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@


/**
* -------questLoader ---------
*/

import { useJigsStore } from '../../stores/jigs';

export default class QuestLoader {

jigs: any;

constructor() {
this.jigs = useJigsStore();
}

add(scene) {
console.log("------------Quest Loader---------------")

if (this.jigs.questsArray) {
this.jigs.questsArray.forEach(function loader(questsItem) {
scene.load.spritesheet('quest_' + questsItem.id, '/assets/images/quest/' + questsItem.file + '.png',
{ frameWidth: questsItem.frameWidth, frameHeight: questsItem.frameHeight });
});
}

}
}
27 changes: 27 additions & 0 deletions client/src/game/loaders/switchLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


/**
* -------switchLoader ---------
*/

import { useJigsStore } from '../../stores/jigs';

export default class SwitchLoader {

jigs: any;

constructor() {
this.jigs = useJigsStore();
}

add(scene) {
console.log("------------Switch Loader---------------")

if (this.jigs.switchesArray) {
this.jigs.switchesArray.forEach(function loader(switchItem) {
scene.load.spritesheet('switch_' + switchItem.entity_id, '/assets/images/switches/' + switchItem.field_file_value,
{ frameWidth: parseInt(switchItem.field_frame_width_value), frameHeight: parseInt(switchItem.field_frame_height_value) });
});
}
}
}
48 changes: 48 additions & 0 deletions client/src/game/loaders/tilesetLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@


/**
* -------mobLoader ---------
*/

import { useJigsStore } from '../../stores/jigs';

export default class TilesetLoader {

jigs: any;

constructor() {
this.jigs = useJigsStore();
}

add(scene) {
console.log("------------Tileset Loader---------------")

this.jigs.tilesetArray_1.forEach(function loader(image) {
if (!textureManager.exists(image)) {
scene.load.image(image, '/assets/images/System/' + image + '.png');
}
}, this);

this.jigs.tilesetArray_2.forEach(function loader(image) {
if (!textureManager.exists(image)) {
scene.load.image(image, '/assets/images/System/' + image + '.png');
}
}, this);

this.jigs.tilesetArray_3.forEach(function loader(image) {
if (!textureManager.exists(image)) {
scene.load.image(image, '/assets/images/System/' + image + '.png');
}
}, this);

if (this.jigs.tilesetArray_4 !== undefined) {
this.jigs.tilesetArray_4.forEach(function loader(image) {
if (!textureManager.exists(image)) {
scene.load.image(image, '/assets/images/System/' + image + '.png');
}
}, this);


}
}
}

0 comments on commit 3e94bd8

Please sign in to comment.