Skip to content

Commit

Permalink
missions: make use of portalRemoved hook
Browse files Browse the repository at this point in the history
instead of Object.observe or monkey-patching iitc internals
  • Loading branch information
johndoe committed Jul 12, 2019
1 parent ff6dac5 commit c1d647a
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions plugins/missions.user.js
Expand Up @@ -1038,29 +1038,13 @@ window.plugin.missions = {

window.addHook('search', this.onSearch.bind(this));

/*
I know iitc has portalAdded event but it is missing portalDeleted. So we have to resort to Object.observe
*/
var me = this;
if (Object.observe) { // Chrome
Object.observe(window.portals, function(changes) {
changes.forEach(function(change) {
me.onPortalChanged(change.type, change.name, change.oldValue);
});
});
} else { // Firefox why no Object.observer ? :<
window.addHook('portalAdded', function(data) {
me.onPortalChanged('add', data.portal.options.guid, data.portal);
});
// TODO: bug iitc dev for portalRemoved event
var oldDeletePortal = window.Render.prototype.deletePortalEntity;
window.Render.prototype.deletePortalEntity = function(guid) {
if (guid in window.portals) {
me.onPortalChanged('delete', guid, window.portals[guid]);
}
oldDeletePortal.apply(this, arguments);
};
}
window.addHook('portalAdded', function(data) {
me.onPortalChanged('add', data.portal.options.guid, data.portal);
});
window.addHook('portalRemoved', function(data) {
me.onPortalChanged('delete', data.portal.options.guid, data.portal);
});

this.missionStartLayer = new L.LayerGroup();
this.missionLayer = new L.LayerGroup();
Expand Down

0 comments on commit c1d647a

Please sign in to comment.