shared/domain/jig/
player.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! Types for Jig short codes for sharing

use std::ops::Deref;

use serde::{Deserialize, Serialize};

/// Settings for the player session.
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct JigPlayerSettings {
    /// Text direction, left-to-right or right-to-left
    #[serde(default)]
    pub direction: TextDirection,
    /// Scoring
    #[serde(default)]
    pub scoring: bool,
    /// Whether or not to enable drag assist
    #[serde(default)]
    pub drag_assist: bool,
}

impl Default for JigPlayerSettings {
    fn default() -> Self {
        Self {
            direction: TextDirection::default(),
            scoring: false,
            drag_assist: false,
        }
    }
}

/// Sets text direction for the jig.
#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "backend", derive(sqlx::Type))]
#[repr(i16)]
pub enum TextDirection {
    /// left to right
    #[serde(rename = "ltr")]
    LeftToRight = 0,

    /// right to left
    #[serde(rename = "rtl")]
    RightToLeft = 1,
}

impl Default for TextDirection {
    fn default() -> Self {
        Self::LeftToRight
    }
}

impl TextDirection {
    /// check if is left to right
    pub fn is_ltr(&self) -> bool {
        self == &Self::LeftToRight
    }

    /// check if is right to left
    pub fn is_rtl(&self) -> bool {
        self == &Self::RightToLeft
    }
}

#[derive(Clone, Default, Serialize, Deserialize, Debug, Eq, PartialEq)]
/// Module config passed to the JIG player when a module starts
pub struct ModuleConfig {
    /// How player navigation should be handled
    pub navigation_handler: PlayerNavigationHandler,
    /// Optional timer to use for the module
    pub timer: Option<Seconds>,
}

#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
/// How JIG player navigation should be handled
pub enum PlayerNavigationHandler {
    /// The JIG player handles the navigation
    Player,
    /// The module handles navigation
    Module,
}

impl Default for PlayerNavigationHandler {
    fn default() -> Self {
        Self::Player
    }
}

#[derive(Clone, Serialize, Deserialize, Debug, Eq, PartialEq)]
/// Newtype for timer seconds
pub struct Seconds(pub u32);

impl Deref for Seconds {
    type Target = u32;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}