@masterbble/dsh-coo-pet 0.0.0-stage → 0.6.29
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/LICENSE +661 -0
- package/README.md +112 -2
- package/assets/desk-main.cjs +623 -0
- package/assets/desk-preload.cjs +116 -0
- package/assets/desk-probe.ps1 +213 -0
- package/assets/icon-snapshot.json +1 -0
- package/assets/pet/desk.html +2734 -0
- package/assets/pet/kit/body.js +1053 -0
- package/assets/pet/kit/rig.js +242 -0
- package/assets/pet/speech/zh.json +1 -0
- package/assets/pet/speech/zh.ogg +0 -0
- package/assets/pet/whale/feat/dizzy_eyeL.png +0 -0
- package/assets/pet/whale/feat/dizzy_eyeR.png +0 -0
- package/assets/pet/whale/feat/dizzy_mouth.png +0 -0
- package/assets/pet/whale/feat/drag_eyeL.png +0 -0
- package/assets/pet/whale/feat/drag_eyeR.png +0 -0
- package/assets/pet/whale/feat/drag_mouth.png +0 -0
- package/assets/pet/whale/feat/eyeL_ball.png +0 -0
- package/assets/pet/whale/feat/eyeL_hl.png +0 -0
- package/assets/pet/whale/feat/eyeL_iris.png +0 -0
- package/assets/pet/whale/feat/eyeL_lash.png +0 -0
- package/assets/pet/whale/feat/eyeR_ball.png +0 -0
- package/assets/pet/whale/feat/eyeR_hl.png +0 -0
- package/assets/pet/whale/feat/eyeR_iris.png +0 -0
- package/assets/pet/whale/feat/eyeR_lash.png +0 -0
- package/assets/pet/whale/feat/happy_eyeL.png +0 -0
- package/assets/pet/whale/feat/happy_eyeR.png +0 -0
- package/assets/pet/whale/feat/happy_mouth.png +0 -0
- package/assets/pet/whale/feat/love_eyeL.png +0 -0
- package/assets/pet/whale/feat/love_eyeR.png +0 -0
- package/assets/pet/whale/feat/love_mouth.png +0 -0
- package/assets/pet/whale/feat/neutral_mouth.png +0 -0
- package/assets/pet/whale/feat/sleep_eyeL.png +0 -0
- package/assets/pet/whale/feat/sleep_eyeR.png +0 -0
- package/assets/pet/whale/feat/sleep_mouth.png +0 -0
- package/assets/pet/whale/feat/surprised_eyeL.png +0 -0
- package/assets/pet/whale/feat/surprised_eyeR.png +0 -0
- package/assets/pet/whale/feat/surprised_mouth.png +0 -0
- package/assets/pet/whale/figure.js +948 -0
- package/assets/pet/whale/figure.json +997 -0
- package/assets/pet/whale/model.json +1710 -0
- package/assets/pet/whale/outfits/cape/arm_far.png +0 -0
- package/assets/pet/whale/outfits/cape/arm_far_end_front.png +0 -0
- package/assets/pet/whale/outfits/cape/arm_near.png +0 -0
- package/assets/pet/whale/outfits/cape/cloak.png +0 -0
- package/assets/pet/whale/outfits/cape/cloak_shoulder_cover.png +0 -0
- package/assets/pet/whale/outfits/cape/hood_back.png +0 -0
- package/assets/pet/whale/outfits/cape/hood_fin_far.png +0 -0
- package/assets/pet/whale/outfits/cape/hood_fin_near.png +0 -0
- package/assets/pet/whale/outfits/cape/hood_front.png +0 -0
- package/assets/pet/whale/outfits/cape/hood_lining.png +0 -0
- package/assets/pet/whale/outfits/cape/hood_tie_far.png +0 -0
- package/assets/pet/whale/outfits/cape/hood_tie_near.png +0 -0
- package/assets/pet/whale/outfits/cape/leg_back.png +0 -0
- package/assets/pet/whale/outfits/cape/leg_front.png +0 -0
- package/assets/pet/whale/outfits/cape/scarf_neck.png +0 -0
- package/assets/pet/whale/outfits/cape/scarf_tail_back.png +0 -0
- package/assets/pet/whale/outfits/cape/scarf_tail_front.png +0 -0
- package/assets/pet/whale/outfits/cape/skirt.png +0 -0
- package/assets/pet/whale/outfits/cape/skirt_sit.png +0 -0
- package/assets/pet/whale/outfits/cape/spout.png +0 -0
- package/assets/pet/whale/outfits/crew/arm_far.png +0 -0
- package/assets/pet/whale/outfits/crew/arm_near.png +0 -0
- package/assets/pet/whale/outfits/crew/bow_near.png +0 -0
- package/assets/pet/whale/outfits/crew/headset.png +0 -0
- package/assets/pet/whale/outfits/crew/leg_back.png +0 -0
- package/assets/pet/whale/outfits/crew/leg_front.png +0 -0
- package/assets/pet/whale/outfits/crew/pony_bow.png +0 -0
- package/assets/pet/whale/outfits/crew/skirt_shadow.png +0 -0
- package/assets/pet/whale/outfits/crew/torso_up.png +0 -0
- package/assets/pet/whale/outfits/crew/visor.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/dizzy_eyeL.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/dizzy_eyeR.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/dizzy_mouth.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/drag_eyeL.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/drag_eyeR.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/drag_mouth.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/eyeL_ball.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/eyeL_iris.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/eyeL_lash.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/eyeR_ball.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/eyeR_iris.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/eyeR_lash.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/happy_eyeL.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/happy_eyeR.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/happy_mouth.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/love_eyeL.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/love_eyeR.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/love_mouth.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/neutral_mouth.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/sleep_eyeL.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/sleep_eyeR.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/sleep_mouth.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/surprised_eyeL.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/surprised_eyeR.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/feat/surprised_mouth.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/ahoge.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/arm_far.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/arm_far_end_front.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/arm_near.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/bangs.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/bow.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/brows.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/crew_hair_back.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/crew_ponytail.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/crew_sidelocks.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/crew_skirt.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/crew_skirt_sit.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/eye_creases.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/face.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/fin_far.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/fin_near.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/hair_back.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/hair_back_curl.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/hair_front_left.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/hair_front_right.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/headdress.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/leg_back.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/leg_front.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/sidelocks.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/skirt.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/skirt_sit.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/tail.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/torso_up.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/waist_bow_front.png +0 -0
- package/assets/pet/whale/schemes/chatgpt/tex/waist_bow_sit_front.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/dizzy_eyeL.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/dizzy_eyeR.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/dizzy_mouth.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/drag_eyeL.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/drag_eyeR.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/drag_mouth.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/eyeL_ball.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/eyeL_iris.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/eyeL_lash.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/eyeR_ball.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/eyeR_iris.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/eyeR_lash.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/happy_eyeL.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/happy_eyeR.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/happy_mouth.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/love_eyeL.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/love_eyeR.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/love_mouth.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/neutral_mouth.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/sleep_eyeL.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/sleep_eyeR.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/sleep_mouth.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/surprised_eyeL.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/surprised_eyeR.png +0 -0
- package/assets/pet/whale/schemes/claude/feat/surprised_mouth.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/ahoge.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/arm_far.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/arm_far_end_front.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/arm_near.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/bangs.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/bow.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/brows.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/crew_hair_back.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/crew_ponytail.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/crew_sidelocks.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/crew_skirt.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/crew_skirt_sit.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/eye_creases.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/face.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/fin_far.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/fin_near.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/hair_back.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/hair_back_curl.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/hair_front_left.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/hair_front_right.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/headdress.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/leg_back.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/leg_front.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/sidelocks.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/skirt.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/skirt_sit.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/tail.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/torso_up.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/waist_bow_front.png +0 -0
- package/assets/pet/whale/schemes/claude/tex/waist_bow_sit_front.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/dizzy_eyeL.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/dizzy_eyeR.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/dizzy_mouth.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/drag_eyeL.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/drag_eyeR.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/drag_mouth.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/eyeL_ball.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/eyeL_iris.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/eyeL_lash.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/eyeR_ball.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/eyeR_iris.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/eyeR_lash.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/happy_eyeL.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/happy_eyeR.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/happy_mouth.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/love_eyeL.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/love_eyeR.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/love_mouth.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/neutral_mouth.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/sleep_eyeL.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/sleep_eyeR.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/sleep_mouth.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/surprised_eyeL.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/surprised_eyeR.png +0 -0
- package/assets/pet/whale/schemes/gemini/feat/surprised_mouth.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/ahoge.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/arm_far.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/arm_far_end_front.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/arm_near.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/bangs.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/bow.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/brows.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/crew_hair_back.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/crew_ponytail.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/crew_sidelocks.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/crew_skirt.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/crew_skirt_sit.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/eye_creases.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/face.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/fin_far.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/fin_near.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/hair_back.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/hair_back_curl.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/hair_front_left.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/hair_front_right.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/headdress.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/leg_back.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/leg_front.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/sidelocks.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/skirt.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/skirt_sit.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/tail.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/torso_up.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/waist_bow_front.png +0 -0
- package/assets/pet/whale/schemes/gemini/tex/waist_bow_sit_front.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/dizzy_eyeL.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/dizzy_eyeR.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/dizzy_mouth.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/drag_eyeL.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/drag_eyeR.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/drag_mouth.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/eyeL_ball.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/eyeL_iris.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/eyeL_lash.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/eyeR_ball.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/eyeR_iris.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/eyeR_lash.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/happy_eyeL.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/happy_eyeR.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/happy_mouth.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/love_eyeL.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/love_eyeR.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/love_mouth.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/neutral_mouth.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/sleep_eyeL.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/sleep_eyeR.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/sleep_mouth.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/surprised_eyeL.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/surprised_eyeR.png +0 -0
- package/assets/pet/whale/schemes/harness/feat/surprised_mouth.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/ahoge.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/arm_far.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/arm_far_end_front.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/arm_near.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/bangs.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/bow.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/brows.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/crew_hair_back.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/crew_ponytail.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/crew_sidelocks.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/crew_skirt.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/crew_skirt_sit.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/eye_creases.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/face.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/fin_far.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/fin_near.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/hair_back.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/hair_back_curl.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/hair_front_left.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/hair_front_right.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/headdress.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/leg_back.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/leg_front.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/sidelocks.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/skirt.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/skirt_sit.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/tail.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/torso_up.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/waist_bow_front.png +0 -0
- package/assets/pet/whale/schemes/harness/tex/waist_bow_sit_front.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/dizzy_eyeL.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/dizzy_eyeR.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/dizzy_mouth.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/drag_eyeL.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/drag_eyeR.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/drag_mouth.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/eyeL_ball.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/eyeL_iris.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/eyeL_lash.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/eyeR_ball.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/eyeR_iris.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/eyeR_lash.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/happy_eyeL.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/happy_eyeR.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/happy_mouth.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/love_eyeL.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/love_eyeR.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/love_mouth.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/neutral_mouth.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/sleep_eyeL.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/sleep_eyeR.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/sleep_mouth.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/surprised_eyeL.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/surprised_eyeR.png +0 -0
- package/assets/pet/whale/schemes/kimi/feat/surprised_mouth.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/ahoge.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/arm_far.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/arm_far_end_front.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/arm_near.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/bangs.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/bow.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/brows.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/crew_hair_back.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/crew_ponytail.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/crew_sidelocks.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/crew_skirt.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/crew_skirt_sit.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/eye_creases.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/face.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/fin_far.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/fin_near.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/hair_back.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/hair_back_curl.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/hair_front_left.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/hair_front_right.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/headdress.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/leg_back.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/leg_front.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/sidelocks.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/skirt.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/skirt_sit.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/tail.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/torso_up.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/waist_bow_front.png +0 -0
- package/assets/pet/whale/schemes/kimi/tex/waist_bow_sit_front.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/dizzy_eyeL.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/dizzy_eyeR.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/dizzy_mouth.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/drag_eyeL.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/drag_eyeR.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/drag_mouth.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/eyeL_ball.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/eyeL_iris.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/eyeL_lash.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/eyeR_ball.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/eyeR_iris.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/eyeR_lash.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/happy_eyeL.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/happy_eyeR.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/happy_mouth.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/love_eyeL.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/love_eyeR.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/love_mouth.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/neutral_mouth.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/sleep_eyeL.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/sleep_eyeR.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/sleep_mouth.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/surprised_eyeL.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/surprised_eyeR.png +0 -0
- package/assets/pet/whale/schemes/minimax/feat/surprised_mouth.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/ahoge.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/arm_far.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/arm_far_end_front.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/arm_near.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/bangs.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/bow.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/brows.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/crew_hair_back.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/crew_ponytail.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/crew_sidelocks.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/crew_skirt.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/crew_skirt_sit.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/eye_creases.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/face.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/fin_far.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/fin_near.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/hair_back.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/hair_back_curl.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/hair_front_left.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/hair_front_right.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/headdress.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/leg_back.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/leg_front.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/sidelocks.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/skirt.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/skirt_sit.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/tail.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/torso_up.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/waist_bow_front.png +0 -0
- package/assets/pet/whale/schemes/minimax/tex/waist_bow_sit_front.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/dizzy_eyeL.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/dizzy_eyeR.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/dizzy_mouth.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/drag_eyeL.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/drag_eyeR.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/drag_mouth.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/eyeL_ball.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/eyeL_iris.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/eyeL_lash.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/eyeR_ball.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/eyeR_iris.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/eyeR_lash.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/happy_eyeL.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/happy_eyeR.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/happy_mouth.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/love_eyeL.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/love_eyeR.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/love_mouth.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/neutral_mouth.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/sleep_eyeL.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/sleep_eyeR.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/sleep_mouth.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/surprised_eyeL.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/surprised_eyeR.png +0 -0
- package/assets/pet/whale/schemes/qwen/feat/surprised_mouth.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/ahoge.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/arm_far.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/arm_far_end_front.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/arm_near.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/bangs.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/bow.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/brows.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/crew_hair_back.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/crew_ponytail.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/crew_sidelocks.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/crew_skirt.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/crew_skirt_sit.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/eye_creases.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/face.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/fin_far.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/fin_near.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/hair_back.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/hair_back_curl.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/hair_front_left.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/hair_front_right.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/headdress.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/leg_back.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/leg_front.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/sidelocks.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/skirt.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/skirt_sit.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/tail.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/torso_up.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/waist_bow_front.png +0 -0
- package/assets/pet/whale/schemes/qwen/tex/waist_bow_sit_front.png +0 -0
- package/assets/pet/whale/tex/ahoge.png +0 -0
- package/assets/pet/whale/tex/arm_far.png +0 -0
- package/assets/pet/whale/tex/arm_far_end_front.png +0 -0
- package/assets/pet/whale/tex/arm_near.png +0 -0
- package/assets/pet/whale/tex/bangs.png +0 -0
- package/assets/pet/whale/tex/bow.png +0 -0
- package/assets/pet/whale/tex/brows.png +0 -0
- package/assets/pet/whale/tex/crew_hair_back.png +0 -0
- package/assets/pet/whale/tex/crew_ponytail.png +0 -0
- package/assets/pet/whale/tex/crew_sidelocks.png +0 -0
- package/assets/pet/whale/tex/crew_skirt.png +0 -0
- package/assets/pet/whale/tex/crew_skirt_sit.png +0 -0
- package/assets/pet/whale/tex/eye_creases.png +0 -0
- package/assets/pet/whale/tex/face.png +0 -0
- package/assets/pet/whale/tex/fin_far.png +0 -0
- package/assets/pet/whale/tex/fin_near.png +0 -0
- package/assets/pet/whale/tex/hair_back.png +0 -0
- package/assets/pet/whale/tex/hair_back_curl.png +0 -0
- package/assets/pet/whale/tex/hair_front_left.png +0 -0
- package/assets/pet/whale/tex/hair_front_right.png +0 -0
- package/assets/pet/whale/tex/headdress.png +0 -0
- package/assets/pet/whale/tex/leg_back.png +0 -0
- package/assets/pet/whale/tex/leg_front.png +0 -0
- package/assets/pet/whale/tex/sidelocks.png +0 -0
- package/assets/pet/whale/tex/skirt.png +0 -0
- package/assets/pet/whale/tex/skirt_shadow.png +0 -0
- package/assets/pet/whale/tex/skirt_sit.png +0 -0
- package/assets/pet/whale/tex/tail.png +0 -0
- package/assets/pet/whale/tex/torso_up.png +0 -0
- package/assets/pet/whale/tex/waist_bow_front.png +0 -0
- package/assets/pet/whale/tex/waist_bow_sit_front.png +0 -0
- package/assets/pet/whale/thumbs/cape.png +0 -0
- package/assets/pet/whale/thumbs/chatgpt.png +0 -0
- package/assets/pet/whale/thumbs/claude.png +0 -0
- package/assets/pet/whale/thumbs/crew.png +0 -0
- package/assets/pet/whale/thumbs/deepseek.png +0 -0
- package/assets/pet/whale/thumbs/gemini.png +0 -0
- package/assets/pet/whale/thumbs/harness.png +0 -0
- package/assets/pet/whale/thumbs/kimi.png +0 -0
- package/assets/pet/whale/thumbs/maid.png +0 -0
- package/assets/pet/whale/thumbs/minimax.png +0 -0
- package/assets/pet/whale/thumbs/qwen.png +0 -0
- package/assets/restart-dsh.cmd +16 -0
- package/assets/restart-dsh.log +195 -0
- package/client.js +1169 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +8 -0
- package/index.js +1273 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +50 -4
|
@@ -0,0 +1,1053 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pet kit: a body that stands on the floor of the stage (or anywhere on it, `ground: 'free'`), walks, runs, jumps, sits, sleeps,
|
|
3
|
+
* is picked up and thrown, makes faces and short gestures, with particles (hearts, tears, z's,
|
|
4
|
+
* dust, notes) and a shadow. A figure pack builds its body on it (`createBody`) and only draws:
|
|
5
|
+
* Coo (web/coo/figure.js) and the whale (web/whale/figure.js) both do. A pack may also ignore the
|
|
6
|
+
* kit and answer the body contract (web/figure-frame.js) on its own.
|
|
7
|
+
*
|
|
8
|
+
* Coordinates: the figure is drawn in logo units, facing right, ground at y=256, inside a 256 square.
|
|
9
|
+
* The stage places it with translate(AX AY) rotate(rot) scale(kx ky) translate(-ax -ay); `toStage`
|
|
10
|
+
* maps a logo point back to stage pixels for hit tests, particles and the bubble's spot.
|
|
11
|
+
*
|
|
12
|
+
* Nothing here plays sound or talks to the World: sounds are asked for through `opts.sfx` and what
|
|
13
|
+
* happens to the body is told through `opts.onEvent`; the page around the frame does the rest.
|
|
14
|
+
*/
|
|
15
|
+
export { createRig } from './rig.js';
|
|
16
|
+
|
|
17
|
+
export const f = n => Math.round(n * 10) / 10;
|
|
18
|
+
export const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
|
|
19
|
+
const lerp = (a, b, k) => a + (b - a) * k;
|
|
20
|
+
const rnd = (a, b) => a + Math.random() * (b - a);
|
|
21
|
+
const ease = (rate, dt) => 1 - Math.exp(-rate * dt);
|
|
22
|
+
const smooth = k => k * k * (3 - 2 * k);
|
|
23
|
+
/** 0 → 1 over [0, a] of k, holds, then back to 0 over [b, 1]: the shape of a gesture held for a moment. */
|
|
24
|
+
export const envelope = (k, a, b) => smooth(clamp(k / a, 0, 1)) * (1 - smooth(clamp((k - b) / (1 - b), 0, 1)));
|
|
25
|
+
|
|
26
|
+
/* ---------- legs and particles ---------- */
|
|
27
|
+
export const HIPS = [[104, 212], [150, 212]];
|
|
28
|
+
export const LEG_W = 30;
|
|
29
|
+
// a foot's round cap touches the ground
|
|
30
|
+
const FOOT_Y = 256 - LEG_W / 2;
|
|
31
|
+
export const STAND = HIPS.map(h => [h[0], h[1], h[0], FOOT_Y]);
|
|
32
|
+
export const DROP = 'M0 -9C4 -3 6 0 6 3.5A6 6 0 0 1 -6 3.5C-6 0 -4 -3 0 -9Z';
|
|
33
|
+
export function heartD(cx, cy, s) {
|
|
34
|
+
const p = (x, y) => `${f(cx + x * s)} ${f(cy + y * s)}`;
|
|
35
|
+
return `M${p(0, 14)}C${p(-7, 8)} ${p(-19, 1)} ${p(-19, -6)}C${p(-19, -15)} ${p(-8, -18)} ${p(0, -9)}C${p(8, -18)} ${p(19, -15)} ${p(19, -6)}C${p(19, 1)} ${p(7, 8)} ${p(0, 14)}Z`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* ---------- faces ----------
|
|
39
|
+
What a face asks of the body and the figure: eye shapes and sizes, mouth gap, blush, marks over
|
|
40
|
+
the head, particles. Coo draws these as they are; a figure with its own art reads what it can. */
|
|
41
|
+
const ring = o => ({ shape: 'ring', rx: 16, ry: 16, ...o });
|
|
42
|
+
const yawn = t => { const p = (t % 4.2) / 1.6; return p < 1 ? Math.sin(Math.PI * p) ** 2 : 0; };
|
|
43
|
+
|
|
44
|
+
export const FACES = {
|
|
45
|
+
neutral: { label: '平静', kao: '(0 0', f: () => ({ gap: [50, 50], eyes: [ring(), ring()] }) },
|
|
46
|
+
happy: { label: '开心', kao: '(^ ^', f: () => ({ gap: [58, 58], eyes: [{ shape: 'up' }, { shape: 'up' }], blush: .45 }) },
|
|
47
|
+
wink: { label: '眨眼', kao: '(0 ^', f: () => ({ gap: [56, 52], eyes: [ring(), { shape: 'up' }] }) },
|
|
48
|
+
love: { label: '喜欢', kao: '(♡ ♡', f: t => { const s = .8 + .08 * Math.sin(t * 9); return { gap: [56, 56], eyes: [{ shape: 'heart', s, sw: 8 }, { shape: 'heart', s, sw: 8 }], blush: .7, emit: 'heart' }; } },
|
|
49
|
+
shy: { label: '害羞', kao: '(o o *', f: () => ({ gap: [40, 40], eyes: [ring({ rx: 13, ry: 12, dx: -3, dy: 5 }), ring({ rx: 13, ry: 12, dx: -3, dy: 5 })], blush: 1, lookLock: true }) },
|
|
50
|
+
surprised: { label: '惊讶', kao: '(O O', f: () => ({ gap: [62, 62], eyes: [ring({ rx: 20, ry: 21 }), ring({ rx: 20, ry: 21 })], bang: true }) },
|
|
51
|
+
angry: { label: '生气', kao: '(ò ó', f: () => ({ gap: [36, 36], eyes: [ring({ ry: 11, dy: 4 }), ring({ ry: 11, dy: 4 })], brows: 'angry', anger: true, shake: true }) },
|
|
52
|
+
sad: { label: '难过', kao: '(ó ò', f: () => ({ gap: [34, 40], eyes: [ring({ ry: 14, dy: 4 }), ring({ ry: 14, dy: 4 })], brows: 'sad', emit: 'tear' }) },
|
|
53
|
+
// a yawn narrows the eyes without squeezing them to a slit
|
|
54
|
+
sleepy: { label: '犯困', kao: '(- -', f: t => { const y = yawn(t); return { gap: [50 + 14 * y, 50 + 14 * y], eyes: [{ shape: 'lid', ry: 10 - 5 * y }, { shape: 'lid', ry: 10 - 5 * y }] }; } },
|
|
55
|
+
sleep: { label: '睡着', kao: '(u u', f: t => { const b = 40 + 6 * Math.sin(t * 1.7); return { gap: [b, b], eyes: [{ shape: 'down' }, { shape: 'down' }], emit: 'z' }; } },
|
|
56
|
+
dizzy: { label: '晕乎', kao: '(@ @', f: t => ({ gap: [54 + 5 * Math.sin(t * 5), 48], eyes: [{ shape: 'spiral', rot: t * 7 }, { shape: 'spiral', rot: t * 7 + 1.4 }], orbit: true }) },
|
|
57
|
+
dragged: { label: '被拎起', kao: '(> <', f: t => { const g = 55 + 3 * Math.sin(t * 22); return { gap: [g, g], eyes: [{ shape: 'gt' }, { shape: 'lt' }], sweat: true }; } },
|
|
58
|
+
// seated eyes rest open; once drowse passes .7 they are the closed sleep sprite (the shape swap hides under a blink)
|
|
59
|
+
content: { label: '惬意', f: (t, p) => { const d = p ? p.drowse : 0; const e = d > .7 ? { shape: 'down' } : { shape: 'lid', ry: 13.5 - 10 * d }; return { gap: [46, 46], eyes: [e, { ...e }] }; } },
|
|
60
|
+
waking: { label: '醒来', f: (t, p) => {
|
|
61
|
+
const mt = p ? p.modeT : 1;
|
|
62
|
+
const k = clamp(mt / .5, 0, 1), y = mt > .5 ? Math.sin(clamp((mt - .5) / .9, 0, 1) * Math.PI) : 0;
|
|
63
|
+
const r = Math.max(0, 10 * k * (1 - .7 * y));
|
|
64
|
+
return { gap: [50 + 12 * y, 50 + 12 * y], eyes: [{ shape: 'lid', ry: r }, { shape: 'lid', ry: r }] };
|
|
65
|
+
} },
|
|
66
|
+
squeeze: { label: '回神', f: () => ({ gap: [44, 44], eyes: [{ shape: 'lid', ry: 0 }, { shape: 'lid', ry: 0 }] }) },
|
|
67
|
+
listening: { label: '倾听', f: () => ({ gap: [44, 44], eyes: [ring({ rx: 17, ry: 18, dy: -1 }), ring({ rx: 17, ry: 18, dy: -1 })], listen: true }) },
|
|
68
|
+
thinking: { label: '思考', f: t => ({ gap: [46, 46], eyes: [ring({ rx: 14, ry: 15, dx: 3, dy: -4 }), ring({ rx: 14, ry: 15, dx: 3, dy: -4 })], think: true }) },
|
|
69
|
+
run: { label: '冲刺', f: t => { const g = 55 + 4 * Math.sin(t * 16); return { gap: [g, g], eyes: [ring(), ring()], sweat: true }; } },
|
|
70
|
+
smug: { label: '得意', kao: '(¬ ¬', f: () => ({ gap: [52, 46], eyes: [{ shape: 'lid', ry: 8, dx: 4 }, { shape: 'lid', ry: 8, dx: 4 }], blush: .25 }) },
|
|
71
|
+
// `lookAt` holds the gaze (and with it a figure's head) on a point, here away from whoever is there
|
|
72
|
+
pout: { label: '嘟嘴', kao: '(o o 3', f: () => ({ gap: [28, 28], eyes: [ring({ rx: 14, ry: 13 }), ring({ rx: 14, ry: 13 })], blush: .6, lookAt: [-5, -1] }) },
|
|
73
|
+
worried: { label: '担心', kao: '(ó ò ;', f: () => ({ gap: [40, 44], eyes: [ring({ ry: 17, dy: 2 }), ring({ ry: 17, dy: 2 })], brows: 'sad', sweat: true }) },
|
|
74
|
+
determined: { label: '认真', kao: '(ò ó', f: () => ({ gap: [42, 42], eyes: [ring({ ry: 13, dy: 1 }), ring({ ry: 13, dy: 1 })], brows: 'angry' }) },
|
|
75
|
+
flustered: { label: '慌张', kao: '(> <;', f: t => ({ gap: [50 + 3 * Math.sin(t * 22), 48], eyes: [{ shape: 'gt' }, { shape: 'lt' }], blush: 1, sweat: true }) },
|
|
76
|
+
// `wide`: eyes wider than open (a figure with drawn eyes may use its surprised ones)
|
|
77
|
+
scared: { label: '害怕', kao: '(O O;', f: () => ({ gap: [38, 38], eyes: [ring({ rx: 18, ry: 19 }), ring({ rx: 18, ry: 19 })], brows: 'sad', wide: true, shake: true, sweat: true }) },
|
|
78
|
+
excited: { label: '期待', kao: '(☆ ☆', f: () => ({ gap: [60, 60], eyes: [ring({ rx: 18, ry: 19, dy: -1 }), ring({ rx: 18, ry: 19, dy: -1 })], sparkle: true, blush: .4 }) },
|
|
79
|
+
cry: { label: '大哭', kao: '(T T', f: t => { const g = 36 + 6 * Math.abs(Math.sin(t * 9)); return { gap: [g, g], eyes: [{ shape: 'lid', ry: 0 }, { shape: 'lid', ry: 0 }], brows: 'sad', emit: 'tears', streams: true }; } },
|
|
80
|
+
// a motion's own face (not one to ask for): eyes shut through a bow
|
|
81
|
+
bowing: { label: '鞠躬', f: () => ({ gap: [48, 48], eyes: [{ shape: 'lid', ry: 0 }, { shape: 'lid', ry: 0 }] }) },
|
|
82
|
+
confused: { label: '疑惑', kao: '(0 o ?', f: () => ({ gap: [44, 40], eyes: [ring(), ring({ rx: 14, ry: 11 })], question: true }) },
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/** The faces a word can ask for, and the motions the kit does by name. */
|
|
86
|
+
export const KIT_EXPRESSIONS = ['neutral', 'happy', 'wink', 'love', 'shy', 'surprised', 'angry', 'sad', 'sleepy', 'thinking',
|
|
87
|
+
'smug', 'pout', 'worried', 'determined', 'flustered', 'scared', 'excited', 'cry', 'confused'];
|
|
88
|
+
export const KIT_MOTIONS = ['stand', 'jump', 'hop', 'look', 'turn', 'nod', 'shake', 'spin', 'sit', 'sleep', 'dizzy', 'walk', 'run',
|
|
89
|
+
'wave', 'bow', 'shiver', 'flap', 'dance'];
|
|
90
|
+
/** The tone each face plays as it comes on (the host's synthesized sounds, web/sound.js), filed as a face sound. */
|
|
91
|
+
const FACE_TONES = {
|
|
92
|
+
happy: 'happy', wink: 'wink', love: 'love', surprised: 'surprised', angry: 'angry', sad: 'sad', shy: 'shy', sleepy: 'yawn',
|
|
93
|
+
smug: 'wink', worried: 'hmm', determined: 'pop', flustered: 'shy', scared: 'surprised', excited: 'sparkle', cry: 'sad', confused: 'hmm',
|
|
94
|
+
};
|
|
95
|
+
/** Body modes in which the figure travels across the stage or squashes fast (dancing steps and sways on the spot). */
|
|
96
|
+
const MOVING_MODES = new Set(['drag', 'air', 'crouch', 'land', 'walk', 'run', 'dance']);
|
|
97
|
+
/** Points on the body in logo units, for a figure that names none: where the eyes look from, where a tear starts,
|
|
98
|
+
* where z's and hearts start ([x from, x to, y]), the bubble's spot. `tears` (one start under each eye) has no default. */
|
|
99
|
+
const ANCHORS = { gaze: [140, 117], tear: [166, 136], z: [196, 40], hearts: [90, 175, 34], bubble: [128, 0] };
|
|
100
|
+
/** The body's box in logo units, for a figure that names none (`figure.extent`), and its hit circles (`figure.hits`). */
|
|
101
|
+
const EXTENT = [20, 12, 236, 256];
|
|
102
|
+
const HITS = [[128, 128, 108]];
|
|
103
|
+
|
|
104
|
+
/* ---------- the live pet: simulation, rendering, pointer ---------- */
|
|
105
|
+
/**
|
|
106
|
+
* `els`: { petG, shadowEl, fxG }, SVG elements the body draws into (the shadow is an ellipse).
|
|
107
|
+
* `opts.bounds()` returns { W, H, floorY, S } in stage pixels.
|
|
108
|
+
* `opts.onEvent(kind, detail)` reports what happened to the body: arrived, interrupted, touch, mode, done.
|
|
109
|
+
* `opts.sfx.play(name, kind, ...args)` asks for a sound (web/sound.js names them); an `sfx` without `play`
|
|
110
|
+
* is called by name instead (`sfx.jump()`), for pages that record the calls.
|
|
111
|
+
* `opts.enter: 'drop'` starts the pet above the top edge, falling to the floor.
|
|
112
|
+
* `opts.ground: 'free'` lets the body stand anywhere on the stage above the floor, as seen from above: it walks
|
|
113
|
+
* to any point (`walkTo` with a y), is set down where it is let go of, a throw tosses it across the stage, and
|
|
114
|
+
* free roaming wanders both ways. Its own ground line (where its feet are) then starts at `opts.startY`, else the floor.
|
|
115
|
+
* `opts.words` are the pack's own words, beyond the kit's (KIT_EXPRESSIONS, KIT_MOTIONS):
|
|
116
|
+
* `{ id: { expression: { like, seconds?, sound? } } }` holds a face that takes its eyes and marks from the kit's
|
|
117
|
+
* face `like` (the figure gets the word as `frame.face` and may draw it its own way);
|
|
118
|
+
* `{ id: { motion: { seconds, face?, sound? } } }` is a gesture the figure draws from `frame.gesture`.
|
|
119
|
+
* `opts.figure` draws the body: `figure.draw(petG, face, frame)` keeps its own elements inside `petG` (logo space,
|
|
120
|
+
* feet at y=256), once for every frame drawn, rest included, so it should write only what changed. Its frame adds
|
|
121
|
+
* the face's name, the mode, how long the mode has run, the talk level, drowsiness, how far the body sits, and
|
|
122
|
+
* `status`: the kind of work the page's status bubble shows (src/status.ts), or null.
|
|
123
|
+
* `figure.groupTilt(mode, tilt, lean)`, if present, returns the rotation (degrees) the whole group gets
|
|
124
|
+
* instead of tilt + lean; the frame carries tilt, lean and that rotation (groupRot) so the figure can bend the rest.
|
|
125
|
+
* `figure.colors.z`, if present, colours the sleep z's (otherwise they take the `eye` class).
|
|
126
|
+
* `figure.gestures`, if present, names the short gestures (nod, shake) the figure draws itself: the body then
|
|
127
|
+
* leaves them out, and the frame's `gesture` ({ kind, k: 0..1 }, or null) says which one is playing and how far.
|
|
128
|
+
* `figure.anchors`, `figure.extent` ([x0, y0, x1, y1]) and `figure.hits` ([[x, y, r]]) are in logo units; each
|
|
129
|
+
* is read every frame, so a getter may follow the skin. `figure.setSkin(skin)` hears each skin change.
|
|
130
|
+
*/
|
|
131
|
+
export function createPet(els, opts) {
|
|
132
|
+
const { petG, shadowEl, fxG } = els;
|
|
133
|
+
let custom = opts.figure;
|
|
134
|
+
const sfx = opts.sfx;
|
|
135
|
+
const play = (name, kind, ...args) => (sfx.play ? sfx.play(name, kind, ...args) : sfx[name]?.(...args));
|
|
136
|
+
const onEvent = opts.onEvent || (() => {});
|
|
137
|
+
const words = opts.words || {};
|
|
138
|
+
let W = 0, H = 0, floorY = 0, S = .42, T = 0;
|
|
139
|
+
let roam = opts.roam ?? 'free';
|
|
140
|
+
let skin = opts.skin || null;
|
|
141
|
+
let hold = 0; // until T: an order from outside is in progress, free roaming waits
|
|
142
|
+
const freeGround = opts.ground === 'free';
|
|
143
|
+
const pet = {
|
|
144
|
+
x: 260, fy: 0, gy: 0, gvy: 0, targetY: 0, vx: 0, vy: 0, facing: 1, faceVis: 1, mode: 'idle', modeT: 0, dur: 0, target: 0,
|
|
145
|
+
speed: 0, stride: 0, lift: 0, bob: 0, phase: 0, lastHalf: 0, lean: 0, tilt: 0, tiltV: 0,
|
|
146
|
+
sq: 0, sqv: 0, sitK: 0, stretch: 0, low: 0, gap: [50, 50], look: [0, 0], drowse: 0,
|
|
147
|
+
feet: STAND.map(l => [l[2], l[3]]), blinkT: 1.5, blinkAge: 9, expr: null, exprUntil: 0,
|
|
148
|
+
nextAt: 1.2, emitAt: 0, airKind: 'jump', turned: false, startle: false, lastAct: '',
|
|
149
|
+
turnAcc: 0, dx: 0, dy: 0, jumpV: 700, jumpVx: 0, xf: null, blushK: 0,
|
|
150
|
+
eyeSig: '', eyeCur: null, eyePrev: null, eyeDims: [[16, 16, 0, 0], [16, 16, 0, 0]], swapAge: 9,
|
|
151
|
+
glance: [0, 0], glanceAt: 0, swing: 0, swingV: 0, prevA: null, velX: 0, talkK: 0, sfxAt: 0, skid: false, cue: 0,
|
|
152
|
+
pulse: null, walkId: 0, walkWord: null, listening: false, thinking: false, thoughtShown: false, placed: false, noteAt: 0, tearN: 0,
|
|
153
|
+
cursor: '', status: null,
|
|
154
|
+
};
|
|
155
|
+
const pointer = { x: -1e4, y: -1e4, inside: false, vx: 0, samples: [] };
|
|
156
|
+
let press = null, strokeAcc = 0, petCool = 0, stillSince = 0;
|
|
157
|
+
/** Whether the last frame found the horizontal speed not finite: a run of such frames is logged once. */
|
|
158
|
+
let velXBad = false;
|
|
159
|
+
const P = [];
|
|
160
|
+
const anchors = () => ({ ...ANCHORS, ...custom?.anchors });
|
|
161
|
+
let A = anchors();
|
|
162
|
+
const minX = () => 104 * S + 8, maxX = () => W - 104 * S - 8;
|
|
163
|
+
/** The highest ground line a free body stands on: its head stays on the stage. */
|
|
164
|
+
const minY = () => Math.min(floorY, 250 * S + 8);
|
|
165
|
+
/** Where the feet rest: the floor, or a free body's own ground line. */
|
|
166
|
+
const groundY = () => (freeGround ? pet.gy : floorY);
|
|
167
|
+
/** Detail for a walk's events: a free body says how far down it stands. */
|
|
168
|
+
const at = () => ({ x: Math.round(pet.x), ...(freeGround ? { y: Math.round(pet.gy) } : {}) });
|
|
169
|
+
const faceDef = n => FACES[n] ?? FACES[words[n]?.expression?.like] ?? FACES.neutral;
|
|
170
|
+
|
|
171
|
+
function resize() {
|
|
172
|
+
const b = opts.bounds();
|
|
173
|
+
W = b.W; H = b.H; floorY = b.floorY; S = b.S;
|
|
174
|
+
if (!pet.placed && W > 0) {
|
|
175
|
+
pet.x = opts.startX != null ? opts.startX : W * .7; pet.placed = true;
|
|
176
|
+
pet.gy = freeGround && opts.startY != null ? opts.startY : floorY;
|
|
177
|
+
if (opts.enter === 'drop') { pet.fy = -8; pet.vy = 0; pet.vx = 0; pet.airKind = 'drop'; setMode('air'); }
|
|
178
|
+
}
|
|
179
|
+
pet.x = clamp(pet.x, minX(), maxX());
|
|
180
|
+
pet.target = clamp(pet.target, minX(), maxX());
|
|
181
|
+
pet.gy = freeGround ? clamp(pet.gy, minY(), floorY) : floorY;
|
|
182
|
+
pet.targetY = freeGround ? clamp(pet.targetY, minY(), floorY) : floorY;
|
|
183
|
+
if (pet.mode !== 'air' && pet.mode !== 'drag') pet.fy = pet.gy;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function toStage(lx, ly) {
|
|
187
|
+
const c = pet.xf;
|
|
188
|
+
if (!c) return { x: pet.x, y: groundY() };
|
|
189
|
+
const x = (lx - c.ax) * c.kx, y = (ly - c.ay) * c.ky, r = c.rot * Math.PI / 180;
|
|
190
|
+
return { x: c.AX + x * Math.cos(r) - y * Math.sin(r), y: c.AY + x * Math.sin(r) + y * Math.cos(r) };
|
|
191
|
+
}
|
|
192
|
+
/** The hit circles in stage pixels. */
|
|
193
|
+
function hits() {
|
|
194
|
+
return (custom?.hits ?? HITS).map(([x, y, r]) => ({ ...toStage(x, y), r: r * S }));
|
|
195
|
+
}
|
|
196
|
+
function hitPet(p) {
|
|
197
|
+
return hits().some((c) => Math.hypot(p.x - c.x, p.y - c.y) < c.r);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function setMode(m, o = {}) {
|
|
201
|
+
const prev = pet.mode;
|
|
202
|
+
// an arrival clears walkId before going idle, so anything else that ends a walk (a turn, a bow, listening) cuts it short
|
|
203
|
+
if ((prev === 'walk' || prev === 'run') && pet.walkId) {
|
|
204
|
+
onEvent('interrupted', { walkId: pet.walkId, ...at(), by: m });
|
|
205
|
+
pet.walkId = 0;
|
|
206
|
+
}
|
|
207
|
+
// a walk or run asked for as a word is done once the body stops going, whatever stopped it
|
|
208
|
+
if ((prev === 'walk' || prev === 'run') && pet.walkWord && m !== prev) { onEvent('done', { word: pet.walkWord }); pet.walkWord = null; }
|
|
209
|
+
pet.mode = m; pet.modeT = 0; pet.turned = false; pet.startle = false; pet.skid = false; pet.cue = 0;
|
|
210
|
+
Object.assign(pet, o);
|
|
211
|
+
if (prev !== m) onEvent('mode', { mode: m });
|
|
212
|
+
}
|
|
213
|
+
const busy = () => pet.mode === 'drag' || pet.mode === 'air' || pet.mode === 'crouch';
|
|
214
|
+
function pickTarget(minDist) {
|
|
215
|
+
for (let i = 0; i < 12; i++) {
|
|
216
|
+
const x = rnd(minX(), maxX());
|
|
217
|
+
if (Math.abs(x - pet.x) > minDist) return x;
|
|
218
|
+
}
|
|
219
|
+
return pet.x - minX() > maxX() - pet.x ? minX() : maxX();
|
|
220
|
+
}
|
|
221
|
+
/** A ground line to walk to: anywhere for a free body, else where it stands. */
|
|
222
|
+
const pickY = () => (freeGround ? rnd(minY(), floorY) : pet.gy);
|
|
223
|
+
|
|
224
|
+
/** Runs a motion. Returns false when the body cannot take it now (in the air, being dragged). */
|
|
225
|
+
function act(a) {
|
|
226
|
+
if (busy()) return false;
|
|
227
|
+
pet.expr = null; pet.lastAct = a;
|
|
228
|
+
const seated = pet.mode === 'sleep' || pet.mode === 'sit';
|
|
229
|
+
switch (a) {
|
|
230
|
+
case 'stand': setMode(seated ? 'wake' : 'idle', seated ? { startle: false } : {}); pet.nextAt = T + 3; break;
|
|
231
|
+
case 'walk': setMode('walk', { target: pickTarget(160), targetY: pickY() }); break;
|
|
232
|
+
case 'run': setMode('run', { target: pet.x < W / 2 ? maxX() - rnd(0, 30) : minX() + rnd(0, 30), targetY: pickY() }); break;
|
|
233
|
+
case 'jump': setMode('crouch', { jumpV: 720, jumpVx: pet.facing * 40 }); break;
|
|
234
|
+
case 'hop': setMode('crouch', { jumpV: 480, jumpVx: 0 }); break;
|
|
235
|
+
case 'look': setMode('look'); break;
|
|
236
|
+
case 'turn': if (!seated) setMode('idle'); pet.facing *= -1; play('tick', 'move'); break;
|
|
237
|
+
case 'nod': pulse('nod', .7); play('nod', 'move'); break;
|
|
238
|
+
case 'shake': pulse('shake', .7); play('shake', 'move'); break;
|
|
239
|
+
case 'spin': if (!seated) setMode('idle'); pulse('spin', .6); play('spin', 'move'); break;
|
|
240
|
+
case 'sit': setMode('sit', { dur: 1e9, willSleep: false }); break;
|
|
241
|
+
case 'sleep': setMode('sleep', { dur: 1e9 }); break;
|
|
242
|
+
case 'dizzy': setMode('dizzy'); break;
|
|
243
|
+
case 'wave': pulse('wave', 1.6); holdFace('happy', 1.8); break;
|
|
244
|
+
case 'bow': if (!seated) setMode('idle'); pulse('bow', 1.6); holdFace('bowing', 1.5); play('tick', 'move'); break;
|
|
245
|
+
case 'shiver': pulse('shiver', 1.8); play('shiver', 'move'); break;
|
|
246
|
+
case 'flap': setMode('crouch', { jumpV: 540, jumpVx: 0 }); pulse('flap', 1.4); holdFace('happy', 1.6); play('chirps', 'move'); break;
|
|
247
|
+
case 'dance': setMode('dance', { dur: 3.2 }); holdFace('happy', 3.4); play('dance', 'move'); break;
|
|
248
|
+
default: {
|
|
249
|
+
// a gesture of the pack's own, drawn by its figure from frame.gesture
|
|
250
|
+
const m = words[a]?.motion;
|
|
251
|
+
if (!m) return false;
|
|
252
|
+
if (!seated) setMode('idle');
|
|
253
|
+
pulse(a, m.seconds);
|
|
254
|
+
if (m.face) holdFace(m.face, m.seconds);
|
|
255
|
+
if (m.sound) play(m.sound, 'move');
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
function pulse(kind, dur) { pet.pulse = { kind, t0: T, dur }; }
|
|
261
|
+
/** A motion's own face, without the expression's sound and bounce (act() has just cleared any held face). */
|
|
262
|
+
function holdFace(n, seconds) { pet.expr = n; pet.exprUntil = T + seconds; pet.nextAt = Math.max(pet.nextAt, pet.exprUntil + .6); }
|
|
263
|
+
|
|
264
|
+
function setExpr(n, seconds) {
|
|
265
|
+
if (n === 'sleep') { act('sleep'); return; }
|
|
266
|
+
if (busy()) return;
|
|
267
|
+
if (n === 'dragged') {
|
|
268
|
+
pet.expr = null;
|
|
269
|
+
pet.vy = -1150; pet.vx = rnd(-120, 120); pet.airKind = 'throw'; pet.sqv -= 3;
|
|
270
|
+
play('whoosh', 'move'); play('jump', 'move');
|
|
271
|
+
setMode('air'); return;
|
|
272
|
+
}
|
|
273
|
+
if (n === 'dizzy') { pet.expr = null; setMode('dizzy'); return; }
|
|
274
|
+
if (pet.mode === 'look' || pet.mode === 'land') setMode('idle');
|
|
275
|
+
const own = words[n]?.expression;
|
|
276
|
+
pet.expr = n; pet.exprUntil = T + (seconds ?? own?.seconds ?? (n === 'sleepy' ? 4.4 : 3.2));
|
|
277
|
+
pet.nextAt = Math.max(pet.nextAt, pet.exprUntil + .6);
|
|
278
|
+
pet.sqv += n === 'surprised' ? -2.2 : .8;
|
|
279
|
+
const tone = own?.sound ?? FACE_TONES[n];
|
|
280
|
+
if (tone) play(tone, 'face');
|
|
281
|
+
if (n === 'love') for (let i = 0; i < 4; i++) emitHeart();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Does a word of the body's vocabulary: one of the kit's faces or motions, or one of the pack's own
|
|
286
|
+
* (`opts.words`). A walk or run goes to the other side of the stage and reports `done` once it stops.
|
|
287
|
+
* Returns false for a word it does not know or cannot take now.
|
|
288
|
+
*/
|
|
289
|
+
function doWord(w) {
|
|
290
|
+
if (w === 'neutral') { setExpr('neutral', .1); return true; }
|
|
291
|
+
if (w === 'walk' || w === 'run') {
|
|
292
|
+
const x = pet.x < W / 2 ? W * (.55 + Math.random() * .35) : W * (.1 + Math.random() * .35);
|
|
293
|
+
if (!walkTo(x, w === 'run', 0, pickY())) return false;
|
|
294
|
+
if (pet.mode === w) pet.walkWord = w;
|
|
295
|
+
else onEvent('done', { word: w });
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
if (KIT_MOTIONS.includes(w) || words[w]?.motion) return act(w);
|
|
299
|
+
if (KIT_EXPRESSIONS.includes(w) || words[w]?.expression) {
|
|
300
|
+
if (busy()) return false;
|
|
301
|
+
setExpr(w);
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Walks (or runs) to stage x, and for a free body to ground line y (where it stands now when left out).
|
|
309
|
+
* Resolves the walk through onEvent('arrived' | 'interrupted').
|
|
310
|
+
*/
|
|
311
|
+
function walkTo(x, run, walkId, y) {
|
|
312
|
+
if (busy()) return false;
|
|
313
|
+
if (pet.mode === 'sleep' || pet.mode === 'sit') setMode('wake', { startle: true });
|
|
314
|
+
const target = clamp(x, minX(), maxX());
|
|
315
|
+
const targetY = freeGround && typeof y === 'number' && Number.isFinite(y) ? clamp(y, minY(), floorY) : pet.gy;
|
|
316
|
+
pet.expr = null;
|
|
317
|
+
if (Math.hypot(target - pet.x, targetY - pet.gy) < 2) { onEvent('arrived', { walkId, ...at() }); return true; }
|
|
318
|
+
setMode(run ? 'run' : 'walk', { target, targetY, walkId });
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** Stops the walk `walkId` where the pet stands; it reports the walk 'interrupted'. A finished walk is left alone.
|
|
323
|
+
* 不带 id 调用 = 停掉当前任何在走的路(菜单/输入框/开麦打断用),别让带 id 的精确停走失灵。 */
|
|
324
|
+
function stopWalk(walkId) {
|
|
325
|
+
if (pet.mode !== 'walk' && pet.mode !== 'run') return;
|
|
326
|
+
if (walkId === undefined || pet.walkId === walkId) setMode('idle');
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function faceName() {
|
|
330
|
+
const m = pet.mode;
|
|
331
|
+
if (m === 'drag') return 'dragged';
|
|
332
|
+
if (m === 'air' && pet.airKind === 'throw') return pet.vy < 0 ? 'dragged' : 'surprised';
|
|
333
|
+
if (m === 'air' && pet.airKind === 'drop') return 'surprised';
|
|
334
|
+
if (m === 'dizzy') return pet.modeT < 2.4 ? 'dizzy' : 'squeeze';
|
|
335
|
+
if (m === 'wake') return pet.startle ? 'surprised' : 'waking';
|
|
336
|
+
if (pet.listening && m !== 'sleep') return 'listening';
|
|
337
|
+
if (m === 'sleep') return 'sleep';
|
|
338
|
+
if (pet.expr && T < pet.exprUntil) return pet.expr;
|
|
339
|
+
if (pet.thinking) return 'thinking';
|
|
340
|
+
if (m === 'sit') return 'content';
|
|
341
|
+
if (m === 'run') return 'run';
|
|
342
|
+
return 'neutral';
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function decide() {
|
|
346
|
+
const calm = roam === 'calm';
|
|
347
|
+
const still = roam === 'off';
|
|
348
|
+
// 原地模式(roam 'off'):不挑走路/跑步,只做原地小动作(张望/原地跳/坐/睡/表情)
|
|
349
|
+
const opts2 = [['walk', still ? 0 : calm ? 10 : 28], ['run', still || calm ? 0 : 12], ['look', 14], ['jump', still ? 0 : calm ? 2 : 8], ['hop', still ? 6 : 0], ['sit', 16], ['expr', 12], ['wait', still ? 22 : calm ? 30 : 10]]
|
|
350
|
+
.filter(o => o[1] > 0 && (o[0] !== pet.lastAct || o[0] === 'wait'));
|
|
351
|
+
let r = Math.random() * opts2.reduce((a, o) => a + o[1], 0), pick = 'wait';
|
|
352
|
+
for (const o of opts2) { if ((r -= o[1]) < 0) { pick = o[0]; break; } }
|
|
353
|
+
if (pick === 'look') { setMode('look'); pet.lastAct = 'look'; }
|
|
354
|
+
else if (pick === 'expr') { setExpr(['happy', 'wink', 'love', 'sleepy', 'surprised', 'shy'][Math.floor(Math.random() * 6)]); pet.lastAct = 'expr'; }
|
|
355
|
+
// a sit she chose decides up front whether it ends in sleep, so she only gets drowsy when she will fall asleep
|
|
356
|
+
else if (pick === 'sit') { setMode('sit', { dur: rnd(6, 9), willSleep: Math.random() < .6 }); pet.lastAct = 'sit'; }
|
|
357
|
+
else if (pick !== 'wait') act(pick);
|
|
358
|
+
if (pet.mode === 'idle' && T >= pet.nextAt) pet.nextAt = T + rnd(2, 4);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/* particles */
|
|
362
|
+
function emit(type, p, o = {}) { P.push({ type, x: p.x, y: p.y, vx: 0, vy: 0, age: 0, life: 1, ...o }); }
|
|
363
|
+
function emitHeart() {
|
|
364
|
+
emit('heart', toStage(rnd(A.hearts[0], A.hearts[1]), A.hearts[2] + pet.low), { vx: rnd(-20, 20), vy: rnd(-70, -45), life: 1.6 });
|
|
365
|
+
}
|
|
366
|
+
function dustAt(lx, n, spread) {
|
|
367
|
+
for (let i = 0; i < n; i++) {
|
|
368
|
+
emit('dust', toStage(lx, 250), { vx: rnd(-spread, spread) - pet.facing * rnd(10, 40), vy: rnd(-30, -8), life: rnd(.4, .65) });
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function step(dt) {
|
|
373
|
+
// a frame that took no time has nothing to advance, and the horizontal speed below divides by its length
|
|
374
|
+
if (!(dt > 0 && dt < Infinity)) return;
|
|
375
|
+
T += dt; pet.modeT += dt;
|
|
376
|
+
A = anchors();
|
|
377
|
+
resize(); // 每帧刷新 bounds(W/H/floorY):宿主的"落点=新地面"(looseGround/myFloor)只有靠这里才能传进引擎,否则 floorY 永远冻结在创建时的屏幕底
|
|
378
|
+
const m = pet.mode, mt = pet.modeT;
|
|
379
|
+
let sqT = 0, strideT = 0, liftT = 0, leanT = 0, sitT = 0, bobT = 0, rate = 0, lookT = [0, 0], tiltT = 0;
|
|
380
|
+
let tk = 160, tc = 12, drowseT = 0;
|
|
381
|
+
const still = !!opts.still?.();
|
|
382
|
+
const free = roam !== 'off' && T > hold && !opts.dialogOpen?.() && !still;
|
|
383
|
+
// 原地模式下不游荡,但仍然自选原地小动作
|
|
384
|
+
const inPlace = roam === 'off' && T > hold && !opts.dialogOpen?.() && !still;
|
|
385
|
+
|
|
386
|
+
pet.blinkT -= dt; pet.blinkAge += dt;
|
|
387
|
+
if (pet.blinkT <= 0) { pet.blinkAge = 0; pet.blinkT = Math.random() < .2 ? .28 : rnd(2.2, 5.2); }
|
|
388
|
+
|
|
389
|
+
const head = toStage(A.gaze[0], A.gaze[1]);
|
|
390
|
+
const pdx = pointer.x - head.x, pdy = pointer.y - head.y, pm = Math.hypot(pdx, pdy) || 1;
|
|
391
|
+
const track = () => {
|
|
392
|
+
if (!pointer.inside) {
|
|
393
|
+
if (T > pet.glanceAt) { pet.glance = Math.random() < .45 ? [0, 0] : [rnd(-3, 5), rnd(-3, 3)]; pet.glanceAt = T + rnd(1.2, 3); }
|
|
394
|
+
return pet.glance;
|
|
395
|
+
}
|
|
396
|
+
const k = Math.min(1, pm / 120);
|
|
397
|
+
return [pdx * pet.facing / pm * 5 * k, pdy / pm * 4 * k];
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
switch (m) {
|
|
401
|
+
case 'idle': {
|
|
402
|
+
lookT = track();
|
|
403
|
+
if (pointer.inside && !press && pdx * pet.facing < -50 && pm < 600) {
|
|
404
|
+
pet.turnAcc += dt;
|
|
405
|
+
if (pet.turnAcc > .9) { pet.facing *= -1; pet.turnAcc = 0; }
|
|
406
|
+
} else pet.turnAcc = 0;
|
|
407
|
+
if (pet.listening) { lookT = [3, -4]; tiltT = -7; leanT = -2; }
|
|
408
|
+
if ((free || inPlace) && !pet.listening && T > pet.nextAt && !(pet.expr && T < pet.exprUntil)) decide();
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
case 'walk': case 'run': {
|
|
412
|
+
// held still: the walk waits where it is, standing, and goes on once released
|
|
413
|
+
if (still) { pet.speed = 0; lookT = track(); break; }
|
|
414
|
+
const run = m === 'run', d = pet.target - pet.x, dy = pet.targetY - pet.gy, dist = Math.hypot(d, dy), dir = Math.sign(d) || pet.facing;
|
|
415
|
+
// a free body walking up or down the stage keeps the way it faces
|
|
416
|
+
if (!freeGround || Math.abs(d) > 2) pet.facing = dir;
|
|
417
|
+
const vMax = run ? 250 : 78;
|
|
418
|
+
const vT = Math.min(vMax, run ? dist * 4 + 20 : dist * 3 + 14);
|
|
419
|
+
strideT = run ? 17 : 10; liftT = run ? 15 : 8; bobT = run ? 7 : 3; rate = run ? 4.4 : 2.1;
|
|
420
|
+
leanT = run ? (dist < 50 && pet.speed > 120 ? -6 : 11) : 4;
|
|
421
|
+
if (leanT < 0 && !pet.skid) { pet.skid = true; play('skid', 'move'); }
|
|
422
|
+
const ramp = Math.min(1, mt / (run ? .35 : .25));
|
|
423
|
+
pet.speed = lerp(pet.speed, vT * smooth(ramp), ease(run ? 6 : 9, dt));
|
|
424
|
+
const go = Math.min(dist, pet.speed * dt);
|
|
425
|
+
if (dist > 0) { pet.x += d / dist * go; pet.gy += dy / dist * go; pet.fy = pet.gy; }
|
|
426
|
+
const k = clamp(pet.speed / vMax, 0, 1);
|
|
427
|
+
strideT *= .4 + .6 * k; liftT *= .4 + .6 * k;
|
|
428
|
+
pet.phase += Math.PI * 2 * rate * dt * Math.max(.35, k);
|
|
429
|
+
lookT = [run ? 4 : 3, run ? 1 : 0];
|
|
430
|
+
const half = Math.floor(pet.phase / Math.PI);
|
|
431
|
+
if (half !== pet.lastHalf) {
|
|
432
|
+
play('step', 'move', run, half & 1);
|
|
433
|
+
if (run && pet.speed > 120) dustAt(128, dist < 50 ? 3 : 1, 20);
|
|
434
|
+
}
|
|
435
|
+
pet.lastHalf = half;
|
|
436
|
+
if (dist < 1.5) {
|
|
437
|
+
pet.speed = 0;
|
|
438
|
+
const id = pet.walkId; pet.walkId = 0;
|
|
439
|
+
setMode('idle'); pet.nextAt = T + rnd(1.2, 3.2);
|
|
440
|
+
if (id) onEvent('arrived', { walkId: id, ...at() });
|
|
441
|
+
}
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
444
|
+
case 'look': {
|
|
445
|
+
if (!pet.cue) { pet.cue = 1; play('look', 'move'); }
|
|
446
|
+
if (mt < .9) lookT = [4, -4];
|
|
447
|
+
else if (mt < 1.8) { if (!pet.turned) { pet.turned = true; pet.facing *= -1; } lookT = [5, 0]; }
|
|
448
|
+
else if (mt < 2.6) lookT = [1, 4];
|
|
449
|
+
else { setMode('idle'); pet.nextAt = T + rnd(1, 2.5); }
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
case 'sit': {
|
|
453
|
+
sitT = 1;
|
|
454
|
+
lookT = track().map(v => v * (1 - pet.drowse));
|
|
455
|
+
if (pet.listening) { lookT = [3, -4]; tiltT = -7; }
|
|
456
|
+
// awake while sitting; a sit that ends in sleep closes over its last ~1.6s; a held sit (the word) never dozes off
|
|
457
|
+
drowseT = pet.willSleep && free ? clamp((mt - (pet.dur - 1.6)) / 1.2, 0, 1) : .15;
|
|
458
|
+
if (pet.drowse > .5) leanT = 7 * pet.drowse * Math.pow(Math.max(0, Math.sin(T * 1.3)), 6);
|
|
459
|
+
if (free && mt > pet.dur) {
|
|
460
|
+
if (pet.willSleep) setMode('sleep', { dur: rnd(8, 12) });
|
|
461
|
+
else { setMode('idle'); pet.sqv -= 1.2; pet.nextAt = T + rnd(1.5, 3); }
|
|
462
|
+
}
|
|
463
|
+
break;
|
|
464
|
+
}
|
|
465
|
+
case 'sleep': {
|
|
466
|
+
sitT = 1; drowseT = 1; leanT = 5;
|
|
467
|
+
if (free && mt > pet.dur) setMode('wake');
|
|
468
|
+
break;
|
|
469
|
+
}
|
|
470
|
+
case 'wake': {
|
|
471
|
+
if (pet.startle) {
|
|
472
|
+
sitT = 0; lookT = [3, -2];
|
|
473
|
+
if (mt > .9) { setMode('idle'); pet.nextAt = T + rnd(1.5, 3); }
|
|
474
|
+
} else {
|
|
475
|
+
sitT = mt < 1.1 ? 1 : 0;
|
|
476
|
+
if (mt > .5 && !pet.cue) { pet.cue = 1; play('yawn', 'face'); }
|
|
477
|
+
sqT = mt > .5 && mt < 1.3 ? -.1 : 0;
|
|
478
|
+
leanT = mt < .5 ? 5 : mt < 1.2 ? -5 : 0;
|
|
479
|
+
lookT = mt > 1.2 ? track() : [0, 0];
|
|
480
|
+
if (mt > 1.8) { setMode('idle'); pet.nextAt = T + rnd(1, 2); }
|
|
481
|
+
}
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
case 'crouch': {
|
|
485
|
+
sqT = .24; sitT = .3;
|
|
486
|
+
if (mt > .16) {
|
|
487
|
+
pet.vy = -pet.jumpV; pet.vx = pet.jumpVx; pet.airKind = 'jump'; pet.sqv -= 2.6;
|
|
488
|
+
play('jump', 'move');
|
|
489
|
+
setMode('air');
|
|
490
|
+
}
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
case 'air': {
|
|
494
|
+
pet.vy += 2300 * dt;
|
|
495
|
+
pet.vx *= Math.exp(-dt * .4);
|
|
496
|
+
pet.x += pet.vx * dt; pet.fy += pet.vy * dt;
|
|
497
|
+
// a free body tossed across the stage: its ground line slides with the throw and slows
|
|
498
|
+
if (freeGround && pet.gvy) {
|
|
499
|
+
pet.gvy *= Math.exp(-dt * 1.2);
|
|
500
|
+
pet.gy += pet.gvy * dt; pet.fy += pet.gvy * dt;
|
|
501
|
+
if (pet.gy < minY()) { pet.fy += minY() - pet.gy; pet.gy = minY(); pet.gvy = Math.abs(pet.gvy) * .55; pet.sqv += .6; }
|
|
502
|
+
if (pet.gy > floorY) { pet.fy -= pet.gy - floorY; pet.gy = floorY; pet.gvy = -Math.abs(pet.gvy) * .55; pet.sqv += .6; }
|
|
503
|
+
}
|
|
504
|
+
if (pet.x < minX()) { pet.x = minX(); pet.vx = Math.abs(pet.vx) * .55; pet.sqv += .6; }
|
|
505
|
+
if (pet.x > maxX()) { pet.x = maxX(); pet.vx = -Math.abs(pet.vx) * .55; pet.sqv += .6; }
|
|
506
|
+
if (pet.fy - 250 * S < 0 && pet.vy < 0) { pet.fy = 250 * S; pet.vy = Math.abs(pet.vy) * .3; }
|
|
507
|
+
sqT = -Math.min(.12, Math.abs(pet.vy) / 6000);
|
|
508
|
+
tiltT = clamp(pet.vx * .025, -30, 30);
|
|
509
|
+
tk = 70; tc = 8;
|
|
510
|
+
if (pet.fy >= pet.gy && pet.vy > 0) land();
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
513
|
+
case 'land': {
|
|
514
|
+
sitT = .35 * (1 - smooth(clamp(mt / .35, 0, 1)));
|
|
515
|
+
lookT = [2, 2];
|
|
516
|
+
if (mt > .4) setMode('idle');
|
|
517
|
+
break;
|
|
518
|
+
}
|
|
519
|
+
case 'dizzy': {
|
|
520
|
+
sitT = mt < 2.6 ? 1 : 0;
|
|
521
|
+
if (mt < 2.4 && T > pet.sfxAt) { play('chirps', 'move'); pet.sfxAt = T + .9; }
|
|
522
|
+
if (mt >= 2.4 && !pet.cue) { pet.cue = 1; play('shake', 'move'); }
|
|
523
|
+
if (mt < 2.4) tiltT = 8 * Math.sin(T * 4.5) * Math.min(1, mt * 2);
|
|
524
|
+
else if (mt < 3) { const k = (mt - 2.4) / .6; tiltT = 12 * Math.sin(mt * 34) * (1 - k); }
|
|
525
|
+
else { setMode('idle'); pet.sqv -= 1; pet.nextAt = T + rnd(1.5, 3); }
|
|
526
|
+
break;
|
|
527
|
+
}
|
|
528
|
+
case 'dance': {
|
|
529
|
+
// a little two-step on the spot: the feet take turns, the body sways with them, notes float up
|
|
530
|
+
strideT = 5; liftT = 10; bobT = 3;
|
|
531
|
+
pet.phase += Math.PI * 2 * 1.1 * dt;
|
|
532
|
+
tiltT = 7 * Math.sin(pet.phase);
|
|
533
|
+
lookT = [3, -2];
|
|
534
|
+
const half = Math.floor(pet.phase / Math.PI);
|
|
535
|
+
if (half !== pet.lastHalf) play('step', 'move', false, half & 1);
|
|
536
|
+
pet.lastHalf = half;
|
|
537
|
+
if (T > pet.noteAt) { emit('note', toStage(A.z[0], A.z[1] + pet.low), { vx: pet.facing * rnd(10, 30), vy: -34, life: 1.8 }); pet.noteAt = T + .6; }
|
|
538
|
+
if (mt > pet.dur) { setMode('idle'); pet.nextAt = T + rnd(1.5, 3); }
|
|
539
|
+
break;
|
|
540
|
+
}
|
|
541
|
+
case 'drag': {
|
|
542
|
+
pet.dx = lerp(pet.dx, pointer.x, ease(28, dt));
|
|
543
|
+
// 拖拽时的"脚不穿地"钳制线用真实屏幕底(H),不用当前 floorY——
|
|
544
|
+
// 站在搁板上时 floorY 是搁板高度,用它当钳制线会把斜下方向焊死(只能横移、不能往下拖)
|
|
545
|
+
pet.dy = lerp(pet.dy, Math.min(pointer.y, H - 245 * S), ease(28, dt));
|
|
546
|
+
tiltT = clamp(pointer.vx * .035, -40, 40); tk = 90; tc = 5;
|
|
547
|
+
if (Math.abs(pointer.vx) > 500 && T > pet.sfxAt) { play('whoosh', 'touch'); pet.sfxAt = T + rnd(.4, .7); } // 拎着甩动也用呼啸声(原来是 squeak)
|
|
548
|
+
break;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
// short gestures layered over whatever the body is doing
|
|
553
|
+
// (a figure that lists a gesture in `figure.gestures` draws it itself, from the frame's `gesture`)
|
|
554
|
+
if (pet.pulse) {
|
|
555
|
+
const k = (T - pet.pulse.t0) / pet.pulse.dur;
|
|
556
|
+
if (k >= 1) pet.pulse = null;
|
|
557
|
+
else if (custom?.gestures?.includes(pet.pulse.kind)) { /* the figure's own */ }
|
|
558
|
+
else if (pet.pulse.kind === 'nod') leanT += 9 * Math.abs(Math.sin(k * Math.PI * 2));
|
|
559
|
+
else if (pet.pulse.kind === 'shake') tiltT += 10 * Math.sin(k * Math.PI * 6) * (1 - k);
|
|
560
|
+
else if (pet.pulse.kind === 'wave') tiltT += 6 * Math.sin(k * Math.PI * 6) * Math.sin(k * Math.PI);
|
|
561
|
+
else if (pet.pulse.kind === 'bow') leanT += 16 * envelope(k, .25, .7);
|
|
562
|
+
else if (pet.pulse.kind === 'flap') { tiltT += 7 * Math.sin(k * Math.PI * 8) * (1 - k); sqT -= .06 * Math.abs(Math.sin(k * Math.PI * 8)) * (1 - k); }
|
|
563
|
+
else if (pet.pulse.kind === 'spin' && k > .5 && !pet.pulse.flipped) { pet.pulse.flipped = true; pet.facing *= -1; }
|
|
564
|
+
else if (pet.pulse.kind === 'spin' && k < .5 && !pet.pulse.first) { pet.pulse.first = true; pet.facing *= -1; pet.sqv -= 1; }
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const fname = faceName(), fc = faceDef(fname).f(T, pet);
|
|
568
|
+
// while the page shows the thought in its status bubble, the face keeps the eyes without a second thought trail
|
|
569
|
+
if (pet.thinking && pet.thoughtShown && fname === 'thinking') fc.think = false;
|
|
570
|
+
if (fc.lookLock || pet.mode === 'sleep' || pet.mode === 'drag') lookT = [0, 0];
|
|
571
|
+
else if (fc.lookAt) lookT = fc.lookAt;
|
|
572
|
+
|
|
573
|
+
// eye shape changes hide under a quick blink; same-shape changes (ring size) ease
|
|
574
|
+
const sig = fc.eyes.map(e => e.shape).join();
|
|
575
|
+
if (sig !== pet.eyeSig) {
|
|
576
|
+
if (pet.eyeCur) { pet.eyePrev = pet.eyeCur; pet.swapAge = 0; }
|
|
577
|
+
pet.eyeSig = sig;
|
|
578
|
+
fc.eyes.forEach((e, i) => { pet.eyeDims[i] = [e.rx ?? 16, e.ry ?? 16, e.dx || 0, e.dy || 0]; });
|
|
579
|
+
}
|
|
580
|
+
pet.swapAge += dt;
|
|
581
|
+
pet.eyeCur = fc.eyes.map((e, i) => {
|
|
582
|
+
if (e.shape !== 'ring' && e.shape !== 'lid') return e;
|
|
583
|
+
const d = pet.eyeDims[i], tgt = [e.rx ?? 16, e.ry ?? 16, e.dx || 0, e.dy || 0];
|
|
584
|
+
for (let j = 0; j < 4; j++) d[j] = lerp(d[j], tgt[j], ease(16, dt));
|
|
585
|
+
return { ...e, rx: d[0], ry: d[1], dx: d[2], dy: d[3] };
|
|
586
|
+
});
|
|
587
|
+
pet.blushK = lerp(pet.blushK, fc.blush || 0, ease(6, dt));
|
|
588
|
+
|
|
589
|
+
// springs & easing
|
|
590
|
+
pet.sqv += ((sqT - pet.sq) * 280 - pet.sqv * 14) * dt;
|
|
591
|
+
pet.sq = clamp(pet.sq + pet.sqv * dt, -.35, .45);
|
|
592
|
+
pet.tiltV += ((tiltT - pet.tilt) * tk - pet.tiltV * tc) * dt;
|
|
593
|
+
pet.tilt += pet.tiltV * dt;
|
|
594
|
+
pet.lean = lerp(pet.lean, leanT, ease(7, dt));
|
|
595
|
+
pet.sitK = lerp(pet.sitK, sitT, ease(m === 'land' ? 18 : 6, dt));
|
|
596
|
+
pet.drowse = lerp(pet.drowse, drowseT, ease(m === 'sleep' ? 1.5 : m === 'sit' ? 4 : 6, dt));
|
|
597
|
+
pet.stretch = lerp(pet.stretch, m === 'drag' ? 1 : 0, ease(8, dt));
|
|
598
|
+
pet.stride = lerp(pet.stride, strideT, ease(10, dt));
|
|
599
|
+
pet.lift = lerp(pet.lift, liftT, ease(10, dt));
|
|
600
|
+
pet.bob = lerp(pet.bob, bobT, ease(10, dt));
|
|
601
|
+
pet.look[0] = lerp(pet.look[0], lookT[0], ease(9, dt));
|
|
602
|
+
pet.look[1] = lerp(pet.look[1], lookT[1], ease(9, dt));
|
|
603
|
+
pet.gap[0] = lerp(pet.gap[0], fc.gap[0], ease(8, dt));
|
|
604
|
+
pet.gap[1] = lerp(pet.gap[1], fc.gap[1], ease(8, dt));
|
|
605
|
+
// turning reads as a quick card flip rather than a mirror snap
|
|
606
|
+
pet.faceVis = lerp(pet.faceVis, pet.facing, ease(15, dt));
|
|
607
|
+
if (m !== 'walk' && m !== 'run' && m !== 'dance') pet.phase = lerp(pet.phase, Math.round(pet.phase / Math.PI) * Math.PI, ease(6, dt));
|
|
608
|
+
pointer.vx *= Math.exp(-dt * 6);
|
|
609
|
+
|
|
610
|
+
// secondary motion for ears/antenna/scarf: lags behind horizontal movement
|
|
611
|
+
const AX = pet.mode === 'drag' ? pet.dx : pet.x;
|
|
612
|
+
if (pet.prevA != null) pet.velX = lerp(pet.velX, (AX - pet.prevA) / dt, .25);
|
|
613
|
+
// lerp keeps a NaN or an infinity for good, and the swing with it: a figure's warps that read the swing then
|
|
614
|
+
// draw nothing. Start the speed over and say what it came from.
|
|
615
|
+
if (!Number.isFinite(pet.velX)) {
|
|
616
|
+
if (!velXBad) console.warn(`[pet] 横向速度不是有限数,已归零:velX=${pet.velX} x=${AX} 上一帧x=${pet.prevA} dt=${dt} 模式=${m}`);
|
|
617
|
+
velXBad = true;
|
|
618
|
+
pet.velX = 0;
|
|
619
|
+
} else velXBad = false;
|
|
620
|
+
pet.prevA = AX;
|
|
621
|
+
// dancing stays put but rocks: the rock swings what hangs off the body (ears, hair, skirt), as moving does
|
|
622
|
+
const swingT = clamp(-(pet.velX * .06 + (m === 'dance' ? pet.tiltV * .22 : 0)) * Math.sign(pet.faceVis || 1), -28, 28);
|
|
623
|
+
pet.swingV += ((swingT - pet.swing) * 110 - pet.swingV * 7) * dt;
|
|
624
|
+
pet.swing = clamp(pet.swing + pet.swingV * dt, -40, 40);
|
|
625
|
+
|
|
626
|
+
pet.low = pet.sitK * 29 + pet.bob * Math.abs(Math.sin(pet.phase));
|
|
627
|
+
pet.feet.forEach((ft, i) => {
|
|
628
|
+
const hx = HIPS[i][0], hy = HIPS[i][1] + pet.low;
|
|
629
|
+
let tx, ty;
|
|
630
|
+
if (m === 'drag') { tx = hx + 7 * Math.sin(T * 11 + i * 2.2); ty = hy + 36; }
|
|
631
|
+
else if (m === 'air') { tx = hx + (i ? 9 : -9); ty = hy + 33; }
|
|
632
|
+
else {
|
|
633
|
+
const ph = pet.phase + i * Math.PI;
|
|
634
|
+
const sx = hx + pet.stride * Math.sin(ph), sy = FOOT_Y - pet.lift * Math.max(0, Math.cos(ph));
|
|
635
|
+
tx = lerp(sx, hx + 26, pet.sitK); ty = lerp(sy, FOOT_Y, pet.sitK);
|
|
636
|
+
}
|
|
637
|
+
const r = m === 'drag' || m === 'air' ? 14 : 40;
|
|
638
|
+
ft[0] = lerp(ft[0], tx, ease(r, dt)); ft[1] = lerp(ft[1], ty, ease(r, dt));
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
if (fc.emit && T > pet.emitAt) {
|
|
642
|
+
if (fc.emit === 'heart') { emitHeart(); pet.emitAt = T + .45; }
|
|
643
|
+
if (fc.emit === 'z') { emit('z', toStage(A.z[0], A.z[1] + pet.low), { vx: pet.facing * 16, vy: -26, life: 2.4 }); pet.emitAt = T + 1.3; play('snore', 'snore', pet.modeT); }
|
|
644
|
+
if (fc.emit === 'tear') { emit('drop', toStage(A.tear[0] + pet.look[0], A.tear[1] + pet.low), { vx: pet.facing * rnd(10, 30), vy: -20, life: 3 }); pet.emitAt = T + .8; }
|
|
645
|
+
if (fc.emit === 'tears') {
|
|
646
|
+
// both eyes cry, taking turns; a figure that names only its one tear spot cries from there
|
|
647
|
+
const eyes = A.tears ?? [A.tear], [ex, ey] = eyes[pet.tearN++ % eyes.length];
|
|
648
|
+
emit('drop', toStage(ex + pet.look[0] + rnd(-6, 6), ey + pet.low), { vx: pet.facing * rnd(-20, 50), vy: rnd(-60, -20), life: 3 }); pet.emitAt = T + .22;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
strokeAcc *= Math.exp(-dt * 1.5);
|
|
652
|
+
petCool -= dt;
|
|
653
|
+
|
|
654
|
+
for (let i = P.length - 1; i >= 0; i--) {
|
|
655
|
+
const p = P[i];
|
|
656
|
+
p.age += dt; p.x += p.vx * dt; p.y += p.vy * dt;
|
|
657
|
+
if (p.type === 'drop') { p.vy += 900 * dt; if (p.y > groundY()) p.age = p.life; }
|
|
658
|
+
if (p.type === 'dust') p.vx *= Math.exp(-dt * 4);
|
|
659
|
+
if (p.age >= p.life) P.splice(i, 1);
|
|
660
|
+
}
|
|
661
|
+
pet.talkK *= Math.exp(-dt * 12);
|
|
662
|
+
pet._fc = fc; pet._fname = fname;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
function land() {
|
|
666
|
+
const impact = pet.vy, kind = pet.airKind;
|
|
667
|
+
pet.fy = pet.gy; pet.vy = 0; pet.vx = 0; pet.gvy = 0;
|
|
668
|
+
pet.sqv += clamp(impact * .0024, .8, 4.5);
|
|
669
|
+
play('land', 'move', kind !== 'jump' && impact > 1000);
|
|
670
|
+
dustAt(128, impact > 900 ? 7 : 3, 70);
|
|
671
|
+
if (kind === 'throw' && impact > 1000) { setMode('dizzy'); onEvent('touch', { kind: 'crash' }); return; }
|
|
672
|
+
setMode('land');
|
|
673
|
+
if (kind === 'throw') { pet.expr = 'surprised'; pet.exprUntil = T + .9; pet.nextAt = T + 2; }
|
|
674
|
+
else if (kind === 'drop') { pet.expr = 'happy'; pet.exprUntil = T + 1.6; pet.nextAt = T + 2.6; }
|
|
675
|
+
else pet.nextAt = T + rnd(.8, 2);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/** What render last wrote into the group's transform, the shadow and the particles; the same value is not written again. */
|
|
679
|
+
const drawn = { xf: '', shadow: '', fx: '' };
|
|
680
|
+
/**
|
|
681
|
+
* Places the body for this frame (`pet.xf`, which `layout` and the hit tests read) and, unless `draw` is false,
|
|
682
|
+
* draws it: the figure into `petG`, the shadow and the particles.
|
|
683
|
+
*/
|
|
684
|
+
function render(draw = true) {
|
|
685
|
+
const fc = pet._fc || FACES.neutral.f(0), fname = pet._fname || 'neutral';
|
|
686
|
+
const drag = pet.mode === 'drag';
|
|
687
|
+
const br = Math.sin(T * (pet.mode === 'sleep' ? 1.7 : 2.4));
|
|
688
|
+
const sx = (1 + pet.sq * .7) * (1 - .05 * pet.stretch) * (1 - .009 * br);
|
|
689
|
+
const sy = (1 - pet.sq) * (1 + .09 * pet.stretch) * (1 + .016 * br);
|
|
690
|
+
const ax = 128, ay = drag ? 36 : 256;
|
|
691
|
+
let AX = drag ? pet.dx : pet.x, AY = drag ? pet.dy : pet.fy;
|
|
692
|
+
if (fc.shake) AX += Math.sin(T * 60) * 1.4;
|
|
693
|
+
else if (pet.pulse?.kind === 'shiver') AX += Math.sin(T * 75) * 1.1 * envelope((T - pet.pulse.t0) / pet.pulse.dur, .08, .85);
|
|
694
|
+
// a figure may keep tilt and lean off the whole group and bend its own parts instead
|
|
695
|
+
const kx = S * pet.faceVis * sx, ky = S * sy, lean = pet.lean * pet.faceVis;
|
|
696
|
+
const rot = custom?.groupTilt ? custom.groupTilt(pet.mode, pet.tilt, lean) : pet.tilt + lean;
|
|
697
|
+
pet.xf = { AX, AY, ax, ay, kx, ky, rot };
|
|
698
|
+
if (!draw) return fname;
|
|
699
|
+
const xf = `translate(${f(AX)} ${f(AY)}) rotate(${f(rot)}) scale(${kx.toFixed(4)} ${ky.toFixed(4)}) translate(${-ax} ${-ay})`;
|
|
700
|
+
if (xf !== drawn.xf) { petG.setAttribute('transform', xf); drawn.xf = xf; }
|
|
701
|
+
|
|
702
|
+
const legs = pet.feet.map((ft, i) => [HIPS[i][0], HIPS[i][1] + pet.low, ft[0], ft[1]]);
|
|
703
|
+
// drowsy blinks are slower
|
|
704
|
+
const bd = .16 + .3 * pet.drowse, blink = pet.blinkAge < bd ? Math.sin(Math.PI * pet.blinkAge / bd) : 0;
|
|
705
|
+
let eyes = pet.eyeCur || fc.eyes, eyeClose = 0;
|
|
706
|
+
if (pet.swapAge < .07 && pet.eyePrev) { eyes = pet.eyePrev; eyeClose = pet.swapAge / .07; }
|
|
707
|
+
else if (pet.swapAge < .16) eyeClose = 1 - (pet.swapAge - .07) / .09;
|
|
708
|
+
const face = { ...fc, eyes, gap: pet.gap.map(g => Math.min(64, g + pet.talkK * 12)), blush: pet.blushK };
|
|
709
|
+
const gesture = pet.pulse ? { kind: pet.pulse.kind, k: clamp((T - pet.pulse.t0) / pet.pulse.dur, 0, 1) } : null;
|
|
710
|
+
custom.draw(petG, face, {
|
|
711
|
+
look: pet.look, legs, low: pet.low, t: T, blink, eyeClose, acc: skin, swing: pet.swing,
|
|
712
|
+
face: fname, mode: pet.mode, modeT: pet.modeT, talk: pet.talkK, status: pet.status, drowse: pet.drowse, sit: pet.sitK, facing: pet.faceVis, tilt: pet.tilt, lean, groupRot: rot, gesture,
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
const footY = drag ? pet.dy + 220 * S * 1.09 : pet.fy;
|
|
716
|
+
// a free body held up casts its shadow just under it, there being no floor below it to fall to
|
|
717
|
+
const shadowY = freeGround && drag ? footY + 40 * S : groundY();
|
|
718
|
+
const k = clamp(1 - (shadowY - footY) / 420, .3, 1);
|
|
719
|
+
const shadow = [f(AX), f(shadowY - 2), f(72 * S * k * (1 + pet.sq * .5)), f(10 * S * k + 1), f(k)];
|
|
720
|
+
if (shadow.join() !== drawn.shadow) {
|
|
721
|
+
['cx', 'cy', 'rx', 'ry', 'opacity'].forEach((name, i) => shadowEl.setAttribute(name, shadow[i]));
|
|
722
|
+
drawn.shadow = shadow.join();
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
let s = '';
|
|
726
|
+
const sc = S / .48;
|
|
727
|
+
// sleep z's take the eye colour, or the figure's own colour for them
|
|
728
|
+
const zPaint = custom?.colors?.z ? `stroke="${custom.colors.z}"` : 'class="eye"';
|
|
729
|
+
for (const p of P) {
|
|
730
|
+
const a = p.age / p.life;
|
|
731
|
+
if (p.type === 'z') {
|
|
732
|
+
const op = a < .15 ? a / .15 : 1 - (a - .15) / .85, z = (.7 + .9 * a) * sc;
|
|
733
|
+
s += `<path ${zPaint} fill="none" stroke-width="${f(3 / z)}" stroke-linecap="round" stroke-linejoin="round" opacity="${f(op)}" transform="translate(${f(p.x + Math.sin(p.age * 2.5) * 6)} ${f(p.y)}) scale(${f(z)})" d="M-6 -7H6L-6 7H6"/>`;
|
|
734
|
+
} else if (p.type === 'heart') {
|
|
735
|
+
s += `<path class="p-heart" fill="none" stroke-width="5" stroke-linejoin="round" opacity="${f(1 - a * a)}" transform="translate(${f(p.x + Math.sin(p.age * 4) * 5)} ${f(p.y)}) scale(${f((.45 + .35 * a) * sc)})" d="${heartD(0, 0, 1)}"/>`;
|
|
736
|
+
} else if (p.type === 'dust') {
|
|
737
|
+
s += `<circle class="p-dust" fill="none" stroke-width="2" cx="${f(p.x)}" cy="${f(p.y)}" r="${f((3 + 8 * a) * sc)}" opacity="${f(.7 * (1 - a))}"/>`;
|
|
738
|
+
} else if (p.type === 'note') {
|
|
739
|
+
const op = a < .15 ? a / .15 : 1 - (a - .15) / .85, z = (.8 + .4 * a) * sc;
|
|
740
|
+
s += `<g opacity="${f(op)}" transform="translate(${f(p.x + Math.sin(p.age * 3) * 8)} ${f(p.y)}) scale(${f(z)})"><path ${zPaint} fill="none" stroke-width="2.4" stroke-linecap="round" d="M3 4V-9L9 -6"/><circle ${zPaint} fill="none" stroke-width="3.6" cx="0" cy="4.5" r="1.8"/></g>`;
|
|
741
|
+
} else if (p.type === 'drop') {
|
|
742
|
+
s += `<path class="tearf" transform="translate(${f(p.x)} ${f(p.y)}) scale(${f(.9 * sc)})" d="${DROP}"/>`;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
if (s !== drawn.fx) { fxG.innerHTML = s; drawn.fx = s; }
|
|
746
|
+
return fname;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/* pointer: stage-pixel coordinates; `p.t` is when it happened (ms), else now */
|
|
750
|
+
const now = (p) => p?.t ?? performance.now();
|
|
751
|
+
function velocity() {
|
|
752
|
+
const s = pointer.samples;
|
|
753
|
+
if (s.length < 2) return { x: 0, y: 0 };
|
|
754
|
+
const a = s[0], b = s[s.length - 1], dt = Math.max(.016, (b.t - a.t) / 1000);
|
|
755
|
+
return { x: (b.x - a.x) / dt, y: (b.y - a.y) / dt };
|
|
756
|
+
}
|
|
757
|
+
/** Picks the body up by the scruff; it then follows the pointer until let go of. */
|
|
758
|
+
function grab() {
|
|
759
|
+
const scruff = toStage(128, 36);
|
|
760
|
+
pet.expr = null;
|
|
761
|
+
setMode('drag', { dx: scruff.x, dy: scruff.y });
|
|
762
|
+
play('whoosh', 'touch'); // 拎起来也用呼啸声(原来叫 grab,用户点名换掉)
|
|
763
|
+
pet.sqv -= 1.2; pet.tiltV = 0;
|
|
764
|
+
onEvent('touch', { kind: 'grab' });
|
|
765
|
+
}
|
|
766
|
+
function pointerDown(p) {
|
|
767
|
+
Object.assign(pointer, { x: p.x, y: p.y, inside: true });
|
|
768
|
+
if (!hitPet(p)) return false;
|
|
769
|
+
press = { x: p.x, y: p.y, t: now(p) };
|
|
770
|
+
stillSince = now(p); // 按住计时起点:松手前停稳够久就算"安放"
|
|
771
|
+
pointer.samples = [{ t: now(p), x: p.x, y: p.y }];
|
|
772
|
+
// caught while falling or flying: held at once, since the body would fall on while the pointer moved the drag threshold
|
|
773
|
+
if (pet.mode === 'air') grab();
|
|
774
|
+
return true;
|
|
775
|
+
}
|
|
776
|
+
/** Returns the cursor the stage should show. */
|
|
777
|
+
function pointerMove(p) {
|
|
778
|
+
const t = now(p);
|
|
779
|
+
const ddx = p.x - pointer.x, ddy = p.y - pointer.y;
|
|
780
|
+
Object.assign(pointer, { x: p.x, y: p.y, inside: true });
|
|
781
|
+
pointer.samples.push({ t, x: p.x, y: p.y });
|
|
782
|
+
while (pointer.samples.length > 2 && t - pointer.samples[0].t > 110) pointer.samples.shift();
|
|
783
|
+
pointer.vx = lerp(pointer.vx, velocity().x, .35);
|
|
784
|
+
|
|
785
|
+
if (press && pet.mode !== 'drag' && Math.hypot(p.x - press.x, p.y - press.y) > 6) grab();
|
|
786
|
+
// 拖拽中:移动超过 3px 视为"还在动",重置静止计时(3px 容差吸收手抖)
|
|
787
|
+
if (press && pet.mode === 'drag' && Math.hypot(ddx, ddy) > 3) stillSince = t;
|
|
788
|
+
if (press) return (pet.cursor = 'grabbing');
|
|
789
|
+
const over = hitPet(p);
|
|
790
|
+
if (over && ['idle', 'look', 'sit', 'sleep'].includes(pet.mode)) {
|
|
791
|
+
strokeAcc += Math.hypot(ddx, ddy);
|
|
792
|
+
if (strokeAcc > 320 && petCool <= 0) {
|
|
793
|
+
strokeAcc = 0; petCool = 2.5;
|
|
794
|
+
play('purr', 'touch');
|
|
795
|
+
if (pet.mode === 'sleep') emitHeart();
|
|
796
|
+
else setExpr(Math.random() < .5 ? 'love' : 'shy');
|
|
797
|
+
onEvent('touch', { kind: 'pet', asleep: pet.mode === 'sleep' });
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
return (pet.cursor = over ? 'grab' : '');
|
|
801
|
+
}
|
|
802
|
+
function pointerUp(p) {
|
|
803
|
+
pet.cursor = '';
|
|
804
|
+
if (!press) return;
|
|
805
|
+
if (pet.mode === 'drag') {
|
|
806
|
+
// hand over from the scruff anchor to the feet anchor without a visual jump
|
|
807
|
+
const foot = toStage(128, 256);
|
|
808
|
+
const v = velocity();
|
|
809
|
+
pet.x = clamp(foot.x, minX(), maxX());
|
|
810
|
+
const speed = Math.hypot(v.x, v.y);
|
|
811
|
+
// 停顿豁免:松手前拿稳 ≥400ms 一律算"轻轻放下"。速度样本在停手时会冻结在停手前的快速拖动上(采样只在移动时修剪),
|
|
812
|
+
// 不可信——停稳松手时把速度清零,别让"僵尸速度"把她抛出去
|
|
813
|
+
const still = now(p) - stillSince >= 400;
|
|
814
|
+
// 向下甩=想把她放到低处:不抛、不弹,就地安放(向下还给她一个向上弹跳很怪)
|
|
815
|
+
const down = !still && v.y > 120 && Math.abs(v.y) > Math.abs(v.x) * 1.3;
|
|
816
|
+
const tossed = !still && !down && speed > 700;
|
|
817
|
+
if (freeGround) {
|
|
818
|
+
// set down where it was let go of; a throw tosses it on across the stage, higher the faster it went
|
|
819
|
+
pet.gy = clamp(foot.y, minY(), floorY); pet.fy = Math.min(pet.gy, foot.y);
|
|
820
|
+
pet.vx = still || down ? 0 : clamp(v.x, -1800, 1800); pet.gvy = still || down ? 0 : clamp(v.y, -1800, 1800) * .6; pet.vy = still || down ? 0 : -Math.min(1400, speed * .6);
|
|
821
|
+
} else {
|
|
822
|
+
// 不再往旧地面收拢:min(floorY, foot.y) 会把"往低处放"的脚位抬回旧搁板,导致搁板永远降不下来。
|
|
823
|
+
// 落点过低由宿主负责夹回屏内(looseGround 已有 Math.max(36, Math.min(h-12, feet)) 保护)
|
|
824
|
+
pet.fy = foot.y;
|
|
825
|
+
pet.vx = still ? 0 : clamp(v.x, -1800, 1800); pet.vy = still ? 0 : clamp(v.y, -1800, 1400);
|
|
826
|
+
}
|
|
827
|
+
pet.airKind = tossed ? 'throw' : 'drop';
|
|
828
|
+
if (tossed) play('whoosh', 'move');
|
|
829
|
+
setMode('air');
|
|
830
|
+
onEvent('touch', { kind: tossed ? 'throw' : 'drop', x: Math.round(pet.x) });
|
|
831
|
+
} else if (now(p) - press.t < 400) {
|
|
832
|
+
if (pet.mode === 'sleep' || pet.mode === 'sit') {
|
|
833
|
+
const wasAsleep = pet.mode === 'sleep';
|
|
834
|
+
setMode('wake', { startle: true }); pet.sqv -= 2.2; pet.nextAt = T + 2.4;
|
|
835
|
+
play('surprised', 'face');
|
|
836
|
+
onEvent('touch', { kind: 'poke', woke: wasAsleep });
|
|
837
|
+
} else if (pet.mode !== 'dizzy') {
|
|
838
|
+
play('poke', 'touch');
|
|
839
|
+
const r = ['happy', 'wink', 'surprised', 'love', 'angry'][Math.floor(Math.random() * 5)];
|
|
840
|
+
setExpr(r);
|
|
841
|
+
if (Math.random() < .5 && pet.mode === 'idle') setMode('crouch', { jumpV: 480, jumpVx: 0 });
|
|
842
|
+
onEvent('touch', { kind: 'poke' });
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
press = null;
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* Ends a drag with the body dropped from under stage point `p` with no throw: the pointer was let
|
|
849
|
+
* go of on another display and the stage now covers that one. Call after `resize()` has taken the
|
|
850
|
+
* new size.
|
|
851
|
+
*/
|
|
852
|
+
function dropAt(p) {
|
|
853
|
+
press = null;
|
|
854
|
+
if (pet.mode !== 'drag') return;
|
|
855
|
+
Object.assign(pointer, { x: p.x, y: p.y, vx: 0, samples: [] });
|
|
856
|
+
pet.x = clamp(p.x, minX(), maxX());
|
|
857
|
+
pet.fy = Math.min(floorY, p.y + 220 * S);
|
|
858
|
+
if (freeGround) pet.gy = clamp(pet.fy, minY(), floorY);
|
|
859
|
+
pet.vx = 0; pet.vy = 0; pet.gvy = 0;
|
|
860
|
+
pet.airKind = 'drop';
|
|
861
|
+
setMode('air');
|
|
862
|
+
onEvent('touch', { kind: 'drop', x: Math.round(pet.x) });
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* Keeps a held body under the pointer when the stage moved to another display mid-drag: every
|
|
866
|
+
* point on screen now sits (dx, dy) stage pixels from where it was.
|
|
867
|
+
*/
|
|
868
|
+
function shiftDrag(dx, dy) {
|
|
869
|
+
if (pet.mode !== 'drag') return;
|
|
870
|
+
pet.dx += dx; pet.dy += dy; pet.x += dx;
|
|
871
|
+
pointer.x += dx; pointer.y += dy;
|
|
872
|
+
for (const s of pointer.samples) { s.x += dx; s.y += dy; }
|
|
873
|
+
if (press) { press.x += dx; press.y += dy; }
|
|
874
|
+
}
|
|
875
|
+
function pointerLeave() { if (!press) pointer.inside = false; }
|
|
876
|
+
|
|
877
|
+
/** Head top in stage pixels, for placing a speech bubble. */
|
|
878
|
+
const anchor = () => toStage(A.bubble[0], A.bubble[1] + pet.low);
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
* Where the body is and what it is doing, in stage pixels, for the page around it: its box and hit
|
|
882
|
+
* circles, the bubble's spot, the point the hover buttons sit beside (`side`, with `reach` from it to
|
|
883
|
+
* the body's edge), and the cursor to show.
|
|
884
|
+
*/
|
|
885
|
+
function layout() {
|
|
886
|
+
const [x0, y0, x1, y1] = custom?.extent ?? EXTENT;
|
|
887
|
+
const corners = [[x0, y0], [x1, y0], [x0, y1], [x1, y1]].map(([x, y]) => toStage(x, y));
|
|
888
|
+
const xs = corners.map((p) => p.x), ys = corners.map((p) => p.y);
|
|
889
|
+
const side = toStage(128, 128 + pet.low);
|
|
890
|
+
return {
|
|
891
|
+
x: pet.x, ...(freeGround ? { y: pet.gy } : {}), facing: pet.facing, mode: pet.mode, busy: busy(), pressing: !!press, cursor: pet.cursor,
|
|
892
|
+
moving: !!press || MOVING_MODES.has(pet.mode) || !!pet.pulse || Math.abs(pet.faceVis - pet.facing) > .05,
|
|
893
|
+
box: { x: Math.min(...xs), y: Math.min(...ys), w: Math.max(...xs) - Math.min(...xs), h: Math.max(...ys) - Math.min(...ys) },
|
|
894
|
+
hit: hits(), bubble: anchor(), side: { x: side.x, y: side.y, reach: 104 * S },
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
resize();
|
|
899
|
+
custom?.setSkin?.(skin);
|
|
900
|
+
return {
|
|
901
|
+
pet, step, render, resize, act, setExpr, doWord, walkTo, stopWalk, toStage, hitPet, busy, layout,
|
|
902
|
+
pointerDown, pointerMove, pointerUp, pointerLeave, dropAt, shiftDrag,
|
|
903
|
+
get pressing() { return !!press; },
|
|
904
|
+
/** Pressed, carried, airborne, walking, running, dancing, turning round, or in a short gesture (nod, wave, bow…): motion that frames far apart show as jumps. */
|
|
905
|
+
get moving() {
|
|
906
|
+
return !!press || MOVING_MODES.has(pet.mode) || !!pet.pulse || Math.abs(pet.faceVis - pet.facing) > .05;
|
|
907
|
+
},
|
|
908
|
+
get time() { return T; },
|
|
909
|
+
get bounds() { return { W, H, floorY, S, minX: minX(), maxX: maxX(), minY: minY() }; },
|
|
910
|
+
/** A free body stands anywhere on the stage (`opts.ground`). */
|
|
911
|
+
freeGround,
|
|
912
|
+
setSkin(s) { skin = s; custom?.setSkin?.(s); },
|
|
913
|
+
/** Swaps the body's drawing (see `opts.figure`). */
|
|
914
|
+
setFigure(fig) {
|
|
915
|
+
if (fig === custom) return;
|
|
916
|
+
// a swapped-out figure may hold a WebGL context; release it now instead of waiting for GC
|
|
917
|
+
custom?.dispose?.();
|
|
918
|
+
custom = fig;
|
|
919
|
+
custom.setSkin?.(skin);
|
|
920
|
+
A = anchors();
|
|
921
|
+
petG.textContent = '';
|
|
922
|
+
render();
|
|
923
|
+
},
|
|
924
|
+
get figure() { return custom; },
|
|
925
|
+
get skin() { return skin; },
|
|
926
|
+
setRoam(r) { roam = r; if (r !== 'off') pet.nextAt = T + 1; },
|
|
927
|
+
get roam() { return roam; },
|
|
928
|
+
/** Outside orders keep free roaming quiet for `seconds`. */
|
|
929
|
+
holdRoam(seconds) { hold = Math.max(hold, T + seconds); },
|
|
930
|
+
talk() { pet.talkK = 1; },
|
|
931
|
+
setListening(on) { pet.listening = on; if (on && (pet.mode === 'walk' || pet.mode === 'run')) setMode('idle'); },
|
|
932
|
+
setThinking(on) { pet.thinking = on; },
|
|
933
|
+
/** What the bot is busy with as the page's status bubble names it (`kind`), or null; the figure reads it from `frame.status`. */
|
|
934
|
+
setStatus(kind) { pet.status = typeof kind === 'string' ? kind : null; },
|
|
935
|
+
/** The page shows the bot's thinking in a bubble of its own. */
|
|
936
|
+
setThoughtShown(on) { pet.thoughtShown = on; },
|
|
937
|
+
anchor,
|
|
938
|
+
emitHeart,
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
/* ---------- the body a pack hands the figure frame ---------- */
|
|
943
|
+
/** Colours of what the kit draws itself (shadow, particles; z's take the `eye` class without a figure colour). */
|
|
944
|
+
const KIT_CSS = `
|
|
945
|
+
:root{--shadow:rgba(27,22,38,.12);--tear:#5AAEF0;--heart:#F0567A;--dust:#A39DB0;--skin-eye:#00A870}
|
|
946
|
+
@media (prefers-color-scheme: dark){:root:not([data-theme="light"]){--shadow:rgba(0,0,0,.32);--tear:#6BBDF7;--heart:#FF6F93;--dust:#5B6472;--skin-eye:#2FD59B}}
|
|
947
|
+
:root[data-theme="dark"]{--shadow:rgba(0,0,0,.32);--tear:#6BBDF7;--heart:#FF6F93;--dust:#5B6472;--skin-eye:#2FD59B}
|
|
948
|
+
.shadow{fill:var(--shadow)} .tearf{fill:var(--tear)} .p-heart{stroke:var(--heart)} .p-dust{stroke:var(--dust)} .eye{stroke:var(--skin-eye)}
|
|
949
|
+
svg.kit{position:absolute;inset:0;width:100%;height:100%;display:block;overflow:visible}
|
|
950
|
+
`;
|
|
951
|
+
const SVGNS = 'http://www.w3.org/2000/svg';
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* The body contract (api 2, web/figure-frame.js) on top of `createPet`: what a pack's factory returns.
|
|
955
|
+
* `host` is what the frame gives the factory: `root` (the element to draw in), `bounds()`, `emit(kind, detail)`
|
|
956
|
+
* for what happens to the body, `sound(name, kind, ...args)` for what it wants heard, and `start` ({ x, y, facing,
|
|
957
|
+
* enter, skin }: where it stands (`y`, its ground line, only for a free body that stood off the floor), or enter
|
|
958
|
+
* 'drop' to fall in from above, and the skin to wear). `opts` are createPet's, with `figure` required; `opts.css` is
|
|
959
|
+
* more style for the frame's document (a figure's own classes) and `opts.skinCss(skin)` the style that follows the skin.
|
|
960
|
+
* `opts.moves` answers the pack's own targets (its manifest's `moves`): `{ id: (params, bounds) => ({ x, y? }) | null }`
|
|
961
|
+
* gives the stage point to walk to for those params (bounds as `bounds()` gives them, with `minX` `maxX` `minY`);
|
|
962
|
+
* null, or a target it does not name, answers the move `busy`.
|
|
963
|
+
*
|
|
964
|
+
* The body takes these calls from the page: step(dt, draw), layout(), do(word), walk(x, run, id), stopWalk(id), pointer(type, p),
|
|
965
|
+
* drop(p), shift(dx, dy), place(x, facing, y), move(args, id), set({ roam, hold, dialogOpen, still, listening, thinking, thoughtShown, status, skin, theme }),
|
|
966
|
+
* cue(kind), talk(), setScheme(id, o), dispose(); `words` lists every word its do() knows.
|
|
967
|
+
*/
|
|
968
|
+
export function createBody(host, opts) {
|
|
969
|
+
const doc = host.root.ownerDocument;
|
|
970
|
+
const style = doc.createElement('style');
|
|
971
|
+
style.textContent = KIT_CSS + (opts.css ?? '');
|
|
972
|
+
doc.head.appendChild(style);
|
|
973
|
+
const svg = doc.createElementNS(SVGNS, 'svg');
|
|
974
|
+
svg.setAttribute('class', 'kit');
|
|
975
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
976
|
+
svg.innerHTML = '<ellipse class="shadow" cx="0" cy="0" rx="0" ry="0"/><g></g><g></g>';
|
|
977
|
+
host.root.appendChild(svg);
|
|
978
|
+
const [shadowEl, petG, fxG] = svg.children;
|
|
979
|
+
const skinStyle = doc.createElement('style');
|
|
980
|
+
doc.head.appendChild(skinStyle);
|
|
981
|
+
const start = host.start ?? {};
|
|
982
|
+
if (opts.skinCss && start.skin) skinStyle.textContent = opts.skinCss(start.skin);
|
|
983
|
+
let dialogOpen = false, still = false;
|
|
984
|
+
const ctl = createPet({ petG, shadowEl, fxG }, {
|
|
985
|
+
...opts,
|
|
986
|
+
skin: start.skin ?? null, startX: start.x, startY: start.y, enter: start.enter,
|
|
987
|
+
bounds: host.bounds,
|
|
988
|
+
onEvent: host.emit,
|
|
989
|
+
sfx: { play: (name, kind, ...args) => host.sound?.(name, kind, ...args) },
|
|
990
|
+
dialogOpen: () => dialogOpen,
|
|
991
|
+
still: () => still,
|
|
992
|
+
});
|
|
993
|
+
if (start.facing === 1 || start.facing === -1) ctl.pet.facing = ctl.pet.faceVis = start.facing;
|
|
994
|
+
return {
|
|
995
|
+
step(dt, draw = true) { ctl.step(dt); ctl.render(draw); },
|
|
996
|
+
layout: ctl.layout,
|
|
997
|
+
resize: ctl.resize,
|
|
998
|
+
do: ctl.doWord,
|
|
999
|
+
// 动作 / 表情直调口:引擎早就支持,包装层一直没暴露,页面调不到(点菜单"来一个"没反应的原因)
|
|
1000
|
+
act: (a) => ctl.act(a),
|
|
1001
|
+
setExpr: (n, s) => ctl.setExpr(n, s),
|
|
1002
|
+
words: [...KIT_EXPRESSIONS, ...KIT_MOTIONS, ...Object.keys(opts.words ?? {}).filter((w) => opts.words[w]?.expression || opts.words[w]?.motion)],
|
|
1003
|
+
walk: (x, run, id) => ctl.walkTo(x, run, id),
|
|
1004
|
+
walkTo: (x, run, id, y) => ctl.walkTo(x, run, id, y),
|
|
1005
|
+
stopWalk: (id) => ctl.stopWalk(id),
|
|
1006
|
+
move(args, id) {
|
|
1007
|
+
const to = opts.moves?.[args?.to];
|
|
1008
|
+
const p = typeof to === 'function' ? to(args.params ?? {}, { ...host.bounds(), ...ctl.bounds }) : null;
|
|
1009
|
+
return !!p && ctl.walkTo(p.x, !!args.run, id, p.y);
|
|
1010
|
+
},
|
|
1011
|
+
pointer(type, p) {
|
|
1012
|
+
if (type === 'down') ctl.pointerDown(p);
|
|
1013
|
+
else if (type === 'move') ctl.pointerMove(p);
|
|
1014
|
+
else if (type === 'up' || type === 'cancel') ctl.pointerUp(p);
|
|
1015
|
+
else if (type === 'leave') ctl.pointerLeave();
|
|
1016
|
+
},
|
|
1017
|
+
drop: ctl.dropAt,
|
|
1018
|
+
shift: ctl.shiftDrag,
|
|
1019
|
+
/** Puts a body that is standing at stage x, turned to `facing` (1 right, -1 left); a free body also on ground line `y`. */
|
|
1020
|
+
place(x, facing, y) {
|
|
1021
|
+
if (ctl.pet.mode === 'drag' || ctl.pet.mode === 'air') return;
|
|
1022
|
+
const { minX, maxX, minY, floorY } = ctl.bounds;
|
|
1023
|
+
ctl.pet.x = ctl.pet.target = clamp(x, minX, maxX);
|
|
1024
|
+
if (ctl.freeGround && typeof y === 'number' && Number.isFinite(y)) ctl.pet.gy = ctl.pet.targetY = ctl.pet.fy = clamp(y, minY, floorY);
|
|
1025
|
+
if (facing === 1 || facing === -1) ctl.pet.facing = ctl.pet.faceVis = facing;
|
|
1026
|
+
},
|
|
1027
|
+
set(s) {
|
|
1028
|
+
if (s.roam) ctl.setRoam(s.roam);
|
|
1029
|
+
if (typeof s.hold === 'number') ctl.holdRoam(s.hold);
|
|
1030
|
+
if (typeof s.dialogOpen === 'boolean') dialogOpen = s.dialogOpen;
|
|
1031
|
+
if (typeof s.still === 'boolean') still = s.still;
|
|
1032
|
+
if (typeof s.listening === 'boolean') ctl.setListening(s.listening);
|
|
1033
|
+
if (typeof s.thinking === 'boolean') ctl.setThinking(s.thinking);
|
|
1034
|
+
if (typeof s.thoughtShown === 'boolean') ctl.setThoughtShown(s.thoughtShown);
|
|
1035
|
+
if ('status' in s) ctl.setStatus(s.status);
|
|
1036
|
+
if (s.skin) { ctl.setSkin(s.skin); if (opts.skinCss) skinStyle.textContent = opts.skinCss(s.skin); }
|
|
1037
|
+
if (s.theme) doc.documentElement.dataset.theme = s.theme;
|
|
1038
|
+
},
|
|
1039
|
+
/** The page's own moments: a talk key tapped (`perk`), speech heard (`heard`), an answer sent (`cheer`), a dress pick (`bounce`). */
|
|
1040
|
+
cue(kind) {
|
|
1041
|
+
if (kind === 'perk') { ctl.pet.sqv += .6; ctl.setExpr('surprised', .5); }
|
|
1042
|
+
else if (kind === 'heard') ctl.pet.sqv += .9;
|
|
1043
|
+
else if (kind === 'cheer') ctl.setExpr('happy');
|
|
1044
|
+
else if (kind === 'bounce') ctl.pet.sqv += 1.2;
|
|
1045
|
+
},
|
|
1046
|
+
talk: ctl.talk,
|
|
1047
|
+
setScheme: (id, o) => opts.figure.setScheme?.(id, o),
|
|
1048
|
+
/** 预热所有配色与衣服的贴图,之后的换肤立即可用(见 figure.preload)。 */
|
|
1049
|
+
preload: () => opts.figure.preload?.(),
|
|
1050
|
+
get z() { return opts.figure.colors?.z ?? null; },
|
|
1051
|
+
dispose() { opts.figure.dispose?.(); svg.remove(); style.remove(); skinStyle.remove(); },
|
|
1052
|
+
};
|
|
1053
|
+
}
|