Browse Source

fixes #1122

tags/v0.3.2
Big Bad Waffle 5 years ago
parent
commit
e42b44bb14
7 changed files with 57 additions and 8 deletions
  1. +29
    -2
      src/client/js/components/components.js
  2. +5
    -1
      src/client/js/components/gatherer.js
  3. +5
    -1
      src/client/js/components/keyboardMover.js
  4. +4
    -2
      src/client/js/components/mouseMover.js
  5. +4
    -0
      src/client/js/components/pather.js
  6. +5
    -1
      src/client/js/components/player.js
  7. +5
    -1
      src/client/js/components/serverActions.js

+ 29
- 2
src/client/js/components/components.js View File

@@ -37,10 +37,37 @@ let components = [
return 'js/components/' + c;
});

define(components, function () {
define([
...components,
'../system/events'
], function () {
const events = arguments[arguments.length - 1];
const hookEvent = function (e, cb) {
if (!this.eventList[e])
this.eventList[e] = [];

this.eventList[e].push(cb);
events.on(e, cb);
};

const unhookEvents = function () {
Object.entries(this.eventList).forEach(([eventName, callbacks]) => {
callbacks.forEach(c => events.off(eventName, c));
});
};

let templates = {};

[].forEach.call(arguments, function (t) {
[].forEach.call(arguments, function (t, i) {
//Don't do this for the events module
if (i === arguments.length - 1)
return;

t.eventList = {};
t.hookEvent = hookEvent.bind(t);
t.unhookEvents = unhookEvents.bind(t);

templates[t.type] = t;
});



+ 5
- 1
src/client/js/components/gatherer.js View File

@@ -13,7 +13,7 @@ define([

init: function () {
this.obj.on('onKeyDown', this.onKeyDown.bind(this));
events.on('onRezone', this.onRezone.bind(this));
this.hookEvent('onRezone', this.onRezone.bind(this));
},

extend: function (msg) {
@@ -72,6 +72,10 @@ define([
method: 'gather'
}
});
},

destroy: function () {
this.unhookEvents();
}
};
});

+ 5
- 1
src/client/js/components/keyboardMover.js View File

@@ -16,7 +16,7 @@ define([
moveCdMax: 8,

init: function () {
events.on('onCanvasKeyDown', this.onCanvasKeyDown.bind(this));
this.hookEvent('onCanvasKeyDown', this.onCanvasKeyDown.bind(this));
},

update: function () {
@@ -74,6 +74,10 @@ define([
this.moveCd = this.moveCdMax;

this.obj.pather.add(newX, newY);
},

destroy: function () {
this.unhookEvents();
}
};
});

+ 4
- 2
src/client/js/components/mouseMover.js View File

@@ -29,8 +29,8 @@ define([
sprite: null,

init: function () {
events.on('onUiHover', this.onUiHover.bind(this, true));
events.on('onUiLeave', this.onUiHover.bind(this, false));
this.hookEvent('onUiHover', this.onUiHover.bind(this, true));
this.hookEvent('onUiLeave', this.onUiHover.bind(this, false));

this.sprite = renderer.buildObject({
layerName: 'effects',
@@ -76,6 +76,8 @@ define([
renderer.destroyObject({
sprite: this.sprite
});

this.unhookEvents();
}
};
});

+ 4
- 0
src/client/js/components/pather.js View File

@@ -116,6 +116,10 @@ define([
return;
}
}
},

destroy: function () {
this.unhookEvents();
}
};
});

+ 5
- 1
src/client/js/components/player.js View File

@@ -30,7 +30,7 @@ define([
obj.addComponent('serverActions');
obj.addComponent('pather');

events.on('onRespawn', this.onRespawn.bind(this));
this.hookEvent('onRespawn', this.onRespawn.bind(this));

events.emit('onGetPortrait', obj.portrait);
},
@@ -70,6 +70,10 @@ define([

onRespawn: function (position) {
this.positionCamera(position.x, position.y, true);
},

destroy: function () {
this.unhookEvents();
}
};
});

+ 5
- 1
src/client/js/components/serverActions.js View File

@@ -11,7 +11,7 @@ define([
actions: [],

init: function (blueprint) {
events.on('onKeyUp', this.onKeyUp.bind(this));
this.hookEvent('onKeyUp', this.onKeyUp.bind(this));
},

onKeyUp: function (key) {
@@ -55,6 +55,10 @@ define([
}

events.emit('onGetServerActions', this.actions);
},

destroy: function () {
this.unhookEvents();
}
};
});

Loading…
Cancel
Save