11"""
2- A factory for all dice types
2+ GoDice factory returning a proper Dice based on a shell
33"""
44import enum
55import bleak
88from . import xyzinterpret
99
1010
11- class DiceType (enum .Enum ):
11+ class DiceShell (enum .Enum ):
1212 """
13- Available types of a dice (shells)
13+ Available shells a dice may be wrapped into
1414 """
1515 D6 = 0
1616 D20 = 1
@@ -21,19 +21,29 @@ class DiceType(enum.Enum):
2121 D12 = 6
2222
2323xyz_interpret_map = {
24- DiceType .D6 : xyzinterpret .get_rolled_number_d6 ,
25- DiceType .D10 : xyzinterpret .get_rolled_number_d10 ,
26- DiceType .D10X : xyzinterpret .get_rolled_number_d10x ,
27- DiceType .D20 : xyzinterpret .get_rolled_number_d20 ,
28- DiceType .D4 : xyzinterpret .get_rolled_number_d4 ,
29- DiceType .D8 : xyzinterpret .get_rolled_number_d8 ,
30- DiceType .D12 : xyzinterpret .get_rolled_number_d12 ,
24+ DiceShell .D6 : xyzinterpret .get_rolled_number_d6 ,
25+ DiceShell .D10 : xyzinterpret .get_rolled_number_d10 ,
26+ DiceShell .D10X : xyzinterpret .get_rolled_number_d10x ,
27+ DiceShell .D20 : xyzinterpret .get_rolled_number_d20 ,
28+ DiceShell .D4 : xyzinterpret .get_rolled_number_d4 ,
29+ DiceShell .D8 : xyzinterpret .get_rolled_number_d8 ,
30+ DiceShell .D12 : xyzinterpret .get_rolled_number_d12 ,
3131}
3232
3333
34- def create (ble_client : bleak .BleakClient , dice_type : DiceType ):
34+ def create (ble_client : bleak .BleakClient , dice_shell : DiceShell ):
3535 """
3636 Creates Dice API object representing the specified type of a dice
3737 """
38- _xyzinterpret_fn = xyz_interpret_map [dice_type ]
39- return dice .Dice (ble_client , _xyzinterpret_fn )
38+ _dice = dice .Dice (ble_client )
39+ set_shell (_dice , dice_shell )
40+ return _dice
41+
42+
43+ def set_shell (_dice : dice .Dice , dice_shell : DiceShell ):
44+ """
45+ Change a dice shell.
46+ Should be called in order to receive correct number notifications corresponding to a newly set shell
47+ """
48+ _xyzinterpret_fn = xyz_interpret_map [dice_shell ]
49+ _dice ._xyz_interpret_fn = _xyzinterpret_fn
0 commit comments