@thewhateverapp/tile-sdk 0.13.34 → 0.13.36

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.
@@ -0,0 +1,156 @@
1
+ /**
2
+ * PixiGame - A wrapper component that abstracts @pixi/react v7's Stage boilerplate
3
+ *
4
+ * @pixi/react v7 uses the Stage component which provides the Application context.
5
+ * Hooks like useTick must be used INSIDE the Stage tree.
6
+ *
7
+ * This component handles all of that setup automatically.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * import { PixiGame, useGameLoop, Container, Graphics } from '@thewhateverapp/tile-sdk';
12
+ *
13
+ * function MyGame() {
14
+ * return (
15
+ * <PixiGame>
16
+ * <GameContent />
17
+ * </PixiGame>
18
+ * );
19
+ * }
20
+ *
21
+ * function GameContent() {
22
+ * const playerRef = useRef({ x: 128, y: 400 });
23
+ *
24
+ * useGameLoop((delta) => {
25
+ * // Game logic here - runs every frame
26
+ * playerRef.current.x += 1 * delta;
27
+ * });
28
+ *
29
+ * return (
30
+ * <Container>
31
+ * <Graphics draw={(g) => {
32
+ * g.beginFill(0xff0000);
33
+ * g.drawRect(playerRef.current.x, playerRef.current.y, 32, 32);
34
+ * g.endFill();
35
+ * }} />
36
+ * </Container>
37
+ * );
38
+ * }
39
+ * ```
40
+ */
41
+ import React, { ReactNode } from 'react';
42
+ import { Container, Sprite, Graphics, Text, AnimatedSprite, TilingSprite, NineSlicePlane, useApp } from '@pixi/react';
43
+ export { Container, Sprite, Graphics, Text, AnimatedSprite, TilingSprite, NineSlicePlane };
44
+ export { useApp };
45
+ /**
46
+ * Tile dimensions - standard tile size
47
+ */
48
+ export declare const TILE_WIDTH = 256;
49
+ export declare const TILE_HEIGHT = 554;
50
+ export interface PixiGameProps {
51
+ children: ReactNode;
52
+ /** Width in pixels (default: 256 for tile) */
53
+ width?: number;
54
+ /** Height in pixels (default: 554 for tile) */
55
+ height?: number;
56
+ /** Background color (default: black) */
57
+ background?: number;
58
+ /** Stage options */
59
+ options?: {
60
+ antialias?: boolean;
61
+ resolution?: number;
62
+ autoDensity?: boolean;
63
+ };
64
+ /** Whether game is paused */
65
+ paused?: boolean;
66
+ /** Callback when Application is ready */
67
+ onMount?: (app: any) => void;
68
+ }
69
+ /**
70
+ * PixiGame - Main wrapper component for pixi.js games
71
+ *
72
+ * Provides the Stage/Application context that @pixi/react hooks need.
73
+ * All game content should be rendered as children of this component.
74
+ *
75
+ * Use pixi components directly:
76
+ * - <Container> - Container for grouping elements
77
+ * - <Sprite texture={...}> - Sprite with texture
78
+ * - <Graphics draw={...}> - Graphics with draw callback
79
+ * - <Text text="..." style={...}> - Text element
80
+ */
81
+ export declare function PixiGame({ children, width, height, background, options, paused, onMount, }: PixiGameProps): React.JSX.Element;
82
+ /**
83
+ * useGameLoop - A more intuitive name for useTick
84
+ *
85
+ * Runs a callback every frame with delta time.
86
+ * Must be used inside a PixiGame component (or any @pixi/react Stage).
87
+ *
88
+ * @param callback - Function called every frame with delta time (in frames, ~1 at 60fps)
89
+ * @param enabled - Whether the loop is active (default: true)
90
+ *
91
+ * @example
92
+ * ```tsx
93
+ * function GameContent() {
94
+ * const posRef = useRef({ x: 0, y: 0 });
95
+ *
96
+ * useGameLoop((delta) => {
97
+ * posRef.current.x += 2 * delta;
98
+ * if (posRef.current.x > 256) posRef.current.x = 0;
99
+ * });
100
+ *
101
+ * return <Sprite x={posRef.current.x} y={posRef.current.y} texture={...} />;
102
+ * }
103
+ * ```
104
+ */
105
+ export declare function useGameLoop(callback: (delta: number) => void, enabled?: boolean): void;
106
+ /**
107
+ * useGameState - Helper for managing game state with refs
108
+ *
109
+ * Returns a ref and a forceUpdate function for when you need to trigger re-renders.
110
+ * Use refs for continuous game state (position, velocity) to avoid re-render loops.
111
+ *
112
+ * @example
113
+ * ```tsx
114
+ * function GameContent() {
115
+ * const [state, forceUpdate] = useGameState({
116
+ * playerX: 128,
117
+ * playerY: 400,
118
+ * score: 0,
119
+ * });
120
+ *
121
+ * useGameLoop((delta) => {
122
+ * state.current.playerX += 1 * delta;
123
+ * if (scoreChanged) {
124
+ * forceUpdate(); // Only re-render when score changes
125
+ * }
126
+ * });
127
+ *
128
+ * return <Text text={`Score: ${state.current.score}`} />;
129
+ * }
130
+ * ```
131
+ */
132
+ export declare function useGameState<T extends object>(initialState: T): [React.MutableRefObject<T>, () => void];
133
+ /**
134
+ * useGameInput - Simple keyboard input hook for games
135
+ *
136
+ * Returns a ref with currently pressed keys.
137
+ * Can be used inside or outside PixiGame component.
138
+ *
139
+ * @example
140
+ * ```tsx
141
+ * function GameContent() {
142
+ * const keys = useGameInput();
143
+ * const posRef = useRef({ x: 128, y: 400 });
144
+ *
145
+ * useGameLoop((delta) => {
146
+ * if (keys.current.ArrowLeft) posRef.current.x -= 5 * delta;
147
+ * if (keys.current.ArrowRight) posRef.current.x += 5 * delta;
148
+ * if (keys.current[' ']) jump(); // Space key
149
+ * });
150
+ *
151
+ * return <Sprite x={posRef.current.x} y={posRef.current.y} texture={...} />;
152
+ * }
153
+ * ```
154
+ */
155
+ export declare function useGameInput(): React.MutableRefObject<Record<string, boolean>>;
156
+ //# sourceMappingURL=PixiGame.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PixiGame.d.ts","sourceRoot":"","sources":["../../src/react/PixiGame.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,KAAK,EAAE,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;AACzE,OAAO,EAEL,SAAS,EACT,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,cAAc,EACd,YAAY,EACZ,cAAc,EAEd,MAAM,EACP,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC;AAG3F,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB;;GAE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4
+ *
5
+ * @pixi/react v7 uses the Stage component which provides the Application context.
6
+ * Hooks like useTick must be used INSIDE the Stage tree.
7
+ *
8
+ * This component handles all of that setup automatically.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * import { PixiGame, useGameLoop, Container, Graphics } from '@thewhateverapp/tile-sdk';
13
+ *
14
+ * function MyGame() {
15
+ * return (
16
+ * <PixiGame>
17
+ * <GameContent />
18
+ * </PixiGame>
19
+ * );
20
+ * }
21
+ *
22
+ * function GameContent() {
23
+ * const playerRef = useRef({ x: 128, y: 400 });
24
+ *
25
+ * useGameLoop((delta) => {
26
+ * // Game logic here - runs every frame
27
+ * playerRef.current.x += 1 * delta;
28
+ * });
29
+ *
30
+ * return (
31
+ * <Container>
32
+ * <Graphics draw={(g) => {
33
+ * g.beginFill(0xff0000);
34
+ * g.drawRect(playerRef.current.x, playerRef.current.y, 32, 32);
35
+ * g.endFill();
36
+ * }} />
37
+ * </Container>
38
+ * );
39
+ * }
40
+ * ```
41
+ */
42
+ import React, { useCallback, useRef, useEffect } from 'react';
43
+ import { Stage, Container, Sprite, Graphics, Text, AnimatedSprite, TilingSprite, NineSlicePlane, useTick, useApp, } from '@pixi/react';
44
+ // Re-export @pixi/react components for convenience
45
+ export { Container, Sprite, Graphics, Text, AnimatedSprite, TilingSprite, NineSlicePlane };
46
+ // Re-export useApp for advanced use cases
47
+ export { useApp };
48
+ /**
49
+ * Tile dimensions - standard tile size
50
+ */
51
+ export const TILE_WIDTH = 256;
52
+ export const TILE_HEIGHT = 554;
53
+ /**
54
+ * PixiGame - Main wrapper component for pixi.js games
55
+ *
56
+ * Provides the Stage/Application context that @pixi/react hooks need.
57
+ * All game content should be rendered as children of this component.
58
+ *
59
+ * Use pixi components directly:
60
+ * - <Container> - Container for grouping elements
61
+ * - <Sprite texture={...}> - Sprite with texture
62
+ * - <Graphics draw={...}> - Graphics with draw callback
63
+ * - <Text text="..." style={...}> - Text element
64
+ */
65
+ export function PixiGame({ children, width = TILE_WIDTH, height = TILE_HEIGHT, background = 0x000000, options = {}, paused = false, onMount, }) {
66
+ const stageOptions = {
67
+ antialias: options.antialias ?? true,
68
+ resolution: options.resolution ?? (typeof window !== 'undefined' ? window.devicePixelRatio : 1),
69
+ autoDensity: options.autoDensity ?? true,
70
+ backgroundColor: background,
71
+ };
72
+ return (React.createElement(Stage, { width: width, height: height, options: stageOptions, onMount: onMount },
73
+ React.createElement(GameWrapper, { paused: paused }, children)));
74
+ }
75
+ /**
76
+ * Internal wrapper that provides pause functionality
77
+ */
78
+ function GameWrapper({ children, paused, }) {
79
+ const app = useApp();
80
+ useEffect(() => {
81
+ if (app?.ticker) {
82
+ if (paused) {
83
+ app.ticker.stop();
84
+ }
85
+ else {
86
+ app.ticker.start();
87
+ }
88
+ }
89
+ }, [app, paused]);
90
+ return React.createElement(React.Fragment, null, children);
91
+ }
92
+ /**
93
+ * useGameLoop - A more intuitive name for useTick
94
+ *
95
+ * Runs a callback every frame with delta time.
96
+ * Must be used inside a PixiGame component (or any @pixi/react Stage).
97
+ *
98
+ * @param callback - Function called every frame with delta time (in frames, ~1 at 60fps)
99
+ * @param enabled - Whether the loop is active (default: true)
100
+ *
101
+ * @example
102
+ * ```tsx
103
+ * function GameContent() {
104
+ * const posRef = useRef({ x: 0, y: 0 });
105
+ *
106
+ * useGameLoop((delta) => {
107
+ * posRef.current.x += 2 * delta;
108
+ * if (posRef.current.x > 256) posRef.current.x = 0;
109
+ * });
110
+ *
111
+ * return <Sprite x={posRef.current.x} y={posRef.current.y} texture={...} />;
112
+ * }
113
+ * ```
114
+ */
115
+ export function useGameLoop(callback, enabled = true) {
116
+ useTick(callback, enabled);
117
+ }
118
+ /**
119
+ * useGameState - Helper for managing game state with refs
120
+ *
121
+ * Returns a ref and a forceUpdate function for when you need to trigger re-renders.
122
+ * Use refs for continuous game state (position, velocity) to avoid re-render loops.
123
+ *
124
+ * @example
125
+ * ```tsx
126
+ * function GameContent() {
127
+ * const [state, forceUpdate] = useGameState({
128
+ * playerX: 128,
129
+ * playerY: 400,
130
+ * score: 0,
131
+ * });
132
+ *
133
+ * useGameLoop((delta) => {
134
+ * state.current.playerX += 1 * delta;
135
+ * if (scoreChanged) {
136
+ * forceUpdate(); // Only re-render when score changes
137
+ * }
138
+ * });
139
+ *
140
+ * return <Text text={`Score: ${state.current.score}`} />;
141
+ * }
142
+ * ```
143
+ */
144
+ export function useGameState(initialState) {
145
+ const stateRef = useRef(initialState);
146
+ const [, setTick] = React.useState(0);
147
+ const forceUpdate = useCallback(() => {
148
+ setTick((t) => t + 1);
149
+ }, []);
150
+ return [stateRef, forceUpdate];
151
+ }
152
+ /**
153
+ * useGameInput - Simple keyboard input hook for games
154
+ *
155
+ * Returns a ref with currently pressed keys.
156
+ * Can be used inside or outside PixiGame component.
157
+ *
158
+ * @example
159
+ * ```tsx
160
+ * function GameContent() {
161
+ * const keys = useGameInput();
162
+ * const posRef = useRef({ x: 128, y: 400 });
163
+ *
164
+ * useGameLoop((delta) => {
165
+ * if (keys.current.ArrowLeft) posRef.current.x -= 5 * delta;
166
+ * if (keys.current.ArrowRight) posRef.current.x += 5 * delta;
167
+ * if (keys.current[' ']) jump(); // Space key
168
+ * });
169
+ *
170
+ * return <Sprite x={posRef.current.x} y={posRef.current.y} texture={...} />;
171
+ * }
172
+ * ```
173
+ */
174
+ export function useGameInput() {
175
+ const keysRef = useRef({});
176
+ useEffect(() => {
177
+ const handleKeyDown = (e) => {
178
+ keysRef.current[e.key] = true;
179
+ keysRef.current[e.code] = true;
180
+ };
181
+ const handleKeyUp = (e) => {
182
+ keysRef.current[e.key] = false;
183
+ keysRef.current[e.code] = false;
184
+ };
185
+ window.addEventListener('keydown', handleKeyDown);
186
+ window.addEventListener('keyup', handleKeyUp);
187
+ return () => {
188
+ window.removeEventListener('keydown', handleKeyDown);
189
+ window.removeEventListener('keyup', handleKeyUp);
190
+ };
191
+ }, []);
192
+ return keysRef;
193
+ }
@@ -4,5 +4,7 @@ export { useTile } from './useTile';
4
4
  export { useKeyboard } from './useKeyboard';
5
5
  export { TileContainer } from './TileContainer';
6
6
  export { withTile } from './withTile';
7
+ export { PixiGame, useGameLoop, useGameState, useGameInput, Container, Sprite, Graphics, Text, AnimatedSprite, TilingSprite, NineSlicePlane, useApp, TILE_WIDTH, TILE_HEIGHT, } from './PixiGame';
8
+ export type { PixiGameProps } from './PixiGame';
7
9
  export * from './overlay';
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC3D,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC3D,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,OAAO,EACL,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,YAAY,EAEZ,SAAS,EACT,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,cAAc,EACd,YAAY,EACZ,cAAc,EACd,MAAM,EAEN,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,cAAc,WAAW,CAAC"}
@@ -5,5 +5,11 @@ export { useKeyboard } from './useKeyboard';
5
5
  export { TileContainer } from './TileContainer';
6
6
  export { withTile } from './withTile';
7
7
  // TileInitializer removed - router should be injected directly into TileProvider
8
+ // PixiGame wrapper for @pixi/react games - abstracts Stage context boilerplate
9
+ export { PixiGame, useGameLoop, useGameState, useGameInput,
10
+ // Re-exported @pixi/react components
11
+ Container, Sprite, Graphics, Text, AnimatedSprite, TilingSprite, NineSlicePlane, useApp,
12
+ // Constants
13
+ TILE_WIDTH, TILE_HEIGHT, } from './PixiGame';
8
14
  // Overlay components for hybrid tiles (video/image with interactive overlays)
9
15
  export * from './overlay';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thewhateverapp/tile-sdk",
3
- "version": "0.13.34",
3
+ "version": "0.13.36",
4
4
  "description": "SDK for building interactive tiles on The Whatever App platform",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -59,13 +59,25 @@
59
59
  "zod": "^3.22.0"
60
60
  },
61
61
  "peerDependencies": {
62
- "react": "^18.0.0"
62
+ "react": "^18.0.0",
63
+ "@pixi/react": "^7.0.0",
64
+ "pixi.js": "^7.0.0"
65
+ },
66
+ "peerDependenciesMeta": {
67
+ "@pixi/react": {
68
+ "optional": true
69
+ },
70
+ "pixi.js": {
71
+ "optional": true
72
+ }
63
73
  },
64
74
  "devDependencies": {
75
+ "@pixi/react": "^7.1.2",
65
76
  "@types/node": "^20.0.0",
66
77
  "@types/react": "^18.2.48",
67
78
  "eslint": "^9.39.1",
68
79
  "next": "^14.2.0",
80
+ "pixi.js": "^7.4.2",
69
81
  "typescript": "^5.3.3"
70
82
  }
71
83
  }