source: binary-improvements2/MapRendering/src/ModApi.cs@ 429

Last change on this file since 429 was 425, checked in by alloc, 19 months ago
  • API "map" added, currently only supports GET with the ID "config"
  • API "player" added, currently only supports getting online players with some of the info not supported yet (playtime, last online, level)
  • Only logged in player's data is shown unless the user has the permission for "webapi.viewallplayers"
  • Internal refactoring
  • (Updated version to 21.0.258)
File size: 913 bytes
RevLine 
[391]1using JetBrains.Annotations;
[402]2using Webserver;
3using Webserver.UrlHandlers;
[224]4
[391]5namespace MapRendering {
6 [UsedImplicitly]
7 public class ModApi : IModApi {
[369]8 public void InitMod (Mod _modInstance) {
[423]9 ModEvents.GameStartDone.RegisterHandler (GameStartDone);
10
[402]11 Web.ServerInitialized += _web => {
[425]12 if (!MapRenderer.Enabled) {
[423]13 return;
14 }
15
[402]16 _web.RegisterPathHandler ("/map/", new StaticHandler (
17 $"{GameIO.GetSaveGameDir ()}/map",
18 MapRenderer.GetTileCache (),
19 false,
20 "web.map")
21 );
22 };
[325]23 }
24
[423]25 private void GameStartDone () {
[425]26 if (!MapRenderer.Enabled) {
[423]27 return;
28 }
29
30 ModEvents.GameShutdown.RegisterHandler (GameShutdown);
31 ModEvents.CalcChunkColorsDone.RegisterHandler (CalcChunkColorsDone);
32 }
33
[324]34 private void GameShutdown () {
[391]35 MapRenderer.Shutdown ();
[299]36 }
37
[324]38 private void CalcChunkColorsDone (Chunk _chunk) {
[391]39 MapRenderer.RenderSingleChunk (_chunk);
[224]40 }
41 }
[423]42}
Note: See TracBrowser for help on using the repository browser.