Line | |
---|
1 | using JetBrains.Annotations;
|
---|
2 | using Webserver;
|
---|
3 | using Webserver.UrlHandlers;
|
---|
4 |
|
---|
5 | namespace 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.