create-pika-minigame 1.2.0 → 1.3.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pika-minigame",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "CLI to scaffold Pika mini-game projects (bare React Native 0.77)",
5
5
  "author": "Pika Team",
6
6
  "license": "MIT",
@@ -9,6 +9,19 @@ import { HostBridge, PronunciationResult } from '../src/types';
9
9
 
10
10
  // Simulate recording state
11
11
  let isRecording = false;
12
+ let recordingStartTime = 0;
13
+
14
+ // Configure mock behavior (edit these for testing)
15
+ const MOCK_CONFIG = {
16
+ // Set to a number (0-100) to always return this score, or null for random
17
+ fixedScore: null as number | null,
18
+ // Minimum recording time in ms (like real API)
19
+ minRecordingMs: 700,
20
+ // Simulate network delay range [min, max] ms
21
+ networkDelay: [800, 1300] as [number, number],
22
+ // Chance to throw error (0-1), set > 0 to test error handling
23
+ errorChance: 0,
24
+ };
12
25
 
13
26
  /**
14
27
  * Generate a random score for testing different UI states.
@@ -43,41 +56,56 @@ export const mockHost: HostBridge = {
43
56
  }
44
57
  console.log('[MockHost] 🎤 Recording started...');
45
58
  isRecording = true;
59
+ recordingStartTime = Date.now();
46
60
  // Simulate recording initialization delay
47
61
  await delay(100);
48
62
  },
49
63
 
50
- stopAndCheck: async (targetWord: string): Promise<PronunciationResult> => {
64
+ stopAndCheck: async (targetText: string): Promise<PronunciationResult> => {
51
65
  if (!isRecording) {
52
66
  console.warn('[MockHost] Not recording');
53
67
  throw new Error('Not recording');
54
68
  }
55
69
 
56
- console.log(`[MockHost] 🛑 Recording stopped. Checking: "${targetWord}"`);
70
+ const elapsed = Date.now() - recordingStartTime;
71
+ console.log(`[MockHost] 🛑 Recording stopped (${elapsed}ms). Checking: "${targetText}"`);
57
72
  isRecording = false;
58
73
 
59
- // Simulate processing delay (like API call)
60
- await delay(800 + Math.random() * 500);
74
+ // Check minimum recording time (like real API)
75
+ if (elapsed < MOCK_CONFIG.minRecordingMs) {
76
+ throw new Error('Giữ nút lâu hơn (1–2 giây) rồi nói to, rõ nhé.');
77
+ }
61
78
 
62
- // Generate mock result
63
- const wordScore = randomScore(50, 100);
64
- const letters = generateLetterScores(targetWord);
65
- const totalScore = Math.round(
66
- letters.reduce((sum, l) => sum + l.score, 0) / letters.length
79
+ // Simulate random errors for testing
80
+ if (MOCK_CONFIG.errorChance > 0 && Math.random() < MOCK_CONFIG.errorChance) {
81
+ throw new Error('Chưa nghe rõ, thử lại nhé');
82
+ }
83
+
84
+ // Simulate network delay
85
+ const [minDelay, maxDelay] = MOCK_CONFIG.networkDelay;
86
+ await delay(minDelay + Math.random() * (maxDelay - minDelay));
87
+
88
+ // Split into words (real API does this)
89
+ const wordList = targetText.trim().split(/\s+/);
90
+
91
+ // Generate scores for each word
92
+ const words = wordList.map((word) => {
93
+ const letters = generateLetterScores(word);
94
+ // Use fixed score if configured, otherwise use average of letters
95
+ const wordScore = MOCK_CONFIG.fixedScore ?? Math.round(
96
+ letters.reduce((sum, l) => sum + l.score, 0) / letters.length
97
+ );
98
+ return { word, score: wordScore, letters };
99
+ });
100
+
101
+ // Total score is average of all words
102
+ const totalScore = MOCK_CONFIG.fixedScore ?? Math.round(
103
+ words.reduce((sum, w) => sum + w.score, 0) / words.length
67
104
  );
68
105
 
69
- console.log(`[MockHost] ✅ Score: ${totalScore}`);
70
-
71
- return {
72
- totalScore,
73
- words: [
74
- {
75
- word: targetWord,
76
- score: wordScore,
77
- letters,
78
- },
79
- ],
80
- };
106
+ console.log(`[MockHost] ✅ Score: ${totalScore} (${words.length} word${words.length > 1 ? 's' : ''})`);
107
+
108
+ return { totalScore, words };
81
109
  },
82
110
 
83
111
  cancel: async () => {