Browse Source

Send paths of client components and wait for them to load

tags/v0.10.4^2
kckckc 2 years ago
parent
commit
b3ae64b37a
40 changed files with 93 additions and 63 deletions
  1. +67
    -57
      src/client/js/components/components.js
  2. +5
    -1
      src/client/js/main.js
  3. +0
    -0
      src/server/clientComponents/animation.js
  4. +0
    -0
      src/server/clientComponents/attackAnimation.js
  5. +0
    -0
      src/server/clientComponents/bumpAnimation.js
  6. +0
    -0
      src/server/clientComponents/chatter.js
  7. +0
    -0
      src/server/clientComponents/chest.js
  8. +0
    -0
      src/server/clientComponents/dialogue.js
  9. +0
    -0
      src/server/clientComponents/effects.js
  10. +0
    -0
      src/server/clientComponents/events.js
  11. +0
    -0
      src/server/clientComponents/explosion.js
  12. +0
    -0
      src/server/clientComponents/fadeInOut.js
  13. +0
    -0
      src/server/clientComponents/flash.js
  14. +0
    -0
      src/server/clientComponents/gatherer.js
  15. +0
    -0
      src/server/clientComponents/inventory.js
  16. +0
    -0
      src/server/clientComponents/keyboardMover.js
  17. +0
    -0
      src/server/clientComponents/light.js
  18. +0
    -0
      src/server/clientComponents/lightPatch.js
  19. +0
    -0
      src/server/clientComponents/lightningEffect.js
  20. +0
    -0
      src/server/clientComponents/mouseMover.js
  21. +0
    -0
      src/server/clientComponents/moveAnimation.js
  22. +0
    -0
      src/server/clientComponents/particles.js
  23. +0
    -0
      src/server/clientComponents/passives.js
  24. +0
    -0
      src/server/clientComponents/pather.js
  25. +0
    -0
      src/server/clientComponents/player.js
  26. +0
    -0
      src/server/clientComponents/projectile.js
  27. +0
    -0
      src/server/clientComponents/quests.js
  28. +0
    -0
      src/server/clientComponents/reputation.js
  29. +0
    -0
      src/server/clientComponents/resourceNode.js
  30. +0
    -0
      src/server/clientComponents/serverActions.js
  31. +0
    -0
      src/server/clientComponents/social.js
  32. +0
    -0
      src/server/clientComponents/sound.js
  33. +0
    -0
      src/server/clientComponents/spellbook.js
  34. +0
    -0
      src/server/clientComponents/stash.js
  35. +0
    -0
      src/server/clientComponents/stats.js
  36. +0
    -0
      src/server/clientComponents/touchMover.js
  37. +0
    -0
      src/server/clientComponents/trade.js
  38. +0
    -0
      src/server/clientComponents/whirlwind.js
  39. +12
    -0
      src/server/config/clientConfig.js
  40. +9
    -5
      src/server/server/requestHandlers.js

+ 67
- 57
src/client/js/components/components.js View File

@@ -1,50 +1,51 @@
let components = [
'keyboardMover',
'mouseMover',
'touchMover',
'player',
'pather',
'attackAnimation',
'lightningEffect',
'moveAnimation',
'bumpAnimation',
'animation',
'light',
'lightPatch',
'projectile',
'particles',
'explosion',
'spellbook',
'inventory',
'stats',
'chest',
'effects',
'quests',
'events',
'resourceNode',
'gatherer',
'stash',
'flash',
'chatter',
'dialogue',
'trade',
'reputation',
'serverActions',
'social',
'passives',
'sound',
'whirlwind',
'fadeInOut'
].map(function (c) {
return 'js/components/' + c;
});
// let components = [
// 'keyboardMover',
// 'mouseMover',
// 'touchMover',
// 'player',
// 'pather',
// 'attackAnimation',
// 'lightningEffect',
// 'moveAnimation',
// 'bumpAnimation',
// 'animation',
// 'light',
// 'lightPatch',
// 'projectile',
// 'particles',
// 'explosion',
// 'spellbook',
// 'inventory',
// 'stats',
// 'chest',
// 'effects',
// 'quests',
// 'events',
// 'resourceNode',
// 'gatherer',
// 'stash',
// 'flash',
// 'chatter',
// 'dialogue',
// 'trade',
// 'reputation',
// 'serverActions',
// 'social',
// 'passives',
// 'sound',
// 'whirlwind',
// 'fadeInOut'
// ].map(function (c) {
// return 'js/components/' + c;
// });

define([
...components,
'../system/events'
], function () {
const events = arguments[arguments.length - 1];
'js/system/events',
'js/system/globals'
], function (
events,
globals
) {
const hookEvent = function (e, cb) {
if (!this.eventList[e])
this.eventList[e] = [];
@@ -59,26 +60,35 @@ define([
});
};

let templates = {};
return {
templates: {},

init: function () {
let cpns = globals.clientConfig.clientComponents;
return Promise.all(cpns.map(c => this.getComponent(c)));
},

[].forEach.call(arguments, function (t, i) {
//Don't do this for the events module
if (i === arguments[2].length - 1)
return;
getComponent: function (cpn) {
return new Promise(resolve => {
require([cpn.path], this.onGetComponent.bind(this, resolve, cpn));
});
},

t.eventList = {};
t.hookEvent = hookEvent;
t.unhookEvents = unhookEvents;
onGetComponent: function (resolve, cpn, template) {
template.eventList = {};
template.hookEvent = hookEvent;
template.unhookEvents = unhookEvents;

templates[t.type] = t;
});
this.templates[cpn.type] = template;

return {
resolve();
},
getTemplate: function (type) {
if (type === 'lightpatch')
type = 'lightPatch';

let template = templates[type] || {
let template = this.templates[type] || {
type: type
};



+ 5
- 1
src/client/js/main.js View File

@@ -10,6 +10,7 @@ define([
'js/resources',
'js/sound/sound',
'js/system/globals',
'js/components/components',
'ui/templates/online/online',
'ui/templates/tooltips/tooltips'
], function (
@@ -23,7 +24,8 @@ define([
events,
resources,
sound,
globals
globals,
components
) {
let fnQueueTick = null;
const getQueueTick = updateMethod => {
@@ -69,6 +71,8 @@ define([
globals.clientConfig = config;

await resources.init();
await components.init();
events.emit('onResourcesLoaded');

this.start();


src/client/js/components/animation.js → src/server/clientComponents/animation.js View File


src/client/js/components/attackAnimation.js → src/server/clientComponents/attackAnimation.js View File


src/client/js/components/bumpAnimation.js → src/server/clientComponents/bumpAnimation.js View File


src/client/js/components/chatter.js → src/server/clientComponents/chatter.js View File


src/client/js/components/chest.js → src/server/clientComponents/chest.js View File


src/client/js/components/dialogue.js → src/server/clientComponents/dialogue.js View File


src/client/js/components/effects.js → src/server/clientComponents/effects.js View File


src/client/js/components/events.js → src/server/clientComponents/events.js View File


src/client/js/components/explosion.js → src/server/clientComponents/explosion.js View File


src/client/js/components/fadeInOut.js → src/server/clientComponents/fadeInOut.js View File


src/client/js/components/flash.js → src/server/clientComponents/flash.js View File


src/client/js/components/gatherer.js → src/server/clientComponents/gatherer.js View File


src/client/js/components/inventory.js → src/server/clientComponents/inventory.js View File


src/client/js/components/keyboardMover.js → src/server/clientComponents/keyboardMover.js View File


src/client/js/components/light.js → src/server/clientComponents/light.js View File


src/client/js/components/lightPatch.js → src/server/clientComponents/lightPatch.js View File


src/client/js/components/lightningEffect.js → src/server/clientComponents/lightningEffect.js View File


src/client/js/components/mouseMover.js → src/server/clientComponents/mouseMover.js View File


src/client/js/components/moveAnimation.js → src/server/clientComponents/moveAnimation.js View File


src/client/js/components/particles.js → src/server/clientComponents/particles.js View File


src/client/js/components/passives.js → src/server/clientComponents/passives.js View File


src/client/js/components/pather.js → src/server/clientComponents/pather.js View File


src/client/js/components/player.js → src/server/clientComponents/player.js View File


src/client/js/components/projectile.js → src/server/clientComponents/projectile.js View File


src/client/js/components/quests.js → src/server/clientComponents/quests.js View File


src/client/js/components/reputation.js → src/server/clientComponents/reputation.js View File


src/client/js/components/resourceNode.js → src/server/clientComponents/resourceNode.js View File


src/client/js/components/serverActions.js → src/server/clientComponents/serverActions.js View File


src/client/js/components/social.js → src/server/clientComponents/social.js View File


src/client/js/components/sound.js → src/server/clientComponents/sound.js View File


src/client/js/components/spellbook.js → src/server/clientComponents/spellbook.js View File


src/client/js/components/stash.js → src/server/clientComponents/stash.js View File


src/client/js/components/stats.js → src/server/clientComponents/stats.js View File


src/client/js/components/touchMover.js → src/server/clientComponents/touchMover.js View File


src/client/js/components/trade.js → src/server/clientComponents/trade.js View File


src/client/js/components/whirlwind.js → src/server/clientComponents/whirlwind.js View File


+ 12
- 0
src/server/config/clientConfig.js View File

@@ -1,6 +1,7 @@
const imageSize = require('image-size');

const events = require('../misc/events');
const fileLister = require('../misc/fileLister');
const tos = require('./tos');

const config = {
@@ -197,6 +198,7 @@ const config = {
player: [],
npc: []
},
clientComponents: [],
sounds: {
ui: []
},
@@ -207,6 +209,16 @@ module.exports = {
config,

init: async function () {
fileLister.getFolder('./clientComponents').forEach(f => {
const type = f.split('.')[0];
const path = 'server/clientComponents/' + f;

config.clientComponents.push({
type,
path
});
});

events.emit('onBeforeGetClientConfig', config);

//Deprecated


+ 9
- 5
src/server/server/requestHandlers.js View File

@@ -11,13 +11,17 @@ const appFile = (req, res) => {
let file = req.params[0];
file = file.replace('/' + root + '/', '');
const validRequest = (
root !== 'server' ||
(
file.includes('mods/') &&
validModPatterns.some(v => file.includes(v))
)
(
root === 'server' &&
file.startsWith('clientComponents/')
) ||
(
file.includes('mods/') &&
validModPatterns.some(v => file.includes(v))
)
);
if (!validRequest)


Loading…
Cancel
Save