star-sdk 0.1.0

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/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # Star SDK
2
+
3
+ Unified SDK for browser game development. Audio, canvas, and leaderboards.
4
+
5
+ ```javascript
6
+ import Star from 'star-sdk';
7
+
8
+ Star.audio.play('coin');
9
+ Star.game(ctx => { ... });
10
+ Star.leaderboard.submit(1500);
11
+ ```
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install star-sdk
17
+ # or
18
+ yarn add star-sdk
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ```javascript
24
+ import Star from 'star-sdk';
25
+
26
+ Star.game(ctx => {
27
+ const { canvas, width, height, ctx: c } = ctx;
28
+ let score = 0;
29
+
30
+ // Preload sounds
31
+ Star.audio.preload({
32
+ coin: 'coin', // Built-in synth preset
33
+ jump: 'jump',
34
+ });
35
+
36
+ // Game loop
37
+ ctx.loop((dt) => {
38
+ c.fillStyle = '#1a1a2e';
39
+ c.fillRect(0, 0, width, height);
40
+
41
+ c.fillStyle = '#fff';
42
+ c.font = '24px sans-serif';
43
+ c.fillText(\`Score: \${score}\`, 20, 40);
44
+ });
45
+
46
+ // Input
47
+ canvas.onclick = () => {
48
+ score += 10;
49
+ Star.audio.play('coin');
50
+ };
51
+ });
52
+ ```
53
+
54
+ ## Features
55
+
56
+ ### Audio
57
+
58
+ Procedural sounds and music with built-in presets.
59
+
60
+ ```javascript
61
+ // Play built-in sounds
62
+ Star.audio.play('coin');
63
+ Star.audio.play('laser');
64
+ Star.audio.play('explosion');
65
+
66
+ // Music control
67
+ Star.audio.music.crossfadeTo('level2', { duration: 2 });
68
+ Star.audio.music.stop(1);
69
+
70
+ // Volume
71
+ Star.audio.setMusicVolume(0.8);
72
+ Star.audio.setSfxVolume(0.9);
73
+ Star.audio.toggleMute();
74
+ ```
75
+
76
+ **Built-in presets:** \`beep\`, \`coin\`, \`pickup\`, \`jump\`, \`hurt\`, \`explosion\`, \`powerup\`, \`shoot\`, \`laser\`, \`error\`, \`click\`, \`success\`, \`bonus\`, \`select\`, \`unlock\`, \`swoosh\`, \`hit\`
77
+
78
+ ### Canvas
79
+
80
+ Game loop with automatic DPR scaling and coordinate conversion.
81
+
82
+ ```javascript
83
+ Star.game(ctx => {
84
+ const { canvas, width, height, ctx: c, ui } = ctx;
85
+
86
+ ctx.loop((dt) => {
87
+ // dt = delta time in seconds
88
+ c.clearRect(0, 0, width, height);
89
+ });
90
+
91
+ // Delegated events
92
+ ctx.on('click', '.button', (e) => { ... });
93
+
94
+ // UI overlay (HTML on top of canvas)
95
+ ui.render(\`<div class="score">Score: \${score}</div>\`);
96
+ }, {
97
+ preset: 'landscape', // or 'portrait', 'responsive'
98
+ });
99
+ ```
100
+
101
+ ### Leaderboard
102
+
103
+ Submit scores and display rankings.
104
+
105
+ ```javascript
106
+ // Submit score
107
+ const result = await Star.leaderboard.submit(1500);
108
+ if (result.success) {
109
+ console.log(\`Ranked #\${result.rank}!\`);
110
+ }
111
+
112
+ // Show platform UI
113
+ Star.leaderboard.show();
114
+
115
+ // Fetch scores manually
116
+ const { scores } = await Star.leaderboard.getScores({
117
+ timeframe: 'weekly',
118
+ limit: 10
119
+ });
120
+ ```
121
+
122
+ ## External Games
123
+
124
+ For games hosted outside the Star platform:
125
+
126
+ ```bash
127
+ # Register your game
128
+ npx star-sdk init "My Game"
129
+ ```
130
+
131
+ This creates a \`.starrc\` file with your game ID. The SDK auto-detects this configuration.
132
+
133
+ ## Deploy to Star
134
+
135
+ Get more from your game with Star hosting:
136
+
137
+ - Free hosting
138
+ - Play session tracking (see how long players play)
139
+ - Analytics dashboard
140
+ - Discovery / game feed
141
+
142
+ ```bash
143
+ npx star-sdk deploy
144
+ ```
145
+
146
+ ## Coming Soon
147
+
148
+ - **Multiplayer** - Real-time game state synchronization (in alpha)
149
+ - **Monetization** - Let players support your games
150
+
151
+ ## Documentation
152
+
153
+ Full documentation at [buildwithstar.com/docs/sdk](https://buildwithstar.com/docs/sdk)
154
+
155
+ ## License
156
+
157
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var u=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var x=(e,t)=>{for(var r in t)u(e,r,{get:t[r],enumerable:!0})},h=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of O(t))!M.call(e,s)&&s!==r&&u(e,s,{get:()=>t[s],enumerable:!(o=b(t,s))||o.enumerable});return e};var G=e=>h(u({},"__esModule",{value:!0}),e);var I={};x(I,{Star:()=>c,audio:()=>f.createStarAudio,default:()=>A,game:()=>S.game,leaderboard:()=>g.createLeaderboard,multiplayer:()=>y.createMultiplayer});module.exports=G(I);var f=require("star-audio"),S=require("star-canvas"),g=require("star-leaderboard"),y=require("star-multiplayer"),p=null,l=null,i=null,d=()=>typeof window<"u",L=()=>typeof process<"u"&&process.versions?.node;function m(){if(d()||!L())return null;try{let e=require("fs"),r=require("path").join(process.cwd(),".starrc");if(!e.existsSync(r))return null;let o=e.readFileSync(r,"utf-8");return JSON.parse(o)}catch{return null}}function a(){if(!l&&d()){let{createStarAudio:e}=require("star-audio");l=e()}return l}function n(){if(!i){let e=p?.gameId,t=p?.apiBase;if(!e){let o=m();o?.gameId&&(e=o.gameId)}let{createLeaderboard:r}=require("star-leaderboard");i=r({gameId:e,apiBase:t})}return i}var c={init(e){p=e,i&&(i.destroy?.(),i=null)},audio:{play:(e,t)=>a().play(e,t),preload:e=>a().preload(e),music:{crossfadeTo:(e,t)=>a().music.crossfadeTo(e,t),stop:e=>a().music.stop(e)},setMusicVolume:e=>a().setMusicVolume(e),setSfxVolume:e=>a().setSfxVolume(e),setMute:e=>a().setMute(e),toggleMute:()=>a().toggleMute(),isMuted:()=>a().isMuted()},game(e,t){let{game:r}=require("star-canvas");r(e,t)},leaderboard:{submit:e=>n().submit(e),show:()=>n().show(),getScores:e=>n().getScores(e),share:e=>n().share(e)},multiplayer:{async create(e){let{createMultiplayer:t}=require("star-multiplayer"),r=t();return await r.start(e),r}},loadConfig:m,version:"0.1.0"},A=c;0&&(module.exports={Star,audio,game,leaderboard,multiplayer});
@@ -0,0 +1,140 @@
1
+ import * as star_leaderboard from 'star-leaderboard';
2
+ import { GetScoresOptions, ShareOptions } from 'star-leaderboard';
3
+ export { GetScoresOptions, LeaderboardData, LeaderboardOptions, ScoreEntry, ShareOptions, ShareResult, StarLeaderboard, SubmitResult, createLeaderboard as leaderboard } from 'star-leaderboard';
4
+ import * as star_audio from 'star-audio';
5
+ import { PlayOptions, Manifest } from 'star-audio';
6
+ export { Manifest, PlayOptions, StarAudio, StarAudioOptions, createStarAudio as audio } from 'star-audio';
7
+ import { GameContext, GameOptions } from 'star-canvas';
8
+ export { GameContext, GameLoop, GameOptions, GameTick, GameUI, game } from 'star-canvas';
9
+ import { StartOptions, StarMultiplayer } from 'star-multiplayer';
10
+ export { StartOptions as MultiplayerOptions, Player, StarMultiplayer, createMultiplayer as multiplayer } from 'star-multiplayer';
11
+
12
+ interface StarConfig {
13
+ gameId: string;
14
+ name?: string;
15
+ email?: string;
16
+ dashboardUrl?: string;
17
+ }
18
+ /**
19
+ * Load configuration from .starrc file (Node.js only).
20
+ * Returns null in browser or if file doesn't exist.
21
+ */
22
+ declare function loadConfigFromFile(): StarConfig | null;
23
+ declare const Star: {
24
+ /**
25
+ * Initialize the SDK for external (non-platform) use.
26
+ * Not needed when running inside Star platform - auto-detected.
27
+ *
28
+ * @param options - Configuration with gameId and optional apiBase
29
+ *
30
+ * @example
31
+ * ```javascript
32
+ * // For external games only
33
+ * Star.init({ gameId: 'abc123' });
34
+ * ```
35
+ */
36
+ init(options: {
37
+ gameId: string;
38
+ apiBase?: string;
39
+ }): void;
40
+ /**
41
+ * Audio manager - procedural sounds and music.
42
+ *
43
+ * @example
44
+ * ```javascript
45
+ * Star.audio.play('coin');
46
+ * Star.audio.music.crossfadeTo('level2');
47
+ * ```
48
+ */
49
+ audio: {
50
+ play: (id: string, opts?: PlayOptions) => star_audio.SoundHandle | null;
51
+ preload: (manifest: Manifest) => Promise<void>;
52
+ music: {
53
+ crossfadeTo: (id: string, opts?: {
54
+ duration?: number;
55
+ loop?: boolean;
56
+ }) => Promise<void>;
57
+ stop: (fadeSec?: number) => void;
58
+ };
59
+ setMusicVolume: (v: number) => void;
60
+ setSfxVolume: (v: number) => void;
61
+ setMute: (m: boolean) => void;
62
+ toggleMute: () => void;
63
+ isMuted: () => boolean;
64
+ };
65
+ /**
66
+ * Initialize the game canvas and context.
67
+ * Handles DOM timing, DPR scaling, and provides a game loop.
68
+ *
69
+ * @param setup - Function called when canvas is ready
70
+ * @param options - Canvas and stage configuration
71
+ *
72
+ * @example
73
+ * ```javascript
74
+ * Star.game(ctx => {
75
+ * const { canvas, width, height } = ctx;
76
+ *
77
+ * ctx.loop((dt) => {
78
+ * ctx.ctx.fillStyle = '#000';
79
+ * ctx.ctx.fillRect(0, 0, width, height);
80
+ * });
81
+ * });
82
+ * ```
83
+ */
84
+ game(setup: (g: GameContext) => void, options?: GameOptions): void;
85
+ /**
86
+ * Leaderboard - submit scores and display rankings.
87
+ *
88
+ * @example
89
+ * ```javascript
90
+ * await Star.leaderboard.submit(1500);
91
+ * Star.leaderboard.show();
92
+ * ```
93
+ */
94
+ leaderboard: {
95
+ submit: (score: number) => Promise<star_leaderboard.SubmitResult>;
96
+ show: () => void;
97
+ getScores: (opts?: GetScoresOptions) => Promise<star_leaderboard.LeaderboardData>;
98
+ share: (opts?: ShareOptions) => Promise<star_leaderboard.ShareResult>;
99
+ };
100
+ /**
101
+ * Multiplayer - real-time game state synchronization.
102
+ *
103
+ * @example
104
+ * ```javascript
105
+ * const mp = await Star.multiplayer.create({ maxPlayers: 4 });
106
+ *
107
+ * mp.onState(state => { gameState = state; });
108
+ * mp.onInput((id, input) => { state.players[id].y = input.y; });
109
+ *
110
+ * ctx.loop((dt) => {
111
+ * mp.hostTick(dt, () => { updatePhysics(dt); return state; });
112
+ * render(state);
113
+ * });
114
+ *
115
+ * canvas.onpointermove = (e) => mp.input({ y: e.clientY });
116
+ * ```
117
+ */
118
+ multiplayer: {
119
+ create(options?: StartOptions): Promise<StarMultiplayer>;
120
+ };
121
+ /**
122
+ * Load configuration from .starrc file (Node.js only).
123
+ * Useful for build scripts or SSR.
124
+ *
125
+ * @returns Config object or null if not found
126
+ *
127
+ * @example
128
+ * ```javascript
129
+ * const config = Star.loadConfig();
130
+ * if (config) {
131
+ * console.log(`Game ID: ${config.gameId}`);
132
+ * }
133
+ * ```
134
+ */
135
+ loadConfig: typeof loadConfigFromFile;
136
+ /** SDK version */
137
+ version: string;
138
+ };
139
+
140
+ export { Star, Star as default };
@@ -0,0 +1,140 @@
1
+ import * as star_leaderboard from 'star-leaderboard';
2
+ import { GetScoresOptions, ShareOptions } from 'star-leaderboard';
3
+ export { GetScoresOptions, LeaderboardData, LeaderboardOptions, ScoreEntry, ShareOptions, ShareResult, StarLeaderboard, SubmitResult, createLeaderboard as leaderboard } from 'star-leaderboard';
4
+ import * as star_audio from 'star-audio';
5
+ import { PlayOptions, Manifest } from 'star-audio';
6
+ export { Manifest, PlayOptions, StarAudio, StarAudioOptions, createStarAudio as audio } from 'star-audio';
7
+ import { GameContext, GameOptions } from 'star-canvas';
8
+ export { GameContext, GameLoop, GameOptions, GameTick, GameUI, game } from 'star-canvas';
9
+ import { StartOptions, StarMultiplayer } from 'star-multiplayer';
10
+ export { StartOptions as MultiplayerOptions, Player, StarMultiplayer, createMultiplayer as multiplayer } from 'star-multiplayer';
11
+
12
+ interface StarConfig {
13
+ gameId: string;
14
+ name?: string;
15
+ email?: string;
16
+ dashboardUrl?: string;
17
+ }
18
+ /**
19
+ * Load configuration from .starrc file (Node.js only).
20
+ * Returns null in browser or if file doesn't exist.
21
+ */
22
+ declare function loadConfigFromFile(): StarConfig | null;
23
+ declare const Star: {
24
+ /**
25
+ * Initialize the SDK for external (non-platform) use.
26
+ * Not needed when running inside Star platform - auto-detected.
27
+ *
28
+ * @param options - Configuration with gameId and optional apiBase
29
+ *
30
+ * @example
31
+ * ```javascript
32
+ * // For external games only
33
+ * Star.init({ gameId: 'abc123' });
34
+ * ```
35
+ */
36
+ init(options: {
37
+ gameId: string;
38
+ apiBase?: string;
39
+ }): void;
40
+ /**
41
+ * Audio manager - procedural sounds and music.
42
+ *
43
+ * @example
44
+ * ```javascript
45
+ * Star.audio.play('coin');
46
+ * Star.audio.music.crossfadeTo('level2');
47
+ * ```
48
+ */
49
+ audio: {
50
+ play: (id: string, opts?: PlayOptions) => star_audio.SoundHandle | null;
51
+ preload: (manifest: Manifest) => Promise<void>;
52
+ music: {
53
+ crossfadeTo: (id: string, opts?: {
54
+ duration?: number;
55
+ loop?: boolean;
56
+ }) => Promise<void>;
57
+ stop: (fadeSec?: number) => void;
58
+ };
59
+ setMusicVolume: (v: number) => void;
60
+ setSfxVolume: (v: number) => void;
61
+ setMute: (m: boolean) => void;
62
+ toggleMute: () => void;
63
+ isMuted: () => boolean;
64
+ };
65
+ /**
66
+ * Initialize the game canvas and context.
67
+ * Handles DOM timing, DPR scaling, and provides a game loop.
68
+ *
69
+ * @param setup - Function called when canvas is ready
70
+ * @param options - Canvas and stage configuration
71
+ *
72
+ * @example
73
+ * ```javascript
74
+ * Star.game(ctx => {
75
+ * const { canvas, width, height } = ctx;
76
+ *
77
+ * ctx.loop((dt) => {
78
+ * ctx.ctx.fillStyle = '#000';
79
+ * ctx.ctx.fillRect(0, 0, width, height);
80
+ * });
81
+ * });
82
+ * ```
83
+ */
84
+ game(setup: (g: GameContext) => void, options?: GameOptions): void;
85
+ /**
86
+ * Leaderboard - submit scores and display rankings.
87
+ *
88
+ * @example
89
+ * ```javascript
90
+ * await Star.leaderboard.submit(1500);
91
+ * Star.leaderboard.show();
92
+ * ```
93
+ */
94
+ leaderboard: {
95
+ submit: (score: number) => Promise<star_leaderboard.SubmitResult>;
96
+ show: () => void;
97
+ getScores: (opts?: GetScoresOptions) => Promise<star_leaderboard.LeaderboardData>;
98
+ share: (opts?: ShareOptions) => Promise<star_leaderboard.ShareResult>;
99
+ };
100
+ /**
101
+ * Multiplayer - real-time game state synchronization.
102
+ *
103
+ * @example
104
+ * ```javascript
105
+ * const mp = await Star.multiplayer.create({ maxPlayers: 4 });
106
+ *
107
+ * mp.onState(state => { gameState = state; });
108
+ * mp.onInput((id, input) => { state.players[id].y = input.y; });
109
+ *
110
+ * ctx.loop((dt) => {
111
+ * mp.hostTick(dt, () => { updatePhysics(dt); return state; });
112
+ * render(state);
113
+ * });
114
+ *
115
+ * canvas.onpointermove = (e) => mp.input({ y: e.clientY });
116
+ * ```
117
+ */
118
+ multiplayer: {
119
+ create(options?: StartOptions): Promise<StarMultiplayer>;
120
+ };
121
+ /**
122
+ * Load configuration from .starrc file (Node.js only).
123
+ * Useful for build scripts or SSR.
124
+ *
125
+ * @returns Config object or null if not found
126
+ *
127
+ * @example
128
+ * ```javascript
129
+ * const config = Star.loadConfig();
130
+ * if (config) {
131
+ * console.log(`Game ID: ${config.gameId}`);
132
+ * }
133
+ * ```
134
+ */
135
+ loadConfig: typeof loadConfigFromFile;
136
+ /** SDK version */
137
+ version: string;
138
+ };
139
+
140
+ export { Star, Star as default };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ var o=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});import{createStarAudio as b}from"star-audio";import{game as M}from"star-canvas";import{createLeaderboard as h}from"star-leaderboard";import{createMultiplayer as L}from"star-multiplayer";var l=null,u=null,i=null,p=()=>typeof window<"u",m=()=>typeof process<"u"&&process.versions?.node;function d(){if(p()||!m())return null;try{let e=o("fs"),r=o("path").join(process.cwd(),".starrc");if(!e.existsSync(r))return null;let s=e.readFileSync(r,"utf-8");return JSON.parse(s)}catch{return null}}function a(){if(!u&&p()){let{createStarAudio:e}=o("star-audio");u=e()}return u}function n(){if(!i){let e=l?.gameId,t=l?.apiBase;if(!e){let s=d();s?.gameId&&(e=s.gameId)}let{createLeaderboard:r}=o("star-leaderboard");i=r({gameId:e,apiBase:t})}return i}var c={init(e){l=e,i&&(i.destroy?.(),i=null)},audio:{play:(e,t)=>a().play(e,t),preload:e=>a().preload(e),music:{crossfadeTo:(e,t)=>a().music.crossfadeTo(e,t),stop:e=>a().music.stop(e)},setMusicVolume:e=>a().setMusicVolume(e),setSfxVolume:e=>a().setSfxVolume(e),setMute:e=>a().setMute(e),toggleMute:()=>a().toggleMute(),isMuted:()=>a().isMuted()},game(e,t){let{game:r}=o("star-canvas");r(e,t)},leaderboard:{submit:e=>n().submit(e),show:()=>n().show(),getScores:e=>n().getScores(e),share:e=>n().share(e)},multiplayer:{async create(e){let{createMultiplayer:t}=o("star-multiplayer"),r=t();return await r.start(e),r}},loadConfig:d,version:"0.1.0"},S=c;export{c as Star,b as audio,S as default,M as game,h as leaderboard,L as multiplayer};
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "star-sdk",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "description": "Unified Star SDK for game development. Audio, canvas, leaderboards, multiplayer.",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "starSdk": {
9
+ "internalImport": "import Star from '/star-sdk/v1/star.js';",
10
+ "publicImport": "import Star from 'star-sdk';",
11
+ "outputs": [{ "src": "dist/index.mjs", "dest": "v1/star.js" }],
12
+ "skill": {
13
+ "name": "star-sdk",
14
+ "description": "Unified Star SDK for game development. Audio, canvas, leaderboards, multiplayer."
15
+ }
16
+ },
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.mjs",
21
+ "require": "./dist/index.cjs"
22
+ }
23
+ },
24
+ "main": "./dist/index.cjs",
25
+ "module": "./dist/index.mjs",
26
+ "types": "./dist/index.d.ts",
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "scripts": {
31
+ "build": "tsup",
32
+ "clean": "rm -rf dist"
33
+ },
34
+ "keywords": [
35
+ "star",
36
+ "sdk",
37
+ "games",
38
+ "web",
39
+ "audio",
40
+ "canvas",
41
+ "leaderboard",
42
+ "multiplayer"
43
+ ],
44
+ "dependencies": {
45
+ "star-audio": "*",
46
+ "star-canvas": "*",
47
+ "star-leaderboard": "*",
48
+ "star-multiplayer": "*"
49
+ },
50
+ "devDependencies": {
51
+ "tsup": "^8.0.0",
52
+ "typescript": "^5.4.5"
53
+ }
54
+ }