@@ -30,19 +30,47 @@ npm install codex-pet-web
3030## Quick Start: React
3131
3232``` tsx
33- import { CodexPet } from " codex-pet-web-react" ;
33+ import {
34+ CodexPet ,
35+ CodexPetProvider ,
36+ useCodexPet ,
37+ useCodexPetRandomActions
38+ } from " codex-pet-web-react" ;
39+
40+ function PetControls() {
41+ const pet = useCodexPet (" assistant" );
42+ useCodexPetRandomActions (" assistant" , {
43+ averageIntervalSeconds: 120 ,
44+ minIntervalSeconds: 45 ,
45+ maxIntervalSeconds: 300 ,
46+ actions: [
47+ { state: " waving" , weight: 3 },
48+ { state: " jumping" , weight: 2 },
49+ { state: " waiting" , weight: 1 },
50+ { state: " review" , weight: 1 }
51+ ]
52+ });
53+
54+ return <button onClick = { () => pet .play (" waving" )} >Wave</button >;
55+ }
3456
3557export function AssistantPet() {
3658 return (
37- <CodexPet
38- aria-label = " Assistant pet"
39- draggable
40- floating = { { x: 24 , y: 24 , zIndex: 1000 }}
41- fps = { 8 }
42- scale = { 0.5 }
43- spritesheetUrl = " /codex-pets/sapling/spritesheet.webp"
44- stateFps = { { idle: 2 , waiting: 3 }}
45- />
59+ <CodexPetProvider
60+ pets = { {
61+ assistant: {
62+ draggable: true ,
63+ floating: { x: 24 , y: 24 , zIndex: 1000 },
64+ fps: 8 ,
65+ scale: 0.45 ,
66+ spritesheetUrl: " /codex-pets/sapling/spritesheet.webp" ,
67+ stateFps: { idle: 2 , waiting: 3 }
68+ }
69+ }}
70+ >
71+ <PetControls />
72+ <CodexPet id = " assistant" aria-label = " Assistant pet" />
73+ </CodexPetProvider >
4674 );
4775}
4876```
@@ -112,6 +140,14 @@ During drag, horizontal movement switches to `running-left` or `running-right`;
112140on release, the pet plays one ` jumping ` loop and returns to its previous base
113141state.
114142
143+ For app-wide control, register pets in ` CodexPetProvider ` and call
144+ ` useCodexPet(id) ` from anywhere inside the provider. Controllers expose
145+ ` play ` , ` setState ` , ` setPosition ` , ` hide ` , ` show ` , and ` remove ` .
146+
147+ For ambient behavior, ` useCodexPetRandomActions ` attempts a weighted random
148+ action on a randomized schedule. It only plays an action when the pet is idle,
149+ visible, mounted, and not paused.
150+
115151## Sprite Contract
116152
117153Codex pets are regular folders:
@@ -163,8 +199,10 @@ npm run copy:pets
163199npm run dev
164200```
165201
166- ` copy:pets ` copies local pets from ` ~/.codex/pets ` into the demo. Production
167- demo builds copy the bundled example pets from ` packages/core/example-pets ` .
202+ ` copy:pets ` copies bundled examples plus local pets from ` ~/.codex/pets ` into
203+ the demo. If a local pet uses the same id as a bundled example, the local pet
204+ wins. Production demo builds copy the bundled example pets from
205+ ` packages/core/example-pets ` .
168206
169207Before publishing:
170208
@@ -175,4 +213,4 @@ npm run build
175213npm run pack:dry
176214```
177215
178- The latest release line is ` 0.2 .x ` .
216+ The latest release line is ` 0.3 .x ` .
0 commit comments