実装例
@consenger/companion-sdk の browser-game integration は、次の形を基準にします。
Vanilla browser game
html
<script src="./companion-sdk.js"></script>
<script>
const companion = window.Consenger.companion;
companion.context("round.current", {
description: "Current round state visible to the player",
read: () => ({
round: 3,
goal: "Pick the matching Japanese word",
choices: ["みず", "そら", "ねこ"]
})
});
companion.command("round.hint", {
title: "Show a hint",
inputSchema: { type: "object", properties: {}, additionalProperties: false },
handler: () => {
showHint();
return { ok: true };
}
});
</script>Phaser scene
ts
import { createCompanionSDK } from "@consenger/companion-sdk";
const companion = createCompanionSDK({ transport: "auto" });
export class QuizScene extends Phaser.Scene {
create() {
companion.context("scene.current", {
description: "Current quiz scene",
read: () => ({
scene: this.scene.key,
score: this.score,
prompt: this.currentPrompt
})
});
}
}Godot Web export
Godot Web export では、SDK browser bundle を Project.html の近くに配置し、JavaScript glue code から呼び出します。gameplay state は Godot 側を source of truth にし、companion.context() では player-facing な小さい snapshot だけを公開します。
