star-sdk-cli 0.1.18 → 0.1.20

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.
Files changed (2) hide show
  1. package/dist/cli.mjs +60 -13
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -122,6 +122,17 @@ function endGame() {
122
122
  }
123
123
  \`\`\`
124
124
 
125
+ ### Submit with Player Name (Arcade Style)
126
+
127
+ Let players enter their name on game over \u2014 classic arcade feel. If skipped, a guest name is auto-generated.
128
+
129
+ \`\`\`javascript
130
+ Star.leaderboard.submit(score, { playerName: 'ACE' }); // Custom name
131
+ Star.leaderboard.submit(score); // Auto guest name
132
+ \`\`\`
133
+
134
+ Collect the name on game over using \`g.ui.render()\` for an input field. See \`leaderboard.md\` Pattern 4.
135
+
125
136
  ### Submit Score Only (No UI)
126
137
 
127
138
  \`\`\`javascript
@@ -154,6 +165,18 @@ Star.audio.preload({ coin: 'coin', jump: 'jump' });
154
165
  Star.audio.play('coin'); // Works on mobile, desktop, everywhere
155
166
  \`\`\`
156
167
 
168
+ ### Hover Effects for Canvas Buttons
169
+
170
+ \`g.pointer\` tracks position every frame \u2014 use it for hover states:
171
+
172
+ \`\`\`javascript
173
+ g.loop((dt) => {
174
+ const hoverLb = state === 'gameover' && inRect(g.pointer, lbBtn);
175
+ drawButton('VIEW LEADERBOARD', lbBtn, hoverLb ? '#9061f9' : '#7c3aed');
176
+ g.canvas.style.cursor = hoverLb ? 'pointer' : 'default';
177
+ });
178
+ \`\`\`
179
+
157
180
  ### Coordinate Handling
158
181
 
159
182
  \`g.tap\` and \`g.pointer\` are already in canvas-space coordinates. No conversion needed:
@@ -574,6 +597,7 @@ A safe manager for your HTML overlay, stacked on top of the canvas.
574
597
  - \`ui.render(html: string)\`: **Use this** to set your UI. It's safe and won't destroy the canvas.
575
598
  - Automatically skips updates if HTML is unchanged (safe to call in loop for static content)
576
599
  - For best performance with dynamic content (score), only call when values actually change
600
+ - **Positioning:** The UI overlay covers the full viewport, not just the letterboxed game area. Use percentage-based positioning (e.g., \`top: 50%; left: 50%; transform: translate(-50%, -50%)\`) to stay centered within the visible area. Fixed offsets like \`bottom: 18px\` may land in the letterbox bars on some screen sizes.
577
601
  - \`ui.el(selector)\`: Scoped \`querySelector\` for the UI root.
578
602
  - \`ui.all(selector)\`: Scoped \`querySelectorAll\` for the UI root.
579
603
 
@@ -630,6 +654,15 @@ g.loop((dt) => {
630
654
  });
631
655
  \`\`\`
632
656
 
657
+ **Hover effects for canvas buttons:**
658
+ \`\`\`ts
659
+ g.loop((dt) => {
660
+ const hoverLb = state === 'gameover' && inRect(g.pointer, lbBtn);
661
+ drawButton('VIEW LEADERBOARD', lbBtn, hoverLb ? '#9061f9' : '#7c3aed');
662
+ g.canvas.style.cursor = hoverLb ? 'pointer' : 'default';
663
+ });
664
+ \`\`\`
665
+
633
666
  Taps on interactive UI elements (from \`on()\` or native \`<button>\`) are automatically suppressed from \`g.tap\`.
634
667
 
635
668
  ### Cursor Management
@@ -1249,10 +1282,11 @@ game(({ ctx, width, height, loop, ui, on, canvas }) => {
1249
1282
 
1250
1283
  **Core Methods:**
1251
1284
  \`\`\`javascript
1252
- leaderboard.submit(score) // Submit score, returns Promise<{ success, rank, scoreId }>
1253
- leaderboard.show() // Show leaderboard UI
1254
- leaderboard.getScores(options) // Fetch scores for custom UI
1255
- leaderboard.share(options) // Generate shareable link
1285
+ leaderboard.submit(score) // Submit score (guest name auto-generated)
1286
+ leaderboard.submit(score, { playerName }) // Submit with custom player name
1287
+ leaderboard.show() // Show leaderboard UI
1288
+ leaderboard.getScores(options) // Fetch scores for custom UI
1289
+ leaderboard.share(options) // Generate shareable link
1256
1290
  \`\`\`
1257
1291
 
1258
1292
  **Properties:**
@@ -1325,7 +1359,20 @@ game(({ ui, on }) => {
1325
1359
  });
1326
1360
  \`\`\`
1327
1361
 
1328
- ### Pattern 4: Custom Leaderboard UI
1362
+ ### Pattern 4: Custom Player Names
1363
+
1364
+ Players can set their own name for the leaderboard:
1365
+
1366
+ \`\`\`javascript
1367
+ leaderboard.submit(score, { playerName: 'ACE' }); // Custom name
1368
+ leaderboard.submit(score); // Auto guest name
1369
+ \`\`\`
1370
+
1371
+ If \`playerName\` is not provided, a guest name like "Guest1234" is auto-generated.
1372
+
1373
+ A natural place to collect the name is on the game over screen (arcade-style "enter your initials"). Use \`ui.render()\` for the input field and \`on()\` for handlers. Call \`submitScore()\` before \`show()\` or \`startGame()\` so the score saves even if the player skips the name input. Store \`playerName\` outside the loop so it persists across rounds.
1374
+
1375
+ ### Pattern 5: Custom Leaderboard UI
1329
1376
 
1330
1377
  \`\`\`javascript
1331
1378
  import { createLeaderboard } from 'star-leaderboard';
@@ -1349,7 +1396,7 @@ async function showCustomLeaderboard() {
1349
1396
  }
1350
1397
  \`\`\`
1351
1398
 
1352
- ### Pattern 5: Full Game Example
1399
+ ### Pattern 6: Full Game Example
1353
1400
 
1354
1401
  \`\`\`javascript
1355
1402
  import { createLeaderboard } from 'star-leaderboard';
@@ -1357,7 +1404,8 @@ import { game } from 'star-canvas';
1357
1404
 
1358
1405
  const leaderboard = createLeaderboard({ gameId: '<gameId from .starrc>' });
1359
1406
 
1360
- game(({ ctx, width, height, loop, ui, on, canvas }) => {
1407
+ game((g) => {
1408
+ const { ctx, width, height, ui, on } = g;
1361
1409
  let score = 0;
1362
1410
  let state = 'menu';
1363
1411
 
@@ -1394,11 +1442,10 @@ game(({ ctx, width, height, loop, ui, on, canvas }) => {
1394
1442
  leaderboard.show();
1395
1443
  });
1396
1444
 
1397
- canvas.addEventListener('pointerdown', () => {
1398
- if (state === 'menu' || state === 'gameover') startGame();
1399
- });
1400
-
1401
- loop((dt) => {
1445
+ g.loop((dt) => {
1446
+ if (g.tap) {
1447
+ if (state === 'menu' || state === 'gameover') startGame();
1448
+ }
1402
1449
  // Game logic...
1403
1450
  });
1404
1451
  });
@@ -1463,7 +1510,7 @@ leaderboard.submit(reactionTimeMs);
1463
1510
 
1464
1511
  4. **Don't store leaderboard state** - Just call the SDK methods when needed. The SDK handles caching.
1465
1512
 
1466
- 5. **Works for guests** - Guests get a generated name like "Guest1234". They can sign in later to claim scores.`;
1513
+ 5. **Works for guests** - Guests get an auto-generated name like "Guest1234". Pass \`{ playerName }\` to let players choose their own name.`;
1467
1514
 
1468
1515
  // src/cli.ts
1469
1516
  var VERSION = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "star-sdk-cli",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "CLI for Star SDK — register games, install AI docs, and deploy to Star hosting",
5
5
  "type": "module",
6
6
  "bin": {