Cubing anim alg

From 2017YANR02/cuberoot.me · View interactive version

Cubing anim alg is an AI agent skill from the GitHub repository 2017YANR02/cuberoot.me. Use when building cubing.js TwistyPlayer or AlgPlayer UI with alg input, 虚拟键盘, 光标同步, caret-driven move sync, or animation-following behavior across alg, recon, admin, and training pages. Code uses alg, not formula.

How to use this skill

Skill file

入口 — 选哪个

命名:用 alg,不用 formula

英文代码 / 类型 / 文件名 / CSS class / data-attr / 字段名一律 alg,不要再写 formula / Formula(2026-05-08 已把历史 FormulaInput / formula_autospace / tokenizeFormula / data-formula 全部 rename)。中文 UI / 注释 / zh.json 里的"公式"是 cubing 圈通用词,保留;但变量 / 类型仍走英文 alg。

数学公式 (frames = ⌈⌋ × ...) / 数学注释里写 formula 是 OK 的(跟 cubing alg 无关)。

fillPane vs 固定 size

alg=空 → 控件全灰

experimentalSetupAlg 是 起始状态,不入播放序列。alg="" 时序列长 0,进度条停在末尾、播放/前进按钮全灰。要播必须给非空 alg。比如 admin editor 默认拿第一条 alg 做 preview,blur 后保留最后一次而不是清空。

光标 → 动画同步

复用 utils/recon_alg_utils.ts 里的:

读 caret offset:

prefix → moves:text.slice(0, caret).trim().split(/\s+/).filter(Boolean).length(简单文本) 或 extractAlgFromText + 同样拆分(含注释)。

重建后再 sync 一次(必做)

打字时 alg 在 debounce → player 重建 → 此时 player 还没 ready,sync 调用 silently no-op,光标停在 0。两种兜底:

  1. useEffect 监听 debouncedAlg,变了就再 sync 一次(ReconSubmitPage.tsx:784)。
  2. 50/200/500ms 三次重试(AdminCaseEditor.tsx)— player ready 时机不确定时用。

必须 debounce alg 输入

每次按键都换 player.alg → 销毁重建 TwistyPlayer (~150KB lazy bundle 已加载但 WebGL ctx 重建仍卡)。打字 → 400-500ms debounce → 再换 player 的 alg。recon / admin editor 都是 400-500ms。

AlgInput 关键 props

CubeKeyboardSection 用法

sq1 / 大魔方特殊

stickering 映射

pickStickering(puzzle, set) 在 AlgPlayer.tsx,把我们的 set slug 映射到 cubing.js 的 experimentalStickering(F2L / OLL / PLL / COLL / ZBLS / WVLS …)。新 alg set 要在那加一行。返回 undefined 时 player 不传 experimentalStickering,所有贴纸正常显示。

暴露 player 实例(高级)

<AlgPlayer ref> 拿 AlgPlayerHandle,getPlayer() 返回内部 TwistyPlayer。给 syncPlayerToMoveCount 用。<TwistySection playerRef={ref}> 直接走 ref.current = player,二者风格不同,选 component 时注意。

禁忌

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.