1 | using JetBrains.Annotations;
|
---|
2 | using Webserver;
|
---|
3 | using Webserver.UrlHandlers;
|
---|
4 |
|
---|
5 | namespace MapRendering {
|
---|
6 | [UsedImplicitly]
|
---|
7 | public class ModApi : IModApi {
|
---|
8 | private const string mapTilesBaseUrl = "/map/";
|
---|
9 |
|
---|
10 | public void InitMod (Mod _modInstance) {
|
---|
11 | ModEvents.GameStartDone.RegisterHandler (GameStartDone);
|
---|
12 |
|
---|
13 | Web.ServerInitialized += _web => {
|
---|
14 | if (!MapRenderer.Enabled) {
|
---|
15 | return;
|
---|
16 | }
|
---|
17 |
|
---|
18 | _web.RegisterPathHandler (mapTilesBaseUrl, new StaticHandler (
|
---|
19 | $"{GameIO.GetSaveGameDir ()}/map",
|
---|
20 | MapRenderer.GetTileCache (),
|
---|
21 | false,
|
---|
22 | "web.map")
|
---|
23 | );
|
---|
24 |
|
---|
25 | _web.OpenApiHelpers.RegisterCustomSpec (GetType ().Assembly, "MapTileHandler", mapTilesBaseUrl);
|
---|
26 | };
|
---|
27 | }
|
---|
28 |
|
---|
29 | private ModEvents.EModEventResult GameStartDone (ref ModEvents.SGameStartDoneData _data) {
|
---|
30 | if (!MapRenderer.Enabled) {
|
---|
31 | return ModEvents.EModEventResult.Continue;
|
---|
32 | }
|
---|
33 |
|
---|
34 | ModEvents.GameShutdown.RegisterHandler (GameShutdown);
|
---|
35 | ModEvents.CalcChunkColorsDone.RegisterHandler (CalcChunkColorsDone);
|
---|
36 |
|
---|
37 | return ModEvents.EModEventResult.Continue;
|
---|
38 | }
|
---|
39 |
|
---|
40 | private ModEvents.EModEventResult GameShutdown (ref ModEvents.SGameShutdownData _data) {
|
---|
41 | MapRenderer.Shutdown ();
|
---|
42 |
|
---|
43 | return ModEvents.EModEventResult.Continue;
|
---|
44 | }
|
---|
45 |
|
---|
46 | private ModEvents.EModEventResult CalcChunkColorsDone (ref ModEvents.SCalcChunkColorsDoneData _data) {
|
---|
47 | MapRenderer.RenderSingleChunk (_data.Chunk);
|
---|
48 |
|
---|
49 | return ModEvents.EModEventResult.Continue;
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|