omnipython-apps 0.1.4.dev8__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 (218) hide show
  1. apps/__init__.py +5 -0
  2. apps/about/__init__.py +257 -0
  3. apps/about/app.json +1 -0
  4. apps/about/credits.py +12 -0
  5. apps/about/facts.py +398 -0
  6. apps/about/fonts/OFL.txt +93 -0
  7. apps/about/fonts/latin1_14.bin +0 -0
  8. apps/about/fonts/latin1_16.bin +0 -0
  9. apps/about/fonts/latin1_24.bin +0 -0
  10. apps/about/fonts/latin1_32.bin +0 -0
  11. apps/about/fonts/latin1_40.bin +0 -0
  12. apps/backline/__init__.py +58 -0
  13. apps/backline/app.json +1 -0
  14. apps/backline/app.py +475 -0
  15. apps/backline/art.py +717 -0
  16. apps/backline/ask.py +781 -0
  17. apps/backline/box.py +502 -0
  18. apps/backline/cast.py +137 -0
  19. apps/backline/desk/__init__.py +329 -0
  20. apps/backline/desk/editor.py +331 -0
  21. apps/backline/desk/grid.py +154 -0
  22. apps/backline/desk/look.py +169 -0
  23. apps/backline/desk/pedals.py +102 -0
  24. apps/backline/desk/perform.py +157 -0
  25. apps/backline/desk/prompt.py +210 -0
  26. apps/backline/desk/strip.py +159 -0
  27. apps/backline/desk_main.py +226 -0
  28. apps/backline/engine.py +622 -0
  29. apps/backline/floor.py +509 -0
  30. apps/backline/footswitch.py +119 -0
  31. apps/backline/glyphs.py +82 -0
  32. apps/backline/kits.py +428 -0
  33. apps/backline/midipedal.py +362 -0
  34. apps/backline/page_data.py +413 -0
  35. apps/backline/parts.py +145 -0
  36. apps/backline/pedal.py +107 -0
  37. apps/backline/remote.py +134 -0
  38. apps/backline/songs/ballad_68.json +1 -0
  39. apps/backline/songs/bossa.json +1 -0
  40. apps/backline/songs/country_train.json +1 -0
  41. apps/backline/songs/funk.json +1 -0
  42. apps/backline/songs/metal.json +1 -0
  43. apps/backline/songs/pop.json +1 -0
  44. apps/backline/songs/rock.json +1 -0
  45. apps/backline/songs/shuffle.json +1 -0
  46. apps/battery/__init__.py +101 -0
  47. apps/battery/app.json +1 -0
  48. apps/bit_world/act_deck.py +683 -0
  49. apps/bit_world/act_game.py +762 -0
  50. apps/bit_world/act_pet.py +1032 -0
  51. apps/bit_world/app.json +1 -0
  52. apps/bit_world/bit_output.py +45 -0
  53. apps/bit_world/bit_palette.py +503 -0
  54. apps/bit_world/bit_sound.py +431 -0
  55. apps/bit_world/bit_sprites.py +632 -0
  56. apps/bit_world/bit_world.py +534 -0
  57. apps/btreceiver/__init__.py +690 -0
  58. apps/btreceiver/app.json +1 -0
  59. apps/btreceiver/chime.py +155 -0
  60. apps/btreceiver/demo.py +529 -0
  61. apps/btreceiver/screen.py +633 -0
  62. apps/camera/__init__.py +316 -0
  63. apps/camera/app.json +1 -0
  64. apps/card/__init__.py +113 -0
  65. apps/card/app.json +1 -0
  66. apps/cast/__init__.py +631 -0
  67. apps/cast/app.json +1 -0
  68. apps/cast/receivers.py +193 -0
  69. apps/chess/__init__.py +18 -0
  70. apps/chess/app.json +1 -0
  71. apps/chess/app.py +922 -0
  72. apps/chess/art.py +323 -0
  73. apps/chess/ble.py +411 -0
  74. apps/chess/engine.py +925 -0
  75. apps/chess/game.py +327 -0
  76. apps/chess/net.py +261 -0
  77. apps/clock/__init__.py +38 -0
  78. apps/clock/app.json +1 -0
  79. apps/detect/__init__.py +214 -0
  80. apps/detect/app.json +1 -0
  81. apps/fmsynth/__init__.py +41 -0
  82. apps/fmsynth/algorithms.py +61 -0
  83. apps/fmsynth/app.json +1 -0
  84. apps/fmsynth/app.py +355 -0
  85. apps/fmsynth/editor.py +206 -0
  86. apps/fmsynth/engine.py +257 -0
  87. apps/fmsynth/meters.py +262 -0
  88. apps/fmsynth/midi.py +375 -0
  89. apps/fmsynth/panel_view.py +1071 -0
  90. apps/fmsynth/patches/fmsynth-01.syx +0 -0
  91. apps/fmsynth/settings.py +138 -0
  92. apps/fmsynth/voice.py +398 -0
  93. apps/gamepad/__init__.py +685 -0
  94. apps/gamepad/app.json +1 -0
  95. apps/gamepad/pad.py +94 -0
  96. apps/gamepad/watch.py +352 -0
  97. apps/hidden/__init__.py +72 -0
  98. apps/hidden/app.json +1 -0
  99. apps/home/__init__.py +483 -0
  100. apps/home/app.json +1 -0
  101. apps/home/main.py +36 -0
  102. apps/homeassistant/__init__.py +213 -0
  103. apps/homeassistant/api.py +104 -0
  104. apps/homeassistant/app.json +1 -0
  105. apps/huey/__init__.py +287 -0
  106. apps/huey/acting.py +184 -0
  107. apps/huey/actor.py +194 -0
  108. apps/huey/app.json +1 -0
  109. apps/huey/client.py +125 -0
  110. apps/huey/servers.py +121 -0
  111. apps/huey/settings.example.json +8 -0
  112. apps/huey/settings.py +97 -0
  113. apps/huey/turn.py +504 -0
  114. apps/huey/voice.py +217 -0
  115. apps/info/__init__.py +810 -0
  116. apps/info/app.json +1 -0
  117. apps/lora/__init__.py +62 -0
  118. apps/lora/app.json +1 -0
  119. apps/manifest.py +71 -0
  120. apps/medialink_baby_monitor/__init__.py +222 -0
  121. apps/medialink_baby_monitor/app.json +1 -0
  122. apps/medialink_doorbell/__init__.py +251 -0
  123. apps/medialink_doorbell/app.json +1 -0
  124. apps/medialink_hands_free/__init__.py +217 -0
  125. apps/medialink_hands_free/app.json +1 -0
  126. apps/medialink_surveillance_camera/__init__.py +258 -0
  127. apps/medialink_surveillance_camera/app.json +1 -0
  128. apps/medialink_video_doorbell/__init__.py +289 -0
  129. apps/medialink_video_doorbell/app.json +1 -0
  130. apps/medialink_videophone/__init__.py +273 -0
  131. apps/medialink_videophone/app.json +1 -0
  132. apps/medialink_walkie_talkie/__init__.py +228 -0
  133. apps/medialink_walkie_talkie/app.json +1 -0
  134. apps/midicontroller/__init__.py +774 -0
  135. apps/midicontroller/app.json +1 -0
  136. apps/midicontroller/links.py +421 -0
  137. apps/midicontroller/surface.py +343 -0
  138. apps/midiengine/__init__.py +977 -0
  139. apps/midiengine/app.json +1 -0
  140. apps/midiengine/banks.py +85 -0
  141. apps/midiengine/midiin.py +165 -0
  142. apps/midiengine/player.py +392 -0
  143. apps/midiengine/umidiparser.py +1413 -0
  144. apps/mp3/__init__.py +240 -0
  145. apps/mp3/app.json +1 -0
  146. apps/perch/__init__.py +119 -0
  147. apps/perch/app.json +1 -0
  148. apps/perch/huey.py +481 -0
  149. apps/perch/huey_props.py +386 -0
  150. apps/perch/huey_shift.py +42 -0
  151. apps/perch/huey_views.py +296 -0
  152. apps/perch/scene_bench.py +680 -0
  153. apps/perch/scene_coast.py +479 -0
  154. apps/perch/scene_desk.py +492 -0
  155. apps/perch/stage.py +1274 -0
  156. apps/perch/vec.py +366 -0
  157. apps/repl/__init__.py +325 -0
  158. apps/repl/app.json +1 -0
  159. apps/roku/__init__.py +156 -0
  160. apps/roku/app.json +1 -0
  161. apps/rokucam/__init__.py +362 -0
  162. apps/rokucam/app.json +1 -0
  163. apps/security/__init__.py +261 -0
  164. apps/security/app.json +1 -0
  165. apps/settings/__init__.py +221 -0
  166. apps/settings/app.json +1 -0
  167. apps/shell/__init__.py +33 -0
  168. apps/shell/app.json +1 -0
  169. apps/spotify/__init__.py +669 -0
  170. apps/spotify/app.json +1 -0
  171. apps/spotify/screen.py +82 -0
  172. apps/steps/__init__.py +58 -0
  173. apps/steps/app.json +1 -0
  174. apps/stompbox/__init__.py +31 -0
  175. apps/stompbox/app.json +1 -0
  176. apps/stompbox/app.py +668 -0
  177. apps/stompbox/boards.json +20 -0
  178. apps/stompbox/effects.py +241 -0
  179. apps/stompbox/engine.py +340 -0
  180. apps/stompbox/footswitch.py +331 -0
  181. apps/stompbox/inputs.py +449 -0
  182. apps/stompbox/meter.py +72 -0
  183. apps/stompbox/outputs.py +135 -0
  184. apps/stompbox/pedals.txt +45 -0
  185. apps/stompbox/presets.py +106 -0
  186. apps/stompbox/styles.py +135 -0
  187. apps/stompbox/ui.py +817 -0
  188. apps/stompbox/wavfile.py +73 -0
  189. apps/synthstation/__init__.py +20 -0
  190. apps/synthstation/app.json +1 -0
  191. apps/synthstation/audio.py +397 -0
  192. apps/synthstation/catalog.py +50 -0
  193. apps/synthstation/meters.py +136 -0
  194. apps/synthstation/midi.py +380 -0
  195. apps/synthstation/pads.py +177 -0
  196. apps/synthstation/parts.py +128 -0
  197. apps/synthstation/station.py +1069 -0
  198. apps/system/__init__.py +11 -0
  199. apps/system/app.json +1 -0
  200. apps/touchcal/__init__.py +324 -0
  201. apps/touchcal/app.json +1 -0
  202. apps/touchcal/fit.py +262 -0
  203. apps/wake/__init__.py +268 -0
  204. apps/wake/app.json +1 -0
  205. apps/wake/feed.py +155 -0
  206. apps/watch/__init__.py +355 -0
  207. apps/watch/app.json +1 -0
  208. apps/watch/faces.py +35 -0
  209. apps/watch/wheel.py +157 -0
  210. apps/weather/__init__.py +278 -0
  211. apps/weather/app.json +1 -0
  212. apps/weather/icons.py +172 -0
  213. apps/weather/sizing.py +71 -0
  214. apps/weather/zippad.py +172 -0
  215. omnipython_apps-0.1.4.dev8.dist-info/METADATA +33 -0
  216. omnipython_apps-0.1.4.dev8.dist-info/RECORD +218 -0
  217. omnipython_apps-0.1.4.dev8.dist-info/WHEEL +5 -0
  218. omnipython_apps-0.1.4.dev8.dist-info/top_level.txt +1 -0
@@ -0,0 +1,534 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """Bit World: three pixel-art scenes with a robot called Bit, drawn with pygraphics and scored with synthio.
6
+
7
+ Follows Bit, a hovering CRT-faced robot companion, across three live scenes:
8
+
9
+ 1. Workshop Companion: expressive desktop pet and smart-home assistant HUD.
10
+ 2. Sky Ruins: four-layer parallax side-scrolling platformer and jetpack runner.
11
+ 3. Cyber-Deck: solarpunk reactor HMI with radial gauges, oscilloscope, FFT
12
+ spectrum analyzer, breaker switches, and an 8-pad live synth sequencer.
13
+
14
+ Plays hands-free in Attract Mode by default; click, tap, or press keys at any
15
+ time to take control or switch scenes. The X at the right of the stage bar,
16
+ or Esc, quits.
17
+
18
+ An appkit script app: choosing it on Home restarts the board into it, so it
19
+ has the panel to itself, and quitting restarts back to Home. Without a
20
+ launcher, put this folder on ``sys.path`` and ``import bit_world``.
21
+
22
+ Needs: audiodsp, multimer, palettes, pygraphics.
23
+ """
24
+
25
+ import gc
26
+ import sys
27
+
28
+ from boarddev import env_get
29
+
30
+ import board_config
31
+ import appdev
32
+
33
+ app = appdev.App(board_config)
34
+ try:
35
+ import board_peripherals
36
+ except ImportError: # a board with no audio out: the game runs silent
37
+ board_peripherals = None
38
+ import keys
39
+ from multimer import ticks_diff, ticks_ms
40
+
41
+ try:
42
+ from uctypes import addressof
43
+ except ImportError:
44
+ addressof = None
45
+ from bit_palette import (
46
+ ABYSS,
47
+ AMBER,
48
+ AQUA_GLOW,
49
+ CORAL,
50
+ CYAN,
51
+ DEEP_SLATE,
52
+ DEEP_TEAL,
53
+ EMERALD,
54
+ GOLD,
55
+ ICE_CYAN,
56
+ LIME_GLOW,
57
+ MIST,
58
+ NEON_PINK,
59
+ NIGHT,
60
+ SILVER,
61
+ SLATE,
62
+ STEEL,
63
+ VOID,
64
+ WHITE,
65
+ Layout,
66
+ OffHeapBuffer,
67
+ PanelState,
68
+ draw_pixel_panel,
69
+ draw_pixel_wipe,
70
+ init_rng,
71
+ make_canvas,
72
+ make_draw,
73
+ make_fb,
74
+ )
75
+ from bit_sprites import SpriteBank
76
+ from bit_output import pick_audio_out
77
+ from bit_sound import SoundEngine
78
+ from act_pet import WorkshopAct
79
+ from act_game import SkyRuinsAct
80
+ from act_deck import CyberDeckAct
81
+
82
+ # Change these to match your setup.
83
+ FRAME_MS = 33 # Target frame interval in milliseconds (~30 FPS)
84
+ PANEL_FRAME_MS = 10 # Frame interval on a board that shares its panel memory with the program
85
+ ACT_MS = 16000 # Milliseconds per scene in hands-free Attract Mode
86
+ WIPE_SPEED = 1.85 # Transition curtain speed (full wipe in ~0.54 seconds)
87
+
88
+ # A browser page has nowhere to go back to, so it shows no exit.
89
+ SHOW_EXIT = sys.platform not in ("webassembly", "emscripten")
90
+
91
+ ACT_TITLES = ("1:WORKSHOP", "2:SKY RUINS", "3:CYBER DECK")
92
+ ACT_SHORT = ("1:PET", "2:GAME", "3:HMI")
93
+ ACT_ACCENTS = (AQUA_GLOW, LIME_GLOW, GOLD)
94
+
95
+ display_drv = board_config.display_drv
96
+ # A portrait panel turns to landscape when the display can turn what's drawn.
97
+ # One that can't, such as a panel's own framebuffer, keeps its portrait layout:
98
+ # turning every frame in Python would be too slow at these sizes.
99
+ if display_drv.width < display_drv.height and getattr(display_drv, "can_rotate", True):
100
+ display_drv.rotation = (display_drv.rotation + 90) % 360
101
+
102
+ WIDTH = display_drv.width
103
+ HEIGHT = display_drv.height
104
+
105
+
106
+ class BitWorldDirector:
107
+ """Coordinate the 3 acts, stage bar UI, transitions, input, and audio."""
108
+
109
+ def __init__(self):
110
+ init_rng(42)
111
+ self.lay = Layout(WIDTH, HEIGHT)
112
+ # A board whose panel hands out two scan-out buffers is drawn into
113
+ # directly; every other display gets one off-screen frame that is
114
+ # copied across.
115
+ self.panels = {}
116
+ self.direct = self._share_panel_buffers()
117
+ # The full-screen buffers come first, one after another, while the
118
+ # heap's free space is still in large pieces. Made after the sprites,
119
+ # the sound and the acts' smaller objects, the last of them can find no
120
+ # piece big enough on a heap with plenty free in total.
121
+ gc.collect()
122
+ if OffHeapBuffer is None and sys.implementation.name == "micropython":
123
+ print("Bit World: this firmware has no offheap, so the frames are in the heap and each collection pauses the picture")
124
+ if not self.direct:
125
+ self.screen_buf, self.screen_fb = make_fb(WIDTH, HEIGHT, VOID)
126
+ # What blit_rect copies from: a display that copies with a slice
127
+ # assignment (a browser canvas's framebuffer) takes a memoryview,
128
+ # not an OffHeapBuffer.
129
+ self.screen_view = memoryview(self.screen_buf)
130
+ self.screen_draw = make_draw(self.screen_fb)
131
+ self.screen_state = PanelState()
132
+ backgrounds = [make_fb(WIDTH, HEIGHT, VOID) for _ in range(3)]
133
+
134
+ self.sprites = SpriteBank(self.lay)
135
+ self.sound = SoundEngine(board_peripherals, app, pick_audio_out())
136
+
137
+ self.act_pet = WorkshopAct(self.lay, self.sprites, self.sound, backgrounds[0])
138
+ self.act_game = SkyRuinsAct(self.lay, self.sprites, self.sound, backgrounds[1])
139
+ self.act_deck = CyberDeckAct(self.lay, self.sprites, self.sound, backgrounds[2])
140
+ self.acts = (self.act_pet, self.act_game, self.act_deck)
141
+
142
+ start_act = env_get("BIT_WORLD_ACT")
143
+ self.act_idx = int(start_act) % 3 if start_act is not None else 0
144
+ self.next_act_idx = self.act_idx
145
+ self.auto_mode = True
146
+ self.act_ms = 0
147
+ self.fps100 = 0 # smoothed frames per second, in hundredths
148
+ self.wipe_progress = 0.0
149
+ self.pointer_down = False
150
+ self.last_ms = ticks_ms()
151
+
152
+ self._compute_bar_geometry()
153
+ self.render_and_present(first_frame=True)
154
+
155
+ # Decide whether to draw straight into the panel's two scan-out buffers.
156
+ def _share_panel_buffers(self):
157
+ drv = display_drv
158
+ if addressof is None or not getattr(drv, "share_framebuffer", False):
159
+ return False
160
+ if drv.rotation or getattr(drv, "requires_byteswap", False):
161
+ return False
162
+ if not callable(getattr(drv, "framebuffers", None)):
163
+ return False
164
+ try:
165
+ bufs = drv.framebuffers()
166
+ except Exception:
167
+ return False
168
+ # One buffer would show every half-drawn frame, so it keeps the copy.
169
+ if len(bufs) < 2 or bufs[1] is None or bufs[3] != WIDTH * 2:
170
+ return False
171
+ if len(bufs[0]) < WIDTH * HEIGHT * 2:
172
+ return False
173
+ app.pause_refresh()
174
+ return True
175
+
176
+ # The panel's back buffer wrapped for drawing: (FrameBuffer, Draw, PanelState).
177
+ def _back_panel(self):
178
+ buf = display_drv.framebuffers()[0]
179
+ key = addressof(buf)
180
+ panel = self.panels.get(key)
181
+ if panel is None:
182
+ fb = make_canvas(buf, WIDTH, HEIGHT)
183
+ panel = (fb, make_draw(fb), PanelState())
184
+ self.panels[key] = panel
185
+ return panel
186
+
187
+ # Compute top stage bar tab and button hit rectangles for the active screen width.
188
+ def _compute_bar_geometry(self):
189
+ w = self.lay.w
190
+ bh = self.lay.bar_h
191
+ pad = self.lay.pad
192
+ btn_y = 3 if self.lay.compact else 4
193
+ btn_h = bh - btn_y * 2
194
+
195
+ # Reserve space on the left for the brand badge when width >= 600.
196
+ self.brand_w = 0 if self.lay.compact else 108
197
+ self.exit_w = (26 if self.lay.compact else 34) if SHOW_EXIT else 0
198
+ right_w = (62 if self.lay.compact else 82) * 2 + pad
199
+ if SHOW_EXIT:
200
+ right_w += self.exit_w + (4 if self.lay.compact else 6)
201
+ tabs_x0 = pad + self.brand_w
202
+ tabs_avail = w - tabs_x0 - right_w - pad * 2
203
+ gap = 4 if self.lay.compact else 6
204
+ tab_w = (tabs_avail - gap * 2) // 3
205
+
206
+ self.tab_rects = []
207
+ for i in range(3):
208
+ tx = tabs_x0 + i * (tab_w + gap)
209
+ self.tab_rects.append((tx, btn_y, tab_w, btn_h))
210
+
211
+ mode_w = 58 if self.lay.compact else 78
212
+ snd_w = 58 if self.lay.compact else 78
213
+ exit_x = w - pad - self.exit_w
214
+ self.rect_exit = (exit_x, btn_y, self.exit_w, btn_h)
215
+ snd_x = (exit_x - gap if SHOW_EXIT else w - pad) - snd_w
216
+ mode_x = snd_x - gap - mode_w
217
+ self.rect_mode = (mode_x, btn_y, mode_w, btn_h)
218
+ self.rect_sound = (snd_x, btn_y, snd_w, btn_h)
219
+
220
+ # Initiate a Bayer pixel-curtain wipe transition to target_idx.
221
+ def start_transition(self, target_idx):
222
+ target_idx = target_idx % len(self.acts)
223
+ if target_idx == self.act_idx and self.wipe_progress == 0.0:
224
+ self.act_ms = 0
225
+ return
226
+ self.next_act_idx = target_idx
227
+ if self.wipe_progress == 0.0:
228
+ self.wipe_progress = 0.02
229
+ self.sound.sfx_switch(True)
230
+
231
+ # Advance active scene simulation, transitions, and procedural soundtrack.
232
+ def step(self, _timer=None):
233
+ if app.quit_requested:
234
+ return
235
+ now = ticks_ms()
236
+ dt_ms = ticks_diff(now, self.last_ms)
237
+ self.last_ms = now
238
+
239
+ # Smooth the frame rate for the deck's frames-per-second dial, in whole numbers so
240
+ # only the deck's own frames make a float of it.
241
+ if dt_ms > 0:
242
+ self.fps100 += (100000 // dt_ms - self.fps100) // 10
243
+ if self.act_idx == 2:
244
+ self.act_deck.fps = self.fps100 / 100.0
245
+ if dt_ms <= 0:
246
+ dt_ms = 16
247
+ elif dt_ms > 100:
248
+ dt_ms = 100
249
+ dt = dt_ms / 1000.0
250
+
251
+ # Advance attract-mode scene cycle timer when no wipe is active.
252
+ if self.auto_mode and self.wipe_progress == 0.0:
253
+ self.act_ms += dt_ms
254
+ if self.act_ms >= ACT_MS:
255
+ self.act_ms = 0
256
+ self.start_transition((self.act_idx + 1) % len(self.acts))
257
+
258
+ # Advance the pixel curtain wipe and swap acts at midpoint (0.5).
259
+ if self.wipe_progress > 0.0:
260
+ prev = self.wipe_progress
261
+ self.wipe_progress += dt * WIPE_SPEED
262
+ if prev < 0.5 <= self.wipe_progress:
263
+ self.act_idx = self.next_act_idx
264
+ self.act_ms = 0
265
+ if self.wipe_progress >= 1.0:
266
+ self.wipe_progress = 0.0
267
+
268
+ self.acts[self.act_idx].update(dt, self.auto_mode)
269
+ self.sound.update(dt, self.act_idx, self.act_deck.state)
270
+ self.render_and_present(first_frame=False)
271
+
272
+ # Render the active act, transition curtain, and top stage bar, then blit to display.
273
+ def render_and_present(self, first_frame=False):
274
+ act = self.acts[self.act_idx]
275
+ if self.direct:
276
+ fb, draw, state = self._back_panel()
277
+ else:
278
+ fb, draw, state = self.screen_fb, self.screen_draw, self.screen_state
279
+ if state.act == self.act_idx and self.wipe_progress == 0.0:
280
+ # This buffer already shows the act: repaint what changed.
281
+ act.draw_changes(fb, draw, state)
282
+ else:
283
+ act.draw(fb, draw, state)
284
+ state.bar = None # the full redraw painted over the stage bar
285
+ # A buffer that gets a curtain wipe no longer shows its act.
286
+ state.act = self.act_idx if self.wipe_progress == 0.0 else -1
287
+
288
+ if self.wipe_progress > 0.0:
289
+ accent = ACT_ACCENTS[self.next_act_idx]
290
+ draw_pixel_wipe(
291
+ fb,
292
+ 0,
293
+ self.lay.scene_y,
294
+ self.lay.w,
295
+ self.lay.scene_h,
296
+ self.wipe_progress,
297
+ VOID,
298
+ accent,
299
+ )
300
+
301
+ # The stage bar only changes when a tab, a toggle or the progress line does.
302
+ # Its fields are compared in place, so a frame that leaves it alone allocates nothing.
303
+ bar = state.bar
304
+ progress = self._bar_progress()
305
+ if (
306
+ bar is not None
307
+ and bar[0] == self.act_idx
308
+ and bar[1] == self.auto_mode
309
+ and bar[2] == self.sound.muted
310
+ and bar[3] < progress
311
+ and self.wipe_progress == 0.0
312
+ ):
313
+ # Only the progress line grew: draw the new stretch of it.
314
+ tx, ty, _, th = self.tab_rects[self.act_idx]
315
+ fb.hline(tx + 3 + bar[3], ty + th - 3, progress - bar[3], ACT_ACCENTS[self.act_idx])
316
+ state.bar = (bar[0], bar[1], bar[2], progress)
317
+ elif (
318
+ bar is None
319
+ or bar[0] != self.act_idx
320
+ or bar[1] != self.auto_mode
321
+ or bar[2] != self.sound.muted
322
+ or bar[3] != progress
323
+ or self.wipe_progress > 0.0
324
+ ):
325
+ self._draw_stage_bar(fb)
326
+ if self.wipe_progress == 0.0:
327
+ state.bar = (self.act_idx, self.auto_mode, self.sound.muted, progress)
328
+ else:
329
+ state.bar = None
330
+ if self.direct:
331
+ # Promote the finished frame; the next frame waits for the flip.
332
+ if hasattr(display_drv, "show_nowait"):
333
+ display_drv.show_nowait()
334
+ else:
335
+ display_drv.show()
336
+ return
337
+ display_drv.blit_rect(self.screen_view, 0, 0, WIDTH, HEIGHT)
338
+ if first_frame:
339
+ display_drv.show()
340
+
341
+ # Width in pixels of the attract-mode progress line on the active tab.
342
+ def _bar_progress(self):
343
+ if not self.auto_mode:
344
+ return 0
345
+ tab_w = self.tab_rects[self.act_idx][2]
346
+ return (tab_w - 6) * min(self.act_ms, ACT_MS) // ACT_MS
347
+
348
+ # Draw the top navigation bar with act tabs, attract-mode progress, and toggles.
349
+ def _draw_stage_bar(self, fb):
350
+ w = self.lay.w
351
+ bh = self.lay.bar_h
352
+ fb.fill_rect(0, 0, w, bh, VOID)
353
+ fb.hline(0, bh - 1, w, STEEL)
354
+
355
+ if not self.lay.compact:
356
+ fb.text16("BIT WORLD", self.lay.pad, (bh - 16) >> 1, GOLD)
357
+
358
+ # Render the 3 scene selector tabs.
359
+ titles = ACT_SHORT if self.lay.compact else ACT_TITLES
360
+ for i, (tx, ty, tw, th) in enumerate(self.tab_rects):
361
+ active = i == self.act_idx
362
+ accent = ACT_ACCENTS[i]
363
+ bg = DEEP_TEAL if active else NIGHT
364
+ border = accent if active else SLATE
365
+ draw_pixel_panel(fb, tx, ty, tw, th, bg, border, WHITE if active else None)
366
+ lbl = titles[i]
367
+ lx = tx + ((tw - len(lbl) * 8) >> 1)
368
+ ly = ty + ((th - 8) >> 1) - (1 if active and self.auto_mode else 0)
369
+ fb.text(lbl, lx, ly, WHITE if active else SILVER)
370
+
371
+ # Draw a live progress bar along the bottom of the active tab in AUTO mode.
372
+ if active and self.auto_mode:
373
+ prog_w = self._bar_progress()
374
+ if prog_w > 0:
375
+ fb.hline(tx + 3, ty + th - 3, prog_w, accent)
376
+
377
+ # Render the AUTO / MANUAL mode button.
378
+ mx, my, mw, mh = self.rect_mode
379
+ m_col = LIME_GLOW if self.auto_mode else AMBER
380
+ draw_pixel_panel(fb, mx, my, mw, mh, NIGHT, m_col)
381
+ m_txt = "AUTO" if self.auto_mode else ("MAN" if self.lay.compact else "MANUAL")
382
+ fb.text(m_txt, mx + ((mw - len(m_txt) * 8) >> 1), my + ((mh - 8) >> 1), m_col)
383
+
384
+ # Render the SOUND / MUTE status button.
385
+ sx, sy, sw, sh = self.rect_sound
386
+ s_on = not self.sound.muted
387
+ s_col = AQUA_GLOW if s_on else CORAL
388
+ draw_pixel_panel(fb, sx, sy, sw, sh, NIGHT, s_col)
389
+ if self.lay.compact:
390
+ s_txt = "SND" if s_on else "MUTE"
391
+ else:
392
+ s_txt = "SND:ON" if s_on else "MUTED"
393
+ fb.text(s_txt, sx + ((sw - len(s_txt) * 8) >> 1), sy + ((sh - 8) >> 1), s_col)
394
+
395
+ # Render the exit button: a pixel X that quits back to Home.
396
+ if SHOW_EXIT:
397
+ ex, ey, ew, eh = self.rect_exit
398
+ draw_pixel_panel(fb, ex, ey, ew, eh, NIGHT, CORAL)
399
+ fb.text("X", ex + ((ew - 8) >> 1), ey + ((eh - 8) >> 1), CORAL)
400
+
401
+ # Route pointer press events to the top stage bar or active scene.
402
+ def on_pointer_down(self, x, y):
403
+ self.pointer_down = True
404
+ self.sound.try_unlock()
405
+
406
+ # Check top stage bar buttons first.
407
+ if y < self.lay.bar_h:
408
+ for i, (tx, ty, tw, th) in enumerate(self.tab_rects):
409
+ if tx <= x < tx + tw and ty <= y < ty + th:
410
+ self.start_transition(i)
411
+ return
412
+ mx, my, mw, mh = self.rect_mode
413
+ if mx <= x < mx + mw and my <= y < my + mh:
414
+ self.auto_mode = not self.auto_mode
415
+ self.act_ms = 0
416
+ self.sound.sfx_switch(self.auto_mode)
417
+ return
418
+ sx, sy, sw, sh = self.rect_sound
419
+ if sx <= x < sx + sw and sy <= y < sy + sh:
420
+ self.sound.toggle_mute()
421
+ return
422
+ ex, ey, ew, eh = self.rect_exit
423
+ if SHOW_EXIT and ex <= x < ex + ew and ey <= y < ey + eh:
424
+ app.request_quit()
425
+ return
426
+
427
+ # Clicking inside the scene engages manual control for the current act.
428
+ self.auto_mode = False
429
+ self.act_ms = 0
430
+ self.acts[self.act_idx].on_pointer_down(x, y)
431
+
432
+ # Route pointer motion events (for Bit eye tracking and Cyber-Deck fader drag).
433
+ def on_pointer_move(self, x, y):
434
+ if self.act_idx == 0:
435
+ self.act_pet.update_pointer_look(x, y)
436
+ elif self.act_idx == 2 and self.pointer_down and y >= self.lay.bar_h:
437
+ self.act_deck.on_pointer_down(x, y, is_drag=True)
438
+
439
+ # Record pointer release.
440
+ def on_pointer_up(self):
441
+ self.pointer_down = False
442
+
443
+ # Route keyboard shortcuts across all 3 acts.
444
+ def on_key_down(self, key):
445
+ if key == keys.K_ESCAPE and SHOW_EXIT:
446
+ app.request_quit()
447
+ return
448
+ self.sound.try_unlock()
449
+ if key == keys.K_1:
450
+ self.start_transition(0)
451
+ elif key == keys.K_2:
452
+ self.start_transition(1)
453
+ elif key == keys.K_3:
454
+ self.start_transition(2)
455
+ elif key in (keys.K_a, keys.K_TAB):
456
+ self.auto_mode = not self.auto_mode
457
+ self.act_ms = 0
458
+ self.sound.sfx_switch(self.auto_mode)
459
+ elif key == keys.K_m:
460
+ self.sound.toggle_mute()
461
+ elif key in (keys.K_SPACE, keys.K_UP, keys.K_w):
462
+ self.auto_mode = False
463
+ if self.act_idx == 0:
464
+ self.act_pet.trigger_action((self.act_pet.active_btn + 1) % 5)
465
+ elif self.act_idx == 1:
466
+ self.act_game.jump()
467
+ else:
468
+ self.act_deck.switches[0] = not self.act_deck.switches[0]
469
+ self.act_deck._sync_state()
470
+ self.sound.sfx_switch(self.act_deck.switches[0])
471
+ elif key in (keys.K_f, keys.K_RETURN, keys.K_RIGHT):
472
+ self.auto_mode = False
473
+ if self.act_idx == 0:
474
+ self.act_pet.trigger_action(2)
475
+ elif self.act_idx == 1:
476
+ self.act_game.fire()
477
+ else:
478
+ self.act_deck.switches[3] = not self.act_deck.switches[3]
479
+ self.act_deck._sync_state()
480
+ self.sound.sfx_switch(self.act_deck.switches[3])
481
+
482
+
483
+ director = BitWorldDirector()
484
+
485
+
486
+ # Periodic timer callback to unlock browser audio after the user's first gesture.
487
+ def _retry_audio(_timer=None):
488
+ if not director.sound.ready:
489
+ director.sound.try_unlock()
490
+
491
+
492
+ # Handle mouse button press and release events.
493
+ def _on_mouse_button(e):
494
+ if app.quit_requested:
495
+ return
496
+ if e.type == app.events.MOUSEBUTTONDOWN:
497
+ director.on_pointer_down(e.pos[0], e.pos[1])
498
+ else:
499
+ director.on_pointer_up()
500
+
501
+
502
+ # Handle mouse motion events.
503
+ def _on_mouse_motion(e):
504
+ if app.quit_requested:
505
+ return
506
+ director.on_pointer_move(e.pos[0], e.pos[1])
507
+
508
+
509
+ # Handle keyboard press events.
510
+ def _on_key(e):
511
+ if app.quit_requested:
512
+ return
513
+ if e.type == app.events.KEYDOWN:
514
+ director.on_key_down(e.key)
515
+
516
+
517
+ # Cleanly shut down audio and display drivers when the app quits, from the exit
518
+ # button, Esc or a closed window.
519
+ def _on_quit(_e=None):
520
+ director.sound.close()
521
+ display_drv.quit()
522
+
523
+
524
+ # A board whose panel memory the program can reach cannot keep up with FRAME_MS, so its
525
+ # frames overrun the period whatever it is. Give it a short period: the frame rate is
526
+ # then set by how long each frame takes.
527
+ frame_timer = app.every(
528
+ PANEL_FRAME_MS if getattr(display_drv, "share_framebuffer", False) else FRAME_MS, director.step
529
+ )
530
+ app.every(250, _retry_audio)
531
+ app.on([app.events.MOUSEBUTTONDOWN, app.events.MOUSEBUTTONUP], _on_mouse_button)
532
+ app.on(app.events.MOUSEMOTION, _on_mouse_motion)
533
+ app.on(app.events.KEYDOWN, _on_key)
534
+ app.on_quit(_on_quit)