star-sdk-cli 0.1.8 → 0.1.10

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 +50 -68
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -35,6 +35,7 @@ import Star from 'star-sdk';
35
35
 
36
36
  \`\`\`javascript
37
37
  import Star from 'star-sdk';
38
+ Star.init({ gameId: 'YOUR_GAME_ID' }); // from .starrc
38
39
 
39
40
  Star.game(ctx => {
40
41
  const { canvas, width, height, ctx: c } = ctx;
@@ -45,7 +46,7 @@ Star.game(ctx => {
45
46
 
46
47
  // Game loop
47
48
  ctx.loop((dt) => {
48
- c.fillStyle = '#1a1a2e';
49
+ c.fillStyle = '#111827';
49
50
  c.fillRect(0, 0, width, height);
50
51
  c.fillStyle = '#fff';
51
52
  c.font = '24px sans-serif';
@@ -60,17 +61,6 @@ Star.game(ctx => {
60
61
  });
61
62
  \`\`\`
62
63
 
63
- ## Initialization (Required for Leaderboards)
64
-
65
- If using leaderboards outside the Star platform (local dev, self-hosted), initialize with your game ID:
66
-
67
- \`\`\`javascript
68
- import Star from 'star-sdk';
69
-
70
- // Get your gameId from .starrc (created by: npx star-sdk init "Game Name")
71
- Star.init({ gameId: 'your-game-id-here' });
72
- \`\`\`
73
-
74
64
  ## Common Patterns
75
65
 
76
66
  ### Game Over -> Submit Score -> Show Leaderboard
@@ -119,9 +109,7 @@ Only these 17 presets exist:
119
109
 
120
110
  \`\`\`javascript
121
111
  import Star from 'star-sdk';
122
-
123
- // Initialize for leaderboard support (get gameId from .starrc)
124
- Star.init({ gameId: 'your-game-id' });
112
+ Star.init({ gameId: 'YOUR_GAME_ID' }); // from .starrc
125
113
 
126
114
  Star.game(ctx => {
127
115
  const { canvas, width, height, ctx: c } = ctx;
@@ -147,7 +135,7 @@ Star.game(ctx => {
147
135
  if (gameOver) return;
148
136
 
149
137
  // Clear
150
- c.fillStyle = '#1a1a2e';
138
+ c.fillStyle = '#111827';
151
139
  c.fillRect(0, 0, width, height);
152
140
 
153
141
  // Update obstacles
@@ -174,13 +162,13 @@ Star.game(ctx => {
174
162
  obstacles = obstacles.filter(o => o.x > -20);
175
163
 
176
164
  // Draw player
177
- c.fillStyle = '#e94560';
165
+ c.fillStyle = '#3b82f6';
178
166
  c.beginPath();
179
167
  c.arc(50, playerY, 15, 0, Math.PI * 2);
180
168
  c.fill();
181
169
 
182
170
  // Draw obstacles
183
- c.fillStyle = '#0f4c75';
171
+ c.fillStyle = '#a855f7';
184
172
  obstacles.forEach(obs => {
185
173
  c.fillRect(obs.x - 10, obs.y - 25, 20, 50);
186
174
  });
@@ -379,7 +367,7 @@ game(({ ctx, width, height, on, loop, ui, canvas }) => {
379
367
  // 1. Draw on the canvas
380
368
  loop((dt) => {
381
369
  ctx.clearRect(0, 0, width, height);
382
- ctx.fillStyle = '#22d3ee'; // cyan-400
370
+ ctx.fillStyle = '#3b82f6'; // blue-500
383
371
  ctx.fillRect(width / 2 - 25, height / 2 - 25, 50, 50);
384
372
  });
385
373
 
@@ -555,10 +543,10 @@ game(({ on, ui }) => {
555
543
  function render() {
556
544
  // UI is interactive by default - buttons, scroll, forms all work
557
545
  ui.render(\`
558
- <div class="min-h-[100dvh] grid place-items-center bg-purple-900 text-white">
546
+ <div class="min-h-[100dvh] grid place-items-center bg-gray-900 text-white">
559
547
  <div class="text-center space-y-4">
560
548
  <h1 class="text-4xl font-bold">Score: \\\${score}</h1>
561
- <button id="clickBtn" class="px-8 py-4 rounded-xl bg-cyan-400 text-slate-900 font-bold">
549
+ <button id="clickBtn" class="px-8 py-4 rounded-xl bg-gradient-to-r from-blue-600 to-purple-600 text-white shadow-lg shadow-blue-500/20 font-bold">
562
550
  Click Me!
563
551
  </button>
564
552
  </div>
@@ -594,10 +582,10 @@ game(({ ctx, width, height, loop }) => {
594
582
  player.x += speed * dt;
595
583
  if (player.x > width) player.x = -playerSize;
596
584
 
597
- ctx.fillStyle = '#0f172a';
585
+ ctx.fillStyle = '#111827';
598
586
  ctx.fillRect(0, 0, width, height);
599
587
 
600
- ctx.fillStyle = '#22d3ee';
588
+ ctx.fillStyle = '#3b82f6';
601
589
  ctx.fillRect(player.x, player.y - playerSize/2, playerSize, playerSize);
602
590
  });
603
591
  });
@@ -628,10 +616,10 @@ game(({ ctx, width, height, loop, canvas, toStagePoint }) => {
628
616
  });
629
617
 
630
618
  loop((dt) => {
631
- ctx.fillStyle = '#1e1b4b';
619
+ ctx.fillStyle = '#111827';
632
620
  ctx.fillRect(0, 0, width, height);
633
621
 
634
- ctx.strokeStyle = '#4338ca';
622
+ ctx.strokeStyle = '#8b5cf6';
635
623
  for (let row = 0; row < gridRows; row++) {
636
624
  for (let col = 0; col < gridCols; col++) {
637
625
  ctx.strokeRect(
@@ -662,10 +650,10 @@ game(({ ctx, width, height, loop, toStagePoint, canvas }) => {
662
650
  });
663
651
 
664
652
  loop((dt) => {
665
- ctx.fillStyle = '#0f172a';
653
+ ctx.fillStyle = '#111827';
666
654
  ctx.fillRect(0, 0, width, height);
667
655
 
668
- ctx.fillStyle = '#22d3ee';
656
+ ctx.fillStyle = '#3b82f6';
669
657
  ctx.fillRect(player.x - 8, player.y - 8, 16, 16);
670
658
  });
671
659
  }, { width: 320, height: 180 }); // Custom resolution with letterboxing
@@ -677,7 +665,7 @@ game(({ ctx, width, height, loop, toStagePoint, canvas }) => {
677
665
  import { game } from 'star-canvas';
678
666
  import { createLeaderboard } from 'star-leaderboard';
679
667
 
680
- const leaderboard = createLeaderboard();
668
+ const leaderboard = createLeaderboard({ gameId: 'YOUR_GAME_ID' });
681
669
 
682
670
  game(({ ctx, width, height, loop, ui, on, canvas, toStagePoint }) => {
683
671
  let score = 0;
@@ -727,7 +715,7 @@ game(({ ctx, width, height, loop, ui, on, canvas, toStagePoint }) => {
727
715
  <div class="h-full flex flex-col items-center justify-center text-white">
728
716
  <div class="text-3xl mb-4">GAME OVER</div>
729
717
  <div class="text-6xl mb-4">\\\${score}</div>
730
- <button id="leaderboard-btn" class="px-6 py-3 mb-4 bg-purple-600 rounded-lg pointer-events-auto">
718
+ <button id="leaderboard-btn" class="px-6 py-3 mb-4 bg-gradient-to-r from-blue-600 to-purple-600 rounded-xl font-bold shadow-lg shadow-blue-500/20 pointer-events-auto">
731
719
  VIEW LEADERBOARD
732
720
  </button>
733
721
  <div class="text-xl animate-pulse">TAP TO RESTART</div>
@@ -799,7 +787,7 @@ game(({ ctx, width, height, loop, canvas, createDrag }) => {
799
787
 
800
788
  const pieces = [
801
789
  { x: width * 0.2, y: height * 0.3, color: '#ef4444' },
802
- { x: width * 0.4, y: height * 0.4, color: '#22c55e' },
790
+ { x: width * 0.4, y: height * 0.4, color: '#10b981' },
803
791
  { x: width * 0.6, y: height * 0.3, color: '#3b82f6' },
804
792
  ];
805
793
 
@@ -843,11 +831,11 @@ game(({ ctx, width, height, loop, canvas, createDrag }) => {
843
831
  });
844
832
 
845
833
  loop(() => {
846
- ctx.fillStyle = '#1e293b';
834
+ ctx.fillStyle = '#1f2937';
847
835
  ctx.fillRect(0, 0, width, height);
848
836
 
849
837
  for (const p of pieces) {
850
- ctx.fillStyle = drag.dragging === p ? '#fbbf24' : p.color;
838
+ ctx.fillStyle = drag.dragging === p ? '#f59e0b' : p.color;
851
839
  ctx.fillRect(p.x, p.y, pieceSize, pieceSize);
852
840
  }
853
841
  });
@@ -867,7 +855,7 @@ game(({ ctx, width, height, loop, canvas, toStagePoint }) => {
867
855
  const pieceSize = height * 0.15;
868
856
  const pieces = [
869
857
  { x: width * 0.2, y: height * 0.3, color: '#ef4444' },
870
- { x: width * 0.4, y: height * 0.4, color: '#22c55e' },
858
+ { x: width * 0.4, y: height * 0.4, color: '#10b981' },
871
859
  ];
872
860
 
873
861
  // Manual drag state
@@ -913,11 +901,11 @@ game(({ ctx, width, height, loop, canvas, toStagePoint }) => {
913
901
  });
914
902
 
915
903
  loop(() => {
916
- ctx.fillStyle = '#1e293b';
904
+ ctx.fillStyle = '#1f2937';
917
905
  ctx.fillRect(0, 0, width, height);
918
906
 
919
907
  for (const p of pieces) {
920
- ctx.fillStyle = dragging === p ? '#fbbf24' : p.color;
908
+ ctx.fillStyle = dragging === p ? '#f59e0b' : p.color;
921
909
  ctx.fillRect(p.x, p.y, pieceSize, pieceSize);
922
910
  }
923
911
  });
@@ -954,12 +942,12 @@ game(({ ctx, width, height, loop }) => {
954
942
  if (bg.complete) {
955
943
  ctx.drawImage(bg, 0, 0, width, height);
956
944
  } else {
957
- ctx.fillStyle = '#1e293b'; // Fallback color while loading
945
+ ctx.fillStyle = '#1f2937'; // Fallback color while loading
958
946
  ctx.fillRect(0, 0, width, height);
959
947
  }
960
948
 
961
949
  // Draw game objects on top
962
- ctx.fillStyle = '#22d3ee';
950
+ ctx.fillStyle = '#3b82f6';
963
951
  ctx.fillRect(player.x - 16, player.y - 16, 32, 32);
964
952
  });
965
953
  });
@@ -987,7 +975,7 @@ game(({ ctx, width, height, loop }) => {
987
975
  ctx.fillStyle = pattern;
988
976
  ctx.fillRect(0, 0, width, height);
989
977
  } else {
990
- ctx.fillStyle = '#22c55e'; // Fallback color while loading
978
+ ctx.fillStyle = '#10b981'; // Fallback color while loading
991
979
  ctx.fillRect(0, 0, width, height);
992
980
  }
993
981
 
@@ -1025,7 +1013,7 @@ yarn add star-leaderboard
1025
1013
  **Import:**
1026
1014
  \`\`\`javascript
1027
1015
  import { createLeaderboard } from 'star-leaderboard';
1028
- const leaderboard = createLeaderboard();
1016
+ const leaderboard = createLeaderboard({ gameId: 'YOUR_GAME_ID' });
1029
1017
  \`\`\`
1030
1018
 
1031
1019
  **CRITICAL:** Import in JavaScript - don't add \`<script>\` tags.
@@ -1038,7 +1026,7 @@ const leaderboard = createLeaderboard();
1038
1026
  import { createLeaderboard } from 'star-leaderboard';
1039
1027
  import { game } from 'star-canvas';
1040
1028
 
1041
- const leaderboard = createLeaderboard();
1029
+ const leaderboard = createLeaderboard({ gameId: 'YOUR_GAME_ID' });
1042
1030
 
1043
1031
  game(({ ctx, width, height, loop, ui, on, canvas }) => {
1044
1032
  let score = 0;
@@ -1057,7 +1045,7 @@ game(({ ctx, width, height, loop, ui, on, canvas }) => {
1057
1045
 
1058
1046
  **That's it!** The SDK handles:
1059
1047
  - Score submission (works for guests and logged-in users)
1060
- - Platform leaderboard UI (modal with rankings)
1048
+ - Leaderboard UI (modal with rankings)
1061
1049
  - Weekly/all-time timeframes
1062
1050
  - AI-detected scoring (score/time/moves - higher or lower is better)
1063
1051
 
@@ -1068,7 +1056,7 @@ game(({ ctx, width, height, loop, ui, on, canvas }) => {
1068
1056
  **Core Methods:**
1069
1057
  \`\`\`javascript
1070
1058
  leaderboard.submit(score) // Submit score, returns Promise<{ success, rank, scoreId }>
1071
- leaderboard.show() // Show platform leaderboard UI
1059
+ leaderboard.show() // Show leaderboard UI
1072
1060
  leaderboard.getScores(options) // Fetch scores for custom UI
1073
1061
  leaderboard.share(options) // Generate shareable link
1074
1062
  \`\`\`
@@ -1076,7 +1064,7 @@ leaderboard.share(options) // Generate shareable link
1076
1064
  **Properties:**
1077
1065
  \`\`\`javascript
1078
1066
  leaderboard.ready // true when SDK is initialized
1079
- leaderboard.gameId // Current game ID (auto-detected on platform)
1067
+ leaderboard.gameId // Current game ID
1080
1068
  \`\`\`
1081
1069
 
1082
1070
  **Aliases (for discoverability):**
@@ -1094,7 +1082,7 @@ leaderboard.showLeaderboard() // Same as show()
1094
1082
  \`\`\`javascript
1095
1083
  import { createLeaderboard } from 'star-leaderboard';
1096
1084
 
1097
- const leaderboard = createLeaderboard();
1085
+ const leaderboard = createLeaderboard({ gameId: 'YOUR_GAME_ID' });
1098
1086
 
1099
1087
  function gameOver(finalScore) {
1100
1088
  // Fire and forget - simplest approach
@@ -1108,7 +1096,7 @@ function gameOver(finalScore) {
1108
1096
  \`\`\`javascript
1109
1097
  import { createLeaderboard } from 'star-leaderboard';
1110
1098
 
1111
- const leaderboard = createLeaderboard();
1099
+ const leaderboard = createLeaderboard({ gameId: 'YOUR_GAME_ID' });
1112
1100
 
1113
1101
  async function gameOver(finalScore) {
1114
1102
  const { success, rank } = await leaderboard.submit(finalScore);
@@ -1127,11 +1115,11 @@ async function gameOver(finalScore) {
1127
1115
  import { createLeaderboard } from 'star-leaderboard';
1128
1116
  import { game } from 'star-canvas';
1129
1117
 
1130
- const leaderboard = createLeaderboard();
1118
+ const leaderboard = createLeaderboard({ gameId: 'YOUR_GAME_ID' });
1131
1119
 
1132
1120
  game(({ ui, on }) => {
1133
1121
  ui.render(\`
1134
- <button id="lb-btn" class="pointer-events-auto">
1122
+ <button id="lb-btn" class="px-6 py-3 bg-gradient-to-r from-blue-600 to-purple-600 rounded-xl font-bold text-white shadow-lg shadow-blue-500/20 pointer-events-auto">
1135
1123
  View Leaderboard
1136
1124
  </button>
1137
1125
  \`);
@@ -1148,7 +1136,7 @@ game(({ ui, on }) => {
1148
1136
  \`\`\`javascript
1149
1137
  import { createLeaderboard } from 'star-leaderboard';
1150
1138
 
1151
- const leaderboard = createLeaderboard();
1139
+ const leaderboard = createLeaderboard({ gameId: 'YOUR_GAME_ID' });
1152
1140
 
1153
1141
  async function showCustomLeaderboard() {
1154
1142
  const { scores, you, config } = await leaderboard.getScores({
@@ -1173,7 +1161,7 @@ async function showCustomLeaderboard() {
1173
1161
  import { createLeaderboard } from 'star-leaderboard';
1174
1162
  import { game } from 'star-canvas';
1175
1163
 
1176
- const leaderboard = createLeaderboard();
1164
+ const leaderboard = createLeaderboard({ gameId: 'YOUR_GAME_ID' });
1177
1165
 
1178
1166
  game(({ ctx, width, height, loop, ui, on, canvas }) => {
1179
1167
  let score = 0;
@@ -1198,7 +1186,7 @@ game(({ ctx, width, height, loop, ui, on, canvas }) => {
1198
1186
  <div class="h-full flex flex-col items-center justify-center text-white">
1199
1187
  <div class="text-3xl mb-4">GAME OVER</div>
1200
1188
  <div class="text-6xl mb-4">\\\${score}</div>
1201
- <button id="lb-btn" class="px-6 py-3 mb-4 bg-purple-600 rounded-lg pointer-events-auto">
1189
+ <button id="lb-btn" class="px-6 py-3 mb-4 bg-gradient-to-r from-blue-600 to-purple-600 rounded-xl font-bold shadow-lg shadow-blue-500/20 pointer-events-auto">
1202
1190
  VIEW LEADERBOARD
1203
1191
  </button>
1204
1192
  <div class="text-xl animate-pulse">TAP TO RESTART</div>
@@ -1224,17 +1212,12 @@ game(({ ctx, width, height, loop, ui, on, canvas }) => {
1224
1212
 
1225
1213
  ---
1226
1214
 
1227
- **Options:**
1215
+ **Configuration:**
1228
1216
 
1217
+ Always pass your gameId (from \`.starrc\`, created by \`npx star-sdk init\`):
1229
1218
  \`\`\`javascript
1230
- // Default - auto-detects gameId on Star platform
1231
- const leaderboard = createLeaderboard();
1232
-
1233
- // Standalone use (outside Star platform)
1234
- const leaderboard = createLeaderboard({
1235
- gameId: 'your-game-uuid',
1236
- apiBase: 'https://buildwithstar.com'
1237
- });
1219
+ import { createLeaderboard } from 'star-leaderboard';
1220
+ const leaderboard = createLeaderboard({ gameId: 'YOUR_GAME_ID' });
1238
1221
  \`\`\`
1239
1222
 
1240
1223
  ---
@@ -1265,9 +1248,9 @@ const data = await leaderboard.getScores({
1265
1248
 
1266
1249
  2. **Fire and forget is fine** - \`submit()\` returns a Promise but you don't need to await it.
1267
1250
 
1268
- 3. **Use \`show()\` for platform UI** - It's the easiest way. Use \`getScores()\` only if you need custom rendering.
1251
+ 3. **Use \`show()\` to display the leaderboard** - It's the easiest way. Use \`getScores()\` only if you need custom rendering.
1269
1252
 
1270
- 4. **Don't store leaderboard state** - Just call the SDK methods when needed. The platform handles caching.
1253
+ 4. **Don't store leaderboard state** - Just call the SDK methods when needed. The SDK handles caching.
1271
1254
 
1272
1255
  5. **Works for guests** - Guests get a generated name like "Guest1234". They can sign in later to claim scores.`;
1273
1256
 
@@ -1409,15 +1392,14 @@ async function initCommand(name, email) {
1409
1392
  log(`${colors.dim}Config saved to${colors.reset} ${colors.bright}.starrc${colors.reset}`);
1410
1393
  log("");
1411
1394
  log(`${colors.dim}Next steps:${colors.reset}`);
1412
- log(` 1. Install: ${colors.cyan}npm install star-sdk${colors.reset}`);
1413
- log(` 2. Import Star SDK in your game`);
1414
- log(` 3. Initialize with your game ID`);
1415
- log(` 4. Use Star.leaderboard.submit(score) to submit scores`);
1395
+ log(` 1. Install the leaderboard package: ${colors.cyan}yarn add star-leaderboard${colors.reset}`);
1396
+ log(` 2. Submit scores and show the leaderboard`);
1416
1397
  log("");
1417
1398
  log(`${colors.dim}Example:${colors.reset}`);
1418
- log(` ${colors.cyan}import Star from 'star-sdk';${colors.reset}`);
1419
- log(` ${colors.cyan}Star.init({ gameId: '${data.gameId}' });${colors.reset}`);
1420
- log(` ${colors.cyan}Star.leaderboard.submit(1500);${colors.reset}`);
1399
+ log(` ${colors.cyan}import { createLeaderboard } from 'star-leaderboard';${colors.reset}`);
1400
+ log(` ${colors.cyan}const leaderboard = createLeaderboard({ gameId: '${data.gameId}' });${colors.reset}`);
1401
+ log(` ${colors.cyan}leaderboard.submit(1500);${colors.reset}`);
1402
+ log(` ${colors.cyan}leaderboard.show();${colors.reset}`);
1421
1403
  log("");
1422
1404
  log(`${colors.dim}Using an AI coding agent?${colors.reset}`);
1423
1405
  log(` ${colors.cyan}npx star-sdk install${colors.reset} ${colors.dim}Claude Code, Codex, Cursor, Windsurf, Aider${colors.reset}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "star-sdk-cli",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "CLI tool for Star SDK - register games and manage leaderboards",
5
5
  "type": "module",
6
6
  "bin": {