star-sdk-cli 0.1.19 → 0.1.21
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/dist/cli.mjs +61 -25
- package/package.json +3 -3
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
|
|
@@ -586,6 +597,7 @@ A safe manager for your HTML overlay, stacked on top of the canvas.
|
|
|
586
597
|
- \`ui.render(html: string)\`: **Use this** to set your UI. It's safe and won't destroy the canvas.
|
|
587
598
|
- Automatically skips updates if HTML is unchanged (safe to call in loop for static content)
|
|
588
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.
|
|
589
601
|
- \`ui.el(selector)\`: Scoped \`querySelector\` for the UI root.
|
|
590
602
|
- \`ui.all(selector)\`: Scoped \`querySelectorAll\` for the UI root.
|
|
591
603
|
|
|
@@ -1270,10 +1282,11 @@ game(({ ctx, width, height, loop, ui, on, canvas }) => {
|
|
|
1270
1282
|
|
|
1271
1283
|
**Core Methods:**
|
|
1272
1284
|
\`\`\`javascript
|
|
1273
|
-
leaderboard.submit(score)
|
|
1274
|
-
leaderboard.
|
|
1275
|
-
leaderboard.
|
|
1276
|
-
leaderboard.
|
|
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
|
|
1277
1290
|
\`\`\`
|
|
1278
1291
|
|
|
1279
1292
|
**Properties:**
|
|
@@ -1346,7 +1359,20 @@ game(({ ui, on }) => {
|
|
|
1346
1359
|
});
|
|
1347
1360
|
\`\`\`
|
|
1348
1361
|
|
|
1349
|
-
### Pattern 4: Custom
|
|
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
|
|
1350
1376
|
|
|
1351
1377
|
\`\`\`javascript
|
|
1352
1378
|
import { createLeaderboard } from 'star-leaderboard';
|
|
@@ -1370,7 +1396,7 @@ async function showCustomLeaderboard() {
|
|
|
1370
1396
|
}
|
|
1371
1397
|
\`\`\`
|
|
1372
1398
|
|
|
1373
|
-
### Pattern
|
|
1399
|
+
### Pattern 6: Full Game Example
|
|
1374
1400
|
|
|
1375
1401
|
\`\`\`javascript
|
|
1376
1402
|
import { createLeaderboard } from 'star-leaderboard';
|
|
@@ -1378,7 +1404,8 @@ import { game } from 'star-canvas';
|
|
|
1378
1404
|
|
|
1379
1405
|
const leaderboard = createLeaderboard({ gameId: '<gameId from .starrc>' });
|
|
1380
1406
|
|
|
1381
|
-
game((
|
|
1407
|
+
game((g) => {
|
|
1408
|
+
const { ctx, width, height, ui, on } = g;
|
|
1382
1409
|
let score = 0;
|
|
1383
1410
|
let state = 'menu';
|
|
1384
1411
|
|
|
@@ -1415,11 +1442,10 @@ game(({ ctx, width, height, loop, ui, on, canvas }) => {
|
|
|
1415
1442
|
leaderboard.show();
|
|
1416
1443
|
});
|
|
1417
1444
|
|
|
1418
|
-
|
|
1419
|
-
if (
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
loop((dt) => {
|
|
1445
|
+
g.loop((dt) => {
|
|
1446
|
+
if (g.tap) {
|
|
1447
|
+
if (state === 'menu' || state === 'gameover') startGame();
|
|
1448
|
+
}
|
|
1423
1449
|
// Game logic...
|
|
1424
1450
|
});
|
|
1425
1451
|
});
|
|
@@ -1484,7 +1510,7 @@ leaderboard.submit(reactionTimeMs);
|
|
|
1484
1510
|
|
|
1485
1511
|
4. **Don't store leaderboard state** - Just call the SDK methods when needed. The SDK handles caching.
|
|
1486
1512
|
|
|
1487
|
-
5. **Works for guests** - Guests get
|
|
1513
|
+
5. **Works for guests** - Guests get an auto-generated name like "Guest1234". Pass \`{ playerName }\` to let players choose their own name.`;
|
|
1488
1514
|
|
|
1489
1515
|
// src/cli.ts
|
|
1490
1516
|
var VERSION = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
@@ -1751,26 +1777,36 @@ async function deployCommand(dirPath) {
|
|
|
1751
1777
|
}
|
|
1752
1778
|
log(`Deploying ${colors.bright}${config.name}${colors.reset} from ${colors.dim}${deployDir}${colors.reset}`);
|
|
1753
1779
|
try {
|
|
1780
|
+
let addDir2 = function(dir, prefix) {
|
|
1781
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
1782
|
+
if (IGNORE.has(entry.name)) continue;
|
|
1783
|
+
const full = path.join(dir, entry.name);
|
|
1784
|
+
const zipPath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
1785
|
+
if (entry.isDirectory()) {
|
|
1786
|
+
addDir2(full, zipPath);
|
|
1787
|
+
} else if (entry.name !== "index.html") {
|
|
1788
|
+
zipfile.addFile(full, zipPath);
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
};
|
|
1792
|
+
var addDir = addDir2;
|
|
1754
1793
|
const originalHtml = fs.readFileSync(indexPath, "utf-8");
|
|
1755
1794
|
const processedHtml = injectImportMapIfNeeded(originalHtml, deployDir);
|
|
1756
1795
|
const htmlModified = processedHtml !== originalHtml;
|
|
1757
1796
|
if (htmlModified) {
|
|
1758
1797
|
info("Injected importmap for bare imports (star-sdk \u2192 esm.sh)");
|
|
1759
1798
|
}
|
|
1760
|
-
const
|
|
1799
|
+
const { ZipFile } = await import("yazl");
|
|
1800
|
+
const zipfile = new ZipFile();
|
|
1801
|
+
const IGNORE = /* @__PURE__ */ new Set(["node_modules", ".starrc", ".git", ".DS_Store"]);
|
|
1802
|
+
addDir2(deployDir, "");
|
|
1803
|
+
zipfile.addBuffer(Buffer.from(processedHtml, "utf-8"), "index.html");
|
|
1804
|
+
zipfile.end();
|
|
1761
1805
|
const zipBuffer = await new Promise((resolve2, reject) => {
|
|
1762
1806
|
const chunks = [];
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
archive.on("error", reject);
|
|
1767
|
-
archive.glob("**/*", {
|
|
1768
|
-
cwd: deployDir,
|
|
1769
|
-
ignore: ["node_modules/**", ".starrc", ".git/**", ".DS_Store", "index.html"],
|
|
1770
|
-
dot: false
|
|
1771
|
-
});
|
|
1772
|
-
archive.append(processedHtml, { name: "index.html" });
|
|
1773
|
-
archive.finalize();
|
|
1807
|
+
zipfile.outputStream.on("data", (chunk) => chunks.push(chunk));
|
|
1808
|
+
zipfile.outputStream.on("end", () => resolve2(Buffer.concat(chunks)));
|
|
1809
|
+
zipfile.outputStream.on("error", reject);
|
|
1774
1810
|
});
|
|
1775
1811
|
log(` ${colors.dim}Uploading ${(zipBuffer.length / 1024).toFixed(1)} KB...${colors.reset}`);
|
|
1776
1812
|
const response = await fetch(`${API_BASE}/api/sdk/games/${config.gameId}/deploy`, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "star-sdk-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "CLI for Star SDK — register games, install AI docs, and deploy to Star hosting",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"hosting"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"
|
|
41
|
+
"yazl": "^3.3.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@types/
|
|
44
|
+
"@types/yazl": "^3.3.0",
|
|
45
45
|
"tsup": "^8.0.0",
|
|
46
46
|
"tsx": "^4.7.0",
|
|
47
47
|
"typescript": "^5.4.5"
|