Skip to content

Commit 70035aa

Browse files
committed
Enable stats viewing if the server supports it
1 parent 144a84e commit 70035aa

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/clientApp.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@ koa.use(async (context, next) => {
366366
}
367367
}
368368
}
369+
// Add an hasFeature function to help with checking specific features from the HTML pages
370+
src = src.replace(
371+
't.Math=Math,t.isOffServer',
372+
't.Math=Math,t.hasFeature=function(feature){var f=m.get("Api").options.serverData.features;if(!f)return false;return f.some((feat)=>feat.name===feature);},t.isOffServer',
373+
);
374+
369375
if (!isOfficial) {
370376
// Replace room-history URL
371377
src = src.replace(
@@ -403,6 +409,55 @@ koa.use(async (context, next) => {
403409
`<img ng:src="{{Profile.mapUrl}}{{isMultiShard() ? shardName+'/' : ''}}{{roomName}}.png">`,
404410
);
405411

412+
// Stats view on profile
413+
src = src.replace(
414+
"<div class='survival' ng-if='isOffServer()'>",
415+
"<div class='survival' ng-if='isOffServer() || hasFeature(\"screepsmod-stats\")'>",
416+
);
417+
src = src.replace(
418+
"<div class='stats-controls' ng-if='isOffServer()'>",
419+
"<div class='stats-controls' ng-if='isOffServer() || hasFeature(\"screepsmod-stats\")'>",
420+
);
421+
src = src.replace(
422+
"<app-profile-stats ng-if='isOffServer()' stats='Profile.data.stats'></app-profile-stats>",
423+
"<app-profile-stats ng-if='isOffServer() || hasFeature(\"screepsmod-stats\")' stats='Profile.data.stats'></app-profile-stats>",
424+
);
425+
426+
return src;
427+
} else if (urlPath === 'components/game/overview/overview.html') {
428+
let src = await file.async('text');
429+
430+
// Enable period filter if we have stats
431+
src = src.replace(
432+
"<ui-drop-group class='btn-more' ng-if='isOffServer()'>",
433+
"<ui-drop-group class='btn-more' ng-if='isOffServer() || hasFeature(\"screepsmod-stats\")'>",
434+
);
435+
436+
// Enable leaderboard overview if we have stats
437+
src = src.replaceAll(
438+
"<div class='overview-rank-right' ng-if='isOffServer()'>",
439+
"<div class='overview-rank-right' ng-if='isOffServer() || hasFeature(\"screepsmod-stats\")'>",
440+
);
441+
src = src.replaceAll(
442+
"<div class='overview-rank-right' ng-if='!isOffServer()'>",
443+
"<div class='overview-rank-right' ng-if='!isOffServer() &amp;&amp; !hasFeature(\"screepsmod-stats\")'>",
444+
);
445+
src = src.replace(
446+
"<div class='overview-rooms-controls' ng-if='isOffServer()'>",
447+
"<div class='overview-rooms-controls' ng-if='isOffServer() || hasFeature(\"screepsmod-stats\")'>",
448+
);
449+
450+
// Show stats section
451+
src = src.replace(
452+
"<app-profile-stats ng-if='isOffServer()' normalize='false' stats='GameOverview.data.overview.totals'></app-profile-stats>",
453+
"<app-profile-stats ng-if='isOffServer() || hasFeature(\"screepsmod-stats\")' normalize='false' stats='GameOverview.data.overview.totals'></app-profile-stats>",
454+
);
455+
456+
src = src.replace(
457+
`<img ng:src="{{GameOverview.mapUrl}}{{isShards() ? shardName+'/' : ''}}{{roomName}}.png">`,
458+
`<img ng:src="{{GameOverview.mapUrl}}{{isMultiShard() ? shardName+'/' : ''}}{{roomName}}.png">`,
459+
);
460+
406461
return src;
407462
} else {
408463
// JSZip doesn't implement their read stream correctly and it causes EPIPE crashes. Pass it

0 commit comments

Comments
 (0)