SOURCE / PINNED RELEASE
Made of little things.
Supersonic RC Revive
- Release
- 1ba42f1ca1d6…
- Author-recorded commit
- baecad10b1cd…
- License
- LICENSE
- Author’s source reference
- nostr://npub1ye5ptcxfyyxl5vjvdjar2ua3f0hynkjzpx552mu5snj3qmx5pzjscpknpr/wss%3A%2F%2Fgit.napplet.soy%2F/n-143146b0d6f
Archive hash verified: 90d22b206672eba4…. The source-to-build association is the author’s claim; it has not been independently rebuilt.
import { INC_DOMAIN, inc } from '@napplet/sdk';
import { runtimeHasDomain } from './domain-availability.js';
import { parsePackLink } from './game/assets.js';
/**
* The NAP-INTENT role this napplet fulfils (the manifest's archetype tag, set
* in vite.config.ts): another napplet runs
* intent.invoke({ archetype: 'supersonicrc', action: 'play', convention: PLAY_CONVENTION, payload: { url } })
* and the shell opens or focuses this napplet and delivers the payload as an
* INC event on the convention's topic.
*/
export const GAME_ARCHETYPE = 'supersonicrc';
export const PLAY_CONVENTION = 'napplet:supersonicrc/play';
const MAX_LINK_LENGTH = 4096;
/**
* The pack link in a play payload: `{ url }` or `{ uri }` (what the emit-only
* query shorthand `napplet:supersonicrc/play?url=…` decodes to), or a bare
* string. Anything parsePackLink accepts: an https Blossom blob URL, a
* blossom: URI or a SHA-256. Null when the payload carries no usable link.
*/
export function playPayloadLink(payload: unknown): string | null {
let value: unknown = payload;
if (payload && typeof payload === 'object') {
const fields = payload as { url?: unknown; uri?: unknown };
value = fields.url ?? fields.uri;
}
if (typeof value !== 'string' || value.length > MAX_LINK_LENGTH) return null;
return parsePackLink(value) ? value.trim() : null;
}
/**
* Listen for play intents. `play` gets each valid pack link; `invalid` is told
* about payloads without one. Payloads come from other napplets, so they are
* untrusted. No-op without a working INC domain.
*/
export function onPlayIntent(play: (link: string) => void, invalid: () => void): () => void {
if (!runtimeHasDomain(INC_DOMAIN)) return () => {};
let sub: { close(): void };
try {
sub = inc.on(PLAY_CONVENTION, (event) => {
if (event?.topic !== PLAY_CONVENTION) return;
const link = playPayloadLink(event.payload);
if (link) play(link);
else invalid();
});
} catch {
// A runtime whose INC domain cannot subscribe: no play intents, the game still runs.
return () => {};
}
return () => sub.close();
}
