Skip to main content

nil_payload/request/
city.rs

1// Copyright (C) Call of Nil contributors
2// SPDX-License-Identifier: AGPL-3.0-only
3
4use bon::Builder;
5use nil_core::city::CitySearch;
6use nil_core::continent::coord::Coord;
7use nil_core::world::config::WorldId;
8use serde::{Deserialize, Serialize};
9use std::collections::HashSet;
10
11#[cfg(feature = "typescript")]
12use ts_rs::TS;
13
14#[derive(Builder, Clone, Debug, Deserialize, Serialize)]
15#[serde(rename_all = "camelCase")]
16#[cfg_attr(feature = "typescript", derive(TS))]
17#[cfg_attr(feature = "typescript", ts(export))]
18pub struct GetCitiesRequest {
19  #[builder(start_fn, into)]
20  pub world: WorldId,
21  #[serde(default)]
22  #[builder(default, with = FromIterator::from_iter)]
23  pub coords: HashSet<Coord>,
24  #[serde(default)]
25  #[builder(default)]
26  pub score: bool,
27}
28
29#[derive(Builder, Clone, Debug, Deserialize, Serialize)]
30#[serde(rename_all = "camelCase")]
31#[cfg_attr(feature = "typescript", derive(TS))]
32#[cfg_attr(feature = "typescript", ts(export))]
33pub struct GetCityRequest {
34  #[builder(start_fn, into)]
35  pub world: WorldId,
36  #[builder(into)]
37  pub coord: Coord,
38  #[serde(default)]
39  #[builder(default)]
40  pub score: bool,
41}
42
43#[derive(Builder, Clone, Debug, Deserialize, Serialize)]
44#[serde(rename_all = "camelCase")]
45#[cfg_attr(feature = "typescript", derive(TS))]
46#[cfg_attr(feature = "typescript", ts(export))]
47pub struct GetCityScoreRequest {
48  #[builder(start_fn, into)]
49  pub world: WorldId,
50  #[builder(into)]
51  pub coord: Coord,
52}
53
54#[derive(Builder, Clone, Debug, Deserialize, Serialize)]
55#[serde(rename_all = "camelCase")]
56#[cfg_attr(feature = "typescript", derive(TS))]
57#[cfg_attr(feature = "typescript", ts(export))]
58pub struct GetPublicCitiesRequest {
59  #[builder(start_fn, into)]
60  pub world: WorldId,
61  #[serde(default)]
62  #[builder(default, with = FromIterator::from_iter)]
63  pub coords: HashSet<Coord>,
64  #[serde(default)]
65  #[builder(default)]
66  pub score: bool,
67  #[serde(default)]
68  #[builder(default)]
69  pub all: bool,
70}
71
72#[derive(Builder, Clone, Debug, Deserialize, Serialize)]
73#[serde(rename_all = "camelCase")]
74#[cfg_attr(feature = "typescript", derive(TS))]
75#[cfg_attr(feature = "typescript", ts(export))]
76pub struct GetPublicCityRequest {
77  #[builder(start_fn, into)]
78  pub world: WorldId,
79  #[builder(into)]
80  pub coord: Coord,
81  #[serde(default)]
82  #[builder(default)]
83  pub score: bool,
84}
85
86#[derive(Builder, Clone, Debug, Deserialize, Serialize)]
87#[serde(rename_all = "camelCase")]
88#[cfg_attr(feature = "typescript", derive(TS))]
89#[cfg_attr(feature = "typescript", ts(export))]
90pub struct RenameCityRequest {
91  #[builder(start_fn, into)]
92  pub world: WorldId,
93  #[builder(into)]
94  pub coord: Coord,
95  #[builder(into)]
96  pub name: String,
97}
98
99#[derive(Builder, Clone, Debug, Deserialize, Serialize)]
100#[serde(rename_all = "camelCase")]
101#[cfg_attr(feature = "typescript", derive(TS))]
102#[cfg_attr(feature = "typescript", ts(export))]
103pub struct SearchCityRequest {
104  #[builder(start_fn, into)]
105  pub world: WorldId,
106  #[builder(into)]
107  pub search: CitySearch,
108}
109
110#[derive(Builder, Clone, Debug, Deserialize, Serialize)]
111#[serde(rename_all = "camelCase")]
112#[cfg_attr(feature = "typescript", derive(TS))]
113#[cfg_attr(feature = "typescript", ts(export))]
114pub struct SearchPublicCityRequest {
115  #[builder(start_fn, into)]
116  pub world: WorldId,
117  #[builder(into)]
118  pub search: CitySearch,
119}