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

Last change on this file since 423 was 423, checked in by alloc, 20 months ago

Fixed: MapRenderer always enabled

File size: 1.1 KB
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 => {
[423]12 if (!GamePrefs.GetBool (EnumUtils.Parse<EnumGamePrefs> (nameof (EnumGamePrefs.EnableMapRendering)))) {
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 () {
26 if (!ConnectionManager.Instance.IsServer) {
27 return;
28 }
29
30 if (!GamePrefs.GetBool (EnumUtils.Parse<EnumGamePrefs> (nameof (EnumGamePrefs.EnableMapRendering)))) {
31 return;
32 }
33
34 ModEvents.GameShutdown.RegisterHandler (GameShutdown);
35 ModEvents.CalcChunkColorsDone.RegisterHandler (CalcChunkColorsDone);
36 }
37
[324]38 private void GameShutdown () {
[391]39 MapRenderer.Shutdown ();
[299]40 }
41
[324]42 private void CalcChunkColorsDone (Chunk _chunk) {
[391]43 MapRenderer.RenderSingleChunk (_chunk);
[224]44 }
45 }
[423]46}
Note: See TracBrowser for help on using the repository browser.