Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ browser flows. Reviewed capture photos and metadata live in `test/fixtures/`
and use Git LFS. Start with the [fixture guide](../test/fixtures/README.md)
before adding one. The Orbit64 browser codec is adapted from
`flix-orbit64` under [Apache-2.0](../third_party/flix-orbit64.LICENSE), with
cross-project vectors in `test/cube/notation/orbit64Vectors.json` and
`test/cube/notation/orbit64LargeVectors.json`.
reference vectors from that project in `test/cube/notation/orbit64Vectors.json`
and `test/cube/notation/orbit64LargeVectors.json`. Only the V2 format exists in
the app: [`Orbit64Token.res`](../src/cube/notation/Orbit64Token.res) writes the
color framed token of the notation card for sizes 2-15 and reads color tokens
in the typed-input field. V2 reads the V1 tokens of sizes 2, 3, 4, 6 and 7 as
color framed tokens at offset 0; the 43-character V1 token of a 5x5 cube is not
read.

The Orbit64 V2 state codec for 2x2-15x15 cubes
([`Orbit64V2.res`](../src/cube/notation/Orbit64V2.res)) works on orbit
Expand Down
4 changes: 2 additions & 2 deletions docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,6 @@ Typing facelets never changes the format the notation panel shows: that is the
**Colors (WRG)** / **Faces (URF)** switch on the panel (faces by default), also
set on the settings page. Input made only of R and B letters fits both formats
and is read in that saved format. The notation panel can also
copy an [Orbit64.Net](https://github.com/wstein/flix-orbit64/blob/main/FORMAT.md#spaced-facelet-reference-vectors)
compact state token for 2×2–7×7. Paste facelets or a state token into **Type
copy an [Orbit64](https://github.com/wstein/flix-orbit64/blob/main/FORMAT-V2.md)
compact state token for 2×2–15×15. Paste facelets or a state token into **Type
colors**; move and algorithm tokens are separate formats and are not accepted.
42 changes: 42 additions & 0 deletions e2e/notation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,45 @@ test('typing colors does not change the saved notation format', async ({
'cube-assembler-notation=wrg',
)
})

// Token width of each size (Orbit64 V2 color framed).
const tokenWidths: [number, number][] = [
[8, 122],
[9, 155],
[10, 195],
[11, 237],
[12, 285],
[13, 336],
[14, 393],
[15, 452],
]

for (const [size, width] of tokenWidths) {
test(`shows and reads an Orbit64 token of a ${size}x${size} cube`, async ({
page,
}) => {
const errors: Error[] = []
page.on('pageerror', (error) => errors.push(error))
await page.goto('/')
await page.getByRole('button', { name: 'Type colors' }).click()
const facelets = ['U', 'R', 'F', 'D', 'L', 'B']
.map((face) => face.repeat(size * size))
.join(' ')
const input = page.getByRole('textbox', { name: /facelets/i })
await input.fill(facelets)
await page.getByRole('button', { name: 'Apply Facelets' }).click()
const notation = page.getByRole('textbox', { name: 'Notation' })
await expect(notation).toHaveValue(facelets)
const token = page.locator('.orbit64-token-row code')
await expect(token).toHaveText(/^[A-Za-z0-9_-]+$/)
const value = await token.innerText()
expect(value).toHaveLength(width)

// Reading the token back gives the same facelets.
await page.getByRole('button', { name: 'Type colors' }).click()
await input.fill(value)
await page.getByRole('button', { name: 'Apply Facelets' }).click()
await expect(notation).toHaveValue(facelets)
expect(errors).toEqual([])
})
}
2 changes: 1 addition & 1 deletion src/client/manualFaceletInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function ManualFaceletInput({
<label htmlFor="manual-facelets">Facelets</label>
<p id="manual-facelets-help" class="notation-hint">
{`6 blocks of ${size * size} letters in U R F D L B order, space-separated - face letters (U, R, F, D, L, B: the face each sticker's color matches when solved) or colors (W, O, G, R, B, Y). The format is detected.`}{' '}
You can also paste an Orbit64 2×2–7×7 state token.
You can also paste an Orbit64 2×2–15×15 state token.
</p>
<textarea
id="manual-facelets"
Expand Down
12 changes: 9 additions & 3 deletions src/client/notationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import {
toURFFacelets,
toWRGFacelets,
} from '../cube/notation/NotationOutput.gen'
import { encodeOrbit64State } from '../cube/notation/orbit64'
import { encodeOrbit64Token } from '../cube/notation/orbit64Token'

// The Orbit64 V2 state token of a cube of any size 2..15, or null when the
// facelets form no valid cube state.
export function orbit64TokenOf(cube: CubeState): string | null {
return encodeOrbit64Token(toURFFacelets(cube))
}

type NotationFormat = 'wrg' | 'urf'
type CopyStatus =
Expand Down Expand Up @@ -40,8 +46,8 @@ export function NotationCard({
: toURFFacelets(cube)
: ''
const orbit64Token = useMemo(
() => (cube && size <= 7 ? encodeOrbit64State(toURFFacelets(cube)) : null),
[cube, size],
() => (cube ? orbit64TokenOf(cube) : null),
[cube],
)
const copyToClipboard = async (
value: string,
Expand Down
6 changes: 3 additions & 3 deletions src/core/capture/CaptureFlow.res
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ type parsedCube =
// text where it can be, else the selected one is used.
let parseCubeInput = (input, selectedFormat: NotationOutput.notationFormat) => {
let trimmed = String.trim(input)
let isToken = Orbit64.looksLikeOrbit64StateToken(trimmed)
let isToken = Orbit64Token.looksLikeToken(trimmed)
let format: NotationOutput.notationFormat = isToken
? Urf
: NotationOutput.detectNotationFormat(input)->Null.toOption->Option.getOr(selectedFormat)
let cube = if isToken {
Orbit64.decodeOrbit64State(trimmed)
Orbit64Token.decodeState(trimmed)
->Null.toOption
->Option.flatMap(facelets => NotationOutput.fromURFFacelets(facelets)->Null.toOption)
} else {
Expand All @@ -148,7 +148,7 @@ let parseCubeInput = (input, selectedFormat: NotationOutput.notationFormat) => {
| None =>
Unreadable({
message: isToken
? "Invalid Orbit64 state token. Only canonical 2×2–7×7 state tokens are supported."
? "Invalid Orbit64 state token. Only Orbit64 V2 color state tokens of 2×2–15×15 cubes are supported."
: format == Wrg
? "Invalid facelets. Must be 6 space-separated blocks of equal, perfect-square length (9 for 3×3, 25 for 5×5, ...) using colors W, O, G, R, B, Y, in U R F D L B order."
: "Invalid facelets. Must be 6 space-separated blocks of equal, perfect-square length (9 for 3×3, 25 for 5×5, ...) using letters U, R, F, D, L, B (the face each sticker matches when solved), in U R F D L B order.",
Expand Down
Loading
Loading