Skip to content

Commit b3f02f1

Browse files
authored
feat: add new server endpoints (#292)
1 parent 85709b9 commit b3f02f1

File tree

28 files changed

+354
-12
lines changed

28 files changed

+354
-12
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src-tauri/src/command/npc/bot.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ pub async fn get_public_bot(app: AppHandle, req: GetPublicBotRequest) -> Result<
2323
.await
2424
.map_err(Into::into)
2525
}
26+
27+
#[tauri::command]
28+
pub async fn get_public_bots(app: AppHandle, req: GetPublicBotsRequest) -> Result<Vec<PublicBot>> {
29+
app
30+
.client(async |cl| cl.get_public_bots(req).await)
31+
.await
32+
.map_err(Into::into)
33+
}

app/src-tauri/src/command/npc/precursor.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,14 @@ pub async fn get_public_precursor(
2929
.await
3030
.map_err(Into::into)
3131
}
32+
33+
#[tauri::command]
34+
pub async fn get_public_precursors(
35+
app: AppHandle,
36+
req: GetPublicPrecursorsRequest,
37+
) -> Result<Vec<PublicPrecursor>> {
38+
app
39+
.client(async |cl| cl.get_public_precursors(req).await)
40+
.await
41+
.map_err(Into::into)
42+
}

app/src-tauri/src/command/player.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use nil_core::military::Military;
1010
use nil_core::player::{Player, PlayerStatus, PublicPlayer};
1111
use nil_core::report::ReportId;
1212
use nil_core::resources::maintenance::Maintenance;
13+
use nil_core::world::config::WorldId;
1314
use nil_payload::player::*;
1415
use tap::Pipe;
1516
use tauri::AppHandle;
@@ -89,6 +90,17 @@ pub async fn get_player_storage_capacity(
8990
.map_err(Into::into)
9091
}
9192

93+
#[tauri::command]
94+
pub async fn get_player_worlds(
95+
app: AppHandle,
96+
req: GetPlayerWorldsRequest,
97+
) -> Result<Vec<WorldId>> {
98+
app
99+
.client(async |cl| cl.get_player_worlds(req).await)
100+
.await
101+
.map_err(Into::into)
102+
}
103+
92104
#[tauri::command]
93105
pub async fn get_players(app: AppHandle, req: GetPlayersRequest) -> Result<Vec<Player>> {
94106
app

app/src-tauri/src/command/world.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
use crate::error::{CoreError, Error, Result};
55
use crate::manager::ManagerExt;
66
use itertools::Itertools;
7+
use nil_core::npc::bot::BotId;
8+
use nil_core::npc::precursor::PrecursorId;
79
use nil_core::player::{Player, PlayerId};
810
use nil_core::savedata::{Savedata, SavedataInfo};
911
use nil_core::world::config::{WorldConfig, WorldId};
@@ -53,6 +55,14 @@ pub async fn get_savedata_players(path: PathBuf) -> Result<Vec<PlayerId>> {
5355
.map_err(Into::into)
5456
}
5557

58+
#[tauri::command]
59+
pub async fn get_world_bots(app: AppHandle, req: GetWorldBotsRequest) -> Result<Vec<BotId>> {
60+
app
61+
.client(async |cl| cl.get_world_bots(req).await)
62+
.await
63+
.map_err(Into::into)
64+
}
65+
5666
#[tauri::command]
5767
pub async fn get_world_config(app: AppHandle, req: GetWorldConfigRequest) -> Result<WorldConfig> {
5868
app
@@ -61,6 +71,28 @@ pub async fn get_world_config(app: AppHandle, req: GetWorldConfigRequest) -> Res
6171
.map_err(Into::into)
6272
}
6373

74+
#[tauri::command]
75+
pub async fn get_world_players(
76+
app: AppHandle,
77+
req: GetWorldPlayersRequest,
78+
) -> Result<Vec<PlayerId>> {
79+
app
80+
.client(async |cl| cl.get_world_players(req).await)
81+
.await
82+
.map_err(Into::into)
83+
}
84+
85+
#[tauri::command]
86+
pub async fn get_world_precursors(
87+
app: AppHandle,
88+
req: GetWorldPrecursorsRequest,
89+
) -> Result<Vec<PrecursorId>> {
90+
app
91+
.client(async |cl| cl.get_world_precursors(req).await)
92+
.await
93+
.map_err(Into::into)
94+
}
95+
6496
#[tauri::command]
6597
pub async fn get_world_stats(app: AppHandle, req: GetWorldStatsRequest) -> Result<WorldStats> {
6698
app

app/src-tauri/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,18 @@ pub fn run() {
114114
command::military::request_maneuver,
115115
command::npc::bot::get_bot_coords,
116116
command::npc::bot::get_public_bot,
117+
command::npc::bot::get_public_bots,
117118
command::npc::precursor::get_precursor_coords,
118119
command::npc::precursor::get_public_precursor,
120+
command::npc::precursor::get_public_precursors,
119121
command::player::get_player,
120122
command::player::get_player_coords,
121123
command::player::get_player_maintenance,
122124
command::player::get_player_military,
123125
command::player::get_player_reports,
124126
command::player::get_player_status,
125127
command::player::get_player_storage_capacity,
128+
command::player::get_player_worlds,
126129
command::player::get_players,
127130
command::player::get_public_player,
128131
command::player::get_public_players,
@@ -153,7 +156,10 @@ pub fn run() {
153156
command::world::get_remote_world,
154157
command::world::get_remote_worlds,
155158
command::world::get_savedata_players,
159+
command::world::get_world_bots,
156160
command::world::get_world_config,
161+
command::world::get_world_players,
162+
command::world::get_world_precursors,
157163
command::world::get_world_stats,
158164
command::world::read_savedata_info,
159165
command::world::save_local_world,

app/src/commands/npc/bot.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: AGPL-3.0-only
33

44
import { invoke } from '@tauri-apps/api/core';
5-
import type { GetBotCoordsRequest, GetPublicBotRequest } from '@/lib/request';
5+
import type { GetBotCoordsRequest, GetPublicBotRequest, GetPublicBotsRequest } from '@/lib/request';
66

77
export async function getBotCoords(id: BotId) {
88
const req: GetBotCoordsRequest = {
@@ -21,3 +21,11 @@ export async function getPublicBot(id: BotId) {
2121

2222
return invoke<PublicBot>('get_public_bot', { req });
2323
}
24+
25+
export async function getPublicBots() {
26+
const req: GetPublicBotsRequest = {
27+
world: NIL.world.getIdStrict(),
28+
};
29+
30+
return invoke<readonly PublicBot[]>('get_public_bots', { req });
31+
}

app/src/commands/npc/precursor.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
// SPDX-License-Identifier: AGPL-3.0-only
33

44
import { invoke } from '@tauri-apps/api/core';
5-
import type { GetPrecursorCoordsRequest, GetPublicPrecursorRequest } from '@/lib/request';
5+
import type {
6+
GetPrecursorCoordsRequest,
7+
GetPublicPrecursorRequest,
8+
GetPublicPrecursorsRequest,
9+
} from '@/lib/request';
610

711
export async function getPrecursorCoords(id: PrecursorId) {
812
const req: GetPrecursorCoordsRequest = {
@@ -21,3 +25,11 @@ export async function getPublicPrecursor(id: PrecursorId) {
2125

2226
return invoke<PublicPrecursor>('get_public_precursor', { req });
2327
}
28+
29+
export async function getPublicPrecursors() {
30+
const req: GetPublicPrecursorsRequest = {
31+
world: NIL.world.getIdStrict(),
32+
};
33+
34+
return invoke<readonly PublicPrecursor[]>('get_public_precursors', { req });
35+
}

app/src/commands/player.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
GetPlayersRequest,
1313
GetPlayerStatusRequest,
1414
GetPlayerStorageCapacityRequest,
15+
GetPlayerWorldsRequest,
1516
GetPublicPlayerRequest,
1617
GetPublicPlayersRequest,
1718
PlayerExistsRequest,
@@ -78,6 +79,11 @@ export async function getPlayerStorageCapacity() {
7879
return invoke<OverallStorageCapacity>('get_player_storage_capacity', { req });
7980
}
8081

82+
export async function getPlayerWorlds(id: PlayerId) {
83+
const req: GetPlayerWorldsRequest = { id };
84+
return invoke<readonly WorldId[]>('get_player_worlds', { req });
85+
}
86+
8187
export async function getPlayers() {
8288
const req: GetPlayersRequest = {
8389
world: NIL.world.getIdStrict(),

app/src/commands/world.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import { type RawWorldStats, WorldStatsImpl } from '@/core/model/stats/world-sta
99
import type {
1010
CreateRemoteWorldRequest,
1111
GetRemoteWorldRequest,
12+
GetWorldBotsRequest,
1213
GetWorldConfigRequest,
14+
GetWorldPlayersRequest,
15+
GetWorldPrecursorsRequest,
1316
GetWorldStatsRequest,
1417
SaveLocalWorldRequest,
1518
} from '@/lib/request';
@@ -41,6 +44,14 @@ export async function getSavedataPlayers(path: string) {
4144
return invoke<readonly PlayerId[]>('get_savedata_players', { path });
4245
}
4346

47+
export async function getWorldBots(world?: Option<WorldId>) {
48+
const req: GetWorldBotsRequest = {
49+
world: world ?? NIL.world.getIdStrict(),
50+
};
51+
52+
return invoke<readonly BotId[]>('get_world_bots', { req });
53+
}
54+
4455
export async function getWorldConfig(world?: Option<WorldId>): Promise<WorldConfigImpl> {
4556
const req: GetWorldConfigRequest = {
4657
world: world ?? NIL.world.getIdStrict(),
@@ -50,6 +61,22 @@ export async function getWorldConfig(world?: Option<WorldId>): Promise<WorldConf
5061
return WorldConfigImpl.create(config);
5162
}
5263

64+
export async function getWorldPlayers(world?: Option<WorldId>) {
65+
const req: GetWorldPlayersRequest = {
66+
world: world ?? NIL.world.getIdStrict(),
67+
};
68+
69+
return invoke<readonly PlayerId[]>('get_world_players', { req });
70+
}
71+
72+
export async function getWorldPrecursors(world?: Option<WorldId>) {
73+
const req: GetWorldPrecursorsRequest = {
74+
world: world ?? NIL.world.getIdStrict(),
75+
};
76+
77+
return invoke<readonly PrecursorId[]>('get_world_precursors', { req });
78+
}
79+
5380
export async function getWorldStats(world?: Option<WorldId>): Promise<WorldStatsImpl> {
5481
const req: GetWorldStatsRequest = {
5582
world: world ?? NIL.world.getIdStrict(),

0 commit comments

Comments
 (0)