import {BlockstateResolver} from "./blockstate"; export class Renderer { constructor() { this.canvas = document.createElement('canvas'); this.canvas.style.display = 'none'; document.body.appendChild(this.canvas); this.gl = this.canvas.getContext('webgl2', {antialias: false, alpha: true}); } } async function parse(src) { const lines = src.replace(/#.*?(?:\n|$)/, '\n').trim().split(/(?:\n[ \t]*)+/); let count = 0; const res = new BlockstateResolver(); function ff() { for (const line of lines) { const args = line.split(/[ \t]+/); const cmd = args[0].toLowerCase(); if (cmd === 'p') { const id = args[1]; const hash = count; count += 1; console.log(id, JSON.stringify(res.getResolver(id)({}, hash))); } } } res.onResolve = (id, fn) => { console.log('resolved', id, 'to', fn) ff() } ff() } export class MCDioramaElement extends HTMLElement { connectedCallback() { const canvas = document.createElement('canvas'); this.appendChild(canvas); const ctx = canvas.getContext('2d'); setTimeout(() => { const script = this.querySelector('script[type="text/mc-world"]'); parse(script.textContent); }, 0) } } customElements.define('mc-diorama', MCDioramaElement);