star-sdk-cli 0.1.4 → 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 +105 -9
- 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
|
|
|
@@ -1767,11 +1860,14 @@ async function initCommand(name, email) {
|
|
|
1767
1860
|
log(`${colors.dim}Config saved to${colors.reset} ${colors.bright}.starrc${colors.reset}`);
|
|
1768
1861
|
log("");
|
|
1769
1862
|
log(`${colors.dim}Next steps:${colors.reset}`);
|
|
1770
|
-
log(` 1.
|
|
1771
|
-
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`);
|
|
1772
1867
|
log("");
|
|
1773
1868
|
log(`${colors.dim}Example:${colors.reset}`);
|
|
1774
1869
|
log(` ${colors.cyan}import Star from 'star-sdk';${colors.reset}`);
|
|
1870
|
+
log(` ${colors.cyan}Star.init({ gameId: '${data.gameId}' });${colors.reset}`);
|
|
1775
1871
|
log(` ${colors.cyan}Star.leaderboard.submit(1500);${colors.reset}`);
|
|
1776
1872
|
log("");
|
|
1777
1873
|
log(`${colors.dim}Using an AI coding agent?${colors.reset}`);
|