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