shared/domain/jig/
player.rs

1//! Types for Jig short codes for sharing
2
3use std::ops::Deref;
4
5use serde::{Deserialize, Serialize};
6
7/// Settings for the player session.
8#[derive(Serialize, Deserialize, Clone, Debug)]
9#[serde(rename_all = "camelCase")]
10pub struct JigPlayerSettings {
11    /// Text direction, left-to-right or right-to-left
12    #[serde(default)]
13    pub direction: TextDirection,
14    /// Scoring
15    #[serde(default)]
16    pub scoring: bool,
17    /// Whether or not to enable drag assist
18    #[serde(default)]
19    pub drag_assist: bool,
20}
21
22impl Default for JigPlayerSettings {
23    fn default() -> Self {
24        Self {
25            direction: TextDirection::default(),
26            scoring: false,
27            drag_assist: false,
28        }
29    }
30}
31
32/// Sets text direction for the jig.
33#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq)]
34#[cfg_attr(feature = "backend", derive(sqlx::Type))]
35#[repr(i16)]
36pub enum TextDirection {
37    /// left to right
38    #[serde(rename = "ltr")]
39    LeftToRight = 0,
40
41    /// right to left
42    #[serde(rename = "rtl")]
43    RightToLeft = 1,
44}
45
46impl Default for TextDirection {
47    fn default() -> Self {
48        Self::LeftToRight
49    }
50}
51
52impl TextDirection {
53    /// check if is left to right
54    pub fn is_ltr(&self) -> bool {
55        self == &Self::LeftToRight
56    }
57
58    /// check if is right to left
59    pub fn is_rtl(&self) -> bool {
60        self == &Self::RightToLeft
61    }
62}
63
64#[derive(Clone, Default, Serialize, Deserialize, Debug, Eq, PartialEq)]
65/// Module config passed to the JIG player when a module starts
66pub struct ModuleConfig {
67    /// How player navigation should be handled
68    pub navigation_handler: PlayerNavigationHandler,
69    /// Optional timer to use for the module
70    pub timer: Option<Seconds>,
71}
72
73#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
74/// How JIG player navigation should be handled
75pub enum PlayerNavigationHandler {
76    /// The JIG player handles the navigation
77    Player,
78    /// The module handles navigation
79    Module,
80}
81
82impl Default for PlayerNavigationHandler {
83    fn default() -> Self {
84        Self::Player
85    }
86}
87
88#[derive(Clone, Serialize, Deserialize, Debug, Eq, PartialEq)]
89/// Newtype for timer seconds
90pub struct Seconds(pub u32);
91
92impl Deref for Seconds {
93    type Target = u32;
94
95    fn deref(&self) -> &Self::Target {
96        &self.0
97    }
98}