Skip to content

Commit 17fccc8

Browse files
authored
Merge pull request #33 from IlyaChichkov/develop
Develop v1.3.0
2 parents 52e1bfc + 0e8b395 commit 17fccc8

49 files changed

Lines changed: 6189 additions & 598 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"isRoot": true,
44
"tools": {
55
"csharpier": {
6-
"version": "1.2.2",
6+
"version": "1.3.0",
77
"commands": [
88
"csharpier"
99
],

.github/workflows/deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
pip install mkdocs-material
3636
pip install mkdocs-mermaid2-plugin
3737
pip install mkdocs-minify-plugin
38+
pip install mkdocs-macros-plugin
39+
pip install mkdocs-llmstxt
3840
3941
- name: Build site
4042
run: mkdocs build --site-dir public

About/About.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<description>RIMAPI is a mod that give you an REST API useable for your current game</description>
55
<packageId>RedEyeDev.RIMAPI</packageId>
66
<author>RedEyeDev</author>
7-
<modVersion>1.2.2</modVersion>
7+
<modVersion>1.3.0</modVersion>
88
<url></url>
99
<supportedVersions>
1010
<li>1.5</li>

About/Manifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
22
<Manifest>
33
<identifier>redeyedev.rimapi</identifier>
4-
<version>1.2.2</version>
4+
<version>1.3.0</version>
55
<manifestUri>
66
https://raw.githubusercontent.com/IlyaChichkov/RIMAPI/refs/heads/main/About/Manifest.xml</manifestUri>
77
<downloadUri>https://github.com/IlyaChichkov/RIMAPI/releases</downloadUri>

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
11
# Changelog
2+
## v1.3.0
3+
4+
Add examples and description for endpoints in documentation
5+
6+
Insert them into auto generated api.md by macroses from api.yml
7+
8+
Add option to use json body for endpoints that accept parameters:
9+
- /api/v1/dev/console
10+
- /api/v1/colonist/time-assignment
11+
12+
Add new endpoints:
13+
[GET]
14+
15+
- /api/v1/world/caravans
16+
- /api/v1/world/settlements
17+
- /api/v1/world/caravans
18+
- /api/v1/world/tile
19+
20+
[POST]
21+
- /api/v1/pawn/edit
22+
23+
Fixes:
24+
- TraitDefDto empty label, description
25+
- /api/v1/colonist/body/image returned GetColonistInventory
26+
- change "throw new Exception" to "return ApiResult.Fail"
27+
- /api/v1/dev/console didn't have message parameter
28+
229
## v1.2.2
330

431
Fix GetItemImageByName

Source/RIMAPI/RIMAPI_Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace RIMAPI
55
{
66
public class RIMAPI_Settings : ModSettings
77
{
8-
public string version = "1.2.0";
8+
public string version = "1.3.0";
99
public string apiVersion = "v1";
1010
public int serverPort = 8765;
1111
public int refreshIntervalTicks = 300;

Source/RIMAPI/RimApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<RootNamespace>RIMAPI</RootNamespace>
77
<AssemblyName>RIMAPI</AssemblyName>
88
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
9-
<Version>1.2.2</Version>
9+
<Version>1.3.0</Version>
1010
</PropertyGroup>
1111

1212
<!-- Conditional properties for RimWorld 1.5 -->

Source/RIMAPI/RimworldRestApi/BaseControllers/DevToolsController.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,21 @@ public DevToolsController(IDevToolsService gameStateService)
2020
[EndpointMetadata("Send message to the debug console")]
2121
public async Task PostConsoleAction(HttpListenerContext context)
2222
{
23-
var action = RequestParser.GetStringParameter(context, "action");
24-
var result = _devToolsService.ConsoleAction(action);
23+
DebugConsoleRequest body;
24+
if (context.Request.HasEntityBody)
25+
{
26+
body = await context.Request.ReadBodyAsync<DebugConsoleRequest>();
27+
}
28+
else
29+
{
30+
body = new DebugConsoleRequest
31+
{
32+
Action = RequestParser.GetStringParameter(context, "action"),
33+
Message = RequestParser.GetStringParameter(context, "message"),
34+
};
35+
}
36+
37+
var result = _devToolsService.ConsoleAction(body);
2538
await context.SendJsonResponse(result);
2639
}
2740

@@ -44,8 +57,8 @@ public async Task PostMaterialsAtlasPoolClear(HttpListenerContext context)
4457
[EndpointMetadata("Change stuff color")]
4558
public async Task PostStuffColor(HttpListenerContext context)
4659
{
47-
var requestData = await context.Request.ReadBodyAsync<StuffColorRequest>();
48-
var result = _devToolsService.SetStuffColor(requestData);
60+
var body = await context.Request.ReadBodyAsync<StuffColorRequest>();
61+
var result = _devToolsService.SetStuffColor(body);
4962
await context.SendJsonResponse(result);
5063
}
5164
}

Source/RIMAPI/RimworldRestApi/BaseControllers/GameController.cs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ ICachingService cachingService
3030
public async Task EnableCache(HttpListenerContext context)
3131
{
3232
_cachingService.SetEnabled(true);
33-
await ResponseBuilder.Success(context.Response, new { message = "Cache enabled" });
33+
await ResponseBuilder.SendSuccess(context.Response, new { message = "Cache enabled" });
3434
}
3535

3636
[Post("/api/v1/cache/disable")]
3737
public async Task DisableCache(HttpListenerContext context)
3838
{
3939
_cachingService.SetEnabled(false);
40-
await ResponseBuilder.Success(context.Response, new { message = "Cache disabled" });
40+
await ResponseBuilder.SendSuccess(context.Response, new { message = "Cache disabled" });
4141
}
4242

4343
[Get("/api/v1/cache/status")]
@@ -47,34 +47,15 @@ public async Task GetCacheStatus(HttpListenerContext context)
4747
var stats = _cachingService.GetStatistics();
4848
var status = new { enabled = _cachingService.IsEnabled(), statistics = stats };
4949

50-
await ResponseBuilder.Success(context.Response, status);
51-
}
52-
53-
[Get("/api/v1/cache/stats")]
54-
[EndpointMetadata("Get cache statistics")]
55-
public async Task GetCacheStats(HttpListenerContext context)
56-
{
57-
var stats = _cachingService.GetStatistics();
58-
await ResponseBuilder.Success(
59-
context.Response,
60-
new
61-
{
62-
stats.TotalEntries,
63-
stats.Hits,
64-
stats.Misses,
65-
stats.HitRatio,
66-
MemoryUsageMB = stats.MemoryUsageBytes / 1024 / 1024,
67-
stats.LastCleanup,
68-
}
69-
);
50+
await ResponseBuilder.SendSuccess(context.Response, status);
7051
}
7152

7253
[Post("/api/v1/cache/clear")]
7354
[EndpointMetadata("Clear cache")]
7455
public async Task ClearCache(HttpListenerContext context)
7556
{
7657
_cachingService.Clear();
77-
await ResponseBuilder.Success(context.Response, new { message = "Cache cleared" });
58+
await ResponseBuilder.SendSuccess(context.Response, new { message = "Cache cleared" });
7859
}
7960

8061
[Get("/api/v1/version")]
@@ -153,7 +134,7 @@ public async Task GetWorldTileDatetime(HttpListenerContext context)
153134
}
154135

155136
[Get("/api/v1/def/all")]
156-
[EndpointMetadata("Get in-game date and time in global map tile", new[] { "Unstable" })]
137+
[EndpointMetadata("Get in-game date and time in global map tile")]
157138
public async Task GetAllDefs(HttpListenerContext context)
158139
{
159140
var body = await context.Request.ReadBodyAsync<AllDefsRequestDto>();
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System;
2+
using System.Linq;
3+
using System.Net;
4+
using System.Threading.Tasks;
5+
using RIMAPI.Core;
6+
using RIMAPI.Http;
7+
using RIMAPI.Services;
8+
9+
namespace RIMAPI.Controllers
10+
{
11+
public class GlobalMapController : BaseController
12+
{
13+
private readonly IGlobalMapService _globalMapService;
14+
private readonly ICachingService _cachingService;
15+
16+
public GlobalMapController(IGlobalMapService globalMapService, ICachingService cachingService)
17+
{
18+
_globalMapService = globalMapService;
19+
_cachingService = cachingService;
20+
}
21+
22+
[Get("/api/v1/world/caravans")]
23+
public async Task GetCaravans(HttpListenerContext context)
24+
{
25+
await _cachingService.CacheAwareResponseAsync(
26+
context,
27+
"caravans",
28+
() => Task.FromResult(_globalMapService.GetCaravans()),
29+
expiration: TimeSpan.FromSeconds(3),
30+
expirationType: CacheExpirationType.GameTick
31+
);
32+
}
33+
34+
[Get("/api/v1/world/settlements")]
35+
public async Task GetSettlements(HttpListenerContext context)
36+
{
37+
await _cachingService.CacheAwareResponseAsync(
38+
context,
39+
"settlements",
40+
() => Task.FromResult(_globalMapService.GetSettlements()),
41+
expiration: TimeSpan.FromSeconds(10),
42+
expirationType: CacheExpirationType.GameTick
43+
);
44+
}
45+
46+
[Get("/api/v1/world/sites")]
47+
public async Task GetSites(HttpListenerContext context)
48+
{
49+
await _cachingService.CacheAwareResponseAsync(
50+
context,
51+
"sites",
52+
() => Task.FromResult(_globalMapService.GetSites()),
53+
expiration: TimeSpan.FromSeconds(5),
54+
expirationType: CacheExpirationType.GameTick
55+
);
56+
}
57+
58+
[Get("/api/v1/world/tile")]
59+
public async Task GetTile(HttpListenerContext context)
60+
{
61+
var tileId = RequestParser.GetIntParameter(context, "id");
62+
await _cachingService.CacheAwareResponseAsync(
63+
context,
64+
$"tile_{tileId}",
65+
() => Task.FromResult(_globalMapService.GetTile(tileId)),
66+
expiration: TimeSpan.FromSeconds(120),
67+
expirationType: CacheExpirationType.Absolute
68+
);
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)