web_lib/offscreen_game/
wrappers.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
use mahjong_core::{score::ScoringRule, Wind};
use wasm_bindgen::prelude::wasm_bindgen;

#[wasm_bindgen(js_name = Wind)]
pub enum WindWasm {
    East,
    North,
    South,
    West,
}

impl From<Wind> for WindWasm {
    fn from(wind: Wind) -> Self {
        match wind {
            Wind::East => WindWasm::East,
            Wind::South => WindWasm::South,
            Wind::West => WindWasm::West,
            Wind::North => WindWasm::North,
        }
    }
}

impl From<WindWasm> for Wind {
    fn from(wind: WindWasm) -> Self {
        match wind {
            WindWasm::East => Wind::East,
            WindWasm::South => Wind::South,
            WindWasm::West => Wind::West,
            WindWasm::North => Wind::North,
        }
    }
}

#[wasm_bindgen(js_name = ScoringRule)]
pub enum ScoringRuleWasm {
    AllFlowers,
    AllInTriplets,
    AllSeasons,
    BasePoint,
    CommonHand,
    GreatDragons,
    LastWallTile,
    NoFlowersSeasons,
    SeatFlower,
    SeatSeason,
    SelfDraw,
}

impl From<ScoringRule> for ScoringRuleWasm {
    fn from(rule: ScoringRule) -> Self {
        match rule {
            ScoringRule::AllFlowers => Self::AllFlowers,
            ScoringRule::AllInTriplets => Self::AllInTriplets,
            ScoringRule::AllSeasons => Self::AllSeasons,
            ScoringRule::BasePoint => Self::BasePoint,
            ScoringRule::CommonHand => Self::CommonHand,
            ScoringRule::GreatDragons => Self::GreatDragons,
            ScoringRule::LastWallTile => Self::LastWallTile,
            ScoringRule::NoFlowersSeasons => Self::NoFlowersSeasons,
            ScoringRule::SeatFlower => Self::SeatFlower,
            ScoringRule::SeatSeason => Self::SeatSeason,
            ScoringRule::SelfDraw => Self::SelfDraw,
        }
    }
}

impl From<ScoringRuleWasm> for ScoringRule {
    fn from(rule: ScoringRuleWasm) -> Self {
        match rule {
            ScoringRuleWasm::AllFlowers => Self::AllFlowers,
            ScoringRuleWasm::AllInTriplets => Self::AllInTriplets,
            ScoringRuleWasm::AllSeasons => Self::AllSeasons,
            ScoringRuleWasm::BasePoint => Self::BasePoint,
            ScoringRuleWasm::CommonHand => Self::CommonHand,
            ScoringRuleWasm::GreatDragons => Self::GreatDragons,
            ScoringRuleWasm::LastWallTile => Self::LastWallTile,
            ScoringRuleWasm::NoFlowersSeasons => Self::NoFlowersSeasons,
            ScoringRuleWasm::SeatFlower => Self::SeatFlower,
            ScoringRuleWasm::SeatSeason => Self::SeatSeason,
            ScoringRuleWasm::SelfDraw => Self::SelfDraw,
        }
    }
}