|
Last change
on this file since 501 was 463, checked in by alloc, 2 years ago |
|
21.1.16.0 release
Completed OpenAPI specs
Add support to path handlers to register OpenAPI specs
Fixed ItemIconHandler throwing error when requested path contains no dot
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 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 void GameStartDone () {
|
|---|
| 30 | if (!MapRenderer.Enabled) {
|
|---|
| 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.