import {BlockstateResolver} from "./blockstate"; import {ModelResolver} from "./model"; 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]*)+/); const bres = new BlockstateResolver(); const mres = new ModelResolver(); function ff() { const drawList = new Map(); for (const line of lines) { const args = line.split(/[ \t]+/); const cmd = args[0].toLowerCase(); if (cmd === 'p') { const pos = [args[1], args[2], args[3]]; const id = args[4]; const state = Object.fromEntries(args.slice(5).map(it => it.split('='))); for (const part of bres.resolve(id, pos, state)) { drawList.set(part.model, null); } } } for (const id of drawList.keys()) { const data = mres.get(id); console.log(id, data); } } bres.onResolve = (id) => { console.log('resolved blockstate', id) ff() } mres.onResolve = (id) => { console.log('resolved model', id) 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);