diff --git a/__init__.py b/__init__.py index cd96e37476ea8adced98828108ab05f7e206e3c7..641c47e158a974425664a2a84ec3d6eccf94978f 100644 --- a/__init__.py +++ b/__init__.py @@ -29,6 +29,7 @@ class PetalHero(Application): self.loaded = False self.blm = None self.fiba_sound = None + self.select = select.SelectView(self.app) #self.blm_extra = bl00mbox.Channel("Petal Hero Extra") #self.blm_extra.background_mute_override = True @@ -123,11 +124,12 @@ class PetalHero(Application): self.repeats += 1 if self.input.buttons.app.middle.pressed: - self.app.in_sound.signals.trigger.start() - self.vm.push(select.SelectView(self.app), ViewTransitionSwipeLeft()) + utils.play_go(self.app) + self.vm.push(self.select, ViewTransitionSwipeLeft()) + self.select.play() if self.input.buttons.os.middle.pressed: - self.app.out_sound.signals.trigger.start() + utils.play_back(self.app) self.unload() if self.exiting: diff --git a/difficulty.py b/difficulty.py index 880d4b1a39e3e845f8951e8d7b0c2599c77c0b40..5c17b66d47eee945123684dd1791024a5975de64 100644 --- a/difficulty.py +++ b/difficulty.py @@ -115,8 +115,8 @@ class DifficultyView(BaseView): utils.play_crunch(self.app) if self.input.buttons.app.middle.pressed: - self.app.in_sound.signals.trigger.start() + utils.play_go(self.app) self.vm.replace(loading.LoadingView(self.app, self.song, self.song.difficulties[self._sc.target_position()]), ViewTransitionBlend()) if self.input.buttons.os.middle.pressed: - self.app.out_sound.signals.trigger.start() + utils.play_back(self.app) diff --git a/select.py b/select.py index 41ea5d150d5a21f551d529026cb244edfe069dbb..1da87d3ed807f4e56ca005bf25ebf12f817161a0 100644 --- a/select.py +++ b/select.py @@ -68,6 +68,8 @@ class SelectView(BaseView): self.processing_now = None self._sc.set_item_count(len(self.songs)) self._scroll_pos = 0 + self.process_delay = 250 + self.pos = -1 def draw(self, ctx: Context) -> None: @@ -86,7 +88,8 @@ class SelectView(BaseView): self.processing_now = None if self.to_process: - self.processing_now = self.to_process.pop() + if self.process_delay <= 0: + self.processing_now = self.to_process.pop() utils.fire_gradient(ctx) @@ -177,8 +180,10 @@ class SelectView(BaseView): def think(self, ins: InputState, delta_ms: int) -> None: super().think(ins, delta_ms) self._sc.think(ins, delta_ms) + if self.process_delay > 0: + self.process_delay -= delta_ms if not self.to_process and not self.processing_now: - media.think(delta_ms) + media.think(delta_ms) self.flower.think(delta_ms) self._scroll_pos += delta_ms / 1000 @@ -203,19 +208,18 @@ class SelectView(BaseView): media.load(self.songs[pos].dirName + "/song.mp3") if self.input.buttons.app.middle.pressed: - self.app.in_sound.signals.trigger.start() + utils.play_go(self.app) if self.songs: self.vm.push(difficulty.DifficultyView(self.app, self.songs[pos]), ViewTransitionSwipeLeft()) if self.input.buttons.os.middle.pressed: - self.app.out_sound.signals.trigger.start() + utils.play_back(self.app) def on_enter(self, vm: Optional[ViewManager]) -> None: super().on_enter(vm) - #self._vm = vm - # Ignore the button which brought us here until it is released - #self.input._ignore_pressed() + + def play(self): if self.songs: media.load(self.songs[self._sc.target_position()].dirName + "/song.mp3") diff --git a/song.py b/song.py index 60002d49cdcb6537607e7de2e35355e58f4a177c..056807f69b4070d61c4e5c37d50f551a4810df0a 100644 --- a/song.py +++ b/song.py @@ -31,10 +31,11 @@ class SongView(BaseView): self.events = [] self.petals = [False] * 5 self.demo_mode = False + self.fps = False + self.debug = False def draw(self, ctx: Context) -> None: - # Paint the background black - if self.delay < 1000: + if self.delay < 1750: sys_display.set_mode(2) ctx.compositing_mode = ctx.COPY @@ -44,15 +45,15 @@ class SongView(BaseView): ctx.gray(0.25) - self.time -= DELAY + self.time += DELAY for i in range(0, 2): - ctx.gray(0.30 - i/5*(1-(self.time/2 / self.data.period) % 1) * 0.15) - ctx.line_width = 2 + i/5*(1-(self.time/2 / self.data.period) % 1) * 2 + ctx.gray(0.4 + i * 0.12 + (1-(self.time/2 / self.data.period) % 1) * 0.12) + ctx.line_width = 1.75 + i * 0.12 + (1-(self.time/2 / self.data.period) % 1) * 0.12 pos = 23*2 * (i+1-(self.time/2 / self.data.period) % 1) if pos > 0: ctx.arc(0, 0, 28 + pos, 0, tau, 0) ctx.stroke() - self.time += DELAY + self.time -= DELAY ctx.line_width = 2 @@ -65,8 +66,8 @@ class SongView(BaseView): for i in range(5): ctx.move_to(0, 0) ctx.line_to(0, -120) - ctx.stroke() ctx.rotate(tau / 5) + ctx.stroke() ctx.restore() ctx.save() @@ -85,7 +86,7 @@ class SongView(BaseView): if self.demo_mode: time -= DELAY if (self.petals[i] or self.demo_mode) and time < self.time and time + length > self.time: - length -= self.time - time + length -= self.time - time + DELAY time = self.time orig_time = time during = True @@ -111,7 +112,7 @@ class SongView(BaseView): if pos >= 0: ctx.arc(0, 0, pos * 92 + 28, -arc + tau / 4, arc + tau / 4, 0) #ctx.arc(0, 0, max(0, - (stop - (time + length)) / (start - stop) * 120), -tau/40, tau/40, 1) - ctx.stroke() + ctx.stroke() ctx.rotate(tau / 5) ctx.restore() @@ -120,7 +121,7 @@ class SongView(BaseView): ctx.save() ctx.scale(0.42, 0.42) - self.time -= DELAY + self.time += DELAY wiggle = math.cos(((self.time / self.data.period / 2) % 1) * tau) * 0.1 self.flower.rot = tau / 5 / 2 + wiggle ctx.rgb(0.945, 0.631, 0.769) @@ -130,7 +131,7 @@ class SongView(BaseView): ctx.gray(0.3 * (1.0 - ((((self.time / self.data.period) % 1)**2) * 0.75) if self.started else 0.0)) ctx.arc(0, 0, 10, 0, tau, 0) ctx.fill() - self.time += DELAY + self.time -= DELAY ctx.save() ctx.gray(0.5) @@ -148,14 +149,21 @@ class SongView(BaseView): ctx.fill() ctx.restore() + ctx.gray(0.8) + ctx.text_align = ctx.CENTER + ctx.text_baseline = ctx.MIDDLE + if self.demo_mode: - ctx.gray(0.8) ctx.font = "Camp Font 2" ctx.font_size = 30 - ctx.text_align = ctx.CENTER - ctx.text_baseline = ctx.MIDDLE ctx.move_to (0, 40) ctx.text("DEMO") + + if self.fps: + ctx.font = "Camp Font 3" + ctx.font_size = 16 + ctx.move_to(0, 105) + ctx.text(f"{sys_display.fps():.2f}") def think(self, ins: InputState, delta_ms: int) -> None: super().think(ins, delta_ms) @@ -175,6 +183,12 @@ class SongView(BaseView): if self.input.buttons.app.middle.pressed: self.demo_mode = not self.demo_mode + if self.input.buttons.app.left.pressed: + self.fps = not self.fps + + if self.input.buttons.app.right.pressed: + self.debug = not self.debug + earlyMargin = 60000.0 / self.data.bpm / 3.5 lateMargin = 60000.0 / self.data.bpm / 3.5 @@ -197,7 +211,9 @@ class SongView(BaseView): p = 4 if petal == 0 else petal - 1 pressed = ins.captouch.petals[p*2].pressed active = self.petals[petal] - utils.petal_leds(petal, 1.0 if pressed and active else (0.15 if pressed else (1.0 if petal in notes and self.demo_mode else 0))) + d = 1.0 if pressed and active else (0.15 if pressed else (1.0 if petal in notes and self.demo_mode else 0)) + if d: + utils.petal_leds(petal, d) if not pressed: self.petals[petal] = False @@ -223,5 +239,5 @@ class SongView(BaseView): sys_display.set_mode(0) super().on_exit() self.app.blm.volume = 14000 - self.app.out_sound.signals.trigger.start() + utils.play_back(self.app) #gc.enable() diff --git a/songinfo.py b/songinfo.py index a9a2467f4ada9be67a29228bcedd214d0e86ee7d..27334df5b4f4b500978fe7e00bc41822d02091fe 100644 --- a/songinfo.py +++ b/songinfo.py @@ -85,7 +85,7 @@ class SongInfo(object): for b in diffs: self._difficulties.append(difficulties[int(b)]) if not self._difficulties: - os.unlink(diffFileName) + #os.unlink(diffFileName) # unlink's broken raise Exception self._difficulties.sort(key = lambda a: a.id, reverse=True) return self._difficulties diff --git a/utils.py b/utils.py index 08eec4e871dce011b3aea71e864ffac887e62f13..306b3b0da110a0358de14443c6c45e52067338b3 100644 --- a/utils.py +++ b/utils.py @@ -21,8 +21,10 @@ def fire_gradient(ctx): PETAL_COLORS = [GO_GREEN, RED, (1.0, 0.69, 0.0), BLUE, PUSH_RED] -def petal_leds(petal, val): - color = dim(PETAL_COLORS[petal], val) +def petal_leds(petal, val, color = None): + if not color: + color = PETAL_COLORS[petal] + color = dim(color, val) start = -11 + petal * 8 for i in range(start, start + 7): led = i @@ -39,3 +41,9 @@ def play_fiba(app): if not app.fiba_sound: return app.fiba_sound[random.randint(0, 5)].signals.trigger.start() + +def play_go(app): + app.in_sound.signals.trigger.start() + +def play_back(app): + app.out_sound.signals.trigger.start()