frontispiece / apps / frontispiece-editor / src / bootstrap / map-config-to-layout.ts
map-config-to-layout.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 { LayoutStateController } from '../state/layout-state'

export const mapConfigToLayout = (configToml) => {
	const layoutState = LayoutStateController
	
	const _setValue = (configKey: string, layoutKey: string = undefined) => {
		if (!layoutKey) {
			layoutKey = configKey
		}
		if (configToml[configKey] === undefined) {
			return
		}
		layoutState[layoutKey].set(configToml[configKey])
	}

	_setValue("oneline")
	_setValue("bg")
	_setValue("title")
	_setValue("subtitle")
	_setValue("clearAfterChoice")
	_setValue("maxVisibleLines")
	_setValue("scrollAfterAdvance")
	_setValue("startButton", "startButtonString")

	if (configToml.showTitleScreen) {
		layoutState.currentRoute.set('title')
	} else {
		layoutState.currentRoute.set('story')
	}
}