frontispiece / packages / ink-processor / src / data / choice.ts
choice.ts
Raw
/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

import { InkChoice } from "../inkTypes"
import { VisualInkChoice } from "../types"
import { parseAtShorthandLine } from "@a-morphous/at-shorthand"

export const createVisualInkChoice = (choice: InkChoice, index: number): VisualInkChoice => {
	const atShorthand = parseAtShorthandLine(choice.text)

	const choiceObj: VisualInkChoice = {
		text: atShorthand.text,
		type: 'choice',
		index: index
	}

	if (atShorthand.primary) {
		choiceObj.meta = {
			primary: atShorthand.primary,
			classes: atShorthand.classes
		}
	}

	return choiceObj
}