Skip to content

Commit 5d563de

Browse files
committed
Enable stats viewing if the server supports it
1 parent 12a2302 commit 5d563de

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
@@ -336,6 +336,12 @@ koa.use(async (context, next) => {
336336
}
337337
}
338338
}
339+
// Add an hasFeature function to help with checking specific features from the HTML pages
340+
src = src.replace(
341+
't.Math=Math,t.isOffServer',
342+
'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',
343+
);
344+
339345
if (!isOfficial) {
340346
// Replace room-history URL
341347
src = src.replace(
@@ -367,6 +373,55 @@ koa.use(async (context, next) => {
367373
`<img ng:src="{{Profile.mapUrl}}{{isMultiShard() ? shardName+'/' : ''}}{{roomName}}.png">`,
368374
);
369375

376+
// Stats view on profile
377+
src = src.replace(
378+
"<div class='survival' ng-if='isOffServer()'>",
379+
"<div class='survival' ng-if='isOffServer() || hasFeature(\"screepsmod-stats\")'>",
380+
);
381+
src = src.replace(
382+
"<div class='stats-controls' ng-if='isOffServer()'>",
383+
"<div class='stats-controls' ng-if='isOffServer() || hasFeature(\"screepsmod-stats\")'>",
384+
);
385+
src = src.replace(
386+
"<app-profile-stats ng-if='isOffServer()' stats='Profile.data.stats'></app-profile-stats>",
387+
"<app-profile-stats ng-if='isOffServer() || hasFeature(\"screepsmod-stats\")' stats='Profile.data.stats'></app-profile-stats>",
388+
);
389+
390+
return src;
391+
} else if (urlPath === 'components/game/overview/overview.html') {
392+
let src = await file.async('text');
393+
394+
// Enable period filter if we have stats
395+
src = src.replace(
396+
"<ui-drop-group class='btn-more' ng-if='isOffServer()'>",
397+
"<ui-drop-group class='btn-more' ng-if='isOffServer() || hasFeature(\"screepsmod-stats\")'>",
398+
);
399+
400+
// Enable leaderboard overview if we have stats
401+
src = src.replaceAll(
402+
"<div class='overview-rank-right' ng-if='isOffServer()'>",
403+
"<div class='overview-rank-right' ng-if='isOffServer() || hasFeature(\"screepsmod-stats\")'>",
404+
);
405+
src = src.replaceAll(
406+
"<div class='overview-rank-right' ng-if='!isOffServer()'>",
407+
"<div class='overview-rank-right' ng-if='!isOffServer() &amp;&amp; !hasFeature(\"screepsmod-stats\")'>",
408+
);
409+
src = src.replace(
410+
"<div class='overview-rooms-controls' ng-if='isOffServer()'>",
411+
"<div class='overview-rooms-controls' ng-if='isOffServer() || hasFeature(\"screepsmod-stats\")'>",
412+
);
413+
414+
// Show stats section
415+
src = src.replace(
416+
"<app-profile-stats ng-if='isOffServer()' normalize='false' stats='GameOverview.data.overview.totals'></app-profile-stats>",
417+
"<app-profile-stats ng-if='isOffServer() || hasFeature(\"screepsmod-stats\")' normalize='false' stats='GameOverview.data.overview.totals'></app-profile-stats>",
418+
);
419+
420+
src = src.replace(
421+
`<img ng:src="{{GameOverview.mapUrl}}{{isShards() ? shardName+'/' : ''}}{{roomName}}.png">`,
422+
`<img ng:src="{{GameOverview.mapUrl}}{{isMultiShard() ? shardName+'/' : ''}}{{roomName}}.png">`,
423+
);
424+
370425
return src;
371426
} else {
372427
// JSZip doesn't implement their read stream correctly and it causes EPIPE crashes. Pass it

0 commit comments

Comments
 (0)