Skip to content

Commit 3e94bd8

Browse files
authored
Merge pull request #208 from Techbot/207-split-loader-class
split loaders
2 parents 7e5d92d + 353cdd5 commit 3e94bd8

6 files changed

Lines changed: 178 additions & 72 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* -------bossLoader ---------
3+
*/
4+
5+
import { useJigsStore } from '../../stores/jigs';
6+
7+
export default class BossLoader {
8+
9+
jigs: any;
10+
11+
constructor() {
12+
this.jigs = useJigsStore();
13+
}
14+
15+
add(scene) {
16+
console.log("---------------Boss Loader-------------")
17+
18+
if (this.jigs.bossesArray) {
19+
this.jigs.bossesArray.forEach(function loader(boss) {
20+
scene.load.spritesheet('boss_' + boss.boss, '/assets/images/Level Bosses/' + boss.boss + '.png',
21+
{ frameWidth: parseInt(boss.field_frame_width), frameHeight: parseInt(boss.field_frame_height) });
22+
});
23+
}
24+
}
25+
}

client/src/game/loaders/loader.ts

Lines changed: 24 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,33 @@ import { createCharacterAnims } from "../entities/anim";
99
import { createSwitchesAnims } from "../entities/anim";
1010
import { createBossAnims } from "../entities/anim";
1111
import MobLoader from "./mobLoader"
12-
12+
import BossLoader from "./bossLoader"
13+
import NpcLoader from "./npcLoader"
14+
import TilesetLoader from "./tilesetLoader"
15+
import SwitchLoader from "./switchLoader"
16+
import QuestLoader from "./questLoader"
1317

1418
export default class Load {
1519

1620
jigs: any;
1721
npcs: any;
1822
sprite: any;
19-
mobloader: any;
23+
mobLoader: any;
24+
bossLoader: any;
25+
npcLoader: any;
26+
tilesetLoader: any;
27+
switchLoader: any;
28+
questLoader: any;
2029

2130
constructor() {
2231
this.jigs = useJigsStore();
23-
this.mobloader= new MobLoader();
32+
this.mobLoader= new MobLoader();
33+
this.bossLoader = new BossLoader();
34+
this.npcLoader = new NpcLoader();
35+
this.tilesetLoader = new TilesetLoader();
36+
this.switchLoader = new SwitchLoader();
37+
this.questLoader = new QuestLoader();
38+
2439
}
2540

2641
padding(n, p, c) {
@@ -37,66 +52,12 @@ export default class Load {
3752
scene.load.image('pink', '/assets/images/pink.png');
3853
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());
3954

40-
this.jigs.tilesetArray_1.forEach(function loader(image) {
41-
if (!textureManager.exists(image)) {
42-
scene.load.image(image, '/assets/images/System/' + image + '.png');
43-
}
44-
}, this);
45-
46-
this.jigs.tilesetArray_2.forEach(function loader(image) {
47-
if (!textureManager.exists(image)) {
48-
scene.load.image(image, '/assets/images/System/' + image + '.png');
49-
}
50-
}, this);
51-
52-
this.jigs.tilesetArray_3.forEach(function loader(image) {
53-
if (!textureManager.exists(image)) {
54-
scene.load.image(image, '/assets/images/System/' + image + '.png');
55-
}
56-
}, this);
57-
58-
if (this.jigs.tilesetArray_4 !== undefined) {
59-
this.jigs.tilesetArray_4.forEach(function loader(image) {
60-
if (!textureManager.exists(image)) {
61-
scene.load.image(image, '/assets/images/System/' + image + '.png');
62-
}
63-
}, this);
64-
}
65-
66-
if (this.jigs.npcArray) {
67-
this.jigs.npcArray.forEach(function loader(Npc) {
68-
scene.load.spritesheet('npc' + Npc[3], '/assets/images/sprites/' + Npc[3] + '.png', { frameWidth: 64, frameHeight: 64 });
69-
}, this);
70-
}
71-
72-
/* if (this.jigs.mobArray) {
73-
this.jigs.mobArray.forEach(function loader(Mob) {
74-
scene.load.spritesheet('mob' + Mob[4], '/assets/images/sprites/' + Mob[4] + '.png', { frameWidth: 64, frameHeight: 64 });
75-
}, this);
76-
} */
77-
this.mobloader.add(scene);
78-
79-
80-
if (this.jigs.bossesArray) {
81-
this.jigs.bossesArray.forEach(function loader(boss) {
82-
scene.load.spritesheet('boss_' + boss.boss, '/assets/images/Level Bosses/' + boss.boss +'.png',
83-
{ frameWidth: parseInt(boss.field_frame_width), frameHeight: parseInt(boss.field_frame_height) });
84-
});
85-
}
86-
87-
if (this.jigs.switchesArray) {
88-
this.jigs.switchesArray.forEach(function loader(switchItem) {
89-
scene.load.spritesheet('switch_' + switchItem.entity_id, '/assets/images/switches/' + switchItem.field_file_value ,
90-
{ frameWidth: parseInt(switchItem.field_frame_width_value), frameHeight: parseInt(switchItem.field_frame_height_value) });
91-
});
92-
}
93-
94-
if (this.jigs.questsArray) {
95-
this.jigs.questsArray.forEach(function loader(questsItem) {
96-
scene.load.spritesheet('quest_' + questsItem.id, '/assets/images/quest/' + questsItem.file + '.png',
97-
{ frameWidth: questsItem.frameWidth, frameHeight: questsItem.frameHeight });
98-
});
99-
}
55+
this.tilesetLoader.add(scene);
56+
this.npcLoader.add(scene);
57+
this.mobLoader.add(scene);
58+
this.bossLoader.add(scene);
59+
this.switchLoader.add(scene);
60+
this.questLoader.add(scene);
10061

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

10768
createCharacterAnims(scene.anims, 'player', null);
108-
10969
createCharacterAnims(scene.anims, 'otherPlayer', null);
11070

11171
if (this.jigs.npcArray) {
11272
this.jigs.npcArray.forEach(function loader(Npc) {
11373
createCharacterAnims(scene.anims, 'npc' , Npc[3]);
11474
});
11575
}
116-
/* if (this.jigs.mobArray) {
117-
this.jigs.mobArray.forEach(function loader(mob) {
118-
createCharacterAnims(scene.anims, 'mob' + mob[4], 'default');
119-
});
120-
} */
12176

12277
if (this.jigs.mobArray) {
12378
this.jigs.mobArray.forEach(function loader(mob) {
@@ -131,9 +86,6 @@ export default class Load {
13186
});
13287
}
13388

134-
135-
136-
13789
if (this.jigs.switchesArray) {
13890
this.jigs.switchesArray.forEach(function loader(switches) {
13991
createSwitchesAnims(scene.anims,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
3+
/**
4+
* -------npcLoader ---------
5+
*/
6+
7+
import { useJigsStore } from '../../stores/jigs';
8+
9+
export default class NpcLoader {
10+
11+
jigs: any;
12+
13+
constructor() {
14+
this.jigs = useJigsStore();
15+
}
16+
17+
add(scene) {
18+
console.log("------------NPC Loader---------------")
19+
20+
if (this.jigs.npcArray) {
21+
this.jigs.npcArray.forEach(function loader(Npc) {
22+
scene.load.spritesheet('npc' + Npc[3], '/assets/images/sprites/' + Npc[3] + '.png', { frameWidth: 64, frameHeight: 64 });
23+
}, this);
24+
}
25+
}
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
3+
/**
4+
* -------questLoader ---------
5+
*/
6+
7+
import { useJigsStore } from '../../stores/jigs';
8+
9+
export default class QuestLoader {
10+
11+
jigs: any;
12+
13+
constructor() {
14+
this.jigs = useJigsStore();
15+
}
16+
17+
add(scene) {
18+
console.log("------------Quest Loader---------------")
19+
20+
if (this.jigs.questsArray) {
21+
this.jigs.questsArray.forEach(function loader(questsItem) {
22+
scene.load.spritesheet('quest_' + questsItem.id, '/assets/images/quest/' + questsItem.file + '.png',
23+
{ frameWidth: questsItem.frameWidth, frameHeight: questsItem.frameHeight });
24+
});
25+
}
26+
27+
}
28+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
3+
/**
4+
* -------switchLoader ---------
5+
*/
6+
7+
import { useJigsStore } from '../../stores/jigs';
8+
9+
export default class SwitchLoader {
10+
11+
jigs: any;
12+
13+
constructor() {
14+
this.jigs = useJigsStore();
15+
}
16+
17+
add(scene) {
18+
console.log("------------Switch Loader---------------")
19+
20+
if (this.jigs.switchesArray) {
21+
this.jigs.switchesArray.forEach(function loader(switchItem) {
22+
scene.load.spritesheet('switch_' + switchItem.entity_id, '/assets/images/switches/' + switchItem.field_file_value,
23+
{ frameWidth: parseInt(switchItem.field_frame_width_value), frameHeight: parseInt(switchItem.field_frame_height_value) });
24+
});
25+
}
26+
}
27+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
3+
/**
4+
* -------mobLoader ---------
5+
*/
6+
7+
import { useJigsStore } from '../../stores/jigs';
8+
9+
export default class TilesetLoader {
10+
11+
jigs: any;
12+
13+
constructor() {
14+
this.jigs = useJigsStore();
15+
}
16+
17+
add(scene) {
18+
console.log("------------Tileset Loader---------------")
19+
20+
this.jigs.tilesetArray_1.forEach(function loader(image) {
21+
if (!textureManager.exists(image)) {
22+
scene.load.image(image, '/assets/images/System/' + image + '.png');
23+
}
24+
}, this);
25+
26+
this.jigs.tilesetArray_2.forEach(function loader(image) {
27+
if (!textureManager.exists(image)) {
28+
scene.load.image(image, '/assets/images/System/' + image + '.png');
29+
}
30+
}, this);
31+
32+
this.jigs.tilesetArray_3.forEach(function loader(image) {
33+
if (!textureManager.exists(image)) {
34+
scene.load.image(image, '/assets/images/System/' + image + '.png');
35+
}
36+
}, this);
37+
38+
if (this.jigs.tilesetArray_4 !== undefined) {
39+
this.jigs.tilesetArray_4.forEach(function loader(image) {
40+
if (!textureManager.exists(image)) {
41+
scene.load.image(image, '/assets/images/System/' + image + '.png');
42+
}
43+
}, this);
44+
45+
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)