Quellcode durchsuchen

fixes #1122

tags/v0.3.2
Big Bad Waffle vor 5 Jahren
Ursprung
Commit
e42b44bb14
7 geänderte Dateien mit 57 neuen und 8 gelöschten Zeilen
  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 Datei anzeigen

@@ -37,10 +37,37 @@ let components = [
return 'js/components/' + c; 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 = {}; 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; templates[t.type] = t;
}); });




+ 5
- 1
src/client/js/components/gatherer.js Datei anzeigen

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


init: function () { init: function () {
this.obj.on('onKeyDown', this.onKeyDown.bind(this)); 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) { extend: function (msg) {
@@ -72,6 +72,10 @@ define([
method: 'gather' method: 'gather'
} }
}); });
},

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

+ 5
- 1
src/client/js/components/keyboardMover.js Datei anzeigen

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


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


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


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

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

+ 4
- 2
src/client/js/components/mouseMover.js Datei anzeigen

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


init: function () { 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({ this.sprite = renderer.buildObject({
layerName: 'effects', layerName: 'effects',
@@ -76,6 +76,8 @@ define([
renderer.destroyObject({ renderer.destroyObject({
sprite: this.sprite sprite: this.sprite
}); });

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

+ 4
- 0
src/client/js/components/pather.js Datei anzeigen

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

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

+ 5
- 1
src/client/js/components/player.js Datei anzeigen

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


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


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


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

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

+ 5
- 1
src/client/js/components/serverActions.js Datei anzeigen

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


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


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


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

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

Laden…
Abbrechen
Speichern