1
1
// @author breunigs
2
2
// @name Player activity tracker
3
3
// @category Layer
4
- // @version 0.13.2
4
+ // @version 0.14.0
5
5
// @description Draw trails for the path a user took onto the map based on status messages in COMMs. Uses up to three hours of data. Does not request chat data on its own, even if that would be useful.
6
6
7
7
/* exported setup, changelog --eslint */
8
- /* global L -- eslint */
8
+ /* global IITC, L -- eslint */
9
9
10
10
var changelog = [
11
+ {
12
+ version : '0.14.0' ,
13
+ changes : [ 'Using `IITC.utils.formatAgo` instead of the plugin own function' , 'Refactoring to make it easier to extend plugin functions' ] ,
14
+ } ,
11
15
{
12
16
version : '0.13.2' ,
13
17
changes : [ 'Refactoring: fix eslint' ] ,
@@ -34,6 +38,7 @@ window.PLAYER_TRACKER_MAX_TIME = 3 * 60 * 60 * 1000; // in milliseconds
34
38
window . PLAYER_TRACKER_MIN_ZOOM = 9 ;
35
39
window . PLAYER_TRACKER_MIN_OPACITY = 0.3 ;
36
40
window . PLAYER_TRACKER_LINE_COLOUR = '#FF00FD' ;
41
+ window . PLAYER_TRACKER_MAX_DISPLAY_EVENTS = 10 ; // Maximum number of events in a popup
37
42
38
43
// use own namespace for plugin
39
44
window . plugin . playerTracker = function ( ) { } ;
@@ -274,24 +279,12 @@ window.plugin.playerTracker.getLatLngFromEvent = function (ev) {
274
279
return L . latLng ( lats / ev . latlngs . length , lngs / ev . latlngs . length ) ;
275
280
} ;
276
281
277
- window . plugin . playerTracker . ago = function ( time , now ) {
278
- var s = ( now - time ) / 1000 ;
279
- var h = Math . floor ( s / 3600 ) ;
280
- var m = Math . floor ( ( s % 3600 ) / 60 ) ;
281
- var returnVal = m + 'm' ;
282
- if ( h > 0 ) {
283
- returnVal = h + 'h' + returnVal ;
284
- }
285
- return returnVal ;
286
- } ;
287
-
288
282
window . plugin . playerTracker . drawData = function ( ) {
289
283
var isTouchDev = window . isTouchDevice ( ) ;
290
284
291
285
var gllfe = window . plugin . playerTracker . getLatLngFromEvent ;
292
286
293
- var polyLineByAgeEnl = [ [ ] , [ ] , [ ] , [ ] ] ;
294
- var polyLineByAgeRes = [ [ ] , [ ] , [ ] , [ ] ] ;
287
+ var polyLineByPlayerAndAge = { } ;
295
288
296
289
var split = window . PLAYER_TRACKER_MAX_TIME / 4 ;
297
290
var now = Date . now ( ) ;
@@ -308,13 +301,15 @@ window.plugin.playerTracker.drawData = function () {
308
301
var ageBucket = Math . min ( Math . trunc ( ( now - p . time ) / split ) , 4 - 1 ) ;
309
302
var line = [ gllfe ( p ) , gllfe ( playerData . events [ i - 1 ] ) ] ;
310
303
311
- if ( playerData . team === 'RESISTANCE' ) polyLineByAgeRes [ ageBucket ] . push ( line ) ;
312
- else polyLineByAgeEnl [ ageBucket ] . push ( line ) ;
304
+ if ( ! polyLineByPlayerAndAge [ plrname ] ) {
305
+ polyLineByPlayerAndAge [ plrname ] = [ [ ] , [ ] , [ ] , [ ] ] ;
306
+ }
307
+ polyLineByPlayerAndAge [ plrname ] [ ageBucket ] . push ( line ) ;
313
308
}
314
309
315
310
var evtsLength = playerData . events . length ;
316
311
var last = playerData . events [ evtsLength - 1 ] ;
317
- var ago = window . plugin . playerTracker . ago ;
312
+ const ago = IITC . utils . formatAgo ;
318
313
319
314
// tooltip for marker - no HTML - and not shown on touchscreen devices
320
315
var tooltip = isTouchDev ? '' : plrname + ', ' + ago ( last . time , now ) + ' ago' ;
@@ -358,7 +353,7 @@ window.plugin.playerTracker.drawData = function () {
358
353
popup . append ( '<br>' ) . append ( '<br>' ) . append ( document . createTextNode ( 'previous locations:' ) ) . append ( '<br>' ) ;
359
354
360
355
var table = $ ( '<table>' ) . appendTo ( popup ) . css ( 'border-spacing' , '0' ) ;
361
- for ( let i = evtsLength - 2 ; i >= 0 && i >= evtsLength - 10 ; i -- ) {
356
+ for ( let i = evtsLength - 2 ; i >= 0 && i >= evtsLength - window . PLAYER_TRACKER_MAX_DISPLAY_EVENTS ; i -- ) {
362
357
var ev = playerData . events [ i ] ;
363
358
$ ( '<tr>' )
364
359
. append ( $ ( '<td>' ) . text ( ago ( ev . time , now ) + ' ago' ) )
@@ -375,7 +370,8 @@ window.plugin.playerTracker.drawData = function () {
375
370
var icon = playerData . team === 'RESISTANCE' ? new window . plugin . playerTracker . iconRes ( ) : new window . plugin . playerTracker . iconEnl ( ) ;
376
371
// as per OverlappingMarkerSpiderfier docs, click events (popups, etc) must be handled via it rather than the standard
377
372
// marker click events. so store the popup text in the options, then display it in the oms click handler
378
- var m = L . marker ( gllfe ( last ) , { icon : icon , opacity : absOpacity , desc : popup [ 0 ] , title : tooltip } ) ;
373
+ const markerPos = gllfe ( last ) ;
374
+ var m = L . marker ( markerPos , { icon : icon , opacity : absOpacity , desc : popup [ 0 ] , title : tooltip } ) ;
379
375
m . addEventListener ( 'spiderfiedclick' , window . plugin . playerTracker . onClickListener ) ;
380
376
381
377
// m.bindPopup(title);
@@ -389,7 +385,7 @@ window.plugin.playerTracker.drawData = function () {
389
385
390
386
playerData . marker = m ;
391
387
392
- m . addTo ( playerData . team === 'RESISTANCE' ? window . plugin . playerTracker . drawnTracesRes : window . plugin . playerTracker . drawnTracesEnl ) ;
388
+ m . addTo ( window . plugin . playerTracker . getDrawnTracesByTeam ( playerData . team ) ) ;
393
389
window . registerMarkerForOMS ( m ) ;
394
390
395
391
// jQueryUI doesn’t automatically notice the new markers
@@ -399,36 +395,27 @@ window.plugin.playerTracker.drawData = function () {
399
395
} ) ;
400
396
401
397
// draw the poly lines to the map
402
- $ . each ( polyLineByAgeEnl , function ( i , polyLine ) {
403
- if ( polyLine . length === 0 ) return true ;
404
-
405
- var opts = {
406
- weight : 2 - 0.25 * i ,
407
- color : window . PLAYER_TRACKER_LINE_COLOUR ,
408
- interactive : false ,
409
- opacity : 1 - 0.2 * i ,
410
- dashArray : '5,8' ,
411
- } ;
398
+ for ( const [ playerName , polyLineByAge ] of Object . entries ( polyLineByPlayerAndAge ) ) {
399
+ polyLineByAge . forEach ( ( polyLine , i ) => {
400
+ if ( polyLine . length === 0 ) return ;
401
+
402
+ const opts = {
403
+ weight : 2 - 0.25 * i ,
404
+ color : window . PLAYER_TRACKER_LINE_COLOUR ,
405
+ interactive : false ,
406
+ opacity : 1 - 0.2 * i ,
407
+ dashArray : '5,8' ,
408
+ } ;
412
409
413
- $ . each ( polyLine , function ( ind , poly ) {
414
- L . polyline ( poly , opts ) . addTo ( window . plugin . playerTracker . drawnTracesEnl ) ;
410
+ polyLine . forEach ( ( poly ) => {
411
+ L . polyline ( poly , opts ) . addTo ( window . plugin . playerTracker . getDrawnTracesByTeam ( window . plugin . playerTracker . stored [ playerName ] . team ) ) ;
412
+ } ) ;
415
413
} ) ;
416
- } ) ;
417
- $ . each ( polyLineByAgeRes , function ( i , polyLine ) {
418
- if ( polyLine . length === 0 ) return true ;
419
-
420
- var opts = {
421
- weight : 2 - 0.25 * i ,
422
- color : window . PLAYER_TRACKER_LINE_COLOUR ,
423
- interactive : false ,
424
- opacity : 1 - 0.2 * i ,
425
- dashArray : '5,8' ,
426
- } ;
414
+ }
415
+ } ;
427
416
428
- $ . each ( polyLine , function ( ind , poly ) {
429
- L . polyline ( poly , opts ) . addTo ( window . plugin . playerTracker . drawnTracesRes ) ;
430
- } ) ;
431
- } ) ;
417
+ window . plugin . playerTracker . getDrawnTracesByTeam = function ( team ) {
418
+ return team === 'RESISTANCE' ? window . plugin . playerTracker . drawnTracesRes : window . plugin . playerTracker . drawnTracesEnl ;
432
419
} ;
433
420
434
421
window . plugin . playerTracker . getPortalLink = function ( data ) {
0 commit comments