Skip to content

Commit

Permalink
Add test code
Browse files Browse the repository at this point in the history
  • Loading branch information
rexrainbow committed Dec 2, 2024
1 parent 832bdc3 commit fc14797
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/loader/load-complete-promise.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off
set main=./examples/loader/load-complete-promise.js
cd ..
cd ..
npm run dev
41 changes: 41 additions & 0 deletions examples/loader/load-complete-promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import phaser from 'phaser/src/phaser.js';
import LoadCompletePromise from '../../plugins/utils/loader/LoadCompletePromise';

class Demo extends Phaser.Scene {
constructor() {
super({
key: 'examples'
})
}

preload() {
LoadCompletePromise(this, {
type: 'image',
key: 'classroom',
url: 'assets/images/backgrounds/classroom.png'
})
.then(function (result) {
console.log(result)
})
}

create() {
this.add.image(400, 300, 'classroom');
}

update() { }
}

var config = {
type: Phaser.AUTO,
parent: 'phaser-example',
width: 800,
height: 600,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
},
scene: Demo
};

var game = new Phaser.Game(config);
19 changes: 19 additions & 0 deletions plugins/utils/loader/LoadCompletePromise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var LoadCompletePromise = function (scene, config) {
return new Promise(function (resolve, reject) {
var type = config.type;
delete config.type;
var key = config.key;
scene
.load[type](config)
.on(`filecomplete-${type}-${key}`, function (key, type, data) {
resolve({
key: key,
type: type,
data: data,
});
})
.start()
});
};

export default LoadCompletePromise;

0 comments on commit fc14797

Please sign in to comment.