veloren_server/settings/
server_physics.rs1use super::{EditableSetting, SERVER_PHYSICS_FORCE_FILENAME as FILENAME, editable::Version};
5use serde::{Deserialize, Serialize};
6use std::convert::Infallible;
7pub use v0::*;
8
9#[derive(Deserialize, Serialize)]
10pub enum ServerPhysicsForceListRaw {
11 V0(ServerPhysicsForceList),
12}
13
14#[expect(clippy::infallible_try_from)] impl TryFrom<ServerPhysicsForceListRaw> for (Version, ServerPhysicsForceList) {
16 type Error = <ServerPhysicsForceList as EditableSetting>::Error;
17
18 fn try_from(value: ServerPhysicsForceListRaw) -> Result<Self, Self::Error> {
19 use ServerPhysicsForceListRaw::*;
20 Ok(match value {
21 V0(mut value) => (value.validate()?, value),
22 })
23 }
24}
25
26impl From<ServerPhysicsForceList> for ServerPhysicsForceListRaw {
27 fn from(value: ServerPhysicsForceList) -> Self { Self::V0(value) }
28}
29
30impl EditableSetting for ServerPhysicsForceList {
31 type Error = Infallible;
32 type Legacy = ServerPhysicsForceList;
33 type Setting = ServerPhysicsForceListRaw;
34
35 const FILENAME: &'static str = FILENAME;
36}
37
38type Latest = ServerPhysicsForceList;
39
40mod v0 {
41 use super::Latest;
42 use authc::Uuid;
43 use serde::{Deserialize, Serialize};
44 use std::{
45 collections::HashMap,
46 ops::{Deref, DerefMut},
47 };
48
49 use crate::settings::{EditableSetting, editable::Version};
50
51 #[derive(Clone, Deserialize, Serialize, Debug)]
52 pub struct ServerPhysicsForceRecord {
53 pub by: Option<(Uuid, String)>,
56 pub reason: Option<String>,
57 }
58
59 #[derive(Clone, Deserialize, Serialize, Default)]
60 pub struct ServerPhysicsForceList(HashMap<Uuid, ServerPhysicsForceRecord>);
61
62 impl Deref for ServerPhysicsForceList {
63 type Target = HashMap<Uuid, ServerPhysicsForceRecord>;
64
65 fn deref(&self) -> &Self::Target { &self.0 }
66 }
67
68 impl DerefMut for ServerPhysicsForceList {
69 fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
70 }
71
72 impl ServerPhysicsForceList {
73 pub(super) fn validate(&mut self) -> Result<Version, <Latest as EditableSetting>::Error> {
74 Ok(Version::Latest)
75 }
76 }
77}