frontispiece / apps / frontispiece-editor / src / index.ts
index.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 { render } from "preact"
import { html, setupStory } from './bootstrap/bootstrap'
import { BG } from './view/bg'
import parseString from '@iarna/toml/parse-string'
import { mapConfigToLayout } from './bootstrap/map-config-to-layout'
import { Router } from './view/router'

import 'normalize.css'
import './styles/index.css'
import { setFavicon } from "./utils/set-favicon"
import { loadScript } from "./utils/load-script"

const Game = () => {
	return html`<${Router} /><${BG}/>`
}

const start = async() => {

	try {
		const configResponse = await fetch("./config.toml")
		const text = await configResponse.text()
		const configObject = parseString(text)
		mapConfigToLayout(configObject)

		document.title = configObject.title ?? "Untitled"
		setFavicon(configObject.favicon ?? "/assets/favicon.png")
		
	} catch (e) {
		console.warn("Error parsing configuration file: ", e, "Default configuration will be used.")
	}

	await setupStory("./story.ink")
	await loadScript("/scripting.js", true, "module")
	render(html`<${Game} />`, document.getElementById('app') as Element)
}

start()