@astrofoundry/pi-astro 0.12.0 → 0.12.2

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.
@@ -1,5 +1,5 @@
1
1
  import type { Theme } from "@mariozechner/pi-coding-agent";
2
- import { matchesKey, visibleWidth } from "@mariozechner/pi-tui";
2
+ import { matchesKey, visibleWidth, type KeyId } from "@mariozechner/pi-tui";
3
3
  import {
4
4
  applyTick,
5
5
  changeDirection,
@@ -15,6 +15,12 @@ export interface TuiHandle {
15
15
  requestRender(): void;
16
16
  }
17
17
 
18
+ type Letter = "q" | "r" | "w" | "a" | "s" | "d";
19
+
20
+ function isLetter(data: string, letter: Letter): boolean {
21
+ return matchesKey(data, letter as KeyId) || matchesKey(data, `shift+${letter}` as KeyId);
22
+ }
23
+
18
24
  export class AstroSnakeComponent {
19
25
  private state: GameState;
20
26
  private timer: ReturnType<typeof setTimeout> | null = null;
@@ -37,12 +43,12 @@ export class AstroSnakeComponent {
37
43
 
38
44
  handleInput(data: string): void {
39
45
  if (this.state.status === "gameover" || this.state.status === "won") {
40
- if (data === "r" || data === "R" || data === " ") {
46
+ if (isLetter(data, "r") || matchesKey(data, "space")) {
41
47
  this.state = createInitialState();
42
48
  this.bump();
43
49
  return;
44
50
  }
45
- if (matchesKey(data, "escape") || data === "q" || data === "Q") {
51
+ if (matchesKey(data, "escape") || isLetter(data, "q")) {
46
52
  this.dispose();
47
53
  this.onClose();
48
54
  return;
@@ -50,17 +56,17 @@ export class AstroSnakeComponent {
50
56
  return;
51
57
  }
52
58
 
53
- if (matchesKey(data, "escape") || data === "q" || data === "Q") {
59
+ if (matchesKey(data, "escape") || isLetter(data, "q")) {
54
60
  this.dispose();
55
61
  this.onClose();
56
62
  return;
57
63
  }
58
64
 
59
65
  let req: Direction | null = null;
60
- if (matchesKey(data, "up") || data === "w" || data === "W") req = "up";
61
- else if (matchesKey(data, "down") || data === "s" || data === "S") req = "down";
62
- else if (matchesKey(data, "left") || data === "a" || data === "A") req = "left";
63
- else if (matchesKey(data, "right") || data === "d" || data === "D") req = "right";
66
+ if (matchesKey(data, "up") || isLetter(data, "w")) req = "up";
67
+ else if (matchesKey(data, "down") || isLetter(data, "s")) req = "down";
68
+ else if (matchesKey(data, "left") || isLetter(data, "a")) req = "left";
69
+ else if (matchesKey(data, "right") || isLetter(data, "d")) req = "right";
64
70
 
65
71
  if (!req) return;
66
72
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrofoundry/pi-astro",
3
- "version": "0.12.0",
3
+ "version": "0.12.2",
4
4
  "description": "Personal pi customizations (extensions, skills, prompts, themes) for the pi coding agent.",
5
5
  "keywords": [
6
6
  "pi-package"