-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathobjective.py
45 lines (34 loc) · 1.41 KB
/
objective.py
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
from dataclasses import dataclass
from mashumaro.mixins.json import DataClassJSONMixin
from cb2game.server.messages.rooms import Role
@dataclass
class ObjectiveMessage(DataClassJSONMixin):
sender: Role = Role.NONE
text: str = ""
uuid: str = ""
completed: bool = False
cancelled: bool = False
feedback_text: str = ""
pos_feedback: int = 0
neg_feedback: int = 0
def update_feedback_text(self):
"""Helper to fully populate ObjectiveMessage.
This function uses the pos_feedback and neg_feedback integer fields of
ObjectiveMessage to populate the feedback_text field with a summary of
the feedback.
Renders the pos and neg feedback into a string using thumbs up/down signs like:
<pos_feedback> 👍 <neg_feedback> 👎
For now, we use a Unity sprite map instead of emoji. This is because
the emoji don't seem to be well supported. The sprite map is stored in
game/Assets/Resources/text_sprites and has two entities: thumbs_up and
thumbs_down (index 1 and index 0, respectively).
"""
pos = self.pos_feedback
neg = self.neg_feedback
if pos == 0 and neg == 0:
self.feedback_text = ""
return
self.feedback_text = f"{pos} <sprite index=1> {neg} <sprite index=0>"
@dataclass(frozen=True)
class ObjectiveCompleteMessage(DataClassJSONMixin):
uuid: str = ""