improcket/js/gui/index.mjs
2018-03-03 00:04:17 +00:00

33 lines
608 B
JavaScript

import {context} from '../graphics/index.mjs';
import * as modules from './modules.mjs';
export const elements = new Set();
export let root;
export function init() {
elements.clear();
root = modules.root();
changeView('title');
}
export function tick() {
root.tick();
}
export function changeView(view) {
root.clear();
if (view == 'title') {
root.append(modules.title());
}
if (view == 'game') {
root.append(modules.game());
}
}
export function measureText(msg, font) {
context.font = font;
let measurement = context.measureText(msg);
return [measurement.width, measurement.height];
}