CubeViewクラス
リファレンスの説明と例は英語です。見出しと目次は日本語です。
A cube on the screen. new CubeView(element, { size: 3 }) draws it in the
element, which it fills, so the element needs a size; destroy() takes it
away again with every listener.
インポート
import { CubeView } from "@johnmorrisdotca/kyuubu";
定義
class CubeView
new CubeView(host: HTMLElement, options: CubeViewOptions): CubeView
引数
| 名前 | 型 | 説明 |
|---|---|---|
host | HTMLElement | The DOM host with a size and position. |
options | CubeViewOptions | View or replay options. |
メンバー
| 名前 | 型 | 説明 |
|---|---|---|
state | string | The stickers as they will be once every turn asked for has finished. |
size | number | The cube's side. |
setTheme | (theme: CubeTheme): void | Change how the cube looks, at once and without redrawing it: any of its
colours, its plastic, and the shape of its stickers. What is left out of
|
setLocale | (locale: KyuubuLanguage): void | The language of the cube's accessible name. A |
setScale | (scale?: CubeScale, width?: number): void | Draw the cube at a scale, or at a width in pixels (which wins), or with
neither, back to filling the box it is in. The box keeps one steady
square, never wider than its container, so nothing round it moves when
the cube does. The cube's own |
setInteractive | (interactive: boolean): void | Whether a person can turn it now. |
setState | (state: string, size?: number): void | Put the stickers as given, at once, dropping any turn still to come. |
turn | (move: CubeMove, { report, animate }?: { report?: boolean; animate?: boolean; }): void | Turn a layer, animated after any turns already on their way. Told to |
turnTogether | (moves: readonly CubeMove[], { animate, ms }?: { animate?: boolean; ms?: number; }): void | Several layers about one axis turned together, the same way and as far,
as one movement: a wide turn ( |
scramble | (moves: readonly CubeMove[], { animate }?: { animate?: boolean; }): void | Scramble the cube with these turns, from the cube as it is. Turned
quickly, the way a hand scrambles it: the last ten are shown, each in
under a tenth of a second, and every one before them is made at once, so a
scramble of a hundred turns on a 7×7 is over in a second and not a blur
that shows nothing. With |
busy | boolean | Whether a turn asked for is still on its way. |
redraw | (): void | The cube taken out of the page and put straight back, so that the browser makes its layers again. Nothing about it changes. |
setTurnMs | (ms: number): void | How long a quarter turn made by a key, by notation or from code takes, in milliseconds, from now on. |
setLook | (yaw: number, pitch: number): void | Look at the cube from another way round, in degrees. |
on | (type: "turn", listener: CubeViewEvents["turn"]): () => void
(type: "look", listener: CubeViewEvents["look"]): () => void | Listen for what the cube tells |
showHint | (moves: CubeMove | readonly CubeMove[] | null): void | Show on the cube how to make a turn: the layer that turns is lit and the
rest dimmed, and an arrow lies across the stickers the way to drag them,
worked out afresh whenever the cube is looked at from somewhere else. The
arrow is the drag's own rules run backwards, so a drag along it from the
sticker at its tail is that turn. Several layers about one axis turned as
far (a wide turn) are lit as one slab with one arrow; each is dragged on
its own. A turn of the whole cube lights nothing: no drag on a sticker
makes it. |
hint | DragHint | null | What the hint shows from where the cube is looked at now: the layers lit, the sticker to take hold of and the way to drag it; null with no hint, or for a turn of the whole cube. |
resetLook | (): void | Back to the way it was first seen. |
looking | { yaw: number; pitch: number; } | The way the cube is looked at now, in degrees. |
destroy | (): void | Take the cube off the page, with every listener it added. |
host | HTMLElement | The element the cube was made in. |
例
import { CubeView } from "@johnmorrisdotca/kyuubu";
const host = document.createElement("div");
host.style.cssText = "width:300px;height:300px;position:relative";
document.body.append(host);
const cube = new CubeView(host, { size: 3, interactive: true });
console.log(cube.state);
// Call cube.destroy() when the host is removed.この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。