iitc-project / ingress-intel-total-conversion

ingress.com/intel total conversion user script with some new features. Should allow easier extension of the intel map.
http://iitc.jonatkins.com/
ISC License
991 stars 552 forks source link

Feature request: modify team value #984

Closed Speeddymon closed 9 years ago

Speeddymon commented 9 years ago

I opened an issue yesterday before I had all of the facts. Now that I've dug into it more, I decided to close the issue and open this one instead.

The window.portals object currently sets the portal.options.team value for each portal to the same as stock intel, 0 for neutral, 1 for resistance, 2 for enlightened. This causes some plugins to have to work around the lack of separation for neutral portals by adding 1 to the value. One such example appears at lines 282 and 283 of the portals list plugin:

  if(filter !== 0) {
    portals = portals.filter(function(obj) {
      return filter < 0
        ? obj.portal.options.team+1 != -filter
        : obj.portal.options.team+1 == filter;
    });
  }

The code in question is obj.portal.options.team+1

This type of hack can be found in other parts of the code and while it works, it feels ugly.

I feel that a workaround for this would be to have IITC create a copy of window.portals that it presents to plugins with the value of portal.options.team already increased by one. Plugins such as portals list could be updated to use this copy instead of the raw stock intel data, in order for them to differentiate between all portals and neutral portals, which would allow them to remove hacks such as this.

jonatkins commented 9 years ago

There's nothing specific about the 0/1/2 values for the team - nothing to do with stock intel.

To improve clarity, code should use the named constants rather than magic numbers, but a few older plugins don't do this.

window.TEAM_NONE = 0;
window.TEAM_RES = 1;
window.TEAM_ENL = 2;

Conversion from the raw data is done by this function (usually - a few pieces of code may do it differently)

window.teamStringToId = function(teamStr) {
  var team = TEAM_NONE;
  if(teamStr === 'ENLIGHTENED') team = TEAM_ENL;
  if(teamStr === 'RESISTANCE') team = TEAM_RES;
  if(teamStr === 'E') team = TEAM_ENL;
  if(teamStr === 'R') team = TEAM_RES;
  return team;
}

the portals-list plugin does have some ugliness with it's handling of team values - but those issues are entirely within that plugin, not anything 'wrong' with the rest of IITC or how the values are used.

Speeddymon commented 9 years ago

Thanks, I'll look into making some cleanups inside the plugin and submitting a pull request On Apr 18, 2015 11:37 AM, "Jon Atkins" notifications@github.com wrote:

There's nothing specific about the 0/1/2 values for the team - nothing to do with stock intel.

To improve clarity, code should use the named constants rather than magic numbers, but a few older plugins don't do this.

window.TEAM_NONE = 0;window.TEAM_RES = 1;window.TEAM_ENL = 2;

Conversion from the raw data is done by this function (usually - a few pieces of code may do it differently)

window.teamStringToId = function(teamStr) { var team = TEAM_NONE; if(teamStr === 'ENLIGHTENED') team = TEAM_ENL; if(teamStr === 'RESISTANCE') team = TEAM_RES; if(teamStr === 'E') team = TEAM_ENL; if(teamStr === 'R') team = TEAM_RES; return team; }

the portals-list plugin does have some ugliness with it's handling of team values - but those issues are entirely within that plugin, not anything 'wrong' with the rest of IITC or how the values are used.

— Reply to this email directly or view it on GitHub https://github.com/jonatkins/ingress-intel-total-conversion/issues/984#issuecomment-94179467 .