@wodzik/cubecore 0.1.7 → 0.1.8
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/bluetooth/rotations.d.ts
CHANGED
|
@@ -64,12 +64,14 @@ export interface HeldOptions {
|
|
|
64
64
|
/**
|
|
65
65
|
* Wide moves to read from one face turn and the core's rotation — the rest
|
|
66
66
|
* stay a face turn and a rotation. Default r, l, f, b: a u or d is almost
|
|
67
|
-
* always a U / D turn and a y regrip.
|
|
68
|
-
* always read.
|
|
67
|
+
* always a U / D turn and a y regrip.
|
|
69
68
|
*/
|
|
70
69
|
wide?: readonly string[];
|
|
70
|
+
/** Slices to read from both faces of an axis and the core's rotation (default M, E, S); the rest stay two face turns and a rotation. */
|
|
71
|
+
slices?: readonly string[];
|
|
71
72
|
}
|
|
72
73
|
export declare const DEFAULT_WIDE: readonly string[];
|
|
74
|
+
export declare const DEFAULT_SLICES: readonly string[];
|
|
73
75
|
export declare function heldTokens(moves: readonly TimedMove[], startRotation: string, rotations: readonly RotationRecord[], options?: HeldOptions): HeldToken[];
|
|
74
76
|
/** A rotation and the face moves around it that make a slice / wide move → that move. */
|
|
75
77
|
export declare function mergeSlicesAndWides(tokens: readonly HeldToken[], allowed?: ReadonlySet<string>): HeldToken[];
|
package/bluetooth/rotations.js
CHANGED
|
@@ -29,8 +29,9 @@ export function heldMove(move, grip) {
|
|
|
29
29
|
return canonical ? canonical + move.slice(1) : move;
|
|
30
30
|
}
|
|
31
31
|
export const DEFAULT_WIDE = ["r", "l", "f", "b"];
|
|
32
|
+
export const DEFAULT_SLICES = ["M", "E", "S"];
|
|
32
33
|
export function heldTokens(moves, startRotation, rotations, options = {}) {
|
|
33
|
-
const allowed = new Set(options.wide ?? DEFAULT_WIDE);
|
|
34
|
+
const allowed = new Set([...(options.wide ?? DEFAULT_WIDE), ...(options.slices ?? DEFAULT_SLICES)]);
|
|
34
35
|
let grip = rotateGrip(IDENTITY_GRIP, startRotation);
|
|
35
36
|
const rots = snapToSlices(moves, grip, [...rotations].sort((a, b) => a.after - b.after || a.t - b.t), allowed);
|
|
36
37
|
const tokens = [];
|
|
@@ -69,13 +70,13 @@ const AXIS_FACES = { x: ["R", "L"], y: ["U", "D"], z: ["F", "B"] };
|
|
|
69
70
|
const SLICE_WIDE = ["M", "E", "S", "r", "l", "u", "d", "f", "b"].flatMap((f) => [f, `${f}'`, `${f}2`]);
|
|
70
71
|
const effect = (alg) => applyMoves(solvedState(), alg).join();
|
|
71
72
|
const SLICE_WIDE_EFFECT = new Map();
|
|
72
|
-
/** The slice
|
|
73
|
+
/** The slice / wide move the group (held letters and a rotation) amounts to, if `allowed` (by its letter), or null. */
|
|
73
74
|
function sliceOrWide(group, allowed) {
|
|
74
75
|
if (SLICE_WIDE_EFFECT.size === 0)
|
|
75
76
|
for (const m of SLICE_WIDE)
|
|
76
77
|
SLICE_WIDE_EFFECT.set(effect(m), m);
|
|
77
78
|
const m = SLICE_WIDE_EFFECT.get(effect(group.join(" ")));
|
|
78
|
-
return m &&
|
|
79
|
+
return m && allowed.has(m[0]) ? m : null;
|
|
79
80
|
}
|
|
80
81
|
/**
|
|
81
82
|
* The consecutive run (up to MAX_GROUP) of moves on the axis nearest to
|
|
@@ -142,7 +143,7 @@ function snapToSlices(moves, startGrip, rotations, allowed) {
|
|
|
142
143
|
return out.sort((a, b) => a.after - b.after || a.t - b.t);
|
|
143
144
|
}
|
|
144
145
|
/** A rotation and the face moves around it that make a slice / wide move → that move. */
|
|
145
|
-
export function mergeSlicesAndWides(tokens, allowed = new Set(DEFAULT_WIDE)) {
|
|
146
|
+
export function mergeSlicesAndWides(tokens, allowed = new Set([...DEFAULT_WIDE, ...DEFAULT_SLICES])) {
|
|
146
147
|
const out = [...tokens];
|
|
147
148
|
for (let k = 0; k < out.length; k++) {
|
|
148
149
|
const rot = out[k];
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.8",
|
|
7
7
|
"description": "A 3×3×3 cube library for the web, built around smart (Bluetooth) cubes: state, notation, methods, solvers and scrambles, a three.js renderer with skins, pictures, web components, React bindings.",
|
|
8
8
|
"license": "MPL-2.0",
|
|
9
9
|
"author": "Tomasz Wodzikowski <wodziszczakow@gmail.com>",
|