star-sdk-cli 0.1.3 → 0.1.5
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 +118 -14
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -61,6 +61,17 @@ Star.game(ctx => {
|
|
|
61
61
|
});
|
|
62
62
|
\`\`\`
|
|
63
63
|
|
|
64
|
+
## Initialization (Required for Leaderboards)
|
|
65
|
+
|
|
66
|
+
If using leaderboards outside the Star platform (local dev, self-hosted), initialize with your game ID:
|
|
67
|
+
|
|
68
|
+
\`\`\`javascript
|
|
69
|
+
import Star from 'star-sdk';
|
|
70
|
+
|
|
71
|
+
// Get your gameId from .starrc (created by: npx star-sdk init "Game Name")
|
|
72
|
+
Star.init({ gameId: 'your-game-id-here' });
|
|
73
|
+
\`\`\`
|
|
74
|
+
|
|
64
75
|
## Common Patterns
|
|
65
76
|
|
|
66
77
|
### Game Over -> Submit Score -> Show Leaderboard
|
|
@@ -110,6 +121,9 @@ Only these 17 presets exist:
|
|
|
110
121
|
\`\`\`javascript
|
|
111
122
|
import Star from 'star-sdk';
|
|
112
123
|
|
|
124
|
+
// Initialize for leaderboard support (get gameId from .starrc)
|
|
125
|
+
Star.init({ gameId: 'your-game-id' });
|
|
126
|
+
|
|
113
127
|
Star.game(ctx => {
|
|
114
128
|
const { canvas, width, height, ctx: c } = ctx;
|
|
115
129
|
let score = 0;
|
|
@@ -314,7 +328,7 @@ var CANVAS_DOCS = `**Installation**
|
|
|
314
328
|
First, add the package to your project:
|
|
315
329
|
|
|
316
330
|
\`\`\`bash
|
|
317
|
-
yarn add star-
|
|
331
|
+
yarn add star-canvas
|
|
318
332
|
\`\`\`
|
|
319
333
|
|
|
320
334
|
### Star DOM SDK
|
|
@@ -662,7 +676,7 @@ game(({ ctx, width, height, loop, toStagePoint, canvas }) => {
|
|
|
662
676
|
|
|
663
677
|
\`\`\`ts
|
|
664
678
|
import { game } from 'star-canvas';
|
|
665
|
-
import { createLeaderboard } from '
|
|
679
|
+
import { createLeaderboard } from 'star-leaderboard';
|
|
666
680
|
|
|
667
681
|
const leaderboard = createLeaderboard();
|
|
668
682
|
|
|
@@ -919,7 +933,86 @@ game(({ ctx, width, height, loop, canvas, toStagePoint }) => {
|
|
|
919
933
|
4. \u274C Not clearing state on pointerup \u2192 \`createDrag()\` fixes this
|
|
920
934
|
5. \u274C Missing \`setPointerCapture()\` (drags break outside canvas) \u2192 **You must add this!**
|
|
921
935
|
|
|
922
|
-
**Recommendation:** Use \`createDrag()\` + \`setPointerCapture()\` for bulletproof drag-and-drop
|
|
936
|
+
**Recommendation:** Use \`createDrag()\` + \`setPointerCapture()\` for bulletproof drag-and-drop.
|
|
937
|
+
|
|
938
|
+
### Recipe 9: Image Backgrounds
|
|
939
|
+
|
|
940
|
+
Two patterns for backgrounds: **full-canvas** (unique scenes) or **tileable patterns** (repeating textures).
|
|
941
|
+
|
|
942
|
+
**Full-canvas background (scaled to fit):**
|
|
943
|
+
|
|
944
|
+
\`\`\`ts
|
|
945
|
+
import { game } from 'star-canvas';
|
|
946
|
+
|
|
947
|
+
game(({ ctx, width, height, loop }) => {
|
|
948
|
+
const bg = new Image();
|
|
949
|
+
bg.src = 'https://example.com/background.png'; // Use generated asset URL
|
|
950
|
+
|
|
951
|
+
const player = { x: 320, y: 300 };
|
|
952
|
+
|
|
953
|
+
loop((dt) => {
|
|
954
|
+
// Draw background scaled to canvas (no tiling)
|
|
955
|
+
if (bg.complete) {
|
|
956
|
+
ctx.drawImage(bg, 0, 0, width, height);
|
|
957
|
+
} else {
|
|
958
|
+
ctx.fillStyle = '#1e293b'; // Fallback color while loading
|
|
959
|
+
ctx.fillRect(0, 0, width, height);
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// Draw game objects on top
|
|
963
|
+
ctx.fillStyle = '#22d3ee';
|
|
964
|
+
ctx.fillRect(player.x - 16, player.y - 16, 32, 32);
|
|
965
|
+
});
|
|
966
|
+
});
|
|
967
|
+
\`\`\`
|
|
968
|
+
|
|
969
|
+
**Tileable pattern background (repeating texture):**
|
|
970
|
+
|
|
971
|
+
\`\`\`ts
|
|
972
|
+
import { game } from 'star-canvas';
|
|
973
|
+
|
|
974
|
+
game(({ ctx, width, height, loop }) => {
|
|
975
|
+
const tile = new Image();
|
|
976
|
+
tile.src = 'https://example.com/grass_tile.png'; // Use generated asset URL (seamlessTile: true)
|
|
977
|
+
|
|
978
|
+
let pattern = null;
|
|
979
|
+
tile.onload = () => {
|
|
980
|
+
pattern = ctx.createPattern(tile, 'repeat');
|
|
981
|
+
};
|
|
982
|
+
|
|
983
|
+
const player = { x: 320, y: 300 };
|
|
984
|
+
|
|
985
|
+
loop((dt) => {
|
|
986
|
+
// Draw tiled background
|
|
987
|
+
if (pattern) {
|
|
988
|
+
ctx.fillStyle = pattern;
|
|
989
|
+
ctx.fillRect(0, 0, width, height);
|
|
990
|
+
} else {
|
|
991
|
+
ctx.fillStyle = '#22c55e'; // Fallback color while loading
|
|
992
|
+
ctx.fillRect(0, 0, width, height);
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
// Draw game objects on top
|
|
996
|
+
ctx.fillStyle = '#3b82f6';
|
|
997
|
+
ctx.fillRect(player.x - 16, player.y - 16, 32, 32);
|
|
998
|
+
});
|
|
999
|
+
});
|
|
1000
|
+
\`\`\`
|
|
1001
|
+
|
|
1002
|
+
**When to use which:**
|
|
1003
|
+
|
|
1004
|
+
| Type | Size | Use Case | Generation Settings |
|
|
1005
|
+
|------|------|----------|---------------------|
|
|
1006
|
+
| Full-canvas | 1024\xD71024 | Unique scenes, landscapes, detailed environments | \`model: "gemini"\`, no \`seamlessTile\` |
|
|
1007
|
+
| Tileable (all directions) | 256\xD7256 or 512\xD7512 | Grass, water, brick, abstract patterns | \`model: "gemini"\`, \`seamlessTile: "both"\` |
|
|
1008
|
+
| Horizontal tiling | 256\xD7512 or similar | Side-scroller parallax layers, horizon lines | \`model: "gemini"\`, \`seamlessTile: "horizontal"\` |
|
|
1009
|
+
| Vertical tiling | 512\xD7256 or similar | Vertical scroller backgrounds | \`model: "gemini"\`, \`seamlessTile: "vertical"\` |
|
|
1010
|
+
|
|
1011
|
+
**Common mistakes:**
|
|
1012
|
+
- \u274C Generating a detailed scene and expecting it to tile \u2192 Use \`seamlessTile\` only for patterns
|
|
1013
|
+
- \u274C Using \`drawImage()\` without size params \u2192 Image won't scale to canvas
|
|
1014
|
+
- \u274C Not handling image load state \u2192 Blank canvas until loaded
|
|
1015
|
+
- \u274C Using \`seamlessTile: "both"\` when you only need one direction \u2192 AI has better success with single-axis tiling`;
|
|
923
1016
|
var LEADERBOARD_DOCS = `**Installation**
|
|
924
1017
|
|
|
925
1018
|
\`\`\`bash
|
|
@@ -944,7 +1037,7 @@ const leaderboard = createLeaderboard();
|
|
|
944
1037
|
|
|
945
1038
|
\`\`\`javascript
|
|
946
1039
|
import { createLeaderboard } from 'star-leaderboard';
|
|
947
|
-
import { game } from '
|
|
1040
|
+
import { game } from 'star-canvas';
|
|
948
1041
|
|
|
949
1042
|
const leaderboard = createLeaderboard();
|
|
950
1043
|
|
|
@@ -1033,7 +1126,7 @@ async function gameOver(finalScore) {
|
|
|
1033
1126
|
|
|
1034
1127
|
\`\`\`javascript
|
|
1035
1128
|
import { createLeaderboard } from 'star-leaderboard';
|
|
1036
|
-
import { game } from '
|
|
1129
|
+
import { game } from 'star-canvas';
|
|
1037
1130
|
|
|
1038
1131
|
const leaderboard = createLeaderboard();
|
|
1039
1132
|
|
|
@@ -1079,7 +1172,7 @@ async function showCustomLeaderboard() {
|
|
|
1079
1172
|
|
|
1080
1173
|
\`\`\`javascript
|
|
1081
1174
|
import { createLeaderboard } from 'star-leaderboard';
|
|
1082
|
-
import { game } from '
|
|
1175
|
+
import { game } from 'star-canvas';
|
|
1083
1176
|
|
|
1084
1177
|
const leaderboard = createLeaderboard();
|
|
1085
1178
|
|
|
@@ -1209,7 +1302,7 @@ const mp = createMultiplayer();
|
|
|
1209
1302
|
|
|
1210
1303
|
\`\`\`javascript
|
|
1211
1304
|
import { createMultiplayer } from 'star-multiplayer';
|
|
1212
|
-
import { game } from '
|
|
1305
|
+
import { game } from 'star-canvas';
|
|
1213
1306
|
|
|
1214
1307
|
const mp = createMultiplayer();
|
|
1215
1308
|
|
|
@@ -1662,7 +1755,7 @@ ${colors.bright}Star SDK CLI${colors.reset} v${VERSION}
|
|
|
1662
1755
|
${colors.dim}Commands:${colors.reset}
|
|
1663
1756
|
${colors.cyan}init <name>${colors.reset} Register a new game
|
|
1664
1757
|
${colors.cyan}install [agent]${colors.reset} Install Star SDK docs for AI coding agents
|
|
1665
|
-
${colors.cyan}docs [topic]${colors.reset} Print API documentation
|
|
1758
|
+
${colors.cyan}docs [topic]${colors.reset} Print API documentation (default: all docs)
|
|
1666
1759
|
${colors.cyan}whoami${colors.reset} Show current configuration
|
|
1667
1760
|
|
|
1668
1761
|
${colors.dim}Supported agents:${colors.reset}
|
|
@@ -1691,8 +1784,9 @@ ${colors.dim}Examples:${colors.reset}
|
|
|
1691
1784
|
npx star-sdk install aider ${colors.dim}# Aider${colors.reset}
|
|
1692
1785
|
|
|
1693
1786
|
${colors.dim}# Print API docs (works with any LLM)${colors.reset}
|
|
1694
|
-
npx star-sdk docs
|
|
1695
|
-
npx star-sdk docs audio
|
|
1787
|
+
npx star-sdk docs ${colors.dim}# All docs${colors.reset}
|
|
1788
|
+
npx star-sdk docs audio ${colors.dim}# Just audio API${colors.reset}
|
|
1789
|
+
npx star-sdk docs skill ${colors.dim}# Just main skill file${colors.reset}
|
|
1696
1790
|
|
|
1697
1791
|
${colors.dim}Learn more:${colors.reset} https://buildwithstar.com/docs
|
|
1698
1792
|
`);
|
|
@@ -1766,11 +1860,14 @@ async function initCommand(name, email) {
|
|
|
1766
1860
|
log(`${colors.dim}Config saved to${colors.reset} ${colors.bright}.starrc${colors.reset}`);
|
|
1767
1861
|
log("");
|
|
1768
1862
|
log(`${colors.dim}Next steps:${colors.reset}`);
|
|
1769
|
-
log(` 1.
|
|
1770
|
-
log(` 2.
|
|
1863
|
+
log(` 1. Install: ${colors.cyan}npm install star-sdk${colors.reset}`);
|
|
1864
|
+
log(` 2. Import Star SDK in your game`);
|
|
1865
|
+
log(` 3. Initialize with your game ID`);
|
|
1866
|
+
log(` 4. Use Star.leaderboard.submit(score) to submit scores`);
|
|
1771
1867
|
log("");
|
|
1772
1868
|
log(`${colors.dim}Example:${colors.reset}`);
|
|
1773
1869
|
log(` ${colors.cyan}import Star from 'star-sdk';${colors.reset}`);
|
|
1870
|
+
log(` ${colors.cyan}Star.init({ gameId: '${data.gameId}' });${colors.reset}`);
|
|
1774
1871
|
log(` ${colors.cyan}Star.leaderboard.submit(1500);${colors.reset}`);
|
|
1775
1872
|
log("");
|
|
1776
1873
|
log(`${colors.dim}Using an AI coding agent?${colors.reset}`);
|
|
@@ -1809,6 +1906,12 @@ function whoamiCommand() {
|
|
|
1809
1906
|
}
|
|
1810
1907
|
log("");
|
|
1811
1908
|
}
|
|
1909
|
+
function transformForStdout(content) {
|
|
1910
|
+
return content.replace(/\[(\w+)\.md\]\(\.\/\1\.md\)/g, "$1 (`npx star-sdk docs $1`)").replace(/see (\w+)\.md/g, "run `npx star-sdk docs $1`").replace(
|
|
1911
|
+
/For detailed API documentation, see the linked files above\./,
|
|
1912
|
+
"For detailed API docs: `npx star-sdk docs <topic>` where topic is audio, canvas, leaderboard, or multiplayer."
|
|
1913
|
+
);
|
|
1914
|
+
}
|
|
1812
1915
|
function getAllDocsContent() {
|
|
1813
1916
|
return `${SKILL_CONTENT}
|
|
1814
1917
|
|
|
@@ -1966,19 +2069,20 @@ function installCommand(agent = "claude", scope = "global") {
|
|
|
1966
2069
|
}
|
|
1967
2070
|
function docsCommand(topic) {
|
|
1968
2071
|
const docs = {
|
|
2072
|
+
skill: SKILL_CONTENT,
|
|
1969
2073
|
audio: AUDIO_DOCS,
|
|
1970
2074
|
canvas: CANVAS_DOCS,
|
|
1971
2075
|
leaderboard: LEADERBOARD_DOCS,
|
|
1972
2076
|
multiplayer: MULTIPLAYER_DOCS
|
|
1973
2077
|
};
|
|
1974
2078
|
if (!topic) {
|
|
1975
|
-
console.log(SKILL_CONTENT);
|
|
2079
|
+
console.log(transformForStdout(SKILL_CONTENT));
|
|
1976
2080
|
} else if (docs[topic]) {
|
|
1977
2081
|
console.log(docs[topic]);
|
|
1978
2082
|
} else {
|
|
1979
2083
|
error(`Unknown topic: ${topic}`);
|
|
1980
2084
|
log("");
|
|
1981
|
-
log("Available topics: audio, canvas, leaderboard, multiplayer");
|
|
2085
|
+
log("Available topics: skill, audio, canvas, leaderboard, multiplayer");
|
|
1982
2086
|
process.exit(1);
|
|
1983
2087
|
}
|
|
1984
2088
|
}
|