Skip to content

Commit 51aa891

Browse files
committed
v2.1.0
1 parent 561a417 commit 51aa891

11 files changed

+223
-60
lines changed

src/dataManager.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ class DataManager {
7777
return retrieveValue('data.'+planetId, {});
7878
}
7979

80-
updatePlanetData(planetId, planet) {
80+
updatePlanetData(planetId, planet, force, timestamp) {
8181
this.planets[planetId] = planet;
82-
storeValue('data.'+planetId, planet);
82+
storeValue('data.'+planetId, planet, force, timestamp);
8383
this.setJsonValue('data.'+planetId, planet);
8484
}
8585

src/displays/planetsProductionDisplay.js

+48-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class PlanetsProductionDisplay {
2424

2525
var prod_mod = PARAMS.prod_display;
2626

27+
// let maxShips = this.dataManager.getIntValue('data.maxships', 0);
28+
2729
for (var i = 0; i < nbPlanets; i++) {
2830
var planetId = myPlanetsRes.snapshotItem(i).textContent;
2931
const [planetdata, moondata, planetProd, moonProd] = await this.dataManager.loadFullPlanet(planetId);
@@ -221,13 +223,14 @@ class PlanetsProductionDisplay {
221223

222224
// mount base html
223225
jQuery('#' + planetId + '>.prod').html(
226+
// Planet production
224227
'<div class="planet_prod">'
225228
+ '<span id="m_dispo" class="dispo" title="Capacity : ' + formatInt(planet.prod.M.capa) + '"></span>' +
226229
(PARAMS.game_style === 'miner' ?
227230
'<span class="prod_per_hour ' + (prod_mod === 'hour' ? '' : 'hidden') + ' ' + m_prod_class + '">+' + formatInt(planet.prod.M.prod) + '/h</span>' +
228231
'<span class="prod_per_day ' + (prod_mod === 'day' ? '' : 'hidden') + ' ' + m_prod_class + '">+' + formatInt(planet.prod.M.prod * 24) + '/d</span>'
229232
: '')
230-
+ '<br/><span id="c_dispo" class="dispo" title="Capacity : ' + formatInt(planet.prod.D.capa) + '"></span>' +
233+
+ '<br/><span id="c_dispo" class="dispo" title="Capacity : ' + formatInt(planet.prod.C.capa) + '"></span>' +
231234
(PARAMS.game_style === 'miner' ?
232235
'<span class="prod_per_hour ' + (prod_mod === 'hour' ? '' : 'hidden') + ' ' + c_prod_class + '">+' + formatInt(planet.prod.C.prod) + '/h</span>' +
233236
'<span class="prod_per_day ' + (prod_mod === 'day' ? '' : 'hidden') + ' ' + c_prod_class + '">+' + formatInt(planet.prod.C.prod * 24) + '/d</span>'
@@ -246,13 +249,14 @@ class PlanetsProductionDisplay {
246249
+ (PARAMS.energie_display == 1 ? '<br/><span id="e_dispo" class="dispo" title="Production : ' + formatInt(planet.prod.E.prod) + '"><span class="' + warnE + '" style="width:' + this.percent(planet.prod.E.prod - planet.prod.E.dispo, planet.prod.E.prod) + '%">E:&nbsp;' + formatInt(planet.prod.E.dispo) + '</span></span>' : '')
247250
//+ '<span class="capa">&nbsp;/&nbsp;'+formatInt(planet.prod.E.prod)+'</span>'
248251
+ cefPercent
252+
// Moon production
249253
+ '</div><div class="moon_prod">'
250254
+ '<span id="m_dispo" class="dispo" title="Capacity : ' + formatInt(planet.moonprod.M.capa) + '"></span>' +
251255
(PARAMS.game_style === 'miner' ?
252256
'<span class="prod_per_hour ' + (prod_mod === 'hour' ? '' : 'hidden') + ' ' + m_prod_class_moon + '">+' + formatInt(planet.moonprod.M.prod) + '/h</span>' +
253257
'<span class="prod_per_day ' + (prod_mod === 'day' ? '' : 'hidden') + ' ' + m_prod_class_moon + '">+' + formatInt(planet.moonprod.M.prod * 24) + '/d</span>'
254258
: '')
255-
+ '<br/><span id="c_dispo" class="dispo" title="Capacity : ' + formatInt(planet.moonprod.D.capa) + '"></span>' +
259+
+ '<br/><span id="c_dispo" class="dispo" title="Capacity : ' + formatInt(planet.moonprod.C.capa) + '"></span>' +
256260
(PARAMS.game_style === 'miner' ?
257261
'<span class="prod_per_hour ' + (prod_mod === 'hour' ? '' : 'hidden') + ' ' + c_prod_class_moon + '">+' + formatInt(planet.moonprod.C.prod) + '/h</span>' +
258262
'<span class="prod_per_day ' + (prod_mod === 'day' ? '' : 'hidden') + ' ' + c_prod_class_moon + '">+' + formatInt(planet.moonprod.C.prod * 24) + '/d</span>'
@@ -270,7 +274,9 @@ class PlanetsProductionDisplay {
270274
//+ '<span class="capa">&nbsp;/&nbsp;'+formatInt(planet.moonprod.E.prod)+'</span>'
271275
+ '</div>'
272276
);
277+
// Incomming fleet base html
273278
jQuery('#'+planetId).append('<span class="incomming_fleet"></span>');
279+
// Store reference to jQuery base HTML elements
274280
// planet
275281
planet.$m_dispo = jQuery('#'+planetId + ' .planet_prod #m_dispo');
276282
planet.$c_dispo = jQuery('#'+planetId + ' .planet_prod #c_dispo');
@@ -292,6 +298,18 @@ class PlanetsProductionDisplay {
292298

293299
planet.$incomming_fleet = jQuery('#'+planetId + ' .incomming_fleet');
294300
this.planetList.push(planet);
301+
302+
if (PARAMS.show_stationed_ships == 1) {
303+
// Indicateurs de présence de flotte
304+
jQuery('#' + planetId + ' a.planetlink').append('<span class="aquai" title="' + formatInt(planetdata.vaissels) + ' ships"><span class="percent" style=""></span></span>');
305+
planet.$fleetAquai = jQuery('#' + planetId + ' a.planetlink span.aquai');
306+
planet.$fleetPercent = jQuery('#' + planetId + ' a.planetlink span.aquai span.percent');
307+
planet.$fleetPercent.data('vaissels', planetdata.vaissels);
308+
jQuery('#' + planetId + ' a.moonlink').append('<span class="aquai" title="' + formatInt(moondata.vaissels) + ' ships"><span class="percent" style=""></span></span>');
309+
planet.$fleetAquai_moon = jQuery('#' + planetId + ' a.moonlink span.aquai');
310+
planet.$fleetPercent_moon = jQuery('#' + planetId + ' a.moonlink span.aquai span.percent');
311+
planet.$fleetPercent_moon.data('vaissels', moondata.vaissels);
312+
}
295313
}
296314

297315
jQuery('#planetList').append('<div class="total_prod">'
@@ -384,7 +402,9 @@ class PlanetsProductionDisplay {
384402
}
385403
}
386404
});
387-
405+
406+
let maxShips = 0;
407+
388408
// display per planet
389409
for (var i =0; i<this.planetList.length; i++) {
390410
var warnM = '';
@@ -396,6 +416,13 @@ class PlanetsProductionDisplay {
396416

397417
const [planetdata, moondata, planetProd, moonProd] = await this.dataManager.loadFullPlanet(planet.id);
398418

419+
420+
// compute maxShips
421+
if (PARAMS.show_stationed_ships == 1 && planetdata.vaissels >= 0) {
422+
maxShips = Math.max(maxShips, planetdata.vaissels);
423+
planet.$fleetPercent.data('vaissels', planetdata.vaissels);
424+
}
425+
399426
planet.prod = planetProd;
400427
planet.moonprod = moonProd;
401428

@@ -487,6 +514,11 @@ class PlanetsProductionDisplay {
487514

488515
// moon production
489516
if (planet.moonprod) {
517+
// compute maxShips
518+
if (PARAMS.show_stationed_ships == 1 && moondata.vaissels >= 0) {
519+
maxShips = Math.max(maxShips, moondata.vaissels);
520+
planet.$fleetPercent_moon.data('vaissels', moondata.vaissels);
521+
}
490522
warnM = '';
491523
warnC = '';
492524
warnD = '';
@@ -612,7 +644,19 @@ class PlanetsProductionDisplay {
612644
}
613645

614646
}
615-
647+
648+
if (PARAMS.show_stationed_ships == 1) {
649+
jQuery('span.aquai span.percent').each(function (index, elt) {
650+
$elt = jQuery(elt);
651+
let vaissels = parseInt($elt.data('vaissels'));
652+
let fleetPercent = vaissels * 100 / maxShips;
653+
let fleetColor = fleetPercent > 75 ? 'red' : (fleetPercent > 50 ? 'orange' : 'green');
654+
let minWidth = fleetPercent > 0 ? 8 : 0;
655+
$elt.attr('style', 'width: ' + fleetPercent + '%; background-color: ' + fleetColor + '; min-width: ' + minWidth + 'px;');
656+
$elt.parent().attr('title', formatInt(vaissels) + ' ships');
657+
});
658+
}
659+
616660
// in flight
617661
jQuery('#planetList .total_prod .in_flight_metal').html(formatInt(inFlight_M));
618662
jQuery('#planetList .total_prod .in_flight_cristal').html(formatInt(inFlight_C));

src/ogameLive.css

+37-1
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,31 @@ span.incomming_fleet {
471471
opacity: 0.5;
472472
}
473473

474+
span.aquai {
475+
display: block;
476+
background-color: rgb(85,85,85);
477+
height: 2px;
478+
position: absolute;
479+
bottom: 0px;
480+
cursor: help;
481+
}
482+
483+
a.planetlink span.aquai {
484+
width: 80px;
485+
}
486+
487+
a.moonlink span.aquai {
488+
width: 40px;
489+
}
490+
491+
span.aquai .percent {
492+
display: block;
493+
height: 100%;
494+
width: 0%;
495+
background-color: green;
496+
}
497+
498+
474499
figure.planetIcon.debrisField {
475500
background: url("https://gf1.geo.gfsrv.net/cdnc5/fa3e396b8af2ae31e28ef3b44eca91.gif") no-repeat;
476501
background-size: 16px;
@@ -709,6 +734,17 @@ li>a.menubutton>a.empire_moon:before {
709734
opacity: 0.7;
710735
}
711736

712-
#OGameLiveEvents .eventFleet[data-mission-type="15"][data-return-flight="false"] {
737+
#OGameLiveEvents .eventFleet[data-mission-type="15"][data-return-flight="false"],
738+
#OGameLiveEvents .eventFleet[data-mission-type="18"][data-return-flight="false"] {
713739
display: none;
714740
}
741+
742+
#rechts .smallplanet a.alert {
743+
right: auto !important;
744+
left: 102px !important;
745+
top: 5px !important;
746+
}
747+
748+
.OGameClock>span {
749+
color: red;
750+
}

src/ogameLive.html

+2-36
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,7 @@
66
<link rel="stylesheet" media="all" type="text/css" href="style.css"/>
77
</head>
88
<body>
9-
<h1>OGameLive Parameters</h1>
10-
11-
<h2>General options</h2>
12-
<div class="parameter">
13-
<label>Game style</label>
14-
<select id="game-style">
15-
<option value="raider">Raider</option>
16-
<option value="miner">Miner</option>
17-
</select>
18-
</div>
19-
<div class="parameter">
20-
<label>Production display</label>
21-
<select id="production-display">
22-
<option value="hour">per hour</option>
23-
<option value="day">per day</option>
24-
<!-- <option value="week">per week</option>-->
25-
</select>
26-
</div>
27-
<div class="parameter">
28-
<label>Production round</label>
29-
<select id="production-round">
30-
<option value="0">No</option>
31-
<option value="1">Yes</option>
32-
</select>
33-
</div>
34-
35-
<h2>Fleet options</h2>
36-
<div class="parameter">
37-
<label>Show fleet speed</label>
38-
<select id="fleet-speed">
39-
<option value="0">No</option>
40-
<option value="1">Yes</option>
41-
</select>
42-
</div>
43-
44-
<script type="application/javascript" src="parameters.js"></script>
9+
<h1>OGameLive</h1>
10+
<p>Thank you for using OGameLive !</p>
4511
</body>
4612
</html>

src/ogameLive.user.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ const DEFAULT_PARAMS = {
5353
energie_display: 1,
5454
sum_display: 1,
5555
show_flights: 1,
56+
show_cost_overlay: 1,
57+
show_stationed_ships: 1,
5658
};
5759

5860
// noinspection ES6ConvertVarToLetConst
@@ -71,9 +73,14 @@ if (PARAMS.lifeform == null || PARAMS.lastServerData == null || parseInt(PARAMS.
7173
// get Universe params if not defined, or Once a day
7274
jQuery.get(urlUnivers + "/api/serverData.xml", function (data) {
7375
let $data = jQuery(data);
76+
console.log('versionUnivers', $data.find('version')[0].textContent )
7477
versionUnivers = $data.find('version')[0].textContent;
78+
79+
console.log('lifeformSettings', $data.find('lifeformSettings').length )
7580
PARAMS.lifeform = $data.find('lifeformSettings').length > 0;
76-
PARAMS.nb_systems = parseInt($data.find('systems').textContent);
81+
82+
console.log('versionUnivers', $data.find('systems')[0].textContent )
83+
PARAMS.nb_systems = parseInt($data.find('systems')[0].textContent);
7784
PARAMS.lastServerData = (new Date()).getTime();
7885
GM_setJsonValue('params', PARAMS);
7986
storeValue('params', PARAMS);
@@ -193,6 +200,9 @@ window.addEventListener('DOMContentLoaded', (event) => {
193200
// with OGameLive Infinity-based planets and moon display, change default tooltip side
194201
jQuery('.smallplanet > a').toggleClass('tooltipRight tooltipLeft');
195202

203+
// Add timer at the bottom of the galaxy view
204+
jQuery('.ctGalaxyFooter #colonized').after('<div style="flex: 1; display: flex"><span class="OGameClock"></span><span class="ogk-ping"></span></div>');
205+
196206
// Finaly detect other plugins and add them into body class (this is not really helpfully if that plugins load after OGameLive)
197207
hasOGInfinity = jQuery('.ogl-harvestOptions').length >= 1;
198208
hasOGLight = jQuery('#menuTable .ogl_leftMenuIcon').length >= 1;

src/parameters.js

+17
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ class Parameters {
7070
min: 0,
7171
max: 99,
7272
},
73+
show_cost_overlay: {
74+
label: 'Show cost overlay',
75+
options: [
76+
{value: 1, label: 'Yes'},
77+
{value: 0, label: 'No'}
78+
],
79+
},
80+
show_stationed_ships: {
81+
label: 'Show stationed ships',
82+
options: [
83+
{value: 1, label: 'Yes'},
84+
{value: 0, label: 'No'}
85+
],
86+
},
7387
}
7488

7589
}
@@ -83,13 +97,16 @@ class Parameters {
8397
'<h2>General options</h2>' +
8498
this._getParamSelect('game_style') +
8599
this._getParamInteger('main_refresh') +
100+
'<h2>Technologies</h2>' +
101+
this._getParamSelect('show_cost_overlay') +
86102
'<h2>Live production</h2>' +
87103
this._getParamSelect('show_production') +
88104
this._getParamSelect('prod_display') +
89105
this._getParamSelect('energie_display') +
90106
this._getParamSelect('sum_display') +
91107
this._getParamSelect('prod_round') +
92108
this._getParamSelect('show_needed_transporters') +
109+
this._getParamSelect('show_stationed_ships') +
93110
'<h2>Fleet options</h2>' +
94111
this._getParamSelect('show_fleet_speed') +
95112
this._getParamInteger('random_system') +

src/parsers/empireParser.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class EmpireParser {
3838
empireObserver.disconnect();
3939
let planetList = Xpath.getUnorderedSnapshotNodes(document,'//div[contains(@class,"planetWrapper")]/div/@id');
4040
let nbPlanets = planetList.snapshotLength;
41+
// reset max fleet in storage
42+
// this.dataManager.setValue('data.maxships', 0);
4143
for (var i = 0; i < nbPlanets; i++) {
4244
let internalId;
4345
let planetId = planetList.snapshotItem(i).textContent;
@@ -54,7 +56,7 @@ class EmpireParser {
5456
this.dataManager.loadPlanetData(internalId),
5557
this.dataManager.loadPlanetProd(internalId)
5658
]);
57-
console.log(planetId, planetData, planetProd);
59+
console.log(planetId, internalId, planetData, planetProd);
5860

5961
// Now we have our planet from dataManager, parse planet data from the empire view
6062
if (!jQuery.isEmptyObject(planetData)) {
@@ -121,6 +123,26 @@ class EmpireParser {
121123
}
122124

123125
this.dataManager.updatePlanetProd(internalId, planetProd, true, loadedTime);
126+
127+
// Parse some other data
128+
129+
// Fleet
130+
if (!planetData.fleet) {
131+
planetData.fleet = {};
132+
}
133+
planetData.vaissels = 0;
134+
Object.keys(OgameConstants.fleet).forEach(function(shipName) {
135+
const shipId = OgameConstants.fleet[shipName];
136+
let quantity = Xpath.getStringValue(document, '//div[contains(@id,"'+planetId+'")]/div[contains(@class,"ships")]/div[contains(@class,"' + shipId + '")]');
137+
quantity = parseInt(quantity.split('.').join(''));
138+
planetData.fleet[shipName] = quantity;
139+
console.log(internalId, shipName, planetData.fleet[shipName])
140+
if (shipName !== 'resbuggy' && shipName !== 'solarSatellite') {
141+
// Do not count resbuggy and solarSatellite
142+
planetData.vaissels += quantity;
143+
}
144+
});
145+
this.dataManager.updatePlanetData(internalId, planetData, true,loadedTime);
124146
}
125147

126148
}

src/parsers/fleetParser.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,18 @@ class FleetParser {
1919
if (!planetData.fleet) {
2020
planetData.fleet = {};
2121
}
22+
planetData.vaissels = 0;
2223
Object.keys(constants).forEach(function(k) {
2324
planetData.fleet[k] =
2425
Xpath.getNumberValue(document, '//div[contains(@id,"technologies")]/div/ul/li[contains(@class,"'+k+'")]/span/span[contains(@class,"amount")]/@data-value');
26+
if (isNaN(planetData.fleet[k])) {
27+
planetData.fleet[k] = 0;
28+
}
29+
console.log(k, planetData.fleet[k]);
30+
if (k !== 'resbuggy' && k !== 'solarSatellite') {
31+
// Do not count resbuggy and solarSatellite
32+
planetData.vaissels += planetData.fleet[k];
33+
}
2534
if (getFleetData) {
2635
jQuery.get(urlUnivers + '/game/index.php?page=ajax&component=technologytree&ajax=1&technologyId='+constants[k]+'&tab=2', function(htmlStr) {
2736
log("get response for " + k, LOG_LEVEL_TRACE);
@@ -42,4 +51,4 @@ class FleetParser {
4251
});
4352
dataManager.updateCurrentPlanetData(planetData);
4453
}
45-
}
54+
}

0 commit comments

Comments
 (0)