@littlepartytime/dev-kit 1.12.1 → 1.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,4 +1,4 @@
1
- import React, { useState, useEffect, useCallback } from 'react';
1
+ import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
2
2
  import { io, Socket } from 'socket.io-client';
3
3
  import PhoneFrame from '../components/PhoneFrame';
4
4
 
@@ -45,23 +45,35 @@ export default function Play() {
45
45
  const isHost = me?.isHost;
46
46
  const isReady = me?.ready;
47
47
 
48
- const platform = socket ? {
49
- getPlayers: () => room.players.map((p: any) => ({ id: p.id, nickname: p.nickname, avatarUrl: null, isHost: p.isHost })),
50
- getLocalPlayer: () => me ? { id: me.id, nickname: me.nickname, avatarUrl: null, isHost: me.isHost } : { id: '', nickname: '', avatarUrl: null, isHost: false },
51
- send: (action: any) => socket.emit('game:action', action),
52
- on: (event: string, handler: Function) => {
53
- if (event === 'stateUpdate') socket.on('game:state', handler as any);
54
- },
55
- off: (event: string, handler: Function) => {
56
- if (event === 'stateUpdate') socket.off('game:state', handler as any);
57
- },
58
- reportResult: () => {},
59
- getAssetUrl: (assetPath: string) => `/assets/${assetPath}`,
60
- getDeviceCapabilities: () => ({ haptics: false, motion: false }),
61
- haptic: () => {},
62
- onShake: () => () => {},
63
- onTilt: () => () => {},
64
- } : null;
48
+ // Use refs to avoid recreating platform on every room/me change
49
+ const roomRef = useRef(room);
50
+ roomRef.current = room;
51
+ const meRef = useRef(me);
52
+ meRef.current = me;
53
+
54
+ const platform = useMemo(() => {
55
+ if (!socket) return null;
56
+ return {
57
+ getPlayers: () => roomRef.current.players.map((p: any) => ({ id: p.id, nickname: p.nickname, avatarUrl: null, isHost: p.isHost })),
58
+ getLocalPlayer: () => {
59
+ const m = meRef.current;
60
+ return m ? { id: m.id, nickname: m.nickname, avatarUrl: null, isHost: m.isHost } : { id: '', nickname: '', avatarUrl: null, isHost: false };
61
+ },
62
+ send: (action: any) => socket.emit('game:action', action),
63
+ on: (event: string, handler: Function) => {
64
+ if (event === 'stateUpdate') socket.on('game:state', handler as any);
65
+ },
66
+ off: (event: string, handler: Function) => {
67
+ if (event === 'stateUpdate') socket.off('game:state', handler as any);
68
+ },
69
+ reportResult: () => {},
70
+ getAssetUrl: (assetPath: string) => `/assets/${assetPath}`,
71
+ getDeviceCapabilities: () => ({ haptics: false, motion: false }),
72
+ haptic: () => {},
73
+ onShake: () => () => {},
74
+ onTilt: () => () => {},
75
+ };
76
+ }, [socket]);
65
77
 
66
78
  if (!joined) {
67
79
  return (
@@ -207,7 +207,7 @@ export default function Preview() {
207
207
  <div style={{ width: '50%', height: '100%' }}>
208
208
  <PhoneFrame>
209
209
  {GameRenderer && platform && viewState ? (
210
- <GameRenderer platform={platform} state={viewState} />
210
+ <GameRenderer key={mockPlayers[playerIndex].id} platform={platform} state={viewState} />
211
211
  ) : (
212
212
  <div style={{ padding: 16, color: '#71717a' }}>
213
213
  {!engine ? 'Loading engine...' : 'Initializing game...'}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@littlepartytime/dev-kit",
3
- "version": "1.12.1",
3
+ "version": "1.12.2",
4
4
  "description": "Development toolkit CLI for Little Party Time game developers",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",