CuboidViewclass
A cuboid on the screen. new CuboidView(element, { dims: [2, 3, 3] }) draws
it in the element, which it fills, so the element needs a size; destroy()
takes it away again with every listener. A turn the puzzle cannot make
throws a RangeError, as turnCuboid does.
Import it
import { CuboidView } from "@johnmorrisdotca/kyuubu/cuboid/draw";
Definition
class CuboidView
new CuboidView(host: HTMLElement, options: CuboidViewOptions): CuboidView
Parameters
| Name | Type | Description |
|---|---|---|
host | HTMLElement | The DOM host with a size and position. |
options | CuboidViewOptions | View or replay options. |
Members
| Name | Type | Description |
|---|---|---|
state | string | The stickers as they will be once every turn asked for has finished. |
dims | CuboidDims | The puzzle's width, height and depth. |
busy | boolean | Whether a turn is on its way or a layer is held. |
looking | { yaw: number; pitch: number; } | The way the puzzle is looked at now, in degrees. |
setTheme | (theme: CubeTheme): void | Change how the puzzle looks, at once and without redrawing it. What is left out of |
setLocale | (locale: KyuubuLanguage): void | The language of the puzzle's accessible name. A |
setInteractive | (interactive: boolean): void | Whether a person can turn it now. |
setTurnMs | (ms: number): void | How long a quarter turn takes, in milliseconds, from now on. |
setState | (state: string, dims?: CuboidDims): void | Put the stickers as given, at once, dropping any turn still to come. Another |
turn | (move: CuboidMove, { report, animate, ms }?: { report?: boolean; animate?: boolean; ms?: number; }): void | Turn a layer, animated after any turns already on their way. Told to |
turnTogether | (moves: readonly CuboidMove[], options?: { animate?: boolean; ms?: number; }): void | The same as |
on | <K extends keyof CuboidViewEvents>(type: K, listener: CuboidViewEvents[K]): () => void | Listen for a turn a person made ( |
setLook | (yaw: number, pitch: number): void | Turn the view to look at the puzzle from here. The pitch stays between −90 and 90 degrees. |
resetLook | (): void | Back to the way the puzzle was first looked at. |
redraw | (): void | Build the 3D layers again, as a browser that let go of them needs. |
destroy | (): void | Take the puzzle off the page, with every listener it added. |
host | HTMLElement | The element the puzzle was made in. |
Examples
import { CuboidView } from "@johnmorrisdotca/kyuubu/cuboid/draw";
const host = document.createElement("div");
host.style.cssText = "width:300px;height:300px;position:relative";
document.body.append(host);
const cube = new CuboidView(host, { dims: [2, 3, 3], interactive: true });
console.log(cube.state);
// Call cube.destroy() when the host is removed.