Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin "Scoreboard": Include information on Machina #746

Merged
merged 6 commits into from
Aug 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 36 additions & 33 deletions plugins/scoreboard.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// @author Costaspap
// @name Localized scoreboard
// @version 0.3.4
// @version 0.4.0
// @category Info
// @description Display a scoreboard about all visible portals with statistics about both teams,like average portal level,link & field counts etc.

/* global IITC -- eslint */
/* exported setup, changelog --eslint */

var changelog = [
{
version: '0.4.0',
changes: ['Includes information on Machina'],
},
{
version: '0.3.4',
changes: ['IITC.toolbox API is used to create plugin buttons'],
Expand Down Expand Up @@ -55,7 +59,7 @@ function getPortalsInfo (portals,bounds) {
});

if (portals.length) {
[TEAM_RES,TEAM_ENL].forEach(function (teamN) {
[window.TEAM_RES, window.TEAM_ENL, window.TEAM_MAC].forEach(function (teamN) {
var team = score[teamN];
team.health = team.total ? (team.health/team.total).toFixed(1)+'%' : '-';
team.levels = team.total ? (team.levels/team.total).toFixed(1) : '-';
Expand All @@ -64,8 +68,9 @@ function getPortalsInfo (portals,bounds) {
team.total = team.placeHolders ? team.total + ' + ' + team.placeHolders : team.total;
});
return {
enl: score[TEAM_ENL],
res: score[TEAM_RES]
enl: score[window.TEAM_ENL],
res: score[window.TEAM_RES],
mac: score[window.TEAM_MAC],
};
}
}
Expand All @@ -86,41 +91,37 @@ function getEntitiesCount (entities,bounds) {
return {
enl: counts[window.TEAM_ENL] || 0,
res: counts[window.TEAM_RES] || 0,
mac: counts[window.TEAM_MAC] || 0,
};
}

function makeTable (portals,linksCount,fieldsCount) {

var html = '';
html += '<table>'
+ '<colgroup><col><col class="enl"><col class="res"></colgroup>'
+ '<tr>'
+ '<th>Metrics</th>'
+ '<th class="enl">Enlightened</th>'
+ '<th class="res">Resistance</th>'
+ '</tr>\n';

html += '<tr><td>Portals</td>'
+'<td>'+portals.enl.total+'</td>'
+'<td>'+portals.res.total+'</td></tr>'
+'<tr><td>avg Level</td>'
+'<td>'+portals.enl.levels+'</td>'
+'<td>'+portals.res.levels+'</td></tr>'
+ '<tr><td>avg Health</td>'
+'<td>'+portals.enl.health+'</td>'
+'<td>'+portals.res.health+'</td></tr>'
+'<tr><td>Level 8</td>'
+'<td>'+portals.enl.level8+'</td>'
+'<td>'+portals.res.level8+'</td></tr>'
+'<tr><td>Max Level</td>'
+'<td>'+portals.enl.maxLevel+'</td>'
+'<td>'+portals.res.maxLevel+'</td></tr>'
+'<tr><td>Links</td>'
+'<td>'+linksCount.enl+'</td>'
+'<td>'+linksCount.res+'</td></tr>'
+'<tr><td>Fields</td>'
+'<td>'+fieldsCount.enl+'</td>'
+'<td>'+fieldsCount.res+'</td></tr>';
html +=
'<table>' +
'<colgroup><col><col class="enl"><col class="res"><col class="mac"></colgroup>' +
'<tr>' +
'<th>Metrics</th>' +
'<th class="enl">Enlightened</th>' +
'<th class="res">Resistance</th>' +
'<th class="mac">__MACHINA__</th>' +
'</tr>\n';

const lines = [
['Portals', portals.enl.total, portals.res.total, portals.mac.total],
['avg Level', portals.enl.levels, portals.res.levels, portals.mac.levels],
['avg Health', portals.enl.health, portals.res.health, portals.mac.health],
['Level 8', portals.enl.level8, portals.res.level8, portals.mac.level8],
['Max Level', portals.enl.maxLevel, portals.res.maxLevel, portals.mac.maxLevel],
['Links', linksCount.enl, linksCount.res, linksCount.mac],
['Fields', fieldsCount.enl, fieldsCount.res, fieldsCount.mac],
];

html += lines.map((line) => {
const cells = line.map((cell) => `<td>${cell}</td>`);
return `<tr>${cells}</tr>`;
});

html += '</table>';
return html;
Expand Down Expand Up @@ -153,6 +154,7 @@ function displayScoreboard () {
} else {
dialog({
html: html,
width: 'auto',
dialogClass: 'ui-dialog-scoreboard',
title: 'Scoreboard',
id: 'Scoreboard'
Expand Down Expand Up @@ -184,6 +186,7 @@ function setup () {
#scoreboard td, #scoreboard th { padding: 3px 10px; text-align: left; }\
#scoreboard col.enl { background-color: #017f01; }\
#scoreboard col.res { background-color: #005684; }\
#scoreboard col.mac { background-color: #7f3333; }\
#scoreboard .disclaimer { margin-top: 10px; color: yellow; }\
#scoreboard.mobile { position: absolute; top: 0; width: 100%; }\
').appendTo('head');
Expand Down
Loading