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
Line 
1using JetBrains.Annotations;
2using Webserver;
3using Webserver.UrlHandlers;
4
5namespace MapRendering {
6 [UsedImplicitly]
7 public class ModApi : IModApi {
8 public void InitMod (Mod _modInstance) {
9 ModEvents.GameStartDone.RegisterHandler (GameStartDone);
10
11 Web.ServerInitialized += _web => {
12 if (!GamePrefs.GetBool (EnumUtils.Parse<EnumGamePrefs> (nameof (EnumGamePrefs.EnableMapRendering)))) {
13 return;
14 }
15
16 _web.RegisterPathHandler ("/map/", new StaticHandler (
17 $"{GameIO.GetSaveGameDir ()}/map",
18 MapRenderer.GetTileCache (),
19 false,
20 "web.map")
21 );
22 };
23 }
24
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
38 private void GameShutdown () {
39 MapRenderer.Shutdown ();
40 }
41
42 private void CalcChunkColorsDone (Chunk _chunk) {
43 MapRenderer.RenderSingleChunk (_chunk);
44 }
45 }
46}
Note: See TracBrowser for help on using the repository browser.