IITC-CE / ingress-intel-total-conversion

intel.ingress.com total conversion user script with some new features. Should allow easier extension of the intel map.
https://iitc.app
ISC License
290 stars 109 forks source link

better API for highlighters #105

Open johnd0e opened 5 years ago

johnd0e commented 5 years ago

https://github.com/IITC-CE/ingress-intel-total-conversion/blob/d77562b91a5b1e0bf170b4257eb33316a0b9daa3/code/portal_marker.js#L27-L40

As we can see API change was planned a long ago.

It is needed in order to simplify marker styles cascading and better incapsulation of internals.

In code above there is 3 consequent calls of the same function marker.setStyle. We could use just 1, if highlighter return style (instead of setting it inside).

johnd0e commented 5 years ago

We can keep window.addPortalHighlighter for compatibility with old plugins, and use separate function for registering hiliters using new api.

BTW, we should think about what argument needed for hiliter function. Currently it is single object data containing just one property: {portal:marker}. We could pass portal data/details directly instead.

angel93ayora commented 5 years ago

so the API should:

what to do when two higlighetrs can be applied at once?

johnd0e commented 5 years ago

what to do when two higlighetrs can be applied at once?

It is impossible currently.

But if it would be possible then we could cascade them, inheriting styles elements from both.

johnd0e commented 5 years ago

Here is very preliminary concept:

function highlight (data) { //  marker.options
  // ...
  var style = {
    // ...
  };
  return style;
}

window.addPortalHighlighter('New highlighter', highlight); // todo: distinguish between old and new api

Todo: actually API is more complex, and besides highlite there is also setSelected callback (https://github.com/iitc-project/ingress-intel-total-conversion/issues/643#issuecomment-28465025). It is currently used in 1 official plugin: https://github.com/IITC-CE/ingress-intel-total-conversion/blob/d77562b91a5b1e0bf170b4257eb33316a0b9daa3/plugins/uniques.user.js#L402-L404

P.S. Also I found a couple of unofficial: iitc-plugin-keyhunt, iitc-plugin-highlight-almost-L8