@@ -45,11 +45,13 @@ define([ | |||
}); | |||
}, | |||
onGetClientConfig: function (config) { | |||
onGetClientConfig: async function (config) { | |||
globals.clientConfig = config; | |||
resources.init(config.resourceList); | |||
events.on('onResourcesLoaded', this.start.bind(this)); | |||
await resources.init(); | |||
events.emit('onResourcesLoaded'); | |||
this.start(); | |||
}, | |||
start: function () { | |||
@@ -6,7 +6,8 @@ define([ | |||
'js/rendering/tileOpacity', | |||
'js/rendering/particles', | |||
'js/rendering/shaders/outline', | |||
'js/rendering/spritePool' | |||
'js/rendering/spritePool', | |||
'js/system/globals' | |||
], function ( | |||
resources, | |||
events, | |||
@@ -15,7 +16,8 @@ define([ | |||
tileOpacity, | |||
particles, | |||
shaderOutline, | |||
spritePool | |||
spritePool, | |||
globals | |||
) { | |||
let pixi = PIXI; | |||
let mRandom = Math.random.bind(Math); | |||
@@ -91,29 +93,25 @@ define([ | |||
window.addEventListener('resize', this.onResize.bind(this)); | |||
$(this.renderer.view) | |||
.appendTo('.canvas-container'); | |||
$(this.renderer.view).appendTo('.canvas-container'); | |||
this.stage = new pixi.Container(); | |||
let layers = this.layers; | |||
Object.keys(layers).forEach(function (l) { | |||
Object.keys(layers).forEach(l => { | |||
layers[l] = new pixi.Container(); | |||
layers[l].layer = (l === 'tileSprites') ? 'tiles' : l; | |||
this.stage.addChild(layers[l]); | |||
}, this); | |||
let spriteNames = ['tiles', 'mobs', 'bosses', 'animBigObjects', 'bigObjects', 'objects', 'characters', 'attacks', 'auras', 'walls', 'ui', 'animChar', 'animMob', 'animBoss', 'white', 'ray']; | |||
resources.spriteNames.forEach(function (s) { | |||
if (s.indexOf('.png') > -1) | |||
spriteNames.push(s); | |||
}); | |||
spriteNames.forEach(function (t) { | |||
this.textures[t] = new pixi.BaseTexture(resources.sprites[t].image); | |||
const textureList = globals.clientConfig.textureList; | |||
const sprites = resources.sprites; | |||
textureList.forEach(t => { | |||
this.textures[t] = new pixi.BaseTexture(sprites[t]); | |||
this.textures[t].scaleMode = pixi.SCALE_MODES.NEAREST; | |||
}, this); | |||
}); | |||
particles.init({ | |||
r: this, | |||
@@ -1,66 +1,27 @@ | |||
define([ | |||
'js/system/events' | |||
'js/system/globals' | |||
], function ( | |||
events | |||
globals | |||
) { | |||
let resources = { | |||
spriteNames: [ | |||
'tiles', | |||
'walls', | |||
'mobs', | |||
'bosses', | |||
'animBigObjects', | |||
'bigObjects', | |||
'objects', | |||
'characters', | |||
'attacks', | |||
'ui', | |||
'auras', | |||
'animChar', | |||
'animMob', | |||
'animBoss', | |||
'white', | |||
'ray', | |||
'images/skins/0001.png', | |||
'images/skins/0010.png', | |||
'images/skins/0012.png' | |||
], | |||
return { | |||
sprites: {}, | |||
ready: false, | |||
init: function (list) { | |||
list.forEach(function (l) { | |||
this.spriteNames.push(l); | |||
}, this); | |||
this.spriteNames.forEach(function (s) { | |||
let sprite = { | |||
image: (new Image()), | |||
ready: false | |||
}; | |||
sprite.image.src = s.indexOf('png') > -1 ? s : 'images/' + s + '.png'; | |||
sprite.image.onload = this.onSprite.bind(this, sprite); | |||
init: async function () { | |||
const { sprites } = this; | |||
const { clientConfig: { resourceList, textureList } } = globals; | |||
this.sprites[s] = sprite; | |||
}, this); | |||
}, | |||
onSprite: function (sprite) { | |||
sprite.ready = true; | |||
const fullList = [].concat(resourceList, textureList); | |||
let readyCount = 0; | |||
for (let s in this.sprites) { | |||
if (this.sprites[s].ready) | |||
readyCount++; | |||
} | |||
return Promise.all(fullList.map(s => { | |||
return new Promise(res => { | |||
const spriteSource = s.includes('.png') ? s : `images/${s}.png`; | |||
if (readyCount === this.spriteNames.length) | |||
this.onReady(); | |||
}, | |||
onReady: function () { | |||
this.ready = true; | |||
events.emit('onResourcesLoaded'); | |||
const sprite = new Image(); | |||
sprites[s] = sprite; | |||
sprite.onload = res; | |||
sprite.src = spriteSource; | |||
}); | |||
})); | |||
} | |||
}; | |||
return resources; | |||
}); |
@@ -4,6 +4,27 @@ const tos = require('./tos'); | |||
const config = { | |||
logoPath: null, | |||
resourceList: [], | |||
textureList: [ | |||
'tiles', | |||
'walls', | |||
'mobs', | |||
'bosses', | |||
'animBigObjects', | |||
'bigObjects', | |||
'objects', | |||
'characters', | |||
'attacks', | |||
'ui', | |||
'auras', | |||
'animChar', | |||
'animMob', | |||
'animBoss', | |||
'white', | |||
'ray', | |||
'images/skins/0001.png', | |||
'images/skins/0010.png', | |||
'images/skins/0012.png' | |||
], | |||
uiList: [], | |||
contextMenuActions: { | |||
player: [], | |||
@@ -21,6 +42,7 @@ module.exports = { | |||
events.emit('onBeforeGetUiList', config.uiList); | |||
events.emit('onBeforeGetContextMenuActions', config.contextMenuActions); | |||
events.emit('onBeforeGetTermsOfService', config.tos); | |||
events.emit('onBeforeGetTextureList', config.textureList); | |||
}, | |||
getClientConfig: function (msg) { | |||