shared/domain/module/body/
legacy.rs

1#[allow(missing_docs)]
2pub mod activity;
3#[allow(missing_docs)]
4pub mod design;
5#[allow(missing_docs)]
6pub mod slide;
7
8use crate::domain::module::{
9    body::{Body, BodyConvert, BodyExt, ThemeId},
10    ModuleKind,
11};
12use serde::{Deserialize, Serialize};
13use std::collections::HashSet;
14
15/// The body for [`Legacy`](crate::domain::module::ModuleKind::Legacy) modules.
16/// This just points to the folder where legacy slides are loaded
17#[derive(Default, Clone, Serialize, Deserialize, Debug)]
18pub struct ModuleData {
19    /// base id for all file loading
20    pub game_id: String,
21
22    /// base id for all file loading
23    pub slide_id: String,
24}
25
26impl BodyExt<(), ()> for ModuleData {
27    fn as_body(&self) -> Body {
28        Body::Legacy(self.clone())
29    }
30
31    fn is_complete(&self) -> bool {
32        true
33    }
34
35    fn is_legacy() -> bool {
36        true
37    }
38    fn has_preload() -> bool {
39        true
40    }
41
42    fn kind() -> ModuleKind {
43        ModuleKind::Legacy
44    }
45
46    fn new_with_mode_and_theme(_mode: (), _theme_id: ThemeId) -> Self {
47        unimplemented!("can't create new legacy modules!")
48    }
49
50    fn mode(&self) -> Option<()> {
51        None
52    }
53
54    fn requires_choose_mode(&self) -> bool {
55        false
56    }
57
58    fn set_editor_state_step(&mut self, _step: ()) {}
59    fn set_editor_state_steps_completed(&mut self, _steps_completed: HashSet<()>) {}
60
61    fn get_editor_state_step(&self) -> Option<()> {
62        None
63    }
64
65    fn get_editor_state_steps_completed(&self) -> Option<HashSet<()>> {
66        None
67    }
68
69    fn set_theme(&mut self, _theme_id: ThemeId) {}
70
71    fn get_theme(&self) -> Option<ThemeId> {
72        None
73    }
74}
75
76impl BodyConvert for ModuleData {}
77
78impl TryFrom<Body> for ModuleData {
79    type Error = &'static str;
80
81    fn try_from(body: Body) -> Result<Self, Self::Error> {
82        match body {
83            Body::Legacy(data) => Ok(data),
84            _ => Err("cannot convert body to legacy!"),
85        }
86    }
87}