web_lib/offscreen_game/
wrappers.rs

1use mahjong_core::{score::ScoringRule, Wind};
2use wasm_bindgen::prelude::wasm_bindgen;
3
4#[wasm_bindgen(js_name = Wind)]
5pub enum WindWasm {
6    East,
7    North,
8    South,
9    West,
10}
11
12impl From<Wind> for WindWasm {
13    fn from(wind: Wind) -> Self {
14        match wind {
15            Wind::East => Self::East,
16            Wind::South => Self::South,
17            Wind::West => Self::West,
18            Wind::North => Self::North,
19        }
20    }
21}
22
23impl From<WindWasm> for Wind {
24    fn from(wind: WindWasm) -> Self {
25        match wind {
26            WindWasm::East => Self::East,
27            WindWasm::South => Self::South,
28            WindWasm::West => Self::West,
29            WindWasm::North => Self::North,
30        }
31    }
32}
33
34#[wasm_bindgen(js_name = ScoringRule)]
35pub enum ScoringRuleWasm {
36    AllFlowers,
37    AllInTriplets,
38    AllSeasons,
39    BasePoint,
40    CommonHand,
41    GreatDragons,
42    LastWallTile,
43    NoFlowersSeasons,
44    SeatFlower,
45    SeatSeason,
46    SelfDraw,
47    Purity,
48}
49
50impl From<ScoringRule> for ScoringRuleWasm {
51    fn from(rule: ScoringRule) -> Self {
52        match rule {
53            ScoringRule::AllFlowers => Self::AllFlowers,
54            ScoringRule::AllInTriplets => Self::AllInTriplets,
55            ScoringRule::AllSeasons => Self::AllSeasons,
56            ScoringRule::BasePoint => Self::BasePoint,
57            ScoringRule::CommonHand => Self::CommonHand,
58            ScoringRule::GreatDragons => Self::GreatDragons,
59            ScoringRule::LastWallTile => Self::LastWallTile,
60            ScoringRule::NoFlowersSeasons => Self::NoFlowersSeasons,
61            ScoringRule::SeatFlower => Self::SeatFlower,
62            ScoringRule::SeatSeason => Self::SeatSeason,
63            ScoringRule::SelfDraw => Self::SelfDraw,
64            ScoringRule::Purity => Self::Purity,
65        }
66    }
67}
68
69impl From<ScoringRuleWasm> for ScoringRule {
70    fn from(rule: ScoringRuleWasm) -> Self {
71        match rule {
72            ScoringRuleWasm::AllFlowers => Self::AllFlowers,
73            ScoringRuleWasm::AllInTriplets => Self::AllInTriplets,
74            ScoringRuleWasm::AllSeasons => Self::AllSeasons,
75            ScoringRuleWasm::BasePoint => Self::BasePoint,
76            ScoringRuleWasm::CommonHand => Self::CommonHand,
77            ScoringRuleWasm::GreatDragons => Self::GreatDragons,
78            ScoringRuleWasm::LastWallTile => Self::LastWallTile,
79            ScoringRuleWasm::NoFlowersSeasons => Self::NoFlowersSeasons,
80            ScoringRuleWasm::SeatFlower => Self::SeatFlower,
81            ScoringRuleWasm::SeatSeason => Self::SeatSeason,
82            ScoringRuleWasm::SelfDraw => Self::SelfDraw,
83            ScoringRuleWasm::Purity => Self::Purity,
84        }
85    }
86}