@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,2734 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<!--
|
|
3
|
+
coo-pet — desktop pet plugin for DeepSeek Harness
|
|
4
|
+
Copyright (C) 2026 Masterbble
|
|
5
|
+
Based on the desktop pet Coopanion by Pal-AI-Lab: https://github.com/Pal-AI-Lab/Coopanion
|
|
6
|
+
SPDX-License-Identifier: AGPL-3.0-or-later (see LICENSE; third-party notices in THIRD_PARTY_NOTICES.md)
|
|
7
|
+
-->
|
|
8
|
+
<html lang="zh-CN">
|
|
9
|
+
<head>
|
|
10
|
+
<meta charset="utf-8" />
|
|
11
|
+
<title>Coo</title>
|
|
12
|
+
<style>
|
|
13
|
+
html,
|
|
14
|
+
body {
|
|
15
|
+
margin: 0;
|
|
16
|
+
height: 100%;
|
|
17
|
+
background: transparent;
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
user-select: none;
|
|
20
|
+
font: 13px/1.6 system-ui, 'Microsoft YaHei', sans-serif;
|
|
21
|
+
}
|
|
22
|
+
#stage {
|
|
23
|
+
position: absolute;
|
|
24
|
+
left: 0;
|
|
25
|
+
top: 0;
|
|
26
|
+
width: 100%;
|
|
27
|
+
height: 100%;
|
|
28
|
+
overflow: visible;
|
|
29
|
+
transform-origin: 0 0;
|
|
30
|
+
will-change: transform;
|
|
31
|
+
}
|
|
32
|
+
#stage svg.kit {
|
|
33
|
+
position: absolute;
|
|
34
|
+
inset: 0;
|
|
35
|
+
width: 100%;
|
|
36
|
+
height: 100%;
|
|
37
|
+
overflow: visible;
|
|
38
|
+
pointer-events: none;
|
|
39
|
+
}
|
|
40
|
+
#bubble {
|
|
41
|
+
position: fixed;
|
|
42
|
+
max-width: 260px;
|
|
43
|
+
padding: 7px 11px;
|
|
44
|
+
border-radius: 11px;
|
|
45
|
+
background: rgba(255, 255, 255, 0.95);
|
|
46
|
+
color: #1d2333;
|
|
47
|
+
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
|
|
48
|
+
opacity: 0;
|
|
49
|
+
transform: translate(-50%, -100%) translateY(-6px);
|
|
50
|
+
transition: opacity 0.16s ease;
|
|
51
|
+
pointer-events: none;
|
|
52
|
+
white-space: pre-wrap;
|
|
53
|
+
}
|
|
54
|
+
#bubble.on {
|
|
55
|
+
opacity: 1;
|
|
56
|
+
}
|
|
57
|
+
#bubble::after {
|
|
58
|
+
content: '';
|
|
59
|
+
position: absolute;
|
|
60
|
+
left: 50%;
|
|
61
|
+
bottom: -6px;
|
|
62
|
+
width: 10px;
|
|
63
|
+
height: 10px;
|
|
64
|
+
margin-left: -5px;
|
|
65
|
+
background: rgba(255, 255, 255, 0.95);
|
|
66
|
+
transform: rotate(45deg);
|
|
67
|
+
}
|
|
68
|
+
.menu {
|
|
69
|
+
position: fixed;
|
|
70
|
+
min-width: 150px;
|
|
71
|
+
padding: 5px;
|
|
72
|
+
border-radius: 10px;
|
|
73
|
+
background: rgba(28, 32, 44, 0.96);
|
|
74
|
+
color: #eef2ff;
|
|
75
|
+
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
|
|
76
|
+
font-family: -apple-system, 'Segoe UI', 'Microsoft YaHei', 'PingFang SC', sans-serif;
|
|
77
|
+
font-size: 13px;
|
|
78
|
+
z-index: 30;
|
|
79
|
+
}
|
|
80
|
+
.menu-item {
|
|
81
|
+
padding: 6px 10px;
|
|
82
|
+
border-radius: 7px;
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
white-space: nowrap;
|
|
85
|
+
font-size: 13px;
|
|
86
|
+
}
|
|
87
|
+
.menu-item:hover {
|
|
88
|
+
background: rgba(255, 255, 255, 0.12);
|
|
89
|
+
}
|
|
90
|
+
.menu-row {
|
|
91
|
+
display: flex;
|
|
92
|
+
align-items: center;
|
|
93
|
+
}
|
|
94
|
+
.menu-row .menu-item {
|
|
95
|
+
flex: 1;
|
|
96
|
+
}
|
|
97
|
+
.menu-del {
|
|
98
|
+
border: 0;
|
|
99
|
+
background: transparent;
|
|
100
|
+
color: #8b93a7;
|
|
101
|
+
font-size: 13px;
|
|
102
|
+
line-height: 1;
|
|
103
|
+
padding: 4px 7px;
|
|
104
|
+
border-radius: 6px;
|
|
105
|
+
cursor: pointer;
|
|
106
|
+
}
|
|
107
|
+
.menu-del:hover {
|
|
108
|
+
background: rgba(255, 90, 90, 0.22);
|
|
109
|
+
color: #ff9d9d;
|
|
110
|
+
}
|
|
111
|
+
.menu-head {
|
|
112
|
+
padding: 4px 10px 6px;
|
|
113
|
+
font-size: 12px;
|
|
114
|
+
opacity: 0.6;
|
|
115
|
+
}
|
|
116
|
+
#chat {
|
|
117
|
+
position: fixed;
|
|
118
|
+
width: 268px;
|
|
119
|
+
padding: 8px;
|
|
120
|
+
border-radius: 12px;
|
|
121
|
+
background: rgba(28, 32, 44, 0.97);
|
|
122
|
+
box-shadow: 0 14px 34px rgba(0, 0, 0, 0.4);
|
|
123
|
+
z-index: 40;
|
|
124
|
+
display: flex;
|
|
125
|
+
gap: 6px;
|
|
126
|
+
align-items: center;
|
|
127
|
+
}
|
|
128
|
+
#chat input {
|
|
129
|
+
flex: 1;
|
|
130
|
+
min-width: 0;
|
|
131
|
+
padding: 6px 8px;
|
|
132
|
+
border: 0;
|
|
133
|
+
border-radius: 8px;
|
|
134
|
+
background: rgba(255, 255, 255, 0.1);
|
|
135
|
+
color: #fff;
|
|
136
|
+
outline: none;
|
|
137
|
+
font-size: 12px;
|
|
138
|
+
}
|
|
139
|
+
#chat button {
|
|
140
|
+
padding: 6px 9px;
|
|
141
|
+
border: 0;
|
|
142
|
+
border-radius: 8px;
|
|
143
|
+
background: #4d6bfe;
|
|
144
|
+
color: #fff;
|
|
145
|
+
cursor: pointer;
|
|
146
|
+
font-size: 12px;
|
|
147
|
+
}
|
|
148
|
+
#chat button.ghost {
|
|
149
|
+
background: rgba(255, 255, 255, 0.12);
|
|
150
|
+
}
|
|
151
|
+
.hidden {
|
|
152
|
+
display: none !important;
|
|
153
|
+
}
|
|
154
|
+
</style>
|
|
155
|
+
</head>
|
|
156
|
+
<body>
|
|
157
|
+
<div id="stage"></div>
|
|
158
|
+
<div id="bubble"></div>
|
|
159
|
+
<div id="chat" class="hidden">
|
|
160
|
+
<input id="chat-text" placeholder="跟她说一句…" />
|
|
161
|
+
<button id="chat-send">发</button>
|
|
162
|
+
<button id="chat-close" class="ghost">×</button>
|
|
163
|
+
</div>
|
|
164
|
+
<script type="module">
|
|
165
|
+
const desk = window.cooDesk || { hit() {}, close() {} }
|
|
166
|
+
const report = (status, payload) => {
|
|
167
|
+
try {
|
|
168
|
+
fetch('/dsh-coo-pet/report', {
|
|
169
|
+
method: 'POST',
|
|
170
|
+
headers: { 'content-type': 'application/json' },
|
|
171
|
+
body: JSON.stringify({ status, ...(payload || {}) }),
|
|
172
|
+
}).catch(() => {})
|
|
173
|
+
} catch {
|
|
174
|
+
/* 无所谓 */
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
window.addEventListener('error', (event) => report('desk-error', { message: String(event.message || event.error) }))
|
|
178
|
+
window.addEventListener('unhandledrejection', (event) =>
|
|
179
|
+
report('desk-error', { message: String((event.reason && event.reason.message) || event.reason) })
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
const ROOT = '/dsh-coo-pet/pet'
|
|
183
|
+
const stage = document.getElementById('stage')
|
|
184
|
+
// kit / pack 在建她的 try 块里才 import(块级作用域),分身(全真实例)也要用,
|
|
185
|
+
// 所以用模块级变量中转(建好前是 null,分身代码先判空)
|
|
186
|
+
let kit = null
|
|
187
|
+
let pack = null
|
|
188
|
+
// buildCloneBody(root, at):给分身造一只完整的本体实例(模型/贴图参数在建她时
|
|
189
|
+
// 才拿得到,所以这里只留个壳,boot 里赋值)。at = { x, y, facing }
|
|
190
|
+
let buildCloneBody = null
|
|
191
|
+
const bubbleEl = document.getElementById('bubble')
|
|
192
|
+
const chatEl = document.getElementById('chat')
|
|
193
|
+
const chatText = document.getElementById('chat-text')
|
|
194
|
+
|
|
195
|
+
let bubbleTimer = 0
|
|
196
|
+
let bubbleAnchor = { x: 0, y: 0 }
|
|
197
|
+
|
|
198
|
+
// 安静模式(纯手动开关,右键菜单「安静模式」):全静音 + 不溜达不碎碎念不搬图标不乱坐;记录存 localStorage
|
|
199
|
+
let offDuty = false
|
|
200
|
+
try { offDuty = localStorage.getItem('coo-offduty') === '1' } catch { /* 新环境没有记录 */ }
|
|
201
|
+
// 平时的小盹儿:白天闲着也会打个盹(作息感保留),一戳/一敲键盘就醒
|
|
202
|
+
let napping = false
|
|
203
|
+
let napTimer = 0
|
|
204
|
+
// 语音录制中(快捷键/鼠标键按着):原地站住别动,输入框里正在填她听到的话
|
|
205
|
+
let voiceHeld = false
|
|
206
|
+
|
|
207
|
+
const say = (text) => {
|
|
208
|
+
if (!text) return
|
|
209
|
+
if (offDuty) return
|
|
210
|
+
bubbleEl.textContent = text
|
|
211
|
+
bubbleEl.classList.add('on')
|
|
212
|
+
// 一开口就站住:不开新步子,正在走的路也立刻打断——
|
|
213
|
+
// 但她身上有正事在办时(去开软件/搬图标/去坐下)例外,别把任务路打断
|
|
214
|
+
try {
|
|
215
|
+
pet?.set?.({ roam: 'off' })
|
|
216
|
+
if (!launchWalk && !iconWalk && !seatWalk) pet?.stopWalk?.()
|
|
217
|
+
} catch {
|
|
218
|
+
/* ignore */
|
|
219
|
+
}
|
|
220
|
+
window.clearTimeout(bubbleTimer)
|
|
221
|
+
bubbleTimer = window.setTimeout(() => {
|
|
222
|
+
bubbleEl.classList.remove('on')
|
|
223
|
+
// 菜单/输入框开着时它们自己管 roam,别插手
|
|
224
|
+
if (!menuEl && (!chatEl || chatEl.classList.contains('hidden'))) applyRoam()
|
|
225
|
+
}, 4600)
|
|
226
|
+
speak(text)
|
|
227
|
+
}
|
|
228
|
+
/* 碎碎念专用口:受「碎碎念气泡」开关管(回答气泡、点她后的操作反馈不受它管)。
|
|
229
|
+
之前开关只拦了闲坐碎碎念那一处,睡觉晚安/孤独嗔怪/坐下感慨这些自言自语照说不误——
|
|
230
|
+
开关关了嘴还在动,这就是「开关和行为不匹配」的根源 */
|
|
231
|
+
const chatterSay = (text) => {
|
|
232
|
+
if (!text) return
|
|
233
|
+
if ((prefs && prefs.idleBubble) === false) return
|
|
234
|
+
say(text)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/* 朗读:用系统语音;咿呀模式就把音调拉高、语速加快,听着像小动物 */
|
|
238
|
+
let voicesCache = []
|
|
239
|
+
const warmVoices = () => {
|
|
240
|
+
try {
|
|
241
|
+
const synth = window.speechSynthesis
|
|
242
|
+
if (!synth) return
|
|
243
|
+
const got = synth.getVoices()
|
|
244
|
+
if (got && got.length) voicesCache = got
|
|
245
|
+
} catch {
|
|
246
|
+
/* ignore */
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
warmVoices()
|
|
250
|
+
try {
|
|
251
|
+
window.speechSynthesis?.addEventListener?.('voiceschanged', warmVoices)
|
|
252
|
+
} catch {
|
|
253
|
+
/* ignore */
|
|
254
|
+
}
|
|
255
|
+
/* 咿呀声:按字取片段现场拼 */
|
|
256
|
+
const babble = {
|
|
257
|
+
ready: false,
|
|
258
|
+
failed: false,
|
|
259
|
+
trying: false,
|
|
260
|
+
attempts: 0,
|
|
261
|
+
retryAt: 0,
|
|
262
|
+
ctx: null,
|
|
263
|
+
buffer: null,
|
|
264
|
+
units: {},
|
|
265
|
+
keys: [],
|
|
266
|
+
pending: '',
|
|
267
|
+
}
|
|
268
|
+
const BABBLE_TRIES = 4
|
|
269
|
+
const BABBLE_BACKOFF = 5000
|
|
270
|
+
const hashChar = (ch) => {
|
|
271
|
+
let n = 0
|
|
272
|
+
for (let i = 0; i < ch.length; i += 1) n = (n * 31 + ch.charCodeAt(i)) % 100000
|
|
273
|
+
return n
|
|
274
|
+
}
|
|
275
|
+
const babbleCtx = () => {
|
|
276
|
+
if (!babble.ctx) {
|
|
277
|
+
const C = window.AudioContext || window.webkitAudioContext
|
|
278
|
+
if (!C) return null
|
|
279
|
+
babble.ctx = new C()
|
|
280
|
+
}
|
|
281
|
+
if (babble.ctx.state === 'suspended') babble.ctx.resume?.().catch(() => {})
|
|
282
|
+
return babble.ctx
|
|
283
|
+
}
|
|
284
|
+
const loadBabble = async () => {
|
|
285
|
+
if (babble.ready || babble.trying || babble.failed) return babble.ready
|
|
286
|
+
// 正在退避就先不理,等下一次碎碎念或定时器再来
|
|
287
|
+
if (babble.retryAt && Date.now() < babble.retryAt) return false
|
|
288
|
+
babble.trying = true
|
|
289
|
+
try {
|
|
290
|
+
const [map, raw] = await Promise.all([
|
|
291
|
+
fetch('/dsh-coo-pet/pet/asset?p=' + encodeURIComponent('speech/zh.json')).then((r) => r.json()),
|
|
292
|
+
fetch('/dsh-coo-pet/pet/asset?p=' + encodeURIComponent('speech/zh.ogg')).then((r) => r.arrayBuffer()),
|
|
293
|
+
])
|
|
294
|
+
const ctx = babbleCtx()
|
|
295
|
+
babble.buffer = await ctx.decodeAudioData(raw)
|
|
296
|
+
babble.units = map.units ?? {}
|
|
297
|
+
babble.keys = Object.keys(babble.units)
|
|
298
|
+
babble.ready = babble.keys.length > 0
|
|
299
|
+
report('desk-voice', { mode: 'babble', units: babble.keys.length, seconds: Math.round(babble.buffer.duration) })
|
|
300
|
+
if (babble.ready && babble.pending) {
|
|
301
|
+
const line = babble.pending
|
|
302
|
+
babble.pending = ''
|
|
303
|
+
babbleSay(line)
|
|
304
|
+
}
|
|
305
|
+
} catch (error) {
|
|
306
|
+
babble.attempts += 1
|
|
307
|
+
babble.retryAt = Date.now() + BABBLE_BACKOFF
|
|
308
|
+
if (babble.attempts >= BABBLE_TRIES) babble.failed = true
|
|
309
|
+
report('desk-voice-error', {
|
|
310
|
+
message: String((error && error.message) || error),
|
|
311
|
+
attempts: babble.attempts,
|
|
312
|
+
willRetry: !babble.failed,
|
|
313
|
+
})
|
|
314
|
+
}
|
|
315
|
+
babble.trying = false
|
|
316
|
+
return babble.ready
|
|
317
|
+
}
|
|
318
|
+
const babbleSay = (text) => {
|
|
319
|
+
if (!babble.ready) {
|
|
320
|
+
babble.pending = String(text ?? '')
|
|
321
|
+
loadBabble()
|
|
322
|
+
return
|
|
323
|
+
}
|
|
324
|
+
const ctx = babbleCtx()
|
|
325
|
+
if (!ctx) return
|
|
326
|
+
const rate = Number(prefs.voiceRate) > 0 ? Math.min(2, Number(prefs.voiceRate)) : 1
|
|
327
|
+
const pitch = Number(prefs.voicePitch) > 0 ? Math.min(2, Number(prefs.voicePitch)) : 1
|
|
328
|
+
const chars = [...String(text ?? '').replace(/\{[a-z]+\}/gi, '')].filter((ch) => !/\s/.test(ch)).slice(0, 60)
|
|
329
|
+
let at = ctx.currentTime + 0.02
|
|
330
|
+
const base = 1 / Math.max(0.5, pitch)
|
|
331
|
+
for (const ch of chars) {
|
|
332
|
+
const key = babble.keys[hashChar(ch) % babble.keys.length]
|
|
333
|
+
const unit = babble.units[key]
|
|
334
|
+
if (!unit) continue
|
|
335
|
+
const src = ctx.createBufferSource()
|
|
336
|
+
src.buffer = babble.buffer
|
|
337
|
+
src.playbackRate.value = base * (0.94 + (hashChar(ch + 'x') % 13) / 100)
|
|
338
|
+
const gain = ctx.createGain()
|
|
339
|
+
gain.gain.value = 0.42
|
|
340
|
+
src.connect(gain).connect(ctx.destination)
|
|
341
|
+
src.start(at, unit[0], Math.min(0.16, unit[1]))
|
|
342
|
+
at += unit[1] / Math.max(0.6, rate)
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const speak = (text) => {
|
|
347
|
+
try {
|
|
348
|
+
if (offDuty || prefs.voice === false) return
|
|
349
|
+
// 咿呀模式优先走音库;音库没就绪就排队,绝不退回朗读
|
|
350
|
+
if ((prefs.voiceMode ?? 'babble') === 'babble') {
|
|
351
|
+
babbleSay(text)
|
|
352
|
+
return
|
|
353
|
+
}
|
|
354
|
+
if (!('speechSynthesis' in window)) return
|
|
355
|
+
const synth = window.speechSynthesis
|
|
356
|
+
if (!voicesCache.length) warmVoices()
|
|
357
|
+
const utter = new SpeechSynthesisUtterance(String(text).replace(/\{[a-z]+\}/gi, ''))
|
|
358
|
+
const wantName = String(prefs.voiceName || '')
|
|
359
|
+
let voice = wantName ? voicesCache.find((v) => v.name === wantName) : null
|
|
360
|
+
if (!voice) voice = voicesCache.find((v) => /^(zh|cmn)/i.test(v.lang)) || voicesCache[0]
|
|
361
|
+
if (voice) utter.voice = voice
|
|
362
|
+
utter.lang = (voice && voice.lang) || 'zh-CN'
|
|
363
|
+
const rate = Number(prefs.voiceRate) > 0 ? Number(prefs.voiceRate) : 1.05
|
|
364
|
+
const pitch = Number(prefs.voicePitch) > 0 ? Number(prefs.voicePitch) : 1.15
|
|
365
|
+
utter.rate = rate
|
|
366
|
+
utter.pitch = pitch
|
|
367
|
+
synth.cancel()
|
|
368
|
+
synth.speak(utter)
|
|
369
|
+
} catch {
|
|
370
|
+
/* 没声音也行 */
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/* 回答朗读:插入会话的回答专用——气泡停久一点,声音完全跟随设置(咿呀就咿呀,tts 就朗读) */
|
|
375
|
+
const answerSay = (text) => {
|
|
376
|
+
if (!text) return
|
|
377
|
+
// 回答到了:想完啦
|
|
378
|
+
thinkingNow = false
|
|
379
|
+
try { pet?.set?.({ thinking: false }) } catch { /* ignore */ }
|
|
380
|
+
// 回答气泡一出就站住:不开新步子,正在走的路也立刻打断(正事在办时除外)
|
|
381
|
+
try {
|
|
382
|
+
pet?.set?.({ roam: 'off' })
|
|
383
|
+
if (!launchWalk && !iconWalk && !seatWalk) pet?.stopWalk?.()
|
|
384
|
+
} catch {
|
|
385
|
+
/* ignore */
|
|
386
|
+
}
|
|
387
|
+
window.clearTimeout(thinkTimer)
|
|
388
|
+
if (prefs.answerBubble !== false) {
|
|
389
|
+
bubbleEl.textContent = text
|
|
390
|
+
bubbleEl.classList.add('on')
|
|
391
|
+
window.clearTimeout(bubbleTimer)
|
|
392
|
+
bubbleTimer = window.setTimeout(() => {
|
|
393
|
+
bubbleEl.classList.remove('on')
|
|
394
|
+
if (!menuEl && (!chatEl || chatEl.classList.contains('hidden'))) applyRoam()
|
|
395
|
+
}, 12000)
|
|
396
|
+
}
|
|
397
|
+
speak(text)
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const placeBubble = () => {
|
|
401
|
+
bubbleEl.style.left = Math.round(bubbleAnchor.x) + 'px'
|
|
402
|
+
bubbleEl.style.top = Math.round(bubbleAnchor.y) + 'px'
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/* ---------- 音效(现场合成,共 34 个) ---------- */
|
|
406
|
+
let actx = null
|
|
407
|
+
let sfxMaster = null
|
|
408
|
+
let noiseBuf = null
|
|
409
|
+
const ac = () => {
|
|
410
|
+
if (!actx) {
|
|
411
|
+
const C = window.AudioContext || window.webkitAudioContext
|
|
412
|
+
if (!C) return null
|
|
413
|
+
actx = new C()
|
|
414
|
+
sfxMaster = actx.createGain()
|
|
415
|
+
sfxMaster.gain.value = 0.55
|
|
416
|
+
const comp = actx.createDynamicsCompressor()
|
|
417
|
+
sfxMaster.connect(comp)
|
|
418
|
+
comp.connect(actx.destination)
|
|
419
|
+
}
|
|
420
|
+
if (actx.state === 'suspended') actx.resume?.().catch(() => {})
|
|
421
|
+
return actx
|
|
422
|
+
}
|
|
423
|
+
const R = (a, b) => a + Math.random() * (b - a)
|
|
424
|
+
const tone = ({ type = 'sine', f0 = 440, f1 = f0, dur = 0.1, vol = 0.2, at = 0, attack = 0.005, vib = 0, vibRate = 0, filter = 0 }) => {
|
|
425
|
+
const ctx = ac()
|
|
426
|
+
if (!ctx) return
|
|
427
|
+
const t0 = ctx.currentTime + at
|
|
428
|
+
const osc = ctx.createOscillator()
|
|
429
|
+
const amp = ctx.createGain()
|
|
430
|
+
osc.type = type
|
|
431
|
+
osc.frequency.setValueAtTime(f0, t0)
|
|
432
|
+
osc.frequency.exponentialRampToValueAtTime(Math.max(20, f1), t0 + dur)
|
|
433
|
+
if (vib) {
|
|
434
|
+
const l = ctx.createOscillator()
|
|
435
|
+
const lg = ctx.createGain()
|
|
436
|
+
l.frequency.value = vibRate
|
|
437
|
+
lg.gain.value = vib
|
|
438
|
+
l.connect(lg)
|
|
439
|
+
lg.connect(osc.frequency)
|
|
440
|
+
l.start(t0)
|
|
441
|
+
l.stop(t0 + dur + 0.05)
|
|
442
|
+
}
|
|
443
|
+
amp.gain.setValueAtTime(0.0001, t0)
|
|
444
|
+
amp.gain.exponentialRampToValueAtTime(vol, t0 + attack)
|
|
445
|
+
amp.gain.exponentialRampToValueAtTime(0.0001, t0 + dur)
|
|
446
|
+
let node = osc
|
|
447
|
+
if (filter) {
|
|
448
|
+
const bq = ctx.createBiquadFilter()
|
|
449
|
+
bq.type = 'lowpass'
|
|
450
|
+
bq.frequency.value = filter
|
|
451
|
+
osc.connect(bq)
|
|
452
|
+
node = bq
|
|
453
|
+
}
|
|
454
|
+
node.connect(amp)
|
|
455
|
+
amp.connect(sfxMaster)
|
|
456
|
+
osc.start(t0)
|
|
457
|
+
osc.stop(t0 + dur + 0.03)
|
|
458
|
+
}
|
|
459
|
+
const noise = ({ type = 'bandpass', f0 = 1000, f1 = f0, q = 1, dur = 0.2, vol = 0.15, at = 0, attack = 0.01 }) => {
|
|
460
|
+
const ctx = ac()
|
|
461
|
+
if (!ctx) return
|
|
462
|
+
if (!noiseBuf) {
|
|
463
|
+
noiseBuf = ctx.createBuffer(1, ctx.sampleRate, ctx.sampleRate)
|
|
464
|
+
const d = noiseBuf.getChannelData(0)
|
|
465
|
+
for (let i = 0; i < d.length; i++) d[i] = Math.random() * 2 - 1
|
|
466
|
+
}
|
|
467
|
+
const t0 = ctx.currentTime + at
|
|
468
|
+
const src = ctx.createBufferSource()
|
|
469
|
+
const bq = ctx.createBiquadFilter()
|
|
470
|
+
const amp = ctx.createGain()
|
|
471
|
+
src.buffer = noiseBuf
|
|
472
|
+
bq.type = type
|
|
473
|
+
bq.Q.value = q
|
|
474
|
+
bq.frequency.setValueAtTime(f0, t0)
|
|
475
|
+
bq.frequency.exponentialRampToValueAtTime(f1, t0 + dur)
|
|
476
|
+
amp.gain.setValueAtTime(0.0001, t0)
|
|
477
|
+
amp.gain.exponentialRampToValueAtTime(vol, t0 + attack)
|
|
478
|
+
amp.gain.exponentialRampToValueAtTime(0.0001, t0 + dur)
|
|
479
|
+
src.connect(bq)
|
|
480
|
+
bq.connect(amp)
|
|
481
|
+
amp.connect(sfxMaster)
|
|
482
|
+
src.start(t0, Math.random() * 0.5)
|
|
483
|
+
src.stop(t0 + dur + 0.03)
|
|
484
|
+
}
|
|
485
|
+
const tones = {
|
|
486
|
+
step(run, i) {
|
|
487
|
+
const k = run ? 1.25 : 1
|
|
488
|
+
tone({ f0: (i ? 520 : 440) * k, f1: (i ? 380 : 330) * k, dur: 0.06, vol: run ? 0.07 : 0.05 })
|
|
489
|
+
if (run) noise({ f0: 2500, q: 0.8, dur: 0.05, vol: 0.03 })
|
|
490
|
+
},
|
|
491
|
+
skid() {
|
|
492
|
+
noise({ type: 'highpass', f0: 1800, f1: 900, dur: 0.22, vol: 0.08 })
|
|
493
|
+
},
|
|
494
|
+
jump() {
|
|
495
|
+
tone({ type: 'triangle', f0: 200, f1: 720, dur: 0.24, vol: 0.22, vib: 40, vibRate: 22 })
|
|
496
|
+
},
|
|
497
|
+
land(hard) {
|
|
498
|
+
tone({ f0: hard ? 160 : 190, f1: 48, dur: hard ? 0.28 : 0.16, vol: hard ? 0.4 : 0.25 })
|
|
499
|
+
noise({ type: 'lowpass', f0: hard ? 700 : 500, f1: 120, dur: 0.12, vol: hard ? 0.25 : 0.12 })
|
|
500
|
+
if (hard) tone({ type: 'square', f0: 420, f1: 300, dur: 0.08, vol: 0.06, at: 0.02, filter: 1600 })
|
|
501
|
+
},
|
|
502
|
+
grab() {
|
|
503
|
+
tone({ type: 'triangle', f0: 680, f1: 1500, dur: 0.14, vol: 0.18, vib: 60, vibRate: 30 })
|
|
504
|
+
},
|
|
505
|
+
squeak() {
|
|
506
|
+
tone({ type: 'triangle', f0: R(900, 1200), f1: R(1300, 1700), dur: 0.09, vol: 0.08, vib: 40, vibRate: 35 })
|
|
507
|
+
},
|
|
508
|
+
whoosh() {
|
|
509
|
+
noise({ f0: 300, f1: 2400, q: 1.4, dur: 0.38, vol: 0.22, attack: 0.08 })
|
|
510
|
+
},
|
|
511
|
+
chirps() {
|
|
512
|
+
for (let i = 0; i < 3; i++) tone({ f0: 2300 + i * 120, f1: 3200, dur: 0.06, vol: 0.06, at: i * 0.11 })
|
|
513
|
+
},
|
|
514
|
+
shake() {
|
|
515
|
+
for (let i = 0; i < 5; i++) tone({ type: 'square', f0: 180, f1: 160, dur: 0.05, vol: 0.05, at: i * 0.06, filter: 900 })
|
|
516
|
+
},
|
|
517
|
+
hmm() {
|
|
518
|
+
tone({ type: 'triangle', f0: 330, f1: 360, dur: 0.12, vol: 0.08 })
|
|
519
|
+
tone({ type: 'triangle', f0: 392, f1: 470, dur: 0.16, vol: 0.08, at: 0.14 })
|
|
520
|
+
},
|
|
521
|
+
yawn() {
|
|
522
|
+
tone({ type: 'triangle', f0: 520, f1: 240, dur: 1, vol: 0.1, vib: 12, vibRate: 5, filter: 1500, attack: 0.15 })
|
|
523
|
+
},
|
|
524
|
+
snore() {
|
|
525
|
+
noise({ type: 'lowpass', f0: 250, f1: 700, dur: 0.7, vol: 0.09, attack: 0.35 })
|
|
526
|
+
},
|
|
527
|
+
purr() {
|
|
528
|
+
tone({ type: 'sawtooth', f0: 62, f1: 58, dur: 0.9, vol: 0.08, vib: 6, vibRate: 24, filter: 320, attack: 0.1 })
|
|
529
|
+
},
|
|
530
|
+
poke() {
|
|
531
|
+
tone({ f0: 320, f1: 200, dur: 0.09, vol: 0.16 })
|
|
532
|
+
},
|
|
533
|
+
shiver() {
|
|
534
|
+
for (let i = 0; i < 8; i++) tone({ type: 'square', f0: 900, f1: 820, dur: 0.03, vol: 0.035, at: i * 0.07, filter: 2400 })
|
|
535
|
+
},
|
|
536
|
+
look() {
|
|
537
|
+
tones.hmm()
|
|
538
|
+
},
|
|
539
|
+
dance() {
|
|
540
|
+
;[523, 659, 784, 659, 880].forEach((fr, i) => tone({ type: 'triangle', f0: fr, dur: 0.13, vol: 0.09, at: i * 0.15 }))
|
|
541
|
+
},
|
|
542
|
+
nod() {
|
|
543
|
+
tone({ type: 'triangle', f0: 520, f1: 440, dur: 0.07, vol: 0.08 })
|
|
544
|
+
tone({ type: 'triangle', f0: 520, f1: 440, dur: 0.07, vol: 0.08, at: 0.2 })
|
|
545
|
+
},
|
|
546
|
+
spin() {
|
|
547
|
+
tone({ type: 'triangle', f0: 300, f1: 1200, dur: 0.3, vol: 0.12, vib: 30, vibRate: 18 })
|
|
548
|
+
},
|
|
549
|
+
happy() {
|
|
550
|
+
tone({ type: 'triangle', f0: 660, f1: 700, dur: 0.1, vol: 0.14 })
|
|
551
|
+
tone({ type: 'triangle', f0: 990, f1: 1050, dur: 0.14, vol: 0.14, at: 0.09 })
|
|
552
|
+
},
|
|
553
|
+
wink() {
|
|
554
|
+
tone({ f0: 1760, dur: 0.5, vol: 0.1 })
|
|
555
|
+
tone({ f0: 2637, dur: 0.45, vol: 0.06, at: 0.04 })
|
|
556
|
+
},
|
|
557
|
+
love() {
|
|
558
|
+
tone({ f0: 480, f1: 820, dur: 0.1, vol: 0.14 })
|
|
559
|
+
tone({ f0: 600, f1: 1000, dur: 0.12, vol: 0.14, at: 0.13 })
|
|
560
|
+
},
|
|
561
|
+
surprised() {
|
|
562
|
+
tone({ f0: 380, f1: 1500, dur: 0.2, vol: 0.16, vib: 15, vibRate: 12 })
|
|
563
|
+
},
|
|
564
|
+
angry() {
|
|
565
|
+
tone({ type: 'sawtooth', f0: 120, f1: 95, dur: 0.5, vol: 0.12, vib: 12, vibRate: 14, filter: 700 })
|
|
566
|
+
},
|
|
567
|
+
sad() {
|
|
568
|
+
tone({ type: 'triangle', f0: 440, f1: 392, dur: 0.3, vol: 0.13, vib: 8, vibRate: 6 })
|
|
569
|
+
tone({ type: 'triangle', f0: 392, f1: 262, dur: 0.55, vol: 0.13, at: 0.3, vib: 10, vibRate: 5 })
|
|
570
|
+
},
|
|
571
|
+
shy() {
|
|
572
|
+
tone({ f0: 1300, f1: 1600, dur: 0.07, vol: 0.07 })
|
|
573
|
+
tone({ f0: 1450, f1: 1750, dur: 0.07, vol: 0.06, at: 0.1 })
|
|
574
|
+
},
|
|
575
|
+
tick() {
|
|
576
|
+
tone({ f0: 1200, f1: 1000, dur: 0.03, vol: 0.05 })
|
|
577
|
+
},
|
|
578
|
+
pop() {
|
|
579
|
+
tone({ f0: 240, f1: 720, dur: 0.07, vol: 0.14 })
|
|
580
|
+
},
|
|
581
|
+
sparkle() {
|
|
582
|
+
;[1568, 2093, 2637].forEach((fr, i) => tone({ f0: fr, dur: 0.25, vol: 0.06, at: i * 0.06 }))
|
|
583
|
+
},
|
|
584
|
+
select() {
|
|
585
|
+
tone({ type: 'triangle', f0: 520, f1: 1040, dur: 0.1, vol: 0.12 })
|
|
586
|
+
},
|
|
587
|
+
babble(ch) {
|
|
588
|
+
const n = typeof ch === 'string' && ch ? ch.codePointAt(0) : Math.floor(Math.random() * 0xffff)
|
|
589
|
+
const fr = (330 + (n % 9) * 28) * 1
|
|
590
|
+
tone({ type: 'square', f0: fr, f1: fr * R(0.85, 1.1), dur: 0.05, vol: 0.05, filter: 1800 })
|
|
591
|
+
},
|
|
592
|
+
blub() {
|
|
593
|
+
tone({ f0: R(500, 700), f1: R(900, 1200), dur: 0.05, vol: 0.05 })
|
|
594
|
+
},
|
|
595
|
+
listenStart() {
|
|
596
|
+
tone({ f0: 880, dur: 0.12, vol: 0.1 })
|
|
597
|
+
tone({ f0: 1320, dur: 0.16, vol: 0.1, at: 0.1 })
|
|
598
|
+
},
|
|
599
|
+
listenEnd() {
|
|
600
|
+
tone({ f0: 1320, dur: 0.1, vol: 0.09 })
|
|
601
|
+
tone({ f0: 990, dur: 0.16, vol: 0.09, at: 0.09 })
|
|
602
|
+
},
|
|
603
|
+
}
|
|
604
|
+
const chime = (name, ...args) => {
|
|
605
|
+
try {
|
|
606
|
+
report('desk-sfx', { name, ctx: actx ? actx.state : 'none', master: !!sfxMaster })
|
|
607
|
+
if (prefs.sfx === false || offDuty) return
|
|
608
|
+
if (Object.hasOwn(tones, name)) tones[name](...args)
|
|
609
|
+
} catch (e) {
|
|
610
|
+
report('desk-sfx-err', { name, err: String((e && (e.stack || e.message)) || e) })
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
const loadImage = (url) =>
|
|
615
|
+
new Promise((resolve, reject) => {
|
|
616
|
+
const img = new Image()
|
|
617
|
+
img.onload = () => resolve(img)
|
|
618
|
+
img.onerror = () => reject(new Error('image failed: ' + url))
|
|
619
|
+
img.src = url
|
|
620
|
+
})
|
|
621
|
+
|
|
622
|
+
let prefs = { look: 'deepseek', outfit: 'maid', size: 190, idleLines: '', answerBubble: true, idleBubble: true, greet: true, sfx: true }
|
|
623
|
+
try {
|
|
624
|
+
const body = await fetch('/dsh-coo-pet/prefs', { credentials: 'same-origin' }).then((res) => res.json())
|
|
625
|
+
if (body && body.config) prefs = body.config
|
|
626
|
+
} catch {
|
|
627
|
+
/* 默认值兜底 */
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
const splitLines = (text) => {
|
|
631
|
+
const who = String(prefs.petName || '').trim() || '你的鱼'
|
|
632
|
+
return String(text ?? '')
|
|
633
|
+
.split('\n')
|
|
634
|
+
.map((line) => line.trim().replace(/\{name\}/g, who))
|
|
635
|
+
.filter(Boolean)
|
|
636
|
+
}
|
|
637
|
+
let lines = splitLines(prefs.idleLines)
|
|
638
|
+
|
|
639
|
+
const idleMs = () => {
|
|
640
|
+
const unit = prefs.idleUnit === 'sec' ? 1000 : prefs.idleUnit === 'hour' ? 3600000 : 60000
|
|
641
|
+
const every = Number(prefs.idleEvery) > 0 ? Number(prefs.idleEvery) : 20
|
|
642
|
+
return Math.max(2000, every * unit)
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
let pet = null
|
|
646
|
+
let hit = { x: 0, y: 0, w: 0, h: 0 }
|
|
647
|
+
|
|
648
|
+
/* 小跟随窗:世界 = 整块工作区,窗口只是世界上的一个取景框 */
|
|
649
|
+
let worldSize = { x: 0, y: 0, w: window.innerWidth, h: window.innerHeight }
|
|
650
|
+
let origin = { x: 0, y: 0 }
|
|
651
|
+
const toLocalX = (v) => v - origin.x
|
|
652
|
+
const toLocalY = (v) => v - origin.y
|
|
653
|
+
const applyView = () => {
|
|
654
|
+
stage.style.width = worldSize.w + 'px'
|
|
655
|
+
stage.style.height = worldSize.h + 'px'
|
|
656
|
+
stage.style.transform = 'translate(' + -origin.x + 'px,' + -origin.y + 'px)'
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
try {
|
|
660
|
+
const meta = await desk.world()
|
|
661
|
+
if (meta && meta.world && meta.world.w) worldSize = meta.world
|
|
662
|
+
if (meta && meta.origin) origin = meta.origin
|
|
663
|
+
applyView()
|
|
664
|
+
} catch {
|
|
665
|
+
/* 拿不到就按窗口大小先跑 */
|
|
666
|
+
}
|
|
667
|
+
try {
|
|
668
|
+
desk.onOrigin((payload) => {
|
|
669
|
+
if (!payload) return
|
|
670
|
+
if (payload.world && payload.world.w) worldSize = payload.world
|
|
671
|
+
if (payload.origin) origin = payload.origin
|
|
672
|
+
applyView()
|
|
673
|
+
})
|
|
674
|
+
} catch {
|
|
675
|
+
/* ignore */
|
|
676
|
+
}
|
|
677
|
+
let anchorSentAt = 0
|
|
678
|
+
const publishAnchor = (box) => {
|
|
679
|
+
if (!box) return
|
|
680
|
+
const now = Date.now()
|
|
681
|
+
if (now - anchorSentAt < 120) return
|
|
682
|
+
anchorSentAt = now
|
|
683
|
+
try {
|
|
684
|
+
desk.anchor({ x: box.x + box.w / 2, y: box.y + box.h, bias: 0.42, moving: box.mode === 'walk' || box.mode === 'run' || box.mode === 'drag' || box.mode === 'air' })
|
|
685
|
+
} catch {
|
|
686
|
+
/* ignore */
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
let dragging = false
|
|
690
|
+
let inside = false
|
|
691
|
+
let seatWalk = null // 走过去再坐:进行中的坐下行走
|
|
692
|
+
let iconWalk = null // 走过去再搬图标:进行中的挪图行走(phase 1 走到图标前 / phase 2 抱着走)
|
|
693
|
+
let launchWalk = null // 指令开软件:小跑到目标位准备戳按的行走
|
|
694
|
+
let carry = null // 搬运中的小包裹标记(非空 = 正举着东西)
|
|
695
|
+
let carryG = null // 搬运牌子的 SVG 覆盖层
|
|
696
|
+
let stayMode = false // 原地模式:开关在菜单里(点菜单里的「原地待着」),不再是点她切换
|
|
697
|
+
let thinkingNow = false // 等回复中:也算原地待着的理由,想完再动
|
|
698
|
+
let busy = false // DSH 正在跑任务(含思考/执行工具):原地站住,别溜达别搬图标
|
|
699
|
+
let lastActive = 0 // DSH 最近一次活动时间(干活节流用)
|
|
700
|
+
// 统一的 roam 设置口:原地模式优先,其次看 prefs.wander
|
|
701
|
+
// 对话框/菜单只要在桌面上就禁跑(不管消息发没发),防止别的时机把 roam 放回 free
|
|
702
|
+
const uiOccupying = () => !!menuEl || !!(chatEl && !chatEl.classList.contains('hidden'))
|
|
703
|
+
// 本体状态闸:所有会按住她的状态(原地待着/值日/睡觉/思考/干活/语音/界面占用)
|
|
704
|
+
const heldRoam = () => !!(stayMode || offDuty || napping || thinkingNow || busy || voiceHeld || uiOccupying())
|
|
705
|
+
const mainRoamFree = () => !heldRoam() && prefs.wander !== false
|
|
706
|
+
const applyRoam = () => {
|
|
707
|
+
try {
|
|
708
|
+
pet?.set?.({ roam: mainRoamFree() ? 'free' : 'off' })
|
|
709
|
+
} catch {
|
|
710
|
+
/* ignore */
|
|
711
|
+
}
|
|
712
|
+
try { applyCloneRoam() } catch { /* ignore */ }
|
|
713
|
+
}
|
|
714
|
+
// 原地模式的两个固定项:点「原地待着」必定待着,点「自由活动」必定恢复,点多少下都一样
|
|
715
|
+
const setStay = (on) => {
|
|
716
|
+
stayMode = on
|
|
717
|
+
try { pet?.stopWalk?.() } catch { /* ignore */ }
|
|
718
|
+
seatWalk = null
|
|
719
|
+
seat = null
|
|
720
|
+
if (on && (iconWalk || carry)) {
|
|
721
|
+
iconWalk = null
|
|
722
|
+
carry = null
|
|
723
|
+
hideCarry()
|
|
724
|
+
}
|
|
725
|
+
applyRoam()
|
|
726
|
+
say(on ? '那我就待在这儿啦' : '又出来溜达咯')
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// 安静模式:静音、不溜达、不碎碎念不搬图标不乱坐;仍可拖拽、点她、对话框照常能用(只是不出声)
|
|
730
|
+
const setOffDuty = (on) => {
|
|
731
|
+
offDuty = on
|
|
732
|
+
try { localStorage.setItem('coo-offduty', on ? '1' : '0') } catch { /* ignore */ }
|
|
733
|
+
try { pet?.stopWalk?.() } catch { /* ignore */ }
|
|
734
|
+
if (on && (iconWalk || carry)) {
|
|
735
|
+
iconWalk = null
|
|
736
|
+
carry = null
|
|
737
|
+
hideCarry()
|
|
738
|
+
}
|
|
739
|
+
try { pet?.set?.({ dialogOpen: on }) } catch { /* ignore */ }
|
|
740
|
+
applyRoam()
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/* ---------- 快捷指令配套:番茄钟(本地定时,不麻烦 AI) ---------- */
|
|
744
|
+
let pomoTimer = 0
|
|
745
|
+
const startPomodoro = () => {
|
|
746
|
+
window.clearTimeout(pomoTimer)
|
|
747
|
+
say('番茄钟开始!25 分钟后我叫你~')
|
|
748
|
+
try { pet?.setExpr?.('determined') } catch { /* ignore */ }
|
|
749
|
+
pomoTimer = window.setTimeout(() => {
|
|
750
|
+
pomoTimer = 0
|
|
751
|
+
say('番茄钟到啦!休息 5 分钟,起来走走~')
|
|
752
|
+
try { pet?.act?.('hop'); pet?.setExpr?.('excited') } catch { /* ignore */ }
|
|
753
|
+
}, 25 * 60 * 1000)
|
|
754
|
+
}
|
|
755
|
+
const stopPomodoro = (manual) => {
|
|
756
|
+
if (!pomoTimer) {
|
|
757
|
+
if (manual) say('现在没有进行中的番茄钟呀')
|
|
758
|
+
return
|
|
759
|
+
}
|
|
760
|
+
window.clearTimeout(pomoTimer)
|
|
761
|
+
pomoTimer = 0
|
|
762
|
+
if (manual) say('好,番茄钟取消了~')
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
const S = () => Math.max(0.18, Math.min(1.6, (prefs.size || 190) / 256))
|
|
766
|
+
|
|
767
|
+
// 她能站的最低脚位:身体高度 ≈ size * 1.15,再留一点余量
|
|
768
|
+
const minFeet = () => Math.round((Number(prefs.size) > 0 ? Number(prefs.size) : 190) * 1.2) + 8
|
|
769
|
+
let seat = null // 坐下的时候临时把「地面」抬到那一条边
|
|
770
|
+
let looseGround = null // 被放到半空后,落点就是她新的地面(不坠落)
|
|
771
|
+
const bounds = () => ({
|
|
772
|
+
W: worldSize.w,
|
|
773
|
+
H: worldSize.h,
|
|
774
|
+
floorY:
|
|
775
|
+
typeof seat === 'number'
|
|
776
|
+
? seat
|
|
777
|
+
: typeof looseGround === 'number'
|
|
778
|
+
? looseGround
|
|
779
|
+
: worldSize.h - (Number(prefs.marginBottom) >= 0 ? Number(prefs.marginBottom) : 8),
|
|
780
|
+
S: S(),
|
|
781
|
+
})
|
|
782
|
+
|
|
783
|
+
const sendHit = (next) => {
|
|
784
|
+
if (next === inside) return
|
|
785
|
+
inside = next
|
|
786
|
+
desk.hit(next)
|
|
787
|
+
}
|
|
788
|
+
// 命中框交给主进程,由它轮询指针位置决定这一层要不要吃点击
|
|
789
|
+
let boxSentAt = 0
|
|
790
|
+
const unionBox = (a, b) => ({
|
|
791
|
+
x: Math.min(a.x, b.x),
|
|
792
|
+
y: Math.min(a.y, b.y),
|
|
793
|
+
w: Math.max(a.x + a.w, b.x + b.w) - Math.min(a.x, b.x),
|
|
794
|
+
h: Math.max(a.y + a.h, b.y + b.h) - Math.min(a.y, b.y),
|
|
795
|
+
})
|
|
796
|
+
const publishBox = (force) => {
|
|
797
|
+
const now = Date.now()
|
|
798
|
+
if (!force && now - boxSentAt < 260) return
|
|
799
|
+
boxSentAt = now
|
|
800
|
+
let box = hit
|
|
801
|
+
const extra = []
|
|
802
|
+
try {
|
|
803
|
+
// 分身各自的矩形也交给主进程:透明窗按「光标在哪个框里」决定接不接鼠标
|
|
804
|
+
for (const b of cloneBoxes()) extra.push(b)
|
|
805
|
+
// 输入框/菜单开着时把它们各自的矩形也交上去:透明窗只认这些框决定接不接鼠标
|
|
806
|
+
if (chatEl && !chatEl.classList.contains('hidden')) {
|
|
807
|
+
const cr = chatEl.getBoundingClientRect()
|
|
808
|
+
if (cr.width > 0 && cr.height > 0) extra.push({ x: cr.left, y: cr.top, w: cr.width, h: cr.height })
|
|
809
|
+
}
|
|
810
|
+
if (menuEl) {
|
|
811
|
+
const mr = menuEl.getBoundingClientRect()
|
|
812
|
+
if (mr.width > 0 && mr.height > 0) extra.push({ x: mr.left, y: mr.top, w: mr.width, h: mr.height })
|
|
813
|
+
}
|
|
814
|
+
} catch {
|
|
815
|
+
/* ignore */
|
|
816
|
+
}
|
|
817
|
+
try {
|
|
818
|
+
desk.hitbox([box, ...extra])
|
|
819
|
+
} catch {
|
|
820
|
+
/* ignore */
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
const inHit = (x, y) => x >= hit.x && y >= hit.y && x <= hit.x + hit.w && y <= hit.y + hit.h
|
|
825
|
+
|
|
826
|
+
/* ---------- 影分身:全真实例 ----------
|
|
827
|
+
每只分身就是一个完整的本体(kit.createBody + 独立 figure 实例):同一套模型与
|
|
828
|
+
引擎,真步态、真眨眼、真睡姿、真表情、真拖拽手感——和本体唯一的区别是:
|
|
829
|
+
不接 emit(没有碎碎念气泡),不参与图标互动,音效只放脚步声(限流防吵)。
|
|
830
|
+
渲染走本体同款 raster 路径(透明窗合成不了 GL 画布,见 createWhaleBody 处的
|
|
831
|
+
注释),帧率压到 12fps 压住读回开销。数量不加限制:点 x1 来 1 只、x10 来
|
|
832
|
+
10 只、x50 来 50 只,全真实例要多少来多少(用户确认不考虑 CPU)。 */
|
|
833
|
+
const CLONE_RASTER_FPS = 12 // 分身每秒最多转 12 帧(本体 24):小动作看起来依旧顺滑
|
|
834
|
+
let clones = [] // { bp(本体实例), layer(挂她自己的 svg.kit 的 fixed 层) }
|
|
835
|
+
let cloneFrozen = false // 兼容旧 act(cloneFreeze):为 true 时等同 cloneMode='frozen'
|
|
836
|
+
let cloneMode = 'free' // 分身自己的行为档位(只管分身,跟本体「原地待着/自由活动」互不影响):free 自由活动 / idle 原地待机 / frozen 立定不动
|
|
837
|
+
let cloneTarget = null // 右键菜单当前指向的分身
|
|
838
|
+
let cloneDrag = null // 正在被左键拖动的分身 { c, vx, vy, lt, lx, ly }
|
|
839
|
+
let cloneMenuAt = 0 // 上次右键弹分身菜单的时间(去抖:pointerdown 已弹过就不再重复弹)
|
|
840
|
+
let cloneStepAt = 0 // 脚步声限流的全局最小间隔
|
|
841
|
+
// 分身的容器:body 层 fixed(#stage 是 will-change:transform 的合成层,动态往里
|
|
842
|
+
// 加的覆盖层会被透明窗合成器整个丢掉——画布里有像素、屏幕上不显示)。插在
|
|
843
|
+
// #stage 之前:分身画在本体身后。
|
|
844
|
+
const cloneStage = document.createElement('div')
|
|
845
|
+
cloneStage.id = 'clone-stage'
|
|
846
|
+
cloneStage.style.cssText = 'position:fixed;left:0;top:0;pointer-events:none;width:100vw;height:100vh;'
|
|
847
|
+
document.body.insertBefore(cloneStage, document.getElementById('stage'))
|
|
848
|
+
// 脚步声限流:一群分身齐步走也不吵(90ms 全局最小间隔 + 45% 概率)
|
|
849
|
+
const stepSfx = () => {
|
|
850
|
+
const now = performance.now()
|
|
851
|
+
if (now - cloneStepAt < 90 || Math.random() > 0.45) return
|
|
852
|
+
cloneStepAt = now
|
|
853
|
+
chime('step')
|
|
854
|
+
}
|
|
855
|
+
// 分身跟随设置:只有明确按住本体的状态(原地待着/值日/睡觉/干活…)才按住分身;
|
|
856
|
+
// 「溜达」开关只管本体走不走动,不管分身——影分身之术召出来就是要满屏跑的
|
|
857
|
+
const cloneRoamMode = () => (!heldRoam() && cloneMode === 'free' ? 'free' : 'off')
|
|
858
|
+
const applyCloneRoam = () => {
|
|
859
|
+
const roam = cloneRoamMode()
|
|
860
|
+
for (const c of clones) {
|
|
861
|
+
try { c.bp.set({ roam }) } catch { /* ignore */ }
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
const applyCloneMode = () => {
|
|
865
|
+
const roam = cloneRoamMode()
|
|
866
|
+
for (const c of clones) {
|
|
867
|
+
try {
|
|
868
|
+
c.bp.set({ roam, still: cloneMode === 'frozen' })
|
|
869
|
+
} catch {
|
|
870
|
+
/* ignore */
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
// 分身当前的可视矩形(世界坐标):直接量她自己的 foreignObject——全真实例自己管
|
|
875
|
+
// 姿势(躺/坐/压扁/被拎),矩形跟着真实画面走,命中框所见即所得
|
|
876
|
+
const cloneRect = (c) => {
|
|
877
|
+
try {
|
|
878
|
+
const el = c.layer.querySelector('svg.kit foreignObject') || c.layer.querySelector('svg.kit image')
|
|
879
|
+
if (!el) return null
|
|
880
|
+
const r = el.getBoundingClientRect()
|
|
881
|
+
if (!r.width || !r.height) return null
|
|
882
|
+
return { x: r.left + origin.x, y: r.top + origin.y, w: r.width, h: r.height }
|
|
883
|
+
} catch {
|
|
884
|
+
return null
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
const cloneBoxes = () => clones.map(cloneRect).filter(Boolean)
|
|
888
|
+
const cloneAt = (x, y) => {
|
|
889
|
+
for (let i = clones.length - 1; i >= 0; i--) {
|
|
890
|
+
const r = cloneRect(clones[i])
|
|
891
|
+
if (r && x >= r.x && x <= r.x + r.w && y >= r.y && y <= r.y + r.h) return clones[i]
|
|
892
|
+
}
|
|
893
|
+
return null
|
|
894
|
+
}
|
|
895
|
+
const dismissClone = (c) => {
|
|
896
|
+
const i = clones.indexOf(c)
|
|
897
|
+
if (i < 0) return
|
|
898
|
+
clones.splice(i, 1)
|
|
899
|
+
try { c.bp.dispose() } catch { /* ignore */ }
|
|
900
|
+
c.layer.remove()
|
|
901
|
+
}
|
|
902
|
+
const dismissAllClones = () => {
|
|
903
|
+
const n = clones.length
|
|
904
|
+
while (clones.length) dismissClone(clones[0])
|
|
905
|
+
cloneTarget = null
|
|
906
|
+
cloneDrag = null
|
|
907
|
+
if (n) say('分身都收回来了')
|
|
908
|
+
}
|
|
909
|
+
const spawnClones = async (n) => {
|
|
910
|
+
if (!kit || !pack || !buildCloneBody) return
|
|
911
|
+
const count = Math.max(1, Math.round(Number(n) || 0))
|
|
912
|
+
const gy = bounds().floorY
|
|
913
|
+
const bx = hit ? hit.x + hit.w / 2 : worldSize.w - 220
|
|
914
|
+
for (let i = 0; i < count; i++) {
|
|
915
|
+
// 绕着本体扇形散开落位,避免全叠在本体脚边
|
|
916
|
+
const side = i % 2 === 0 ? 1 : -1
|
|
917
|
+
let x = bx + side * (90 + Math.random() * 560 + (i > 1 ? Math.random() * 320 : 0))
|
|
918
|
+
if (x < 60 || x > worldSize.w - 60) x = Math.random() * (worldSize.w - 120) + 60
|
|
919
|
+
const layer = document.createElement('div')
|
|
920
|
+
layer.style.cssText = 'position:fixed;left:0;top:0;pointer-events:none;width:100%;height:100%;'
|
|
921
|
+
cloneStage.appendChild(layer)
|
|
922
|
+
try {
|
|
923
|
+
const bp = await buildCloneBody(layer, {
|
|
924
|
+
x: Math.round(x),
|
|
925
|
+
y: gy,
|
|
926
|
+
facing: Math.random() < 0.5 ? -1 : 1,
|
|
927
|
+
})
|
|
928
|
+
bp.set({ roam: cloneRoamMode(), still: cloneMode === 'frozen' })
|
|
929
|
+
clones.push({ bp, layer })
|
|
930
|
+
} catch (e) {
|
|
931
|
+
layer.remove()
|
|
932
|
+
try { report('clone-live-err', { m: String((e && e.message) || e) }) } catch { /* ignore */ }
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
say('影分身之术!' + clones.length + ' 只就位')
|
|
936
|
+
try { publishBox(true) } catch { /* ignore */ }
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/* ---------- 菜单 / 输入框 ---------- */
|
|
940
|
+
let menuEl = null
|
|
941
|
+
const closeMenu = () => {
|
|
942
|
+
if (menuWatch) {
|
|
943
|
+
document.removeEventListener('pointerdown', menuWatch, true)
|
|
944
|
+
menuWatch = null
|
|
945
|
+
}
|
|
946
|
+
if (menuEl) {
|
|
947
|
+
menuEl.remove()
|
|
948
|
+
menuEl = null
|
|
949
|
+
}
|
|
950
|
+
try {
|
|
951
|
+
desk.menu(false)
|
|
952
|
+
} catch {
|
|
953
|
+
/* ignore */
|
|
954
|
+
}
|
|
955
|
+
try {
|
|
956
|
+
pet?.set?.({ dialogOpen: false })
|
|
957
|
+
applyRoam()
|
|
958
|
+
} catch {
|
|
959
|
+
/* ignore */
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
const openApp = (target) => {
|
|
963
|
+
fetch('/dsh-coo-pet/open', {
|
|
964
|
+
method: 'POST',
|
|
965
|
+
headers: { 'content-type': 'application/json' },
|
|
966
|
+
body: JSON.stringify({ target }),
|
|
967
|
+
}).catch(() => {})
|
|
968
|
+
}
|
|
969
|
+
// 一键复位:按名字把她搬乱的图标写回最新一档快照并弹出该档;连按可连撤
|
|
970
|
+
const restoreIconsAll = async () => {
|
|
971
|
+
iconWalk = null
|
|
972
|
+
carry = null
|
|
973
|
+
hideCarry()
|
|
974
|
+
try { pet?.stopWalk?.() } catch { /* ignore */ }
|
|
975
|
+
let ok = false
|
|
976
|
+
try {
|
|
977
|
+
const r = await desk.restoreIcons?.()
|
|
978
|
+
ok = !!(r && r.ok)
|
|
979
|
+
} catch { /* ignore */ }
|
|
980
|
+
iconCache = { at: 0, data: [] }
|
|
981
|
+
say(ok ? '图标归位啦' : '没有可用的图标快照')
|
|
982
|
+
return ok
|
|
983
|
+
}
|
|
984
|
+
// 一键全复位:把历史栈里的快照一档档全部撤光,回到她第一次搬乱前的样子
|
|
985
|
+
const restoreIconsAllEvery = async () => {
|
|
986
|
+
try { report('restore-all-call', { hasApi: typeof desk.restoreIconsAll }) } catch { /* ignore */ }
|
|
987
|
+
iconWalk = null
|
|
988
|
+
carry = null
|
|
989
|
+
hideCarry()
|
|
990
|
+
try { pet?.stopWalk?.() } catch { /* ignore */ }
|
|
991
|
+
let r = null
|
|
992
|
+
try {
|
|
993
|
+
r = await desk.restoreIconsAll?.()
|
|
994
|
+
} catch (e) {
|
|
995
|
+
try { report('restore-all-err', { m: String((e && e.message) || e) }) } catch { /* ignore */ }
|
|
996
|
+
}
|
|
997
|
+
try { report('restore-all-res', { ok: !!(r && r.ok), restored: (r && r.restored) || 0, err: (r && r.error) || '' }) } catch { /* ignore */ }
|
|
998
|
+
iconCache = { at: 0, data: [] }
|
|
999
|
+
say(r && r.ok ? '全部归位啦,回到最初的样子' : '没有可用的图标快照')
|
|
1000
|
+
return !!(r && r.ok)
|
|
1001
|
+
}
|
|
1002
|
+
const MENU_NAMES = {
|
|
1003
|
+
open: '打开DSH',
|
|
1004
|
+
input: '输入…',
|
|
1005
|
+
restart: '重启DSH',
|
|
1006
|
+
reset: '图标复位',
|
|
1007
|
+
resetAll: '一键全复位',
|
|
1008
|
+
clone: '影分身',
|
|
1009
|
+
stay: '原地待着',
|
|
1010
|
+
free: '自由活动',
|
|
1011
|
+
duty: '安静模式',
|
|
1012
|
+
actions: '特殊动作',
|
|
1013
|
+
look: '换形象',
|
|
1014
|
+
outfit: '换衣服',
|
|
1015
|
+
none: '藏起来',
|
|
1016
|
+
}
|
|
1017
|
+
const menuItems = () => {
|
|
1018
|
+
// 老版短排序兑底:旧配置只有五项(open,input,voice,close,none),换形象/换衣服这些
|
|
1019
|
+
// 新功能永远出不来——检测到就直接换成新版全项;自定义过的排序不动
|
|
1020
|
+
const LEGACY = 'open,input,voice,close,none'
|
|
1021
|
+
let orderStr = String((prefs && prefs.menuOrder) || '')
|
|
1022
|
+
if (!orderStr.trim() || orderStr.replace(/\s/g, '') === LEGACY) {
|
|
1023
|
+
orderStr = 'open,input,restart,reset,resetAll,stay,free,duty,actions,look,outfit,clone,none'
|
|
1024
|
+
}
|
|
1025
|
+
let order = orderStr
|
|
1026
|
+
.split(',')
|
|
1027
|
+
.map((s) => s.trim())
|
|
1028
|
+
.filter((id) => MENU_NAMES[id])
|
|
1029
|
+
// 新功能项补位:老自定义排序里没有的新项,插到「藏起来」前面
|
|
1030
|
+
for (const nid of ['resetAll', 'clone']) {
|
|
1031
|
+
if (!order.includes(nid)) {
|
|
1032
|
+
const idx = order.indexOf('none')
|
|
1033
|
+
if (idx >= 0) order.splice(idx, 0, nid)
|
|
1034
|
+
else order.push(nid)
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
// 排序以设置页保存的 menuOrder 为唯一来源:删了就是删了,要找回在设置页点「加回」
|
|
1038
|
+
const seen = {}
|
|
1039
|
+
const out = []
|
|
1040
|
+
for (const id of order) {
|
|
1041
|
+
if (seen[id]) continue
|
|
1042
|
+
seen[id] = true
|
|
1043
|
+
if (id === 'open') out.push(['打开DSH', () => openApp('dsh')])
|
|
1044
|
+
else if (id === 'input') out.push(['输入…', () => openChat()])
|
|
1045
|
+
else if (id === 'restart') out.push(['重启DSH', () => {
|
|
1046
|
+
closeMenu()
|
|
1047
|
+
say('我去重启啦,马上回来~')
|
|
1048
|
+
window.setTimeout(async () => {
|
|
1049
|
+
try { await desk.restartDsh?.() } catch { /* 重启脚本接管 */ }
|
|
1050
|
+
}, 1200)
|
|
1051
|
+
}])
|
|
1052
|
+
else if (id === 'reset') out.push(['图标复位', () => { restoreIconsAll(); closeMenu() }])
|
|
1053
|
+
else if (id === 'resetAll') out.push(['一键全复位', () => { restoreIconsAllEvery(); closeMenu() }])
|
|
1054
|
+
else if (id === 'stay') out.push(['原地待着', () => { setStay(true); closeMenu() }])
|
|
1055
|
+
else if (id === 'free') out.push(['自由活动', () => { setStay(false); closeMenu() }])
|
|
1056
|
+
else if (id === 'duty') out.push([offDuty ? '关闭安静模式' : '安静模式', () => {
|
|
1057
|
+
closeMenu()
|
|
1058
|
+
if (!offDuty) {
|
|
1059
|
+
say('好,那我安静会儿~')
|
|
1060
|
+
setOffDuty(true)
|
|
1061
|
+
} else {
|
|
1062
|
+
setOffDuty(false)
|
|
1063
|
+
say('安静模式关闭,我又活蹦乱跳咯!')
|
|
1064
|
+
}
|
|
1065
|
+
}])
|
|
1066
|
+
else if (id === 'actions') out.push(['特殊动作›', () => openMenu(menuAnchor.x, menuAnchor.y, 'actions')])
|
|
1067
|
+
else if (id === 'look') out.push(['换形象›', () => openMenu(menuAnchor.x, menuAnchor.y, 'look')])
|
|
1068
|
+
else if (id === 'outfit') out.push(['换衣服›', () => openMenu(menuAnchor.x, menuAnchor.y, 'outfit')])
|
|
1069
|
+
else if (id === 'clone') out.push(['影分身›', () => openMenu(menuAnchor.x, menuAnchor.y, 'clones')])
|
|
1070
|
+
else if (id === 'none') out.push(['藏起来', () => setDisplay('none')])
|
|
1071
|
+
}
|
|
1072
|
+
return out
|
|
1073
|
+
}
|
|
1074
|
+
/* ---------- 换形象 / 换衣服:改 prefs 后页面会自动重载换装 ---------- */
|
|
1075
|
+
const LOOKS = [
|
|
1076
|
+
['deepseek', '深蓝经典'], ['claude', '橘色'], ['chatgpt', '青绿'], ['gemini', '蓝白'],
|
|
1077
|
+
['kimi', '银灰'], ['qwen', '紫调'], ['minimax', '暖橙'], ['harness', '暗金'],
|
|
1078
|
+
]
|
|
1079
|
+
const OUTFITS = [['maid', '女仆装'], ['cape', '披风'], ['crew', '水手服']]
|
|
1080
|
+
const lookItems = () => LOOKS.map(([id, label]) => [
|
|
1081
|
+
(((prefs.look || 'deepseek') === id ? '· ' : '') + label + '(' + id + ')'),
|
|
1082
|
+
() => { savePrefs({ look: id }); closeMenu(); say('换件新衣裳~') },
|
|
1083
|
+
])
|
|
1084
|
+
const outfitItems = () => OUTFITS.map(([id, label]) => [
|
|
1085
|
+
(((prefs.outfit || 'maid') === id ? '· ' : '') + label),
|
|
1086
|
+
() => { savePrefs({ outfit: id }); closeMenu(); say('换件新衣裳~') },
|
|
1087
|
+
])
|
|
1088
|
+
// 切分身行为档位:只动分身,本体照旧(她的「原地待着/自由活动」是另一套)
|
|
1089
|
+
const setCloneMode = (m) => {
|
|
1090
|
+
cloneMode = m === 'idle' || m === 'frozen' ? m : 'free'
|
|
1091
|
+
applyCloneMode()
|
|
1092
|
+
try { say(cloneMode === 'free' ? '分身自由活动~' : cloneMode === 'idle' ? '分身原地待机(还喘气呢)' : '分身都定格了') } catch { /* ignore */ }
|
|
1093
|
+
}
|
|
1094
|
+
const cloneSpawnItems = () => [
|
|
1095
|
+
['x1', () => { closeMenu(); spawnClones(1) }],
|
|
1096
|
+
['x10', () => { closeMenu(); spawnClones(10) }],
|
|
1097
|
+
['x50', () => { closeMenu(); spawnClones(50) }],
|
|
1098
|
+
['取消分身', () => { closeMenu(); dismissAllClones() }],
|
|
1099
|
+
]
|
|
1100
|
+
const cloneMenuItems = () => {
|
|
1101
|
+
const one = cloneTarget
|
|
1102
|
+
return [
|
|
1103
|
+
['解除分身', () => {
|
|
1104
|
+
if (one) dismissClone(one)
|
|
1105
|
+
closeMenu()
|
|
1106
|
+
}],
|
|
1107
|
+
['解除全部分身', () => { dismissAllClones(); closeMenu() }],
|
|
1108
|
+
]
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
/* ---------- 动作 / 表情:引擎里现成但一直没入口的一批 ---------- */
|
|
1112
|
+
const ACTIONS = [
|
|
1113
|
+
['点头', 'nod'], ['摇头', 'shake'], ['转圈', 'spin'], ['挥手', 'wave'], ['鞠躬', 'bow'],
|
|
1114
|
+
['发抖', 'shiver'], ['扑腾', 'flap'], ['跳舞', 'dance'], ['晕一下', 'dizzy'], ['原地跳', 'hop'],
|
|
1115
|
+
['跳一下', 'jump'], ['张望', 'look'], ['转个身', 'turn'], ['坐下', 'sit'], ['打个盹', 'sleep'],
|
|
1116
|
+
]
|
|
1117
|
+
const EXPRESSIONS = [
|
|
1118
|
+
['开心', 'happy'], ['眨眼', 'wink'], ['爱心眼', 'love'], ['害羞', 'shy'], ['惊讶', 'surprised'],
|
|
1119
|
+
['生气', 'angry'], ['难过', 'sad'], ['犯困', 'sleepy'], ['思考', 'thinking'], ['得意', 'smug'],
|
|
1120
|
+
['嘟嘴', 'pout'], ['担心', 'worried'], ['认真', 'determined'], ['慌张', 'flustered'], ['吓到', 'scared'],
|
|
1121
|
+
['兴奋', 'excited'], ['掉眼泪', 'cry'], ['疑惑', 'confused'],
|
|
1122
|
+
]
|
|
1123
|
+
const performAction = (kind, id) => {
|
|
1124
|
+
closeMenu()
|
|
1125
|
+
try {
|
|
1126
|
+
if (kind === 'expr') pet?.setExpr?.(id)
|
|
1127
|
+
else if (pet?.act?.(id) === false) say('现在做不了这个动作')
|
|
1128
|
+
} catch {
|
|
1129
|
+
/* ignore */
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
const actionItems = () => {
|
|
1133
|
+
const out = [
|
|
1134
|
+
['随机来一个', () => {
|
|
1135
|
+
const pool = []
|
|
1136
|
+
for (const [, id] of ACTIONS) pool.push(['act', id])
|
|
1137
|
+
for (const [, id] of EXPRESSIONS) pool.push(['expr', id])
|
|
1138
|
+
const pick = pool[Math.floor(Math.random() * pool.length)]
|
|
1139
|
+
performAction(pick[0], pick[1])
|
|
1140
|
+
}],
|
|
1141
|
+
]
|
|
1142
|
+
for (const [label, id] of ACTIONS) out.push([label, () => performAction('act', id)])
|
|
1143
|
+
for (const [label, id] of EXPRESSIONS) out.push(['表情' + label, () => performAction('expr', id)])
|
|
1144
|
+
return out
|
|
1145
|
+
}
|
|
1146
|
+
const savePrefs = (patch) => {
|
|
1147
|
+
Object.assign(prefs, patch)
|
|
1148
|
+
fetch('/dsh-coo-pet/prefs', {
|
|
1149
|
+
method: 'POST',
|
|
1150
|
+
headers: { 'content-type': 'application/json' },
|
|
1151
|
+
body: JSON.stringify(patch),
|
|
1152
|
+
}).catch(() => {})
|
|
1153
|
+
}
|
|
1154
|
+
const zhVoices = () => {
|
|
1155
|
+
try {
|
|
1156
|
+
const all = window.speechSynthesis ? window.speechSynthesis.getVoices() : []
|
|
1157
|
+
return all.filter((v) => /^(zh|cmn)/i.test(v.lang || '')).slice(0, 6)
|
|
1158
|
+
} catch {
|
|
1159
|
+
return []
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
const voiceItems = () => {
|
|
1163
|
+
const out = [
|
|
1164
|
+
[(prefs.voiceMode !== 'tts' ? '· ' : '') + '咿呀声(她的音库)', () => { savePrefs({ voiceMode: 'babble' }); closeMenu() }],
|
|
1165
|
+
[(prefs.voiceMode === 'tts' ? '· ' : '') + '系统朗读', () => { savePrefs({ voiceMode: 'tts' }); closeMenu() }],
|
|
1166
|
+
]
|
|
1167
|
+
for (const v of zhVoices()) {
|
|
1168
|
+
out.push([v.name, () => { savePrefs({ voiceMode: 'tts', voiceName: v.name }); closeMenu() }])
|
|
1169
|
+
}
|
|
1170
|
+
if (out.length <= 2) out.push(['(系统里没有中文音色)', () => closeMenu()])
|
|
1171
|
+
return out
|
|
1172
|
+
}
|
|
1173
|
+
const setDisplay = (value) => {
|
|
1174
|
+
fetch('/dsh-coo-pet/prefs', {
|
|
1175
|
+
method: 'POST',
|
|
1176
|
+
headers: { 'content-type': 'application/json' },
|
|
1177
|
+
body: JSON.stringify({ display: value }),
|
|
1178
|
+
}).catch(() => {})
|
|
1179
|
+
if (value === 'none') desk.hit(false)
|
|
1180
|
+
}
|
|
1181
|
+
let menuWatch = null
|
|
1182
|
+
let menuAnchor = { x: 0, y: 0 }
|
|
1183
|
+
const openMenu = (x, y, view = 'main') => {
|
|
1184
|
+
try { report('menu-open', { view, x: Math.round(x), y: Math.round(y) }) } catch { /* ignore */ }
|
|
1185
|
+
// 换视图时沿用当前列表的位置(拖过就不弹回她头顶)
|
|
1186
|
+
const carried = menuEl ? { x: parseFloat(menuEl.style.left) || 0, y: parseFloat(menuEl.style.top) || 0 } : null
|
|
1187
|
+
closeMenu()
|
|
1188
|
+
menuAnchor = { x, y }
|
|
1189
|
+
// 打开列表时她原地等着,别乱跑(roam 'off' 止走动,dialogOpen 止自选动作)
|
|
1190
|
+
try {
|
|
1191
|
+
pet?.set?.({ roam: 'off', dialogOpen: true })
|
|
1192
|
+
pet?.stopWalk?.()
|
|
1193
|
+
} catch {
|
|
1194
|
+
/* ignore */
|
|
1195
|
+
}
|
|
1196
|
+
menuWatch = (event) => {
|
|
1197
|
+
if (menuEl && menuEl.contains(event.target)) return
|
|
1198
|
+
closeMenu()
|
|
1199
|
+
}
|
|
1200
|
+
setTimeout(() => document.addEventListener('pointerdown', menuWatch, true), 0)
|
|
1201
|
+
// 列表开着的时候窗口不吃「穿透」,否则点外面点不到这边、菜单关不掉
|
|
1202
|
+
try {
|
|
1203
|
+
desk.menu(true)
|
|
1204
|
+
} catch {
|
|
1205
|
+
/* ignore */
|
|
1206
|
+
}
|
|
1207
|
+
const el = document.createElement('div')
|
|
1208
|
+
el.className = 'menu'
|
|
1209
|
+
if (carried) {
|
|
1210
|
+
el.style.left = carried.x + 'px'
|
|
1211
|
+
el.style.top = carried.y + 'px'
|
|
1212
|
+
} else {
|
|
1213
|
+
el.style.left = Math.max(8, Math.min(window.innerWidth - 168, toLocalX(x))) + 'px'
|
|
1214
|
+
el.style.top = Math.max(8, Math.min(window.innerHeight - 230, toLocalY(y))) + 'px'
|
|
1215
|
+
}
|
|
1216
|
+
const head = document.createElement('div')
|
|
1217
|
+
head.className = 'menu-head'
|
|
1218
|
+
const VIEW_HEADS = { voice: '‹换声音', actions: '‹特殊动作', look: '‹换形象', outfit: '‹换衣服', clones: '‹影分身', clone: '‹返回' }
|
|
1219
|
+
head.textContent = view === 'main' ? String((prefs && prefs.petName) || '你的鱼') : (VIEW_HEADS[view] || '‹ 返回')
|
|
1220
|
+
head.style.cursor = 'grab'
|
|
1221
|
+
head.title = '按住拖动列表'
|
|
1222
|
+
head.addEventListener('click', (event) => {
|
|
1223
|
+
event.stopPropagation()
|
|
1224
|
+
if (menuDrag && menuDrag.moved) return
|
|
1225
|
+
if (view !== 'main') openMenu(menuAnchor.x, menuAnchor.y, 'main')
|
|
1226
|
+
})
|
|
1227
|
+
head.addEventListener('pointerdown', (event) => {
|
|
1228
|
+
if (event.button !== 0) return
|
|
1229
|
+
menuDrag = { sx: event.clientX, sy: event.clientY, ox: parseFloat(el.style.left) || 0, oy: parseFloat(el.style.top) || 0, moved: false }
|
|
1230
|
+
})
|
|
1231
|
+
el.appendChild(head)
|
|
1232
|
+
const rows = view === 'voice' ? voiceItems() : view === 'actions' ? actionItems() : view === 'look' ? lookItems() : view === 'outfit' ? outfitItems() : view === 'clones' ? cloneSpawnItems() : view === 'clone' ? cloneMenuItems() : menuItems()
|
|
1233
|
+
for (const [label, run] of rows) {
|
|
1234
|
+
const item = document.createElement('div')
|
|
1235
|
+
item.className = 'menu-item'
|
|
1236
|
+
item.textContent = label
|
|
1237
|
+
item.addEventListener('click', (event) => {
|
|
1238
|
+
event.stopPropagation()
|
|
1239
|
+
run()
|
|
1240
|
+
})
|
|
1241
|
+
el.appendChild(item)
|
|
1242
|
+
}
|
|
1243
|
+
if (rows.length > 12) {
|
|
1244
|
+
el.style.maxHeight = Math.round(window.innerHeight * 0.72) + 'px'
|
|
1245
|
+
el.style.overflowY = 'auto'
|
|
1246
|
+
}
|
|
1247
|
+
document.body.appendChild(el)
|
|
1248
|
+
menuEl = el
|
|
1249
|
+
// 按实际尺寸防出屏:屏幕边缘也保证完整显示(覆盖旧的高度估算)
|
|
1250
|
+
clampMenuToScreen(el)
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
// 列表拖动状态:按住标题栏拖,移动超过 4px 才算拖(不误伤点击返回)
|
|
1254
|
+
let menuDrag = null
|
|
1255
|
+
const clampMenuToScreen = (el) => {
|
|
1256
|
+
const w = el.offsetWidth
|
|
1257
|
+
const h = el.offsetHeight
|
|
1258
|
+
el.style.left = Math.max(8, Math.min(window.innerWidth - w - 8, parseFloat(el.style.left))) + 'px'
|
|
1259
|
+
el.style.top = Math.max(8, Math.min(window.innerHeight - h - 8, parseFloat(el.style.top))) + 'px'
|
|
1260
|
+
}
|
|
1261
|
+
document.addEventListener('pointermove', (event) => {
|
|
1262
|
+
if (!menuEl || !menuDrag) return
|
|
1263
|
+
const dx = event.clientX - menuDrag.sx
|
|
1264
|
+
const dy = event.clientY - menuDrag.sy
|
|
1265
|
+
if (!menuDrag.moved && Math.abs(dx) + Math.abs(dy) < 4) return
|
|
1266
|
+
menuDrag.moved = true
|
|
1267
|
+
menuEl.style.left = Math.max(8, Math.min(window.innerWidth - menuEl.offsetWidth - 8, menuDrag.ox + dx)) + 'px'
|
|
1268
|
+
menuEl.style.top = Math.max(8, Math.min(window.innerHeight - menuEl.offsetHeight - 8, menuDrag.oy + dy)) + 'px'
|
|
1269
|
+
})
|
|
1270
|
+
document.addEventListener('pointerup', (event) => {
|
|
1271
|
+
if (!menuDrag) return
|
|
1272
|
+
const wasDrag = menuDrag.moved
|
|
1273
|
+
menuDrag = null
|
|
1274
|
+
if (wasDrag && menuEl) {
|
|
1275
|
+
event.stopPropagation()
|
|
1276
|
+
menuEl.style.cursor = ''
|
|
1277
|
+
}
|
|
1278
|
+
}, true)
|
|
1279
|
+
|
|
1280
|
+
const openChat = (wantFocus = true) => {
|
|
1281
|
+
closeMenu()
|
|
1282
|
+
try {
|
|
1283
|
+
pet?.set?.({ roam: 'off', dialogOpen: true })
|
|
1284
|
+
pet?.stopWalk?.()
|
|
1285
|
+
} catch {
|
|
1286
|
+
/* ignore */
|
|
1287
|
+
}
|
|
1288
|
+
chatEl.classList.remove('hidden')
|
|
1289
|
+
const box = hit
|
|
1290
|
+
chatEl.style.left = Math.max(8, Math.min(window.innerWidth - 280, toLocalX(box.x + box.w / 2 - 134))) + 'px'
|
|
1291
|
+
chatEl.style.top = Math.max(8, Math.min(window.innerHeight - 120, toLocalY(box.y) - 92)) + 'px'
|
|
1292
|
+
publishBox(true)
|
|
1293
|
+
if (wantFocus === false) return
|
|
1294
|
+
// 借键盘:窗口平时 focusable:false,打字前临时要焦点
|
|
1295
|
+
try {
|
|
1296
|
+
desk?.chatFocus?.(true)
|
|
1297
|
+
} catch {
|
|
1298
|
+
/* ignore */
|
|
1299
|
+
}
|
|
1300
|
+
chatText.focus()
|
|
1301
|
+
report('dbg-chat-open', {})
|
|
1302
|
+
}
|
|
1303
|
+
const closeChat = () => {
|
|
1304
|
+
chatEl.classList.add('hidden')
|
|
1305
|
+
// 关一次就清空:不保留上次输入的内容
|
|
1306
|
+
try {
|
|
1307
|
+
chatText.value = ''
|
|
1308
|
+
chatText.placeholder = '跟她说一句…'
|
|
1309
|
+
} catch {
|
|
1310
|
+
/* ignore */
|
|
1311
|
+
}
|
|
1312
|
+
try {
|
|
1313
|
+
desk?.chatFocus?.(false)
|
|
1314
|
+
} catch {
|
|
1315
|
+
/* ignore */
|
|
1316
|
+
}
|
|
1317
|
+
try {
|
|
1318
|
+
pet?.set?.({ dialogOpen: false })
|
|
1319
|
+
applyRoam()
|
|
1320
|
+
} catch {
|
|
1321
|
+
/* ignore */
|
|
1322
|
+
}
|
|
1323
|
+
publishBox(true)
|
|
1324
|
+
}
|
|
1325
|
+
document.getElementById('chat-close').addEventListener('click', closeChat)
|
|
1326
|
+
document.getElementById('chat-send').addEventListener('click', () => submitChat())
|
|
1327
|
+
chatText.addEventListener('keydown', (event) => {
|
|
1328
|
+
event.stopPropagation()
|
|
1329
|
+
// 诊断:确认按键真的到达输入框(遥测只留最后一条)
|
|
1330
|
+
report('dbg-chat-key', { key: event.key, composing: event.isComposing ? 1 : 0 })
|
|
1331
|
+
// 输入法选字/确认用的 Enter(isComposing)不能当成发送
|
|
1332
|
+
if (event.isComposing || event.keyCode === 229) return
|
|
1333
|
+
if (event.key === 'Enter') submitChat()
|
|
1334
|
+
if (event.key === 'Escape') closeChat()
|
|
1335
|
+
})
|
|
1336
|
+
// 点对话框任意处都补借一次键盘:窗口平时 focusable:false,
|
|
1337
|
+
// 焦点被别的窗口抢走后 Enter 会失灵——点一下输入框就恢复
|
|
1338
|
+
chatEl.addEventListener('pointerdown', () => {
|
|
1339
|
+
try {
|
|
1340
|
+
desk.chatFocus?.(true)
|
|
1341
|
+
} catch {
|
|
1342
|
+
/* ignore */
|
|
1343
|
+
}
|
|
1344
|
+
})
|
|
1345
|
+
/* ---------- 指令开软件:识别「打开X」,小跑过去戳一下,然后真的启动 ---------- */
|
|
1346
|
+
let thinkTimer = null
|
|
1347
|
+
// 「等回复」也原地待着:想着的时候不开新步子,想完(或 45 秒安全阀到)恢复
|
|
1348
|
+
const clearThinking = () => {
|
|
1349
|
+
thinkingNow = false
|
|
1350
|
+
try { pet?.set?.({ thinking: false }) } catch { /* ignore */ }
|
|
1351
|
+
applyRoam()
|
|
1352
|
+
}
|
|
1353
|
+
const startThinking = () => {
|
|
1354
|
+
thinkingNow = true
|
|
1355
|
+
try {
|
|
1356
|
+
pet?.set?.({ thinking: true, roam: 'off' })
|
|
1357
|
+
// 想的时候也不走:正在走的路立刻站住(正事在办时除外)
|
|
1358
|
+
if (!launchWalk && !iconWalk && !seatWalk) pet?.stopWalk?.()
|
|
1359
|
+
} catch {
|
|
1360
|
+
/* ignore */
|
|
1361
|
+
}
|
|
1362
|
+
window.clearTimeout(thinkTimer)
|
|
1363
|
+
// 安全阀:最多想 45 秒,回不来就自己缓过神
|
|
1364
|
+
thinkTimer = window.setTimeout(clearThinking, 45000)
|
|
1365
|
+
}
|
|
1366
|
+
const LAUNCH_RE = /^(?:帮我|麻烦|请)?(?:打开|启动|运行|开一下|开个|开启)\s*([^,。!?\s]{1,24}?)\s*(?:软件|程序|应用)?[吧呀呢]?$/
|
|
1367
|
+
const performTapAndLaunch = (name) => {
|
|
1368
|
+
try { pet?.act?.('hop') } catch { /* ignore */ }
|
|
1369
|
+
try { pet?.setExpr?.('happy') } catch { /* ignore */ }
|
|
1370
|
+
Promise.resolve()
|
|
1371
|
+
.then(() => desk.launch(name))
|
|
1372
|
+
.then((res) => {
|
|
1373
|
+
if (res && res.ok) say('打开咯:' + (res.app || name))
|
|
1374
|
+
else say('没找到「' + name + '」,我认不出这个名字')
|
|
1375
|
+
})
|
|
1376
|
+
.catch(() => say('打开失败了,你再试试?'))
|
|
1377
|
+
}
|
|
1378
|
+
const launchTheater = async (name) => {
|
|
1379
|
+
// 菜单/输入框开着就不做带行走的开场(她得原地待着),直接启动
|
|
1380
|
+
// 注意:服务端 busy(DSH 会话在跑)不拦这里——她正是在执行用户的开软件指令
|
|
1381
|
+
if (!pet || stayMode || dragging || menuEl || !(chatEl && chatEl.classList.contains('hidden'))) {
|
|
1382
|
+
report('dbg-launch-skip', { why: !pet ? 'no-pet' : stayMode ? 'stayMode' : dragging ? 'dragging' : menuEl ? 'menu' : 'chat-open', name })
|
|
1383
|
+
performTapAndLaunch(name)
|
|
1384
|
+
return
|
|
1385
|
+
}
|
|
1386
|
+
// 先在桌面上找这个名字的图标:找到了就走到它旁边,站定戳一下再启动
|
|
1387
|
+
let icon = null
|
|
1388
|
+
try {
|
|
1389
|
+
const res = await desk.icons()
|
|
1390
|
+
const list = res && res.ok && Array.isArray(res.data) ? res.data : []
|
|
1391
|
+
const want = String(name || '').toLowerCase()
|
|
1392
|
+
for (const it of list) {
|
|
1393
|
+
const nm = String(it.name || '').replace(/\.lnk$/i, '').toLowerCase()
|
|
1394
|
+
if (!nm) continue
|
|
1395
|
+
if ((nm === want || nm.includes(want) || want.includes(nm)) && (!icon || nm.length < icon._nm.length)) {
|
|
1396
|
+
icon = { ...it, _nm: nm }
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
report('dbg-launch-icons', { name, count: list.length, matched: icon ? icon.name : null, wx: icon ? Math.max(70, Math.min(worldSize.w - 70, icon.x + 85)) : null, wy: icon ? Math.max(minFeet(), Math.min(bounds().floorY, icon.y + 92)) : null })
|
|
1400
|
+
} catch (err) {
|
|
1401
|
+
report('dbg-launch-icons-err', { name, msg: String(err && err.message || err) })
|
|
1402
|
+
}
|
|
1403
|
+
const id = 'launch-' + Math.round(Math.random() * 1e6)
|
|
1404
|
+
if (icon) {
|
|
1405
|
+
// 站到图标旁边(贴右沿、脚踩图标格子底),够不着就贴边(图标坐标已是 CSS 像素,格子约 77×96)
|
|
1406
|
+
const ix = Math.max(70, Math.min(worldSize.w - 70, icon.x + 85))
|
|
1407
|
+
const iy = Math.max(minFeet(), Math.min(bounds().floorY, icon.y + 92))
|
|
1408
|
+
const okWalk = pet.walkTo?.(ix, true, id, iy)
|
|
1409
|
+
report('dbg-launch-walk', { toIcon: true, ix, iy, ok: okWalk === true, name })
|
|
1410
|
+
if (okWalk) {
|
|
1411
|
+
launchWalk = { id, name }
|
|
1412
|
+
say('好嘞,去开' + name)
|
|
1413
|
+
return
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
// 图标没找到:走到屏幕下沿(任务栏方向)戳一下
|
|
1417
|
+
const me = pet.layout?.()
|
|
1418
|
+
const tx = Math.max(60, Math.min(worldSize.w - 60, Math.round((me ? me.x : worldSize.w / 2) + (Math.random() < 0.5 ? -220 : 220))))
|
|
1419
|
+
const okFall = pet.walkTo?.(tx, true, id, worldSize.h - 8)
|
|
1420
|
+
report('dbg-launch-walk', { toIcon: false, tx, ok: okFall === true, name })
|
|
1421
|
+
if (okFall) {
|
|
1422
|
+
launchWalk = { id, name }
|
|
1423
|
+
say('好嘞,去开' + name)
|
|
1424
|
+
} else {
|
|
1425
|
+
performTapAndLaunch(name)
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
const submitChat = () => {
|
|
1430
|
+
const text = String(chatText.value || '').trim()
|
|
1431
|
+
// 诊断:确认提交函数被调到、拿到的是什么文本
|
|
1432
|
+
report('dbg-chat-submit', { text: text.slice(0, 30), len: text.length })
|
|
1433
|
+
if (!text) return
|
|
1434
|
+
chatText.value = ''
|
|
1435
|
+
// 先拦一道本地指令:打开某软件就不用麻烦 AI 了
|
|
1436
|
+
const m = text.match(LAUNCH_RE)
|
|
1437
|
+
if (m && m[1]) {
|
|
1438
|
+
closeChat()
|
|
1439
|
+
launchTheater(m[1].trim())
|
|
1440
|
+
return
|
|
1441
|
+
}
|
|
1442
|
+
// 本地快捷指令:不麻烦 AI,她自己做(和「打开XX」同一层拦截)
|
|
1443
|
+
const cmd = text.replace(/\s+/g, '')
|
|
1444
|
+
if (/^(?:开启)?安静模式$/.test(cmd)) {
|
|
1445
|
+
closeChat()
|
|
1446
|
+
if (!offDuty) {
|
|
1447
|
+
say('好,那我安静会儿~')
|
|
1448
|
+
setOffDuty(true)
|
|
1449
|
+
}
|
|
1450
|
+
return
|
|
1451
|
+
}
|
|
1452
|
+
if (/^(?:关闭|取消|解除)安静模式$/.test(cmd)) {
|
|
1453
|
+
closeChat()
|
|
1454
|
+
if (offDuty) {
|
|
1455
|
+
setOffDuty(false)
|
|
1456
|
+
say('安静模式关闭,我又活蹦乱跳咯!')
|
|
1457
|
+
}
|
|
1458
|
+
return
|
|
1459
|
+
}
|
|
1460
|
+
if (/^(?:开始|启动)?番茄钟$/.test(cmd)) {
|
|
1461
|
+
closeChat()
|
|
1462
|
+
startPomodoro()
|
|
1463
|
+
return
|
|
1464
|
+
}
|
|
1465
|
+
if (/^(?:结束|停止|取消)番茄钟$/.test(cmd)) {
|
|
1466
|
+
closeChat()
|
|
1467
|
+
stopPomodoro(true)
|
|
1468
|
+
return
|
|
1469
|
+
}
|
|
1470
|
+
// 插入会话优先:填了 Session ID 就发进那个会话,没填才跟当前会话
|
|
1471
|
+
// 只认绑定的会话:填了谁就问谁,绝不另找会话(问题串到别的会话里回答就会被桥接走);
|
|
1472
|
+
// 不填不说话——提醒去设置里填
|
|
1473
|
+
const sessionId = String((prefs && prefs.attachSession) || '').trim()
|
|
1474
|
+
if (!sessionId) {
|
|
1475
|
+
closeChat()
|
|
1476
|
+
say('还没绑定会话哦,去设置页填一个 Session ID 吧')
|
|
1477
|
+
return
|
|
1478
|
+
}
|
|
1479
|
+
fetch('/dsh-coo-pet/prompt', {
|
|
1480
|
+
method: 'POST',
|
|
1481
|
+
headers: { 'content-type': 'application/json' },
|
|
1482
|
+
body: JSON.stringify({ text, sessionId }),
|
|
1483
|
+
}).catch(() => {})
|
|
1484
|
+
say('说了:' + text.slice(0, 30))
|
|
1485
|
+
startThinking()
|
|
1486
|
+
closeChat()
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
/* ---------- 建她 ---------- */
|
|
1490
|
+
try {
|
|
1491
|
+
// 本仓库不随附鲸鱼美术资源(权利说明见 THIRD_PARTY_NOTICES.md):图没就位时给出引导而不是白屏
|
|
1492
|
+
const whaleOk = await fetch(`${ROOT}/whale/model.json`, { method: 'GET' })
|
|
1493
|
+
.then((res) => res.ok)
|
|
1494
|
+
.catch(() => false)
|
|
1495
|
+
if (!whaleOk) {
|
|
1496
|
+
const hint = document.createElement('div')
|
|
1497
|
+
hint.textContent = '🐳 鲸鱼贴图缺失 —— 插件文件不完整,重新下载完整的插件包后重启 DSH'
|
|
1498
|
+
hint.style.cssText =
|
|
1499
|
+
'position:fixed;left:50%;top:38%;transform:translateX(-50%);padding:10px 16px;background:rgba(255,255,255,0.95);color:#1d2333;border-radius:10px;box-shadow:0 6px 18px rgba(0,0,0,0.22);font:13px/1.6 system-ui,"Microsoft YaHei",sans-serif;white-space:nowrap;'
|
|
1500
|
+
document.body.appendChild(hint)
|
|
1501
|
+
throw new Error('whale textures missing: plugin package incomplete')
|
|
1502
|
+
}
|
|
1503
|
+
kit = await import(`${ROOT}/kit/body.js`)
|
|
1504
|
+
pack = await import(`${ROOT}/whale/figure.js`)
|
|
1505
|
+
const model = await fetch(`${ROOT}/whale/model.json`).then((res) => res.json())
|
|
1506
|
+
|
|
1507
|
+
const host = {
|
|
1508
|
+
root: stage,
|
|
1509
|
+
bounds,
|
|
1510
|
+
emit(kind, detail) {
|
|
1511
|
+
// 行走结局:到了就坐下 / 挪图标;被打断就放弃这轮,下次再试
|
|
1512
|
+
if (kind === 'arrived' || kind === 'interrupted') {
|
|
1513
|
+
const id = detail && detail.walkId
|
|
1514
|
+
const sw = seatWalk
|
|
1515
|
+
const iw = iconWalk
|
|
1516
|
+
const lw = launchWalk
|
|
1517
|
+
if (lw && lw.id === id) {
|
|
1518
|
+
launchWalk = null
|
|
1519
|
+
if (kind === 'arrived') {
|
|
1520
|
+
say('咚——我戳它一下')
|
|
1521
|
+
performTapAndLaunch(lw.name)
|
|
1522
|
+
}
|
|
1523
|
+
return
|
|
1524
|
+
}
|
|
1525
|
+
if (sw && sw.id === id) {
|
|
1526
|
+
seatWalk = null
|
|
1527
|
+
if (kind === 'arrived') sitAt(sw.x, sw.y)
|
|
1528
|
+
if (kind === 'arrived' && sw.line && lines.length) chatterSay(sw.line)
|
|
1529
|
+
}
|
|
1530
|
+
if (iw && iw.id === id) {
|
|
1531
|
+
if (kind === 'arrived' && iw.phase === 1) {
|
|
1532
|
+
// 到了图标跟前:举起包裹,抱着走到新位置再放下
|
|
1533
|
+
const dx = Math.random() < 0.5 ? -96 : 96
|
|
1534
|
+
const toX = Math.max(8, Math.min(worldSize.w - 120, iw.icon.x + dx))
|
|
1535
|
+
const toY = Math.max(8, Math.min(window.innerHeight - 120, iw.icon.y + (Math.random() < 0.4 ? 96 : 0)))
|
|
1536
|
+
const id2 = 'icon2-' + Math.round(Math.random() * 1e6)
|
|
1537
|
+
if (pet.walkTo?.(toX, false, id2, worldSize.h - 8)) {
|
|
1538
|
+
iconWalk = { id: id2, icon: iw.icon, phase: 2, toX, toY }
|
|
1539
|
+
carry = { toX, toY }
|
|
1540
|
+
showCarry()
|
|
1541
|
+
say('抱起来咯')
|
|
1542
|
+
} else {
|
|
1543
|
+
iconWalk = null
|
|
1544
|
+
}
|
|
1545
|
+
return
|
|
1546
|
+
}
|
|
1547
|
+
iconWalk = null
|
|
1548
|
+
carry = null
|
|
1549
|
+
hideCarry()
|
|
1550
|
+
if (kind === 'arrived' && iw.phase === 2) {
|
|
1551
|
+
const fw = iw
|
|
1552
|
+
window.setTimeout(async () => {
|
|
1553
|
+
// 落地前最后一道闸:这会儿有窗口开着就不真动图标
|
|
1554
|
+
if (!(await deskClean(true))) {
|
|
1555
|
+
report('dbg-carry-skip', { why: 'windows-before-place' })
|
|
1556
|
+
return
|
|
1557
|
+
}
|
|
1558
|
+
await desk.moveIcon({ index: fw.icon.i, x: fw.toX, y: fw.toY }).catch(() => {})
|
|
1559
|
+
iconCache = { at: 0, data: [] } // 图标位置变了,刷新缓存
|
|
1560
|
+
say('放这儿')
|
|
1561
|
+
}, 300)
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
return
|
|
1565
|
+
}
|
|
1566
|
+
if (kind !== 'touch' || !detail) return
|
|
1567
|
+
// 拎起/甩出/戳碰的音效由 kit 引擎自己发(grab/whoosh/poke),页面不重复播
|
|
1568
|
+
if (detail.kind === 'poke') {
|
|
1569
|
+
const pick = lines.length ? lines[Math.floor(Math.random() * lines.length)] : '诶?'
|
|
1570
|
+
say(pick)
|
|
1571
|
+
}
|
|
1572
|
+
let dropFeet = null
|
|
1573
|
+
if (detail.kind === 'drop') {
|
|
1574
|
+
// 轻轻放下:落点变成新地面,她就在这儿接着溜达
|
|
1575
|
+
let boxNow = null
|
|
1576
|
+
try {
|
|
1577
|
+
boxNow = pet && pet.layout ? pet.layout() : null
|
|
1578
|
+
} catch {
|
|
1579
|
+
boxNow = null
|
|
1580
|
+
}
|
|
1581
|
+
const feet = boxNow && boxNow.box ? Math.round(boxNow.box.y + boxNow.box.h) : null
|
|
1582
|
+
dropFeet = feet
|
|
1583
|
+
if (typeof feet === 'number') {
|
|
1584
|
+
looseGround = Math.max(minFeet(), Math.min(worldSize.h - 12, feet))
|
|
1585
|
+
if (seat !== null) seat = null
|
|
1586
|
+
try {
|
|
1587
|
+
pet.place(Math.round(boxNow.x), boxNow.facing || -1, looseGround)
|
|
1588
|
+
} catch {
|
|
1589
|
+
/* ignore */
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
} else if (detail.kind === 'throw') {
|
|
1593
|
+
// 扔出去:地面回到屏幕底,她自己掉下去
|
|
1594
|
+
looseGround = null
|
|
1595
|
+
if (seat !== null) seat = null
|
|
1596
|
+
}
|
|
1597
|
+
// 静默遥测:每次松手上报判定/落点/地面(不显示给用户,供远程排查)
|
|
1598
|
+
report('desk-drop', { kind: detail.kind, feet: dropFeet, ground: looseGround, world: worldSize.h })
|
|
1599
|
+
},
|
|
1600
|
+
sound(name, ...args) {
|
|
1601
|
+
chime(name, ...args)
|
|
1602
|
+
},
|
|
1603
|
+
start: { x: Math.round(worldSize.w - 220), y: bounds().floorY, facing: -1 },
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
pet = await pack.createWhaleBody('', {
|
|
1607
|
+
model,
|
|
1608
|
+
scheme: `${prefs.look || 'deepseek'}-${prefs.outfit || 'maid'}`,
|
|
1609
|
+
kit,
|
|
1610
|
+
loadImage,
|
|
1611
|
+
asset: (p) => `${ROOT}/asset?p=${encodeURIComponent('whale/' + p)}`,
|
|
1612
|
+
host,
|
|
1613
|
+
ground: 'free',
|
|
1614
|
+
// 本环境(透明置顶窗 + DWM 合成)实测合成不了 GL 画布本体:走 foreignObject 直渲
|
|
1615
|
+
// 会在几十秒~两分钟内把页面拖进休眠、窗口直接消失(两次复现)。raster 模式每帧把
|
|
1616
|
+
// 画面转成 dataURL 塞进 SVG <image>——CPU 读回,稳定可靠,是唯一验证过能长跑的
|
|
1617
|
+
// 本体显示路径,所以必须开着。配 rasterFps 节流压住最坏情况的开销。
|
|
1618
|
+
raster: true,
|
|
1619
|
+
rasterFps: 24, // 每秒最多转 24 帧(走路 60fps 时省 ~60% 读回;待机本来就只有 ~8fps 不受影响)
|
|
1620
|
+
})
|
|
1621
|
+
// 分身的造法:和本体同一套模型/贴图/引擎,独立 figure 实例 + raster(12fps)。
|
|
1622
|
+
// start 里的 skin 让她穿同一件衣服;host 不接 emit(没有气泡),声音只放脚步声。
|
|
1623
|
+
buildCloneBody = async (root, at) => kit.createBody({
|
|
1624
|
+
root,
|
|
1625
|
+
bounds,
|
|
1626
|
+
emit: () => {},
|
|
1627
|
+
sound: (name, kind, ...args) => { if (name === 'step') stepSfx(); else chime(name, ...args) },
|
|
1628
|
+
start: { x: at.x, y: at.y, facing: at.facing, skin: prefs.outfit || 'maid' },
|
|
1629
|
+
}, {
|
|
1630
|
+
figure: await pack.createWhaleFigure('', {
|
|
1631
|
+
model,
|
|
1632
|
+
scheme: `${prefs.look || 'deepseek'}-${prefs.outfit || 'maid'}`,
|
|
1633
|
+
kit,
|
|
1634
|
+
loadImage,
|
|
1635
|
+
asset: (p) => `${ROOT}/asset?p=${encodeURIComponent('whale/' + p)}`,
|
|
1636
|
+
raster: true,
|
|
1637
|
+
rasterFps: 12, // 分身画面每秒最多转 12 帧,压住每只一条管线的读回开销
|
|
1638
|
+
}),
|
|
1639
|
+
ground: 'free',
|
|
1640
|
+
})
|
|
1641
|
+
try {
|
|
1642
|
+
pet.place(Math.round(worldSize.w - 220), -1, bounds().floorY)
|
|
1643
|
+
} catch {
|
|
1644
|
+
/* 位置随便 */
|
|
1645
|
+
}
|
|
1646
|
+
try {
|
|
1647
|
+
applyRoam()
|
|
1648
|
+
} catch {
|
|
1649
|
+
/* ignore */
|
|
1650
|
+
}
|
|
1651
|
+
// 开机就处于安静模式:原地待着、不做自发动作、不出声
|
|
1652
|
+
if (offDuty) {
|
|
1653
|
+
try { pet?.set?.({ dialogOpen: true }) } catch { /* ignore */ }
|
|
1654
|
+
}
|
|
1655
|
+
// 后台预热全部配色×衣服的贴图:之后菜单里换装原地无缝、零等待
|
|
1656
|
+
try {
|
|
1657
|
+
pet?.preload?.()
|
|
1658
|
+
} catch {
|
|
1659
|
+
/* ignore */
|
|
1660
|
+
}
|
|
1661
|
+
} catch (error) {
|
|
1662
|
+
report('desk-error', { message: String((error && (error.stack || error.message)) || error) })
|
|
1663
|
+
say('启动失败:' + ((error && error.message) || error))
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
if (pet) {
|
|
1667
|
+
report('desk-ready', { scheme: String(prefs.look) + '-' + String(prefs.outfit), w: worldSize.w, h: worldSize.h, size: prefs.size })
|
|
1668
|
+
window.setInterval(() => {
|
|
1669
|
+
try {
|
|
1670
|
+
const box = pet.layout?.()
|
|
1671
|
+
report('desk-tick', { petX: Math.round((box && box.x) || 0), mode: (box && box.mode) || '', hit, origin, worldW: worldSize.w, seat, clones: clones.length, cloneModes: clones.slice(0, 8).map((c) => { try { return (c.bp.layout && c.bp.layout().mode) || '' } catch { return '' } }), cloneBoxes: cloneBoxes().slice(0, 8), cloneRects: clones.slice(0, 8).map((c) => { const r = cloneRect(c); return r ? { x: Math.round(r.x), y: Math.round(r.y), w: Math.round(r.w), h: Math.round(r.h) } : null }), fps: (window.__cooFps || 0), petG: (() => { try { const nodes = stage.querySelectorAll('svg.kit g[transform]'); const last = nodes[nodes.length - 1]; const r = last && last.getBoundingClientRect(); return r ? { t: last.getAttribute('transform'), x: Math.round(r.x), y: Math.round(r.y), w: Math.round(r.width), h: Math.round(r.height) } : null } catch { return null } })(), stageRect: (() => { try { const r = stage.getBoundingClientRect(); return { x: Math.round(r.x), y: Math.round(r.y), w: Math.round(r.width), h: Math.round(r.height) } } catch { return null } })(), screenX: window.screenX, screenY: window.screenY, viewW: window.innerWidth, viewH: window.innerHeight, dpr: window.devicePixelRatio })
|
|
1672
|
+
} catch (error) {
|
|
1673
|
+
report('desk-error', { message: String((error && error.message) || error) })
|
|
1674
|
+
}
|
|
1675
|
+
}, 6000)
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
/* ---------- 指针:靠 forwarded mousemove 判断她在不在下面 ---------- */
|
|
1679
|
+
window.addEventListener('mousemove', (event) => {
|
|
1680
|
+
if (dragging) return
|
|
1681
|
+
const wx = event.clientX + origin.x
|
|
1682
|
+
const wy = event.clientY + origin.y
|
|
1683
|
+
// 光标停在分身身上时她先站住别走:不然你一凑过去她就溜了,永远点不到
|
|
1684
|
+
const hovered = cloneAt(wx, wy)
|
|
1685
|
+
if (hovered) hovered.pauseT = 0.8
|
|
1686
|
+
sendHit(inHit(wx, wy) || !!hovered)
|
|
1687
|
+
})
|
|
1688
|
+
window.addEventListener('blur', () => sendHit(false))
|
|
1689
|
+
|
|
1690
|
+
window.addEventListener('pointerdown', (event) => {
|
|
1691
|
+
// 菜单 / 对话框上有自己的交互,点它们不是拖她
|
|
1692
|
+
if (menuEl && menuEl.contains(event.target)) return
|
|
1693
|
+
if (chatEl && !chatEl.classList.contains('hidden') && chatEl.contains(event.target)) return
|
|
1694
|
+
const wx = event.clientX + origin.x
|
|
1695
|
+
const wy = event.clientY + origin.y
|
|
1696
|
+
// 分身交互:左键拖着走,右键弹「解除」专用菜单(右键在这里就弹,
|
|
1697
|
+
// 不等 contextmenu——透明窗刚从穿透切回来时 contextmenu 可能被吞)
|
|
1698
|
+
if (!inHit(wx, wy)) {
|
|
1699
|
+
const c = cloneAt(wx, wy)
|
|
1700
|
+
if (c) {
|
|
1701
|
+
try { report('clone-act', { kind: event.button === 0 ? 'drag' : 'menu', x: Math.round(wx), y: Math.round(wy), n: clones.length }) } catch { /* ignore */ }
|
|
1702
|
+
if (event.button === 0) {
|
|
1703
|
+
cloneDrag = { c, vx: 0, vy: 0, lt: performance.now(), lx: wx, ly: wy }
|
|
1704
|
+
// 轻点/拎起/甩出/落地的手感与声音全由引擎出(和本体同一套:pointer 系列驱动)
|
|
1705
|
+
try { c.bp.pointer('down', { x: wx, y: wy }) } catch { /* ignore */ }
|
|
1706
|
+
// 借用主进程的拖拽租约:拖动期间透明窗保持不穿透,快了也不丢事件
|
|
1707
|
+
try { desk.drag(true) } catch { /* ignore */ }
|
|
1708
|
+
return
|
|
1709
|
+
}
|
|
1710
|
+
if (event.button === 2 && Date.now() - cloneMenuAt > 350) {
|
|
1711
|
+
cloneMenuAt = Date.now()
|
|
1712
|
+
cloneTarget = c
|
|
1713
|
+
openMenu(wx, wy, 'clone')
|
|
1714
|
+
}
|
|
1715
|
+
return
|
|
1716
|
+
}
|
|
1717
|
+
return
|
|
1718
|
+
}
|
|
1719
|
+
// 只有左键才拖她:右键是菜单,鼠标中键/侧键留给语音快捷键
|
|
1720
|
+
if (event.button !== 0) return
|
|
1721
|
+
dragging = true
|
|
1722
|
+
sendHit(true)
|
|
1723
|
+
try {
|
|
1724
|
+
desk.drag(true)
|
|
1725
|
+
} catch {
|
|
1726
|
+
/* ignore */
|
|
1727
|
+
}
|
|
1728
|
+
try {
|
|
1729
|
+
pet?.pointer?.('down', { x: event.clientX + origin.x, y: event.clientY + origin.y })
|
|
1730
|
+
} catch {
|
|
1731
|
+
/* ignore */
|
|
1732
|
+
}
|
|
1733
|
+
})
|
|
1734
|
+
window.addEventListener('pointermove', (event) => {
|
|
1735
|
+
// 拖分身:跟随交给引擎(bp.pointer('move')),页面只记光标和甩出速度
|
|
1736
|
+
if (cloneDrag) {
|
|
1737
|
+
const wx = event.clientX + origin.x
|
|
1738
|
+
const wy = event.clientY + origin.y
|
|
1739
|
+
const now = performance.now()
|
|
1740
|
+
const mdt = Math.max(8, now - cloneDrag.lt)
|
|
1741
|
+
if (mdt > 24) { cloneDrag.vx = (wx - cloneDrag.lx) / mdt; cloneDrag.vy = (wy - cloneDrag.ly) / mdt; cloneDrag.lt = now; cloneDrag.lx = wx; cloneDrag.ly = wy }
|
|
1742
|
+
try { cloneDrag.c.bp.pointer('move', { x: wx, y: wy }) } catch { /* ignore */ }
|
|
1743
|
+
return
|
|
1744
|
+
}
|
|
1745
|
+
if (!dragging) return
|
|
1746
|
+
try {
|
|
1747
|
+
pet?.pointer?.('move', { x: event.clientX + origin.x, y: event.clientY + origin.y })
|
|
1748
|
+
} catch {
|
|
1749
|
+
/* ignore */
|
|
1750
|
+
}
|
|
1751
|
+
})
|
|
1752
|
+
const endDrag = (event) => {
|
|
1753
|
+
if (cloneDrag) {
|
|
1754
|
+
const c = cloneDrag.c
|
|
1755
|
+
const wx = event.clientX + origin.x
|
|
1756
|
+
const wy = event.clientY + origin.y
|
|
1757
|
+
try { report('clone-drop', { x: Math.round(wx), y: Math.round(wy), throw: Math.round(Math.hypot(cloneDrag.vx, cloneDrag.vy) * 100) / 100 }) } catch { /* ignore */ }
|
|
1758
|
+
// 松手全交给引擎(和本体同一套:轻点=戳一下随表情、慢放=安放不弹、
|
|
1759
|
+
// 快甩=抛出去、摔重了自己晕;声音也由引擎经 host.sound 出)
|
|
1760
|
+
try { c.bp.pointer('up', { x: wx, y: wy }) } catch { /* ignore */ }
|
|
1761
|
+
cloneDrag = null
|
|
1762
|
+
try { desk.drag(false) } catch { /* ignore */ }
|
|
1763
|
+
try { publishBox(true) } catch { /* ignore */ }
|
|
1764
|
+
return
|
|
1765
|
+
}
|
|
1766
|
+
if (!dragging) return
|
|
1767
|
+
dragging = false
|
|
1768
|
+
try {
|
|
1769
|
+
desk.drag(false)
|
|
1770
|
+
} catch {
|
|
1771
|
+
/* ignore */
|
|
1772
|
+
}
|
|
1773
|
+
try {
|
|
1774
|
+
pet?.pointer?.('up', { x: event.clientX + origin.x, y: event.clientY + origin.y })
|
|
1775
|
+
} catch {
|
|
1776
|
+
/* ignore */
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
window.addEventListener('pointerup', endDrag)
|
|
1780
|
+
window.addEventListener('pointercancel', endDrag)
|
|
1781
|
+
|
|
1782
|
+
/* 左键:出声 + 晕;右键:菜单;右键双击:输入框 */
|
|
1783
|
+
let rightTap = 0
|
|
1784
|
+
window.addEventListener('click', (event) => {
|
|
1785
|
+
if (!inHit(event.clientX + origin.x, event.clientY + origin.y)) return
|
|
1786
|
+
// 左键点她:换表情 / 小动作(右侧键才是菜单)
|
|
1787
|
+
if (prefs.sfx !== false) chime('poke')
|
|
1788
|
+
try {
|
|
1789
|
+
pet?.act?.('dizzy')
|
|
1790
|
+
} catch {
|
|
1791
|
+
/* ignore */
|
|
1792
|
+
}
|
|
1793
|
+
})
|
|
1794
|
+
window.addEventListener('contextmenu', (event) => {
|
|
1795
|
+
event.preventDefault()
|
|
1796
|
+
const wx = event.clientX + origin.x
|
|
1797
|
+
const wy = event.clientY + origin.y
|
|
1798
|
+
if (!inHit(wx, wy)) {
|
|
1799
|
+
// 不在本体上:看看是不是点在分身上(pointerdown 里通常已经弹过,去抖防重复)
|
|
1800
|
+
const c = cloneAt(wx, wy)
|
|
1801
|
+
if (c && Date.now() - cloneMenuAt > 350) {
|
|
1802
|
+
cloneMenuAt = Date.now()
|
|
1803
|
+
cloneTarget = c
|
|
1804
|
+
openMenu(wx, wy, 'clone')
|
|
1805
|
+
}
|
|
1806
|
+
return
|
|
1807
|
+
}
|
|
1808
|
+
const now = Date.now()
|
|
1809
|
+
if (now - rightTap < 360) {
|
|
1810
|
+
rightTap = 0
|
|
1811
|
+
openChat()
|
|
1812
|
+
return
|
|
1813
|
+
}
|
|
1814
|
+
rightTap = now
|
|
1815
|
+
openMenu(wx, wy)
|
|
1816
|
+
})
|
|
1817
|
+
window.addEventListener('keydown', (event) => {
|
|
1818
|
+
if (event.key === 'Escape') {
|
|
1819
|
+
closeMenu()
|
|
1820
|
+
closeChat()
|
|
1821
|
+
}
|
|
1822
|
+
})
|
|
1823
|
+
|
|
1824
|
+
/* ---------- 语音快捷键:桌面窗口也认它的组合键 / 鼠标侧键 ---------- */
|
|
1825
|
+
let voiceChat = false // 这次输入框是语音开的:录完自动收走
|
|
1826
|
+
/* 本地语音识别(whisper.cpp,不联网):
|
|
1827
|
+
浏览器 SpeechRecognition 走 Google 服务,国内网络直接 network 错误(实测),
|
|
1828
|
+
所以改成:她自己的窗口录音(16kHz 单声)→ POST 给插件 → 插件跑本机
|
|
1829
|
+
whisper-cli 转写。录音期间每 3 秒把"已录的全程"转写一次当中间结果,
|
|
1830
|
+
字一句句冒出来;松开后最终转写也只填进输入框——**不自动发送**,
|
|
1831
|
+
master 自己回车或点发送。
|
|
1832
|
+
主窗口麦克风桥的最终结果(voicetext 轮询)仍保留,同样只填不发送。 */
|
|
1833
|
+
let voiceStream = null
|
|
1834
|
+
let lastFinal = { text: '', at: 0 }
|
|
1835
|
+
const VOICE_RATE = 16000
|
|
1836
|
+
const encodeWav = (samples) => {
|
|
1837
|
+
const n = samples.length
|
|
1838
|
+
const buffer = new ArrayBuffer(44 + n * 2)
|
|
1839
|
+
const view = new DataView(buffer)
|
|
1840
|
+
const str = (offset, text) => {
|
|
1841
|
+
for (let i = 0; i < text.length; i += 1) view.setUint8(offset + i, text.charCodeAt(i))
|
|
1842
|
+
}
|
|
1843
|
+
str(0, 'RIFF')
|
|
1844
|
+
view.setUint32(4, 36 + n * 2, true)
|
|
1845
|
+
str(8, 'WAVEfmt ')
|
|
1846
|
+
view.setUint32(16, 16, true)
|
|
1847
|
+
view.setUint16(20, 1, true)
|
|
1848
|
+
view.setUint16(22, 1, true)
|
|
1849
|
+
view.setUint32(24, VOICE_RATE, true)
|
|
1850
|
+
view.setUint32(28, VOICE_RATE * 2, true)
|
|
1851
|
+
view.setUint16(32, 2, true)
|
|
1852
|
+
view.setUint16(34, 16, true)
|
|
1853
|
+
str(36, 'data')
|
|
1854
|
+
view.setUint32(40, n * 2, true)
|
|
1855
|
+
let offset = 44
|
|
1856
|
+
for (let i = 0; i < n; i += 1) {
|
|
1857
|
+
const v = Math.max(-1, Math.min(1, samples[i]))
|
|
1858
|
+
view.setInt16(offset, v < 0 ? v * 0x8000 : v * 0x7fff, true)
|
|
1859
|
+
offset += 2
|
|
1860
|
+
}
|
|
1861
|
+
return buffer
|
|
1862
|
+
}
|
|
1863
|
+
const mergePcm = (chunks, bytes) => {
|
|
1864
|
+
const merged = new Float32Array(bytes)
|
|
1865
|
+
let offset = 0
|
|
1866
|
+
for (const c of chunks) {
|
|
1867
|
+
merged.set(c, offset)
|
|
1868
|
+
offset += c.length
|
|
1869
|
+
}
|
|
1870
|
+
return merged
|
|
1871
|
+
}
|
|
1872
|
+
const postWav = async (buffer, final) => {
|
|
1873
|
+
try {
|
|
1874
|
+
const res = await fetch(`/dsh-coo-pet/voicerec${final ? '?final=1' : ''}`, {
|
|
1875
|
+
method: 'POST',
|
|
1876
|
+
headers: { 'content-type': 'application/octet-stream' },
|
|
1877
|
+
body: buffer,
|
|
1878
|
+
}).then((r) => r.json())
|
|
1879
|
+
return res && res.ok ? String(res.text || '') : ''
|
|
1880
|
+
} catch {
|
|
1881
|
+
return ''
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
// 录音期间的中间结果刷新:每 3 秒把已录的全量转写一次(whisper 单进程排队,忙就跳过)
|
|
1885
|
+
let partialTimer = 0
|
|
1886
|
+
const schedulePartialFlush = () => {
|
|
1887
|
+
window.clearInterval(partialTimer)
|
|
1888
|
+
partialTimer = window.setInterval(async () => {
|
|
1889
|
+
const s = voiceStream
|
|
1890
|
+
if (!s || !voiceHeld) return
|
|
1891
|
+
// 一个字节都没录到:录音上下文没在跑(多半是 suspended)——打点实锤
|
|
1892
|
+
if (s.bytes === 0) {
|
|
1893
|
+
if (Date.now() - s.startedAt > 3500 && !s.zeroReported) {
|
|
1894
|
+
s.zeroReported = true
|
|
1895
|
+
report('dbg-voice-noaudio', { ctx: s.ctx.state, sampleRate: s.ctx.sampleRate })
|
|
1896
|
+
}
|
|
1897
|
+
return
|
|
1898
|
+
}
|
|
1899
|
+
if (s.bytes < VOICE_RATE) return
|
|
1900
|
+
const snap = mergePcm(s.chunks, s.bytes)
|
|
1901
|
+
const text = await postWav(encodeWav(snap), false)
|
|
1902
|
+
// 只在还在录音时填中间结果:松手后迟到的响应丢弃,
|
|
1903
|
+
// 最终转写(服务端排队后总会回来)负责填最后一版
|
|
1904
|
+
if (text && voiceHeld && !chatEl.classList.contains('hidden')) chatText.value = text
|
|
1905
|
+
}, 3000)
|
|
1906
|
+
}
|
|
1907
|
+
const stopVoiceCapture = () => {
|
|
1908
|
+
window.clearInterval(partialTimer)
|
|
1909
|
+
partialTimer = 0
|
|
1910
|
+
const s = voiceStream
|
|
1911
|
+
voiceStream = null
|
|
1912
|
+
if (!s) return null
|
|
1913
|
+
try { s.processor.disconnect() } catch { /* ignore */ }
|
|
1914
|
+
try { s.source.disconnect() } catch { /* ignore */ }
|
|
1915
|
+
try { s.ctx.close() } catch { /* ignore */ }
|
|
1916
|
+
try { s.stream.getTracks().forEach((t) => t.stop()) } catch { /* ignore */ }
|
|
1917
|
+
return s.bytes > 0 ? encodeWav(mergePcm(s.chunks, s.bytes)) : null
|
|
1918
|
+
}
|
|
1919
|
+
const startVoiceCapture = () => {
|
|
1920
|
+
if (voiceStream) return
|
|
1921
|
+
if (!navigator.mediaDevices?.getUserMedia) {
|
|
1922
|
+
report('dbg-voice-cap-err', { msg: 'no getUserMedia' })
|
|
1923
|
+
return
|
|
1924
|
+
}
|
|
1925
|
+
navigator.mediaDevices
|
|
1926
|
+
.getUserMedia({ audio: { channelCount: 1, echoCancellation: true, noiseSuppression: true } })
|
|
1927
|
+
.then((stream) => {
|
|
1928
|
+
const ctx = new AudioContext({ sampleRate: VOICE_RATE })
|
|
1929
|
+
// 快捷键经 IPC 触发不算用户手势,ctx 可能是 suspended——主动唤醒,
|
|
1930
|
+
// 唤不醒就打点报出来(录音字节流不会动,表现为「在听但没字」)
|
|
1931
|
+
const wake = ctx.resume().catch(() => {})
|
|
1932
|
+
const source = ctx.createMediaStreamSource(stream)
|
|
1933
|
+
const processor = ctx.createScriptProcessor(4096, 1, 1)
|
|
1934
|
+
const chunks = []
|
|
1935
|
+
let bytes = 0
|
|
1936
|
+
let state = null
|
|
1937
|
+
processor.onaudioprocess = (event) => {
|
|
1938
|
+
if (!state || voiceStream !== state) return
|
|
1939
|
+
const input = event.inputBuffer.getChannelData(0)
|
|
1940
|
+
chunks.push(new Float32Array(input))
|
|
1941
|
+
bytes += input.length
|
|
1942
|
+
// bytes 是闭包变量:state 创建时只复制过一次值(0),必须回写,
|
|
1943
|
+
// 否则所有 s.bytes 检查永远看到 0(表现为「在听但永远没字」)
|
|
1944
|
+
state.bytes = bytes
|
|
1945
|
+
}
|
|
1946
|
+
source.connect(processor)
|
|
1947
|
+
processor.connect(ctx.destination)
|
|
1948
|
+
state = { ctx, source, processor, stream, chunks, bytes, startedAt: Date.now() }
|
|
1949
|
+
voiceStream = state
|
|
1950
|
+
schedulePartialFlush()
|
|
1951
|
+
wake.then(() => {
|
|
1952
|
+
if (voiceStream === state && ctx.state !== 'running') {
|
|
1953
|
+
report('dbg-voice-ctx-stuck', { state: ctx.state, sampleRate: ctx.sampleRate })
|
|
1954
|
+
} else {
|
|
1955
|
+
report('dbg-voice-cap-start', { state: ctx.state, sampleRate: ctx.sampleRate })
|
|
1956
|
+
}
|
|
1957
|
+
})
|
|
1958
|
+
})
|
|
1959
|
+
.catch((error) => {
|
|
1960
|
+
report('dbg-voice-cap-err', { msg: String((error && error.message) || error) })
|
|
1961
|
+
})
|
|
1962
|
+
}
|
|
1963
|
+
const setVoice = (on) => {
|
|
1964
|
+
if (on === voiceHeld) return
|
|
1965
|
+
voiceHeld = on
|
|
1966
|
+
// 开麦时她进入「听」状态(头顶有听声弧线)且原地不动,闭麦恢复;
|
|
1967
|
+
// 录音期间也不搬图标不坐不睡(定时器都有 voiceHeld 闸)
|
|
1968
|
+
chime(on ? 'listenStart' : 'listenEnd')
|
|
1969
|
+
try { pet?.set?.({ listening: on }) } catch { /* ignore */ }
|
|
1970
|
+
try {
|
|
1971
|
+
if (on) {
|
|
1972
|
+
pet?.set?.({ roam: 'off', dialogOpen: true })
|
|
1973
|
+
pet?.stopWalk?.()
|
|
1974
|
+
// 开麦就把她的输入框弹出来(不抢焦点):识别到的字实时填进去看得到
|
|
1975
|
+
if (chatEl.classList.contains('hidden')) {
|
|
1976
|
+
openChat(false)
|
|
1977
|
+
voiceChat = true
|
|
1978
|
+
}
|
|
1979
|
+
chatText.placeholder = '在听…说话(字会填进来,松开自己发)'
|
|
1980
|
+
startVoiceCapture()
|
|
1981
|
+
} else {
|
|
1982
|
+
// 闭麦:收录音 → 最终转写 → 只把字填进输入框,**不自动发送**,
|
|
1983
|
+
// master 自己回车或点发送
|
|
1984
|
+
;(async () => {
|
|
1985
|
+
const wav = stopVoiceCapture()
|
|
1986
|
+
if (!wav) {
|
|
1987
|
+
report('dbg-voice-final-empty', { reason: 'no-wav' })
|
|
1988
|
+
return
|
|
1989
|
+
}
|
|
1990
|
+
const ms = Math.round(wav.byteLength / 2 / (VOICE_RATE / 1000))
|
|
1991
|
+
const text = (await postWav(wav, true)).trim()
|
|
1992
|
+
if (!text) {
|
|
1993
|
+
report('dbg-voice-final-empty', { reason: 'no-text', ms })
|
|
1994
|
+
return
|
|
1995
|
+
}
|
|
1996
|
+
lastFinal = { text, at: Date.now() }
|
|
1997
|
+
chatText.value = text
|
|
1998
|
+
voiceChat = false
|
|
1999
|
+
})()
|
|
2000
|
+
chatText.placeholder = '说完啦,回车或点发送'
|
|
2001
|
+
pet?.set?.({ dialogOpen: false })
|
|
2002
|
+
applyRoam()
|
|
2003
|
+
// 闭麦后短时间内没有最终文字(识别失败/空话)就把语音开的输入框收走
|
|
2004
|
+
if (voiceChat) {
|
|
2005
|
+
window.setTimeout(() => {
|
|
2006
|
+
if (voiceChat && !chatText.value.trim()) {
|
|
2007
|
+
voiceChat = false
|
|
2008
|
+
closeChat()
|
|
2009
|
+
}
|
|
2010
|
+
}, 2500)
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
} catch {
|
|
2014
|
+
/* ignore */
|
|
2015
|
+
}
|
|
2016
|
+
fetch('/dsh-coo-pet/voice', {
|
|
2017
|
+
method: 'POST',
|
|
2018
|
+
headers: { 'content-type': 'application/json' },
|
|
2019
|
+
body: JSON.stringify({ on }),
|
|
2020
|
+
}).catch(() => {})
|
|
2021
|
+
}
|
|
2022
|
+
const parseHot = (spec) => {
|
|
2023
|
+
const raw = String(spec || '').trim()
|
|
2024
|
+
if (!raw) return null
|
|
2025
|
+
if (/^mouse[345]$/i.test(raw)) return { mouse: Number(raw.slice(5)) }
|
|
2026
|
+
const parts = raw.split('+').map((s) => s.trim()).filter(Boolean)
|
|
2027
|
+
const key = (parts.pop() || '').toLowerCase()
|
|
2028
|
+
const mods = { ctrl: false, alt: false, shift: false, meta: false }
|
|
2029
|
+
for (const p of parts) {
|
|
2030
|
+
const l = p.toLowerCase()
|
|
2031
|
+
if (l === 'ctrl' || l === 'control') mods.ctrl = true
|
|
2032
|
+
else if (l === 'alt') mods.alt = true
|
|
2033
|
+
else if (l === 'shift') mods.shift = true
|
|
2034
|
+
else if (l === 'meta' || l === 'win') mods.meta = true
|
|
2035
|
+
}
|
|
2036
|
+
return { key, mods }
|
|
2037
|
+
}
|
|
2038
|
+
const hotMatch = (event, spec) => {
|
|
2039
|
+
const want = parseHot(spec)
|
|
2040
|
+
if (!want || want.mouse) return false
|
|
2041
|
+
if (String(event.key || '').toLowerCase() !== want.key) return false
|
|
2042
|
+
return (
|
|
2043
|
+
event.ctrlKey === want.mods.ctrl &&
|
|
2044
|
+
event.altKey === want.mods.alt &&
|
|
2045
|
+
event.shiftKey === want.mods.shift &&
|
|
2046
|
+
event.metaKey === want.mods.meta
|
|
2047
|
+
)
|
|
2048
|
+
}
|
|
2049
|
+
window.addEventListener(
|
|
2050
|
+
'keydown',
|
|
2051
|
+
(event) => {
|
|
2052
|
+
if (prefs.hotkeyOn === false) return
|
|
2053
|
+
if (!hotMatch(event, prefs.hotkey)) return
|
|
2054
|
+
event.preventDefault()
|
|
2055
|
+
setVoice(true)
|
|
2056
|
+
},
|
|
2057
|
+
true
|
|
2058
|
+
)
|
|
2059
|
+
window.addEventListener(
|
|
2060
|
+
'keyup',
|
|
2061
|
+
(event) => {
|
|
2062
|
+
if (prefs.hotkeyOn === false) return
|
|
2063
|
+
if (!hotMatch(event, prefs.hotkey)) return
|
|
2064
|
+
event.preventDefault()
|
|
2065
|
+
setVoice(false)
|
|
2066
|
+
},
|
|
2067
|
+
true
|
|
2068
|
+
)
|
|
2069
|
+
const mouseHot = (button) => {
|
|
2070
|
+
const want = parseHot(prefs.hotkey)
|
|
2071
|
+
return !!(want && want.mouse === button)
|
|
2072
|
+
}
|
|
2073
|
+
window.addEventListener(
|
|
2074
|
+
'mousedown',
|
|
2075
|
+
(event) => {
|
|
2076
|
+
if (prefs.hotkeyOn === false) return
|
|
2077
|
+
if (!mouseHot(event.button)) return
|
|
2078
|
+
event.preventDefault()
|
|
2079
|
+
setVoice(true)
|
|
2080
|
+
},
|
|
2081
|
+
true
|
|
2082
|
+
)
|
|
2083
|
+
window.addEventListener(
|
|
2084
|
+
'mouseup',
|
|
2085
|
+
(event) => {
|
|
2086
|
+
if (prefs.hotkeyOn === false) return
|
|
2087
|
+
if (!mouseHot(event.button)) return
|
|
2088
|
+
event.preventDefault()
|
|
2089
|
+
setVoice(false)
|
|
2090
|
+
},
|
|
2091
|
+
true
|
|
2092
|
+
)
|
|
2093
|
+
window.addEventListener('auxclick', (event) => {
|
|
2094
|
+
if (prefs.hotkeyOn !== false && mouseHot(event.button)) event.preventDefault()
|
|
2095
|
+
})
|
|
2096
|
+
|
|
2097
|
+
// 键盘组合键交给主进程做系统级注册后回调(窗口是 focusable:false,收不到键盘)
|
|
2098
|
+
try {
|
|
2099
|
+
desk.hotkey(prefs.hotkey)
|
|
2100
|
+
} catch {
|
|
2101
|
+
/* ignore */
|
|
2102
|
+
}
|
|
2103
|
+
try {
|
|
2104
|
+
desk.onHot((detail) => {
|
|
2105
|
+
if (prefs.hotkeyOn === false) return
|
|
2106
|
+
// 键盘:按一次开麦再按一次收工(无状态);鼠标:按住说、松开收(down/up)
|
|
2107
|
+
if (detail && detail.state === 'down') setVoice(true)
|
|
2108
|
+
else if (detail && detail.state === 'up') setVoice(false)
|
|
2109
|
+
else setVoice(!voiceHeld)
|
|
2110
|
+
})
|
|
2111
|
+
} catch {
|
|
2112
|
+
/* ignore */
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
/* ---------- 桌面动作:随便坐 / 拖图标 ---------- */
|
|
2116
|
+
let quietSince = Date.now()
|
|
2117
|
+
|
|
2118
|
+
let winCache = { at: 0, data: [] }
|
|
2119
|
+
const windowsOf = async () => {
|
|
2120
|
+
if (Date.now() - winCache.at < 25000) return winCache.data
|
|
2121
|
+
try {
|
|
2122
|
+
const res = await desk.windows()
|
|
2123
|
+
const data = res && res.ok && Array.isArray(res.data) ? res.data : []
|
|
2124
|
+
winCache = { at: Date.now(), data }
|
|
2125
|
+
return data
|
|
2126
|
+
} catch {
|
|
2127
|
+
return []
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
let iconCache = { at: 0, data: [] }
|
|
2131
|
+
const iconsOf = async () => {
|
|
2132
|
+
if (Date.now() - iconCache.at < 60000) return iconCache.data
|
|
2133
|
+
try {
|
|
2134
|
+
const res = await desk.icons()
|
|
2135
|
+
const data = res && res.ok && Array.isArray(res.data) ? res.data : []
|
|
2136
|
+
iconCache = { at: Date.now(), data }
|
|
2137
|
+
return data
|
|
2138
|
+
} catch {
|
|
2139
|
+
return []
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
const sitAt = (x, feetY) => {
|
|
2144
|
+
if (!pet) return
|
|
2145
|
+
seat = Math.max(minFeet(), Math.min(worldSize.h - 20, Math.round(feetY)))
|
|
2146
|
+
try {
|
|
2147
|
+
pet.place?.(Math.round(x), pet.layout?.()?.facing ?? 1, seat)
|
|
2148
|
+
} catch {
|
|
2149
|
+
/* ignore */
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
const standUp = () => {
|
|
2153
|
+
if (seat === null) return
|
|
2154
|
+
seat = null
|
|
2155
|
+
try {
|
|
2156
|
+
applyRoam()
|
|
2157
|
+
} catch {
|
|
2158
|
+
/* ignore */
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
// 界面占用中:菜单或输入框开着时,定时器们不该让她走来走去(坐图标/搬图标/坐下都会把人拉走)
|
|
2163
|
+
const uiBusy = () => !!menuEl || !!(chatEl && !chatEl.classList.contains('hidden'))
|
|
2164
|
+
|
|
2165
|
+
const trySit = async () => {
|
|
2166
|
+
if (!prefs.actSit || offDuty || napping || seat !== null || dragging || busy || stayMode || thinkingNow || voiceHeld || uiBusy() || launchWalk) return
|
|
2167
|
+
if (!pet || seatWalk) return
|
|
2168
|
+
const mode = pet.layout?.()?.mode ?? 'idle'
|
|
2169
|
+
if (!['idle', 'sit', 'sleep', 'look'].includes(mode)) return
|
|
2170
|
+
const roll = Math.random()
|
|
2171
|
+
let spot = null
|
|
2172
|
+
if (roll < 0.5) {
|
|
2173
|
+
const icons = await iconsOf()
|
|
2174
|
+
if (icons.length) {
|
|
2175
|
+
const icon = icons[Math.floor(Math.random() * icons.length)]
|
|
2176
|
+
// 坐在图标上:脚踩在图标图案的上沿(格子约 77×96,图案占中上)
|
|
2177
|
+
spot = { x: icon.x + 38, y: icon.y + 40, line: '这张好坐' }
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
if (!spot) {
|
|
2181
|
+
const wins = await windowsOf()
|
|
2182
|
+
const live = wins.filter((w) => w.w > 320 && w.y >= minFeet() && w.y < worldSize.h - 120)
|
|
2183
|
+
if (!live.length) return
|
|
2184
|
+
const target = live[Math.floor(Math.random() * live.length)]
|
|
2185
|
+
spot = { x: target.x + 40 + Math.random() * Math.max(1, target.w - 80), y: target.y, line: '边沿挺舒服的' }
|
|
2186
|
+
}
|
|
2187
|
+
// 不再瞬移:先走到落点,到了再坐;走不了(忙着呢)就这轮放弃
|
|
2188
|
+
const id = 'sit-' + Math.round(Math.random() * 1e6)
|
|
2189
|
+
if (!pet.walkTo?.(spot.x, false, id, spot.y)) return
|
|
2190
|
+
seatWalk = { id, x: spot.x, y: spot.y, line: spot.line }
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
// 桌面干净(只剩壁纸)才允许碰图标:force=真时绕过缓存实查一次(动手前的最后一道闸)
|
|
2194
|
+
let cleanCache = { at: 0, empty: false }
|
|
2195
|
+
const deskClean = async (force) => {
|
|
2196
|
+
if (!force && Date.now() - cleanCache.at < 1200) return cleanCache.empty
|
|
2197
|
+
try {
|
|
2198
|
+
const res = await desk.windows()
|
|
2199
|
+
const data = res && res.ok && Array.isArray(res.data) ? res.data : null
|
|
2200
|
+
if (!data) return false // 探不到窗口就当她别搬
|
|
2201
|
+
cleanCache = { at: Date.now(), empty: data.length === 0 }
|
|
2202
|
+
return cleanCache.empty
|
|
2203
|
+
} catch {
|
|
2204
|
+
return false
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
// 抱起某个图标:挑一个不压到别的图标的新位置,抱着走过去放下
|
|
2209
|
+
const startCarry = (icon, others) => {
|
|
2210
|
+
if (!pet) return false
|
|
2211
|
+
// 动手前先存一份全部图标位置——「一键复位」就是回到这份快照
|
|
2212
|
+
try { desk.snapshotIcons?.().catch(() => {}) } catch { /* ignore */ }
|
|
2213
|
+
// 在全屏找一块「空地」:离所有其他图标至少 110px、离原位置至少 180px(图标格子约 77×96,中心 ≈ +38/+48)
|
|
2214
|
+
const centers = (others || []).filter((o) => o.i !== icon.i).map((o) => ({ x: o.x + 38, y: o.y + 48 }))
|
|
2215
|
+
const homeX = icon.x + 38
|
|
2216
|
+
const homeY = icon.y + 48
|
|
2217
|
+
let best = null
|
|
2218
|
+
let bestScore = -Infinity
|
|
2219
|
+
for (let k = 0; k < 24; k++) {
|
|
2220
|
+
const tx = 60 + Math.random() * Math.max(1, worldSize.w - 180)
|
|
2221
|
+
const ty = 60 + Math.random() * Math.max(1, window.innerHeight - 200)
|
|
2222
|
+
const clear = centers.reduce((m, o) => Math.min(m, Math.hypot(o.x - (tx + 24), o.y - (ty + 30))), Infinity)
|
|
2223
|
+
const fromHome = Math.hypot(homeX - (tx + 24), homeY - (ty + 30))
|
|
2224
|
+
if (clear >= 110 && fromHome >= 180) {
|
|
2225
|
+
best = { x: tx, y: ty }
|
|
2226
|
+
break
|
|
2227
|
+
}
|
|
2228
|
+
const score = Math.min(clear, fromHome)
|
|
2229
|
+
if (score > bestScore) {
|
|
2230
|
+
bestScore = score
|
|
2231
|
+
best = { x: tx, y: ty }
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
if (!best) return false
|
|
2235
|
+
const id2 = 'icon2-' + Math.round(Math.random() * 1e6)
|
|
2236
|
+
// 抱着走到空地正上方,走到哪放到哪(脚下就是落点)
|
|
2237
|
+
if (!pet.walkTo?.(best.x, false, id2, best.y)) return false
|
|
2238
|
+
iconWalk = { id: id2, icon, phase: 2, toX: best.x, toY: best.y }
|
|
2239
|
+
carry = { toX: best.x, toY: best.y }
|
|
2240
|
+
showCarry()
|
|
2241
|
+
say('抱起来咯')
|
|
2242
|
+
return true
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
// 搬运间隔:两次搬图标之间至少隔这么久(设置页可调;0 = 不限制)
|
|
2246
|
+
let lastCarryAt = 0
|
|
2247
|
+
const carryEveryMs = () => {
|
|
2248
|
+
const n = Math.max(0, Math.round(Number(prefs.carryEvery) || 0))
|
|
2249
|
+
return n > 0 ? n * (prefs.carryUnit === 'sec' ? 1000 : 60000) : 0
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
// 巡查:桌面干净时,她走着走着撞到图标,就顺手抱走
|
|
2253
|
+
window.setInterval(async () => {
|
|
2254
|
+
// 搬运途中冒出窗口:立刻放手(真图标要走到落点才真动,放手=图标原地不动)
|
|
2255
|
+
if (iconWalk || carry) {
|
|
2256
|
+
if (!(await deskClean(true))) {
|
|
2257
|
+
iconWalk = null
|
|
2258
|
+
carry = null
|
|
2259
|
+
hideCarry()
|
|
2260
|
+
report('dbg-carry-abort', { why: 'windows-open' })
|
|
2261
|
+
}
|
|
2262
|
+
return
|
|
2263
|
+
}
|
|
2264
|
+
if (!prefs.actIcons || offDuty || napping || prefs.display !== 'desktop' || stayMode || thinkingNow || voiceHeld || uiBusy()) return
|
|
2265
|
+
// 正在去开软件的路上不搬图标:要开的就是那个,别把它抱走、也别打断启动行走
|
|
2266
|
+
if (launchWalk) return
|
|
2267
|
+
// DSH 在跑任务(或有近期活动)时不搬图标:别在她干活时捣乱
|
|
2268
|
+
if (busy || Date.now() - lastActive < 30000) return
|
|
2269
|
+
// 搬运间隔没到就不搬
|
|
2270
|
+
if (Date.now() - lastCarryAt < carryEveryMs()) return
|
|
2271
|
+
if (!pet || dragging || busy || seat !== null || iconWalk || carry) return
|
|
2272
|
+
const mode = pet.layout?.()?.mode
|
|
2273
|
+
if (mode !== 'walk' && mode !== 'run') return
|
|
2274
|
+
if (!(await deskClean())) return
|
|
2275
|
+
const icons = await iconsOf()
|
|
2276
|
+
if (!icons.length) return
|
|
2277
|
+
const me = pet.layout?.()
|
|
2278
|
+
if (!me) return
|
|
2279
|
+
const near = icons.find((ic) => Math.abs(me.x - (ic.x + 38)) < 62 && Math.abs((me.y || 0) - (ic.y + 48)) < 80)
|
|
2280
|
+
if (!near) return
|
|
2281
|
+
// 临动手前再实查一次窗口(不信缓存):有窗口开着就绝不抱
|
|
2282
|
+
if (!(await deskClean(true))) {
|
|
2283
|
+
report('dbg-carry-skip', { why: 'windows-before-grab' })
|
|
2284
|
+
return
|
|
2285
|
+
}
|
|
2286
|
+
say('这个图标挡路了')
|
|
2287
|
+
if (startCarry(near, icons)) lastCarryAt = Date.now()
|
|
2288
|
+
}, 700)
|
|
2289
|
+
|
|
2290
|
+
// 搬运牌子:一只举在头顶的小包裹(画在宠物 SVG 上层,跟着她走,走路时一颠一颠)
|
|
2291
|
+
const showCarry = () => {
|
|
2292
|
+
try {
|
|
2293
|
+
const svg = stage.querySelector('svg.kit')
|
|
2294
|
+
if (!svg) return
|
|
2295
|
+
if (!carryG) {
|
|
2296
|
+
carryG = document.createElementNS('http://www.w3.org/2000/svg', 'g')
|
|
2297
|
+
carryG.style.pointerEvents = 'none'
|
|
2298
|
+
svg.appendChild(carryG)
|
|
2299
|
+
}
|
|
2300
|
+
carryG.innerHTML =
|
|
2301
|
+
'<rect x="-30" y="-28" width="60" height="46" rx="7" fill="#f7d9a0" stroke="#b8863b" stroke-width="3"/>' +
|
|
2302
|
+
'<line x1="-30" y1="-7" x2="30" y2="-7" stroke="#b8863b" stroke-width="3"/>' +
|
|
2303
|
+
'<line x1="0" y1="-28" x2="0" y2="-7" stroke="#b8863b" stroke-width="3"/>'
|
|
2304
|
+
carryG.style.display = ''
|
|
2305
|
+
} catch {
|
|
2306
|
+
/* ignore */
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
const hideCarry = () => {
|
|
2310
|
+
if (carryG) carryG.style.display = 'none'
|
|
2311
|
+
}
|
|
2312
|
+
const updateCarry = () => {
|
|
2313
|
+
if (!carry || !carryG || carryG.style.display === 'none' || !pet) return
|
|
2314
|
+
try {
|
|
2315
|
+
const b = pet.layout?.()
|
|
2316
|
+
if (!b || !b.box) return
|
|
2317
|
+
const bob = Math.round(Math.sin(performance.now() / 180) * 3)
|
|
2318
|
+
const cx = b.box.x + b.box.w / 2
|
|
2319
|
+
const cy = b.box.y - 6
|
|
2320
|
+
carryG.setAttribute('transform', 'translate(' + Math.round(cx) + ',' + Math.round(cy + bob) + ')')
|
|
2321
|
+
} catch {
|
|
2322
|
+
/* ignore */
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
window.setInterval(() => {
|
|
2327
|
+
if (busy) {
|
|
2328
|
+
quietSince = Date.now()
|
|
2329
|
+
return
|
|
2330
|
+
}
|
|
2331
|
+
if (Date.now() - quietSince < 4000) return
|
|
2332
|
+
trySit()
|
|
2333
|
+
// 坐久了就自己下来
|
|
2334
|
+
if (seat !== null && Math.random() < 0.35) {
|
|
2335
|
+
window.setTimeout(standUp, 6000 + Math.random() * 8000)
|
|
2336
|
+
}
|
|
2337
|
+
}, 9000)
|
|
2338
|
+
|
|
2339
|
+
/* ---------- 每帧推进 ---------- */
|
|
2340
|
+
let last = 0
|
|
2341
|
+
let lastStep = 0
|
|
2342
|
+
let fpsFrames = 0
|
|
2343
|
+
let fpsAt = 0
|
|
2344
|
+
window.__cooFps = 0
|
|
2345
|
+
let frameNo = 0
|
|
2346
|
+
let cloneLast = 0 // 分身自己的时钟:不跟本体降帧(本体睡着/闲着降帧时分身照样顺滑)
|
|
2347
|
+
const step = (time) => {
|
|
2348
|
+
// 全真分身:每只都是完整本体实例,自己 step(AI/物理/渲染全在引擎里)
|
|
2349
|
+
try {
|
|
2350
|
+
const cdt = cloneLast === 0 ? 0.016 : Math.min(0.05, (time - cloneLast) / 1000)
|
|
2351
|
+
cloneLast = time
|
|
2352
|
+
for (const c of clones) c.bp.step(cdt)
|
|
2353
|
+
} catch {
|
|
2354
|
+
/* 安静 */
|
|
2355
|
+
}
|
|
2356
|
+
// rAF 与兜底定时器共用,限到约 30fps,绝不自己再排 rAF(会指数爆炸把电脑卡死)
|
|
2357
|
+
// 按状态自适应帧率:睡觉 6fps、闲着 12fps、走动/拖拽 20fps
|
|
2358
|
+
const modeNow = pet?.layout?.()?.mode || 'idle'
|
|
2359
|
+
// 走动时跟着 rAF 走(60fps),站定才降帧;限帧会弄出 30/60 交替的节奏抖动
|
|
2360
|
+
// 除「真站定」和「睡着」之外一律跟着刷新率走:只有这两档才降帧,其余动作都别限
|
|
2361
|
+
const moving = !(modeNow === 'idle' || modeNow === 'sleep' || modeNow === 'sit')
|
|
2362
|
+
const off = String((prefs && prefs.actOff) || '')
|
|
2363
|
+
.split(',')
|
|
2364
|
+
.map((s) => s.trim())
|
|
2365
|
+
.filter(Boolean)
|
|
2366
|
+
if (
|
|
2367
|
+
off.length > 0 &&
|
|
2368
|
+
off.includes(modeNow) &&
|
|
2369
|
+
modeNow !== 'walk' &&
|
|
2370
|
+
modeNow !== 'run' &&
|
|
2371
|
+
modeNow !== 'air' &&
|
|
2372
|
+
modeNow !== 'drag' &&
|
|
2373
|
+
modeNow !== 'land'
|
|
2374
|
+
) {
|
|
2375
|
+
try {
|
|
2376
|
+
pet.do('idle')
|
|
2377
|
+
} catch {
|
|
2378
|
+
/* ignore */
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
const minGap = moving ? 31 : modeNow === 'sleep' ? 400 : modeNow === 'sit' ? 100 : 120
|
|
2382
|
+
if (time - lastStep < minGap) return
|
|
2383
|
+
// 真正画一帧才计数:给探针用,也方便以后调帧率
|
|
2384
|
+
fpsFrames += 1
|
|
2385
|
+
if (time - fpsAt >= 1000) {
|
|
2386
|
+
window.__cooFps = Math.round((fpsFrames * 1000) / (time - fpsAt))
|
|
2387
|
+
fpsFrames = 0
|
|
2388
|
+
fpsAt = time
|
|
2389
|
+
}
|
|
2390
|
+
lastStep = time
|
|
2391
|
+
const dt = last === 0 ? 0.016 : Math.min(0.05, ( time - last ) / 1000)
|
|
2392
|
+
last = time
|
|
2393
|
+
if (!pet) return
|
|
2394
|
+
const speed = Number(prefs.speed) > 0 ? Number(prefs.speed) : 1
|
|
2395
|
+
try {
|
|
2396
|
+
pet.step(dt * speed, true)
|
|
2397
|
+
} catch {
|
|
2398
|
+
/* 安静 */
|
|
2399
|
+
}
|
|
2400
|
+
try {
|
|
2401
|
+
updateCarry()
|
|
2402
|
+
} catch {
|
|
2403
|
+
/* 安静 */
|
|
2404
|
+
}
|
|
2405
|
+
try {
|
|
2406
|
+
frameNo += 1
|
|
2407
|
+
if (frameNo % 3 !== 0) return
|
|
2408
|
+
const box = pet.layout?.()
|
|
2409
|
+
if (box) {
|
|
2410
|
+
const hits = Array.isArray(box.hit) ? box.hit : []
|
|
2411
|
+
if (hits.length) {
|
|
2412
|
+
let x1 = Infinity
|
|
2413
|
+
let y1 = Infinity
|
|
2414
|
+
let x2 = -Infinity
|
|
2415
|
+
let y2 = -Infinity
|
|
2416
|
+
for (const circle of hits) {
|
|
2417
|
+
x1 = Math.min(x1, circle.x - circle.r)
|
|
2418
|
+
y1 = Math.min(y1, circle.y - circle.r)
|
|
2419
|
+
x2 = Math.max(x2, circle.x + circle.r)
|
|
2420
|
+
y2 = Math.max(y2, circle.y + circle.r)
|
|
2421
|
+
}
|
|
2422
|
+
hit = { x: x1, y: y1, w: x2 - x1, h: y2 - y1 }
|
|
2423
|
+
} else if (box.box) {
|
|
2424
|
+
hit = { x: box.box.x, y: box.box.y, w: box.box.w, h: box.box.h }
|
|
2425
|
+
}
|
|
2426
|
+
bubbleAnchor = {
|
|
2427
|
+
x: Math.min(Math.max(140, hit.x + hit.w / 2), worldSize.w - 140),
|
|
2428
|
+
y: Math.max(70, hit.y - 6),
|
|
2429
|
+
}
|
|
2430
|
+
placeBubble()
|
|
2431
|
+
publishBox(false)
|
|
2432
|
+
publishAnchor(box.box || hit)
|
|
2433
|
+
}
|
|
2434
|
+
} catch {
|
|
2435
|
+
/* ignore */
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
const loop = (time) => {
|
|
2439
|
+
step(time)
|
|
2440
|
+
window.requestAnimationFrame(loop)
|
|
2441
|
+
}
|
|
2442
|
+
window.requestAnimationFrame(loop)
|
|
2443
|
+
// 被别的全屏窗口盖住时 rAF 会被节流,定时器只做兜底,平时什么都不做
|
|
2444
|
+
window.setInterval(() => {
|
|
2445
|
+
if (performance.now() - lastStep > 220) step(performance.now())
|
|
2446
|
+
}, 120)
|
|
2447
|
+
|
|
2448
|
+
/* ---------- 碎碎念:气泡 + 朗读,间隔按设置来 ---------- */
|
|
2449
|
+
let idleTimer = 0
|
|
2450
|
+
const idleTick = () => {
|
|
2451
|
+
try {
|
|
2452
|
+
if (pet && !dragging && !offDuty && !napping && prefs.idleBubble !== false && prefs.greet !== false && lines.length) {
|
|
2453
|
+
say(lines[Math.floor(Math.random() * lines.length)])
|
|
2454
|
+
}
|
|
2455
|
+
} catch {
|
|
2456
|
+
/* ignore */
|
|
2457
|
+
}
|
|
2458
|
+
idleTimer = window.setTimeout(idleTick, idleMs())
|
|
2459
|
+
}
|
|
2460
|
+
idleTimer = window.setTimeout(idleTick, idleMs())
|
|
2461
|
+
|
|
2462
|
+
/* ---------- 作息感:深夜犯困去睡觉,清早醒来问早安 ---------- */
|
|
2463
|
+
let routinePhase = 'day'
|
|
2464
|
+
{
|
|
2465
|
+
const h0 = new Date().getHours()
|
|
2466
|
+
routinePhase = (h0 >= 23 || h0 < 5) ? 'night' : (h0 < 9) ? 'morning' : 'day'
|
|
2467
|
+
// 开机就在深夜:她已经在睡(不喊晚安,别一上来就出声)
|
|
2468
|
+
if (routinePhase === 'night' && pet) { try { pet?.act?.('sleep') } catch { /* ignore */ } }
|
|
2469
|
+
}
|
|
2470
|
+
window.setInterval(() => {
|
|
2471
|
+
try {
|
|
2472
|
+
// 作息的睡觉不受安静模式限制(睡觉本身就是安静的);但深夜标记阶段里不重复去睡
|
|
2473
|
+
if (!pet || dragging) return
|
|
2474
|
+
const h = new Date().getHours()
|
|
2475
|
+
if ((h >= 23 || h < 5) && routinePhase !== 'night' && !stayMode) {
|
|
2476
|
+
routinePhase = 'night'
|
|
2477
|
+
chatterSay('好困了…我去睡觉啦,晚安~')
|
|
2478
|
+
try { pet?.act?.('sleep') } catch { /* ignore */ }
|
|
2479
|
+
} else if (h >= 5 && h < 9 && routinePhase === 'night') {
|
|
2480
|
+
routinePhase = 'morning'
|
|
2481
|
+
try { pet?.act?.('wake') } catch { /* ignore */ }
|
|
2482
|
+
chatterSay('早呀!新的一天开始咯~')
|
|
2483
|
+
} else if (h >= 9 && h < 23 && routinePhase !== 'day') {
|
|
2484
|
+
routinePhase = 'day'
|
|
2485
|
+
}
|
|
2486
|
+
} catch { /* ignore */ }
|
|
2487
|
+
}, 60000)
|
|
2488
|
+
|
|
2489
|
+
/* ---------- 被冷落的小情绪:5 分钟没人理她蔫了,一互动就缓过来 ---------- */
|
|
2490
|
+
const GLOOM_MS = 5 * 60 * 1000
|
|
2491
|
+
let lastTouch = Date.now()
|
|
2492
|
+
let gloomSaidAt = 0
|
|
2493
|
+
const noteTouch = () => {
|
|
2494
|
+
lastTouch = Date.now()
|
|
2495
|
+
// 打盹中被打扰:立刻醒来
|
|
2496
|
+
wakeNap()
|
|
2497
|
+
// 刚蔫过不久就互动:立刻开心起来
|
|
2498
|
+
if (Date.now() - gloomSaidAt < 90000 && !offDuty) {
|
|
2499
|
+
try { pet?.setExpr?.('happy') } catch { /* ignore */ }
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2502
|
+
for (const ev of ['pointerdown', 'click', 'keydown']) {
|
|
2503
|
+
window.addEventListener(ev, noteTouch, { passive: true })
|
|
2504
|
+
}
|
|
2505
|
+
window.setInterval(() => {
|
|
2506
|
+
try {
|
|
2507
|
+
if (offDuty || !pet || dragging || uiBusy() || busy) return
|
|
2508
|
+
if (stayMode) return
|
|
2509
|
+
if (napping || Date.now() - lastTouch < GLOOM_MS) return
|
|
2510
|
+
if (Date.now() - gloomSaidAt < GLOOM_MS) return
|
|
2511
|
+
gloomSaidAt = Date.now()
|
|
2512
|
+
chatterSay(['咦,大家都去哪儿了呀…', '一个人待着有点冷清呢…', '喂——还在吗?(小声戳戳)'][Math.floor(Math.random() * 3)])
|
|
2513
|
+
try { pet?.setExpr?.(['cry', 'worried', 'pout'][Math.floor(Math.random() * 3)]) } catch { /* ignore */ }
|
|
2514
|
+
} catch { /* ignore */ }
|
|
2515
|
+
}, 60000)
|
|
2516
|
+
|
|
2517
|
+
/* ---------- 平时的小盹儿:白天闲着没事打个盹(作息感保留),一戳/一敲键盘就醒 ---------- */
|
|
2518
|
+
const wakeNap = () => {
|
|
2519
|
+
if (!napping) return
|
|
2520
|
+
napping = false
|
|
2521
|
+
window.clearTimeout(napTimer)
|
|
2522
|
+
napTimer = 0
|
|
2523
|
+
try { pet?.do?.('stand') } catch { /* 引擎被戳醒过就不必再叫 */ }
|
|
2524
|
+
applyRoam()
|
|
2525
|
+
}
|
|
2526
|
+
const startNap = () => {
|
|
2527
|
+
if (napping || !pet || dragging || busy || thinkingNow || voiceHeld || uiBusy() || launchWalk || seat !== null) return
|
|
2528
|
+
napping = true
|
|
2529
|
+
applyRoam()
|
|
2530
|
+
try { pet?.do?.('sleep') } catch { /* ignore */ }
|
|
2531
|
+
// 打盹 18~34 秒自己醒:伸个懒腰犯个困,接着该干嘛干嘛
|
|
2532
|
+
napTimer = window.setTimeout(() => {
|
|
2533
|
+
napTimer = 0
|
|
2534
|
+
napping = false
|
|
2535
|
+
try { pet?.do?.('stand') } catch { /* ignore */ }
|
|
2536
|
+
try { pet?.setExpr?.('sleepy') } catch { /* ignore */ }
|
|
2537
|
+
applyRoam()
|
|
2538
|
+
}, R(18, 34) * 1000)
|
|
2539
|
+
}
|
|
2540
|
+
window.setInterval(() => {
|
|
2541
|
+
try {
|
|
2542
|
+
if (napping || !pet || dragging || busy || thinkingNow || uiBusy() || launchWalk || seat !== null) return
|
|
2543
|
+
if (routinePhase === 'night') return // 夜里有正经觉,白天才打小盹
|
|
2544
|
+
if (Date.now() - lastTouch < 3 * 60 * 1000) return // 刚互动过不睡
|
|
2545
|
+
if (Math.random() > 0.12) return // 闲着每分钟约一成概率犯困
|
|
2546
|
+
startNap()
|
|
2547
|
+
} catch { /* ignore */ }
|
|
2548
|
+
}, 60000)
|
|
2549
|
+
|
|
2550
|
+
/* ---------- 设置页「试一下」:把动作广播到这只 ---------- */
|
|
2551
|
+
let actSeq = 0
|
|
2552
|
+
window.setInterval(async () => {
|
|
2553
|
+
try {
|
|
2554
|
+
const body = await fetch(`/dsh-coo-pet/act?since=${actSeq}`, { credentials: 'same-origin' }).then((res) => res.json())
|
|
2555
|
+
const seq = Number(body && body.seq) || 0
|
|
2556
|
+
if (seq > actSeq) {
|
|
2557
|
+
actSeq = seq
|
|
2558
|
+
const act = body && body.act && body.act.act
|
|
2559
|
+
try { report('act-recv', { seq, act: act || String(body && body.act && body.act.act) }) } catch { /* ignore */ }
|
|
2560
|
+
if (act === 'reset') {
|
|
2561
|
+
restoreIconsAll()
|
|
2562
|
+
} else if (act === 'resetAll') {
|
|
2563
|
+
restoreIconsAllEvery()
|
|
2564
|
+
} else if (act === 'launch') {
|
|
2565
|
+
// 语音说「打开XX」走这里:和打字同一个开软件流程
|
|
2566
|
+
const nm = String((body.act && body.act.name) || '').trim()
|
|
2567
|
+
if (nm) launchTheater(nm)
|
|
2568
|
+
} else if (act === 'spawnClones') {
|
|
2569
|
+
// 远程召唤分身(设置页/调试用)
|
|
2570
|
+
spawnClones(Number((body.act && body.act.name) || '') || 10)
|
|
2571
|
+
} else if (act === 'clearClones') {
|
|
2572
|
+
dismissAllClones()
|
|
2573
|
+
} else if (act === 'cloneFreeze') {
|
|
2574
|
+
// 调试:让全部分身立定不动(再发一次解除)——等同「分身行为›立定不动」
|
|
2575
|
+
cloneFrozen = !cloneFrozen
|
|
2576
|
+
cloneMode = cloneFrozen ? 'frozen' : 'free'
|
|
2577
|
+
applyCloneMode()
|
|
2578
|
+
} else if (act && pet && typeof pet.do === 'function') {
|
|
2579
|
+
pet.do(act)
|
|
2580
|
+
chime(act === 'dance' ? 'dance' : act === 'spin' ? 'spin' : 'select')
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
} catch {
|
|
2584
|
+
/* 断线先这样 */
|
|
2585
|
+
}
|
|
2586
|
+
}, 700)
|
|
2587
|
+
|
|
2588
|
+
/* ---------- 插入会话的回答:填了 Session ID 后,回答回流到气泡并朗读 ---------- */
|
|
2589
|
+
let answerSeq = 0
|
|
2590
|
+
window.setInterval(async () => {
|
|
2591
|
+
if (!String((prefs && prefs.attachSession) || '').trim()) return
|
|
2592
|
+
try {
|
|
2593
|
+
const body = await fetch(`/dsh-coo-pet/answer?since=${answerSeq}`, { credentials: 'same-origin' }).then((res) => res.json())
|
|
2594
|
+
const seq = Number(body && body.seq) || 0
|
|
2595
|
+
if (seq > answerSeq) {
|
|
2596
|
+
answerSeq = seq
|
|
2597
|
+
const text = body && body.answer && body.answer.text
|
|
2598
|
+
if (text) answerSay(String(text).slice(0, 600))
|
|
2599
|
+
}
|
|
2600
|
+
} catch {
|
|
2601
|
+
/* 断线先这样 */
|
|
2602
|
+
}
|
|
2603
|
+
}, 900)
|
|
2604
|
+
|
|
2605
|
+
/* ---------- 设置页「试听 / 测试」:把一句话喊出来 ---------- */
|
|
2606
|
+
let saySeq = 0
|
|
2607
|
+
window.setInterval(async () => {
|
|
2608
|
+
try {
|
|
2609
|
+
const body = await fetch(`/dsh-coo-pet/say?since=${saySeq}`, { credentials: 'same-origin' }).then((res) => res.json())
|
|
2610
|
+
const seq = Number(body && body.seq) || 0
|
|
2611
|
+
if (seq <= saySeq) return
|
|
2612
|
+
saySeq = seq
|
|
2613
|
+
const item = body && body.say
|
|
2614
|
+
if (!item || !item.text) return
|
|
2615
|
+
say(item.text)
|
|
2616
|
+
} catch {
|
|
2617
|
+
/* 断线先这样 */
|
|
2618
|
+
}
|
|
2619
|
+
}, 700)
|
|
2620
|
+
|
|
2621
|
+
/* ---------- 语音识别文字:实时填进她的输入框,最终一句也只填不发送 ---------- */
|
|
2622
|
+
let vtSeq = 0
|
|
2623
|
+
window.setInterval(async () => {
|
|
2624
|
+
try {
|
|
2625
|
+
const body = await fetch(`/dsh-coo-pet/voicetext?since=${vtSeq}`, { credentials: 'same-origin' }).then((res) => res.json())
|
|
2626
|
+
const seq = Number(body && body.seq) || 0
|
|
2627
|
+
if (seq <= vtSeq) return
|
|
2628
|
+
vtSeq = seq
|
|
2629
|
+
const item = body && body.text
|
|
2630
|
+
if (!item) return
|
|
2631
|
+
const text = String(item.text || '')
|
|
2632
|
+
if (item.final) {
|
|
2633
|
+
// 最终结果只填框,**不自动发送**(master 自己回车或点发送)
|
|
2634
|
+
if (text.trim()) {
|
|
2635
|
+
if (chatEl.classList.contains('hidden')) {
|
|
2636
|
+
openChat(false)
|
|
2637
|
+
voiceChat = false
|
|
2638
|
+
}
|
|
2639
|
+
chatText.value = text
|
|
2640
|
+
} else {
|
|
2641
|
+
closeChat()
|
|
2642
|
+
}
|
|
2643
|
+
} else {
|
|
2644
|
+
// 中间结果:输入框没开就开(不抢焦点),字边听边往上打
|
|
2645
|
+
if (chatEl.classList.contains('hidden')) openChat(false)
|
|
2646
|
+
chatText.value = text
|
|
2647
|
+
}
|
|
2648
|
+
} catch {
|
|
2649
|
+
/* 断线先这样 */
|
|
2650
|
+
}
|
|
2651
|
+
}, 350)
|
|
2652
|
+
|
|
2653
|
+
/* 设置变化:换配色/衣服/大小就重载,其余即时生效 */
|
|
2654
|
+
let watch = JSON.stringify({ look: prefs.look, outfit: prefs.outfit })
|
|
2655
|
+
let watchSize = String(prefs.size ?? '')
|
|
2656
|
+
let attachLostFor = ''
|
|
2657
|
+
window.setInterval(async () => {
|
|
2658
|
+
try {
|
|
2659
|
+
const body = await fetch('/dsh-coo-pet/prefs', { credentials: 'same-origin' }).then((res) => res.json())
|
|
2660
|
+
const next = body && body.config
|
|
2661
|
+
if (!next) return
|
|
2662
|
+
const hotChanged = next.hotkey !== prefs.hotkey
|
|
2663
|
+
const wanderChanged = next.wander !== prefs.wander
|
|
2664
|
+
const idleKeyBefore = JSON.stringify([prefs.idleLines, prefs.petName])
|
|
2665
|
+
prefs = { ...prefs, ...next }
|
|
2666
|
+
// 碎碎念内容或姓名变了:词表跟着重算(之前只在启动时算一次,改配置她也不换词)
|
|
2667
|
+
if (idleKeyBefore !== JSON.stringify([prefs.idleLines, prefs.petName])) {
|
|
2668
|
+
lines = splitLines(prefs.idleLines)
|
|
2669
|
+
}
|
|
2670
|
+
if (hotChanged) {
|
|
2671
|
+
try {
|
|
2672
|
+
desk.hotkey(prefs.hotkey)
|
|
2673
|
+
} catch {
|
|
2674
|
+
/* ignore */
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
// 溜达开关变了立即应用;值没变不动(避免干扰气泡/思考时的临时 roam 状态)
|
|
2678
|
+
if (wanderChanged) applyRoam()
|
|
2679
|
+
// busy / lastActiveAt 在响应顶层(不在 config 里),从 body 读——之前误从 config 读,
|
|
2680
|
+
// busy 永远是 false,「干活别搬图标 / 别乱走」的拦截从来没生效过
|
|
2681
|
+
lastActive = Number(body.lastActiveAt || 0)
|
|
2682
|
+
const nowBusy = body.busy === true
|
|
2683
|
+
if (nowBusy !== busy) {
|
|
2684
|
+
busy = nowBusy
|
|
2685
|
+
if (busy) {
|
|
2686
|
+
// DSH 开始干活(思考/执行工具):原地站住别溜达,手里的搬运就地放下
|
|
2687
|
+
thinkingNow = true
|
|
2688
|
+
try { pet?.set?.({ thinking: true, roam: 'off' }) } catch { /* ignore */ }
|
|
2689
|
+
if (!launchWalk && !seatWalk) { try { pet?.stopWalk?.() } catch { /* ignore */ } }
|
|
2690
|
+
if (iconWalk || carry) { iconWalk = null; carry = null; hideCarry() }
|
|
2691
|
+
} else {
|
|
2692
|
+
// 干完活了,恢复平时的活动状态(回答气泡还挂着就先别动,等气泡收掉再放行)
|
|
2693
|
+
thinkingNow = false
|
|
2694
|
+
try { pet?.set?.({ thinking: false }) } catch { /* ignore */ }
|
|
2695
|
+
window.clearTimeout(thinkTimer)
|
|
2696
|
+
if (bubbleEl && !bubbleEl.classList.contains('on')) applyRoam()
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
// 插入会话状态:确认跟丢了只喊一次(同一个会话 ID 不重复喊,避免状态抖动刷屏)
|
|
2700
|
+
const attach = body.attach
|
|
2701
|
+
if (attach && attach.id) {
|
|
2702
|
+
if (attach.ok === false && attachLostFor !== attach.id) {
|
|
2703
|
+
attachLostFor = attach.id
|
|
2704
|
+
say('插入的会话好像跟丢了,去设置里看看 Session ID 吧')
|
|
2705
|
+
}
|
|
2706
|
+
} else {
|
|
2707
|
+
attachLostFor = ''
|
|
2708
|
+
}
|
|
2709
|
+
// 体型变了才整页重载;形象 / 衣服变了走原地无缝换肤(不闪不跳,动作不打断)
|
|
2710
|
+
const now = JSON.stringify({ look: prefs.look, outfit: prefs.outfit })
|
|
2711
|
+
if (now !== watch) {
|
|
2712
|
+
watch = now
|
|
2713
|
+
try {
|
|
2714
|
+
pet?.setScheme?.(`${prefs.look || 'deepseek'}-${prefs.outfit || 'maid'}`, { fade: 0.6 })
|
|
2715
|
+
} catch {
|
|
2716
|
+
/* ignore */
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
const sz = String(prefs.size ?? '')
|
|
2720
|
+
if (sz !== watchSize) {
|
|
2721
|
+
watchSize = sz
|
|
2722
|
+
window.location.reload()
|
|
2723
|
+
return
|
|
2724
|
+
}
|
|
2725
|
+
if (prefs.display === 'none') desk.close()
|
|
2726
|
+
stage.style.opacity = String(prefs.opacity ?? 1)
|
|
2727
|
+
lines = splitLines(prefs.idleLines)
|
|
2728
|
+
} catch {
|
|
2729
|
+
/* 断线先这样 */
|
|
2730
|
+
}
|
|
2731
|
+
}, 3000)
|
|
2732
|
+
</script>
|
|
2733
|
+
</body>
|
|
2734
|
+
</html>
|