gamemstr_common/
world.rs

1use serde::{Deserialize, Serialize};
2use uuid::Uuid;
3
4pub mod campaign;
5pub mod location;
6pub mod map;
7pub mod npc;
8
9#[derive(Serialize, Deserialize, Debug)]
10pub struct World {
11    pub id: String,
12    pub name: String,
13    pub description: String,
14}
15
16impl World {
17    pub fn new(name: String, description: String) -> Self {
18        Self {
19            id: Uuid::new_v4().to_string(),
20            name,
21            description,
22        }
23    }
24}
25
26#[derive(Serialize, Deserialize, Debug)]
27pub struct WorldRequest {
28    pub name: Option<String>,
29    pub description: Option<String>,
30}
31
32impl WorldRequest {
33    pub fn to_world(&self) -> Option<World> {
34        match &self.name {
35            Some(name) => Some(World::new(
36                name.to_string(),
37                self.description.clone().expect("no description provided"),
38            )),
39            None => None,
40        }
41    }
42}