ovos-skill-code-breaker 0.1.0a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. ovos_skill_code_breaker/__init__.py +63 -0
  2. ovos_skill_code_breaker/boardgame.py +381 -0
  3. ovos_skill_code_breaker/controlpanel.json +96 -0
  4. ovos_skill_code_breaker/controlpanel.svg +1 -0
  5. ovos_skill_code_breaker/engine.py +246 -0
  6. ovos_skill_code_breaker/icon.png +0 -0
  7. ovos_skill_code_breaker/icon.svg +1 -0
  8. ovos_skill_code_breaker/locale/ca-ES/codebreaker.json +237 -0
  9. ovos_skill_code_breaker/locale/ca-ES/codebreaker_skill.voc +5 -0
  10. ovos_skill_code_breaker/locale/ca-ES/controlpanel.json +21 -0
  11. ovos_skill_code_breaker/locale/ca-ES/play.intent +12 -0
  12. ovos_skill_code_breaker/locale/ca-ES/skill.json +28 -0
  13. ovos_skill_code_breaker/locale/da-DK/codebreaker.json +248 -0
  14. ovos_skill_code_breaker/locale/da-DK/codebreaker_skill.voc +5 -0
  15. ovos_skill_code_breaker/locale/da-DK/controlpanel.json +21 -0
  16. ovos_skill_code_breaker/locale/da-DK/play.intent +13 -0
  17. ovos_skill_code_breaker/locale/da-DK/skill.json +28 -0
  18. ovos_skill_code_breaker/locale/de-DE/codebreaker.json +244 -0
  19. ovos_skill_code_breaker/locale/de-DE/codebreaker_skill.voc +5 -0
  20. ovos_skill_code_breaker/locale/de-DE/controlpanel.json +21 -0
  21. ovos_skill_code_breaker/locale/de-DE/play.intent +12 -0
  22. ovos_skill_code_breaker/locale/de-DE/skill.json +28 -0
  23. ovos_skill_code_breaker/locale/en-US/codebreaker.json +241 -0
  24. ovos_skill_code_breaker/locale/en-US/codebreaker_skill.voc +6 -0
  25. ovos_skill_code_breaker/locale/en-US/controlpanel.json +21 -0
  26. ovos_skill_code_breaker/locale/en-US/play.intent +13 -0
  27. ovos_skill_code_breaker/locale/en-US/skill.json +28 -0
  28. ovos_skill_code_breaker/locale/es-ES/codebreaker.json +242 -0
  29. ovos_skill_code_breaker/locale/es-ES/codebreaker_skill.voc +5 -0
  30. ovos_skill_code_breaker/locale/es-ES/controlpanel.json +21 -0
  31. ovos_skill_code_breaker/locale/es-ES/play.intent +12 -0
  32. ovos_skill_code_breaker/locale/es-ES/skill.json +28 -0
  33. ovos_skill_code_breaker/locale/eu-ES/codebreaker.json +233 -0
  34. ovos_skill_code_breaker/locale/eu-ES/codebreaker_skill.voc +5 -0
  35. ovos_skill_code_breaker/locale/eu-ES/controlpanel.json +21 -0
  36. ovos_skill_code_breaker/locale/eu-ES/play.intent +12 -0
  37. ovos_skill_code_breaker/locale/eu-ES/skill.json +28 -0
  38. ovos_skill_code_breaker/locale/fr-FR/codebreaker.json +240 -0
  39. ovos_skill_code_breaker/locale/fr-FR/codebreaker_skill.voc +5 -0
  40. ovos_skill_code_breaker/locale/fr-FR/controlpanel.json +21 -0
  41. ovos_skill_code_breaker/locale/fr-FR/play.intent +12 -0
  42. ovos_skill_code_breaker/locale/fr-FR/skill.json +28 -0
  43. ovos_skill_code_breaker/locale/gl-ES/codebreaker.json +236 -0
  44. ovos_skill_code_breaker/locale/gl-ES/codebreaker_skill.voc +5 -0
  45. ovos_skill_code_breaker/locale/gl-ES/controlpanel.json +21 -0
  46. ovos_skill_code_breaker/locale/gl-ES/play.intent +12 -0
  47. ovos_skill_code_breaker/locale/gl-ES/skill.json +28 -0
  48. ovos_skill_code_breaker/locale/it-IT/codebreaker.json +241 -0
  49. ovos_skill_code_breaker/locale/it-IT/codebreaker_skill.voc +5 -0
  50. ovos_skill_code_breaker/locale/it-IT/controlpanel.json +21 -0
  51. ovos_skill_code_breaker/locale/it-IT/play.intent +12 -0
  52. ovos_skill_code_breaker/locale/it-IT/skill.json +28 -0
  53. ovos_skill_code_breaker/locale/nb-NO/codebreaker.json +240 -0
  54. ovos_skill_code_breaker/locale/nb-NO/codebreaker_skill.voc +5 -0
  55. ovos_skill_code_breaker/locale/nb-NO/controlpanel.json +21 -0
  56. ovos_skill_code_breaker/locale/nb-NO/play.intent +12 -0
  57. ovos_skill_code_breaker/locale/nb-NO/skill.json +28 -0
  58. ovos_skill_code_breaker/locale/nl-NL/codebreaker.json +236 -0
  59. ovos_skill_code_breaker/locale/nl-NL/codebreaker_skill.voc +5 -0
  60. ovos_skill_code_breaker/locale/nl-NL/controlpanel.json +21 -0
  61. ovos_skill_code_breaker/locale/nl-NL/play.intent +12 -0
  62. ovos_skill_code_breaker/locale/nl-NL/skill.json +28 -0
  63. ovos_skill_code_breaker/locale/pt-BR/codebreaker.json +239 -0
  64. ovos_skill_code_breaker/locale/pt-BR/codebreaker_skill.voc +5 -0
  65. ovos_skill_code_breaker/locale/pt-BR/controlpanel.json +21 -0
  66. ovos_skill_code_breaker/locale/pt-BR/play.intent +12 -0
  67. ovos_skill_code_breaker/locale/pt-BR/skill.json +28 -0
  68. ovos_skill_code_breaker/locale/pt-PT/codebreaker.json +238 -0
  69. ovos_skill_code_breaker/locale/pt-PT/codebreaker_skill.voc +5 -0
  70. ovos_skill_code_breaker/locale/pt-PT/controlpanel.json +21 -0
  71. ovos_skill_code_breaker/locale/pt-PT/play.intent +12 -0
  72. ovos_skill_code_breaker/locale/pt-PT/skill.json +28 -0
  73. ovos_skill_code_breaker/locale/sv-SE/codebreaker.json +240 -0
  74. ovos_skill_code_breaker/locale/sv-SE/codebreaker_skill.voc +5 -0
  75. ovos_skill_code_breaker/locale/sv-SE/controlpanel.json +21 -0
  76. ovos_skill_code_breaker/locale/sv-SE/play.intent +12 -0
  77. ovos_skill_code_breaker/locale/sv-SE/skill.json +28 -0
  78. ovos_skill_code_breaker/picture.py +198 -0
  79. ovos_skill_code_breaker/screenshot-portrait.png +0 -0
  80. ovos_skill_code_breaker/screenshot.png +0 -0
  81. ovos_skill_code_breaker-0.1.0a1.dist-info/METADATA +129 -0
  82. ovos_skill_code_breaker-0.1.0a1.dist-info/RECORD +86 -0
  83. ovos_skill_code_breaker-0.1.0a1.dist-info/WHEEL +5 -0
  84. ovos_skill_code_breaker-0.1.0a1.dist-info/entry_points.txt +2 -0
  85. ovos_skill_code_breaker-0.1.0a1.dist-info/licenses/LICENSE +201 -0
  86. ovos_skill_code_breaker-0.1.0a1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,63 @@
1
+ # Copyright 2026 emkay-voice
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Code Breaker: crack a secret colour code by voice.
16
+
17
+ "Play Code Breaker" - Emkay hides a code of four colours and you guess it:
18
+ "red, blue, green, yellow". After each guess Emkay tells how many are in the
19
+ right place, and how many more are a right colour in the wrong place. Or the
20
+ other way round: "play Code Breaker, you guess" - you think of a code and
21
+ Emkay cracks it from your answers ("two and one"). Easy and hard games too.
22
+ The board is on the screen. The game is saved as you go - also for your
23
+ other devices with My Emkay. Made for Emkay, works on any OpenVoiceOS."""
24
+ from .boardgame import BoardGameSkill, normalize
25
+ from .engine import Game, new_game
26
+ from .picture import compose
27
+
28
+
29
+ class CodeBreakerSkill(BoardGameSkill):
30
+ WORDS = "codebreaker.json"
31
+ VOC = "codebreaker_skill"
32
+ BUS = "codebreaker"
33
+ URI = "codebreaker:game"
34
+ ICON = "https://raw.githubusercontent.com/emkay-voice/ovos-skill-code-breaker/main/icon.png"
35
+ BACKGROUND = "#0d1326"
36
+
37
+ def new_game(self, utterance=""):
38
+ words = self._words()
39
+ said = f" {normalize(utterance)} "
40
+ mode = "make" if self.match(utterance, "you_guess") else "break"
41
+ level = "normal"
42
+ for name, spoken in words.get("levels", {}).items():
43
+ if any(f" {normalize(w)} " in said for w in spoken):
44
+ level = name
45
+ return new_game(mode, level)
46
+
47
+ def wants_new(self, utterance):
48
+ if not utterance:
49
+ return False
50
+ said = f" {normalize(utterance)} "
51
+ levels = [w for spoken in self._words().get("levels", {}).values() for w in spoken]
52
+ return self.match(utterance, "you_guess") or any(f" {normalize(w)} " in said for w in levels)
53
+
54
+ def make_game(self, g):
55
+ return Game(g, self._words())
56
+
57
+ def picture(self, game, portrait):
58
+ return compose(game.g, game.words, game.words["title"], portrait=portrait)
59
+
60
+ def panel_status(self, g):
61
+ words = self._words()
62
+ mode = words.get("panel", {}).get("mode_" + g["mode"], g["mode"])
63
+ return {"mode": mode, "guesses": f'{len(g["guesses"])} / {g["max"]}'}
@@ -0,0 +1,381 @@
1
+ # Copyright 2026 emkay-voice
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """What every board game of emkay-voice does the same way, so each game is
16
+ only its rules (engine.py) and its picture (picture.py).
17
+
18
+ * "play <game>" comes through OCP's search (OCP takes every "play ...") as a
19
+ game, and through the skill's own play.intent.
20
+ * While a game is on, what is said goes to the game first (converse), so
21
+ "down" or "seven" is the game's and not another skill's. The answer to
22
+ ovos-core is quick; the turn is played on the skill's own event.
23
+ * "stop" (can_stop/stop) saves the game and ends it; "play <game>" goes on.
24
+ * The game is saved after every turn, and on your other devices too (My
25
+ Emkay sync).
26
+ * The picture is drawn for a lying or a standing screen, as the screen says
27
+ (ovos-phal-plugin-browser) or as set.
28
+ * The control panel's page asks ovos.<bus>.status/start/reset/stop.
29
+
30
+ The same file is in every board game of emkay-voice; keep them alike.
31
+
32
+ A game (engine.Game) is made from its saved dict and the words of the
33
+ language: Game(g, words). It has .g (the dict that is saved), .handle(said)
34
+ -> the answer to say, .describe() -> where the game stands, and g["over"]
35
+ is None while it goes on, else "won", "lost" or "draw"."""
36
+ import json
37
+ import random
38
+ import re
39
+ import threading
40
+ import unicodedata
41
+ from pathlib import Path
42
+
43
+ from ovos_bus_client.message import Message
44
+ from ovos_utils import classproperty
45
+ from ovos_utils.ocp import MediaEntry, MediaType, PlaybackType, PlayerState, Playlist
46
+ from ovos_utils.process_utils import RuntimeRequirements
47
+ from ovos_workshop.decorators import intent_handler, ocp_featured_media, ocp_search
48
+ from ovos_workshop.skills.common_play import OVOSCommonPlaybackSkill
49
+ from ovos_workshop.skills.converse import ConversationalSkill
50
+
51
+
52
+ def normalize(text):
53
+ text = unicodedata.normalize("NFKC", str(text or "")).lower()
54
+ return " ".join(re.sub(r"[^\w\s]", " ", text).split())
55
+
56
+
57
+ def data_url(svg):
58
+ import base64
59
+ return "data:image/svg+xml;base64," + base64.b64encode(svg.encode("utf-8")).decode("ascii")
60
+
61
+
62
+ class BoardGameSkill(ConversationalSkill, OVOSCommonPlaybackSkill):
63
+ """Subclasses set the class names below and implement new_game, make_game,
64
+ picture and (optionally) panel_status."""
65
+
66
+ WORDS = "game.json" # the texts of the language (locale/<lang>/)
67
+ VOC = "game_skill" # OCP's keywords for this skill (locale/<lang>/<VOC>.voc)
68
+ BUS = "game" # the control panel's messages: ovos.<BUS>.status ...
69
+ URI = "game:play"
70
+ ICON = ""
71
+ BACKGROUND = "#0b1020"
72
+ DEFAULTS = {"pictures": True, "layout": "auto"}
73
+
74
+ @classproperty
75
+ def runtime_requirements(self):
76
+ return RuntimeRequirements(
77
+ internet_before_load=False, network_before_load=False,
78
+ requires_internet=False, requires_network=False,
79
+ no_internet_fallback=True, no_network_fallback=True)
80
+
81
+ def __init__(self, *args, **kwargs):
82
+ self.game = None # the Game while one is on
83
+ self._query = "" # what OCP was last asked to play
84
+ self._orientation = None # "portrait" or "landscape", as the screen says
85
+ kwargs.setdefault("supported_media", list(MediaType))
86
+ kwargs.setdefault("skill_voc_filename", self.VOC)
87
+ kwargs.setdefault("skill_icon", self.ICON)
88
+ super().__init__(*args, playback_handler=self._ocp_play, pause_handler=self._ocp_pause,
89
+ resume_handler=self._ocp_resume, **kwargs)
90
+
91
+ # -- what each game is -------------------------------------------------------
92
+
93
+ def new_game(self, utterance=""):
94
+ """The dict of a new game (as said: "play code breaker with five colours")."""
95
+ raise NotImplementedError
96
+
97
+ def make_game(self, g):
98
+ """The Game for this dict, in the words of the language."""
99
+ raise NotImplementedError
100
+
101
+ def picture(self, game, portrait):
102
+ """The SVG of the game as it is."""
103
+ raise NotImplementedError
104
+
105
+ def panel_status(self, g):
106
+ """Extra rows for the control panel's status block (saved game g)."""
107
+ return {}
108
+
109
+ def wants_new(self, utterance):
110
+ """Was a new game of some kind asked for ("play chess as black")? Then a
111
+ saved game is not taken up."""
112
+ return False
113
+
114
+ def resumable(self, g):
115
+ return isinstance(g, dict) and bool(g) and not g.get("over")
116
+
117
+ # -- start -------------------------------------------------------------------
118
+
119
+ def initialize(self):
120
+ self.add_event(f"{self.skill_id}.turn", self.handle_turn)
121
+ for msg_type, handler in (("status", self.handle_panel_status), ("start", self.handle_panel_start),
122
+ ("reset", self.handle_panel_reset), ("stop", self.handle_panel_stop)):
123
+ self.add_event(f"ovos.{self.BUS}.{msg_type}", handler)
124
+ self.add_event("ovos.phal.sensor", self.handle_sensor)
125
+ threading.Thread(target=self._ask_orientation, daemon=True).start()
126
+ try:
127
+ words = self._words()
128
+ self.register_ocp_keyword(MediaType.GAME, "game_name", words["names"] + [words["title"]])
129
+ except Exception as e: # an older OCP, or none
130
+ self.log.debug(f"no OCP keywords: {e}")
131
+
132
+ # -- the screen: standing or lying -----------------------------------------
133
+
134
+ def _ask_orientation(self):
135
+ """Emkay's browser tells which way the screen stands (ovos-phal-plugin-browser)."""
136
+ answer = self.bus.wait_for_response(
137
+ Message("ovos.phal.sensor.get", {"sensor_ids": ["screen_orientation"]}),
138
+ "ovos.phal.sensor.get.response", timeout=3)
139
+ reading = ((answer.data.get("sensors") or {}).get("screen_orientation") or {}) if answer else {}
140
+ if reading.get("state") in ("portrait", "landscape"):
141
+ self._orientation = reading["state"]
142
+
143
+ def handle_sensor(self, message):
144
+ data = message.data or {}
145
+ if data.get("sensor_id") == "screen_orientation" and data.get("state") in ("portrait", "landscape"):
146
+ changed = data["state"] != self._orientation
147
+ self._orientation = data["state"]
148
+ if changed and self.game:
149
+ self._show()
150
+
151
+ def portrait(self):
152
+ """A standing screen: set so, or (auto) the screen says it stands."""
153
+ layout = self.setting("layout")
154
+ if layout in ("portrait", "landscape"):
155
+ return layout == "portrait"
156
+ return self._orientation == "portrait"
157
+
158
+ # -- settings and texts --------------------------------------------------
159
+
160
+ def setting(self, key):
161
+ return self.settings.get(key, self.DEFAULTS.get(key))
162
+
163
+ def _words(self):
164
+ return self.resources.load_json_file(self.WORDS)
165
+
166
+ def say(self, key, **values):
167
+ text = self._words()["say"][key]
168
+ return (random.choice(text) if isinstance(text, list) else text).format(**values)
169
+
170
+ def match(self, utterance, key):
171
+ said = f" {normalize(utterance)} "
172
+ return any(f" {normalize(w)} " in said for w in self._words().get(key, []))
173
+
174
+ # -- saving --------------------------------------------------------------------
175
+
176
+ def _save_path(self):
177
+ folder = Path(self.file_system.path)
178
+ folder.mkdir(parents=True, exist_ok=True)
179
+ return folder / "game.json"
180
+
181
+ def load_game(self):
182
+ try:
183
+ return json.loads(self._save_path().read_text(encoding="utf-8"))
184
+ except (OSError, ValueError):
185
+ return None
186
+
187
+ def save(self):
188
+ if self.game:
189
+ self._save_path().write_text(json.dumps(self.game.g), encoding="utf-8")
190
+ self.bus.emit(Message("ovos.sync.set", {"ns": self.skill_id, "key": "game", "value": self.game.g}))
191
+
192
+ def forget_save(self):
193
+ self._save_path().unlink(missing_ok=True)
194
+ self.bus.emit(Message("ovos.sync.set", {"ns": self.skill_id, "key": "game", "value": None}))
195
+
196
+ def synced_game(self):
197
+ """A game saved on another of your devices (My Emkay)."""
198
+ answer = self.bus.wait_for_response(Message("ovos.sync.get", {"ns": self.skill_id, "key": "game"}),
199
+ "ovos.sync.get.response", timeout=1.5)
200
+ value = answer.data.get("value") if answer else None
201
+ return value if self.resumable(value) else None
202
+
203
+ # -- playing ---------------------------------------------------------------------
204
+
205
+ @intent_handler("play.intent")
206
+ def handle_play(self, message):
207
+ """"Play <game>", "start <game> over"."""
208
+ utterance = message.data.get("utterance", "")
209
+ self.start(fresh=self.match(utterance, "restart"), utterance=utterance)
210
+
211
+ def start(self, fresh=False, utterance=""):
212
+ fresh = fresh or self.wants_new(utterance)
213
+ saved = None if fresh else (self.load_game() or self.synced_game())
214
+ if self.resumable(saved):
215
+ self.game = self.make_game(saved)
216
+ opening = self.say("welcome_back") + " " + self.game.describe()
217
+ else:
218
+ self.game = self.make_game(self.new_game(utterance))
219
+ opening = self.say("intro") + " " + self.game.describe()
220
+ self._show()
221
+ self.speak(opening.strip(), expect_response=True)
222
+ self.save()
223
+ self._keep_active()
224
+
225
+ def _leave(self):
226
+ """Out of the active skills: what is said is everybody's again."""
227
+ try:
228
+ self.deactivate()
229
+ except Exception:
230
+ pass
231
+
232
+ def _keep_active(self):
233
+ try:
234
+ self.activate()
235
+ except Exception:
236
+ pass
237
+
238
+ def can_converse(self, message=None):
239
+ return self.game is not None
240
+
241
+ def converse(self, message=None):
242
+ if not self.game or message is None:
243
+ return False
244
+ utterance = (message.data.get("utterances") or [""])[0]
245
+ self.bus.emit(message.forward(f"{self.skill_id}.turn", {"utterance": utterance}))
246
+ return True
247
+
248
+ def handle_turn(self, message):
249
+ if self.game:
250
+ self.play_turn(message.data.get("utterance", ""))
251
+
252
+ def play_turn(self, utterance):
253
+ if self.match(utterance, "quit"):
254
+ self.save()
255
+ self.end()
256
+ self.speak(self.say("bye"))
257
+ return
258
+ if self.match(utterance, "restart"):
259
+ self.start(fresh=True, utterance=utterance)
260
+ return
261
+ game = self.game
262
+ game.words = self._words()
263
+ answer = game.handle(utterance)
264
+ self._show()
265
+ if game.g.get("over"):
266
+ self.forget_save()
267
+ self.speak(answer)
268
+ self.game = None
269
+ self._leave()
270
+ self._ocp_stopped()
271
+ return
272
+ self.save()
273
+ self.speak(answer, expect_response=True)
274
+ self._keep_active()
275
+
276
+ def end(self):
277
+ self.game = None
278
+ self._leave()
279
+ self._ocp_stopped()
280
+ try:
281
+ self.gui.release()
282
+ except Exception:
283
+ pass
284
+
285
+ def can_stop(self, message=None):
286
+ """The stop pipeline asks first: "stop" ends a game that is on."""
287
+ return bool(self.game)
288
+
289
+ def stop(self):
290
+ """"Stop": the game is saved and ends - "play ..." goes on with it."""
291
+ if self.game:
292
+ self.save()
293
+ bye = self.say("bye")
294
+ self.end()
295
+ self.speak(bye)
296
+ return True
297
+ return False
298
+
299
+ # -- OCP: "play ..." -------------------------------------------------------------------
300
+
301
+ def _entry(self, confidence):
302
+ return MediaEntry(uri=self.URI, title=self._words()["title"], image=self.ICON, skill_icon=self.ICON,
303
+ playback=PlaybackType.SKILL, media_type=MediaType.GAME, match_confidence=confidence)
304
+
305
+ @ocp_search()
306
+ def search_game(self, phrase, media_type=MediaType.GENERIC):
307
+ """"play <game>" -> the game."""
308
+ said = normalize(phrase)
309
+ self._query = phrase
310
+ names = sorted((normalize(n) for n in self._words()["names"]), key=len, reverse=True)
311
+ for n in names:
312
+ if n and f" {n} " in f" {said} ":
313
+ whole = len(n) >= len(said) - 4
314
+ game = media_type in (MediaType.GAME, MediaType.GENERIC)
315
+ confidence = (100 if whole else 90) if game else (80 if whole else 0)
316
+ return [self._entry(confidence)] if confidence else []
317
+ return []
318
+
319
+ @ocp_featured_media()
320
+ def featured_game(self):
321
+ playlist = Playlist(title=self._words()["title"], image=self.ICON, skill_icon=self.ICON,
322
+ playback=PlaybackType.SKILL, media_type=MediaType.GAME, match_confidence=100)
323
+ playlist.add_entry(self._entry(100))
324
+ return playlist
325
+
326
+ def _ocp_play(self, message=None):
327
+ self.start(utterance=self._query)
328
+
329
+ def _ocp_pause(self, message=None):
330
+ self.save()
331
+ return True
332
+
333
+ def _ocp_resume(self, message=None):
334
+ if self.game:
335
+ self.speak(self.game.describe(), expect_response=True)
336
+ return True
337
+
338
+ def _ocp_stopped(self):
339
+ """Tell OCP the game is over, so "next", "pause" and "play" are its own again."""
340
+ playing = getattr(self, "_playing", None)
341
+ if playing is not None and playing.is_set():
342
+ playing.clear()
343
+ self.bus.emit(Message("ovos.common_play.player.state", {"state": PlayerState.STOPPED}))
344
+
345
+ # -- the screen ------------------------------------------------------------------------
346
+
347
+ def _show(self):
348
+ if not self.game or not self.setting("pictures"):
349
+ return
350
+ words = self._words()
351
+ self.game.words = words
352
+ self.gui["image"] = data_url(self.picture(self.game, self.portrait()))
353
+ self.gui["title"] = words["title"]
354
+ self.gui["caption"] = ""
355
+ self.gui["fill"] = "PreserveAspectFit"
356
+ self.gui["background_color"] = self.BACKGROUND
357
+ self.gui.show_page("SYSTEM_ImageFrame", override_idle=True)
358
+
359
+ # -- the control panel ----------------------------------------------------------------
360
+
361
+ def handle_panel_status(self, message):
362
+ """The game on now, or the saved one: for the page's status block."""
363
+ g = self.game.g if self.game else self.load_game()
364
+ saved = self.resumable(g)
365
+ data = {"saved": saved, "playing": self.game is not None}
366
+ if saved:
367
+ data.update(self.panel_status(g))
368
+ self.bus.emit(message.response(data))
369
+
370
+ def handle_panel_start(self, message):
371
+ self.start()
372
+ self.bus.emit(message.response({"started": True}))
373
+
374
+ def handle_panel_reset(self, message):
375
+ if self.game:
376
+ self.end()
377
+ self.forget_save()
378
+ self.bus.emit(message.response({"reset": True}))
379
+
380
+ def handle_panel_stop(self, message):
381
+ self.bus.emit(message.response({"stopped": self.stop()}))
@@ -0,0 +1,96 @@
1
+ {
2
+ "controlpanel": 1,
3
+ "id": "codebreaker",
4
+ "title": "codebreaker.title",
5
+ "group": "everyday",
6
+ "order": 76,
7
+ "icon": "controlpanel.svg",
8
+ "bus": "ovos.codebreaker.",
9
+ "blocks": [
10
+ {
11
+ "type": "text",
12
+ "text": "codebreaker.intro"
13
+ },
14
+ {
15
+ "type": "status",
16
+ "heading": "codebreaker.game",
17
+ "query": "ovos.codebreaker.status",
18
+ "refresh": 10,
19
+ "rows": [
20
+ {
21
+ "text": "codebreaker.none",
22
+ "when": "!saved"
23
+ },
24
+ {
25
+ "text": "codebreaker.playing",
26
+ "when": "playing"
27
+ },
28
+ {
29
+ "label": "codebreaker.mode",
30
+ "value": "{mode}",
31
+ "when": "saved"
32
+ },
33
+ {
34
+ "label": "codebreaker.guesses",
35
+ "value": "{guesses}",
36
+ "when": "saved"
37
+ }
38
+ ],
39
+ "actions": [
40
+ {
41
+ "label": "codebreaker.play",
42
+ "send": "ovos.codebreaker.start",
43
+ "done": "codebreaker.started",
44
+ "when": "!playing"
45
+ },
46
+ {
47
+ "label": "codebreaker.reset",
48
+ "send": "ovos.codebreaker.reset",
49
+ "done": "codebreaker.was_reset",
50
+ "when": "saved",
51
+ "confirm": "codebreaker.confirm_reset"
52
+ },
53
+ {
54
+ "label": "codebreaker.stop",
55
+ "send": "ovos.codebreaker.stop",
56
+ "when": "playing"
57
+ }
58
+ ]
59
+ },
60
+ {
61
+ "type": "form",
62
+ "heading": "codebreaker.settings",
63
+ "save": {
64
+ "settings": true
65
+ },
66
+ "fields": [
67
+ {
68
+ "name": "pictures",
69
+ "label": "codebreaker.pictures",
70
+ "type": "checkbox",
71
+ "default": true
72
+ },
73
+ {
74
+ "name": "layout",
75
+ "label": "codebreaker.layout",
76
+ "type": "select",
77
+ "default": "auto",
78
+ "options": [
79
+ {
80
+ "value": "auto",
81
+ "label": "codebreaker.layout_auto"
82
+ },
83
+ {
84
+ "value": "portrait",
85
+ "label": "codebreaker.layout_portrait"
86
+ },
87
+ {
88
+ "value": "landscape",
89
+ "label": "codebreaker.layout_landscape"
90
+ }
91
+ ]
92
+ }
93
+ ]
94
+ }
95
+ ]
96
+ }
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><rect width="512" height="512" rx="96" fill="#134E4A"/><circle cx="106" cy="206" r="40" fill="#fff"/><circle cx="206" cy="206" r="40" fill="#fff"/><circle cx="306" cy="206" r="40" fill="#fff"/><circle cx="406" cy="206" r="34" fill="none" stroke="#fff" stroke-width="12"/><circle cx="186" cy="336" r="22" fill="#fff"/><circle cx="256" cy="336" r="22" fill="#fff"/><circle cx="326" cy="336" r="18" fill="none" stroke="#fff" stroke-width="9"/></svg>