import { html } from "./libs/uhtml.js"; import { dispatch } from "./dispatch.js"; import { challenges } from "./challenges.js"; import { docs } from "./views/docs.js"; import "./pixel-editor/pixel-editor.js"; import "./sequencer/sequencer.js"; import "./map-editor/map-editor.js"; import "./views/bitmap-preview.js"; export const view = (state) => html` ${menu(state)}
${state.logs.map(x => html`${x}
`)}
${docs(state)}
${state.uploadState !== 'idle' ? html`
${state.uploadLogs}${state.uploadState === "done" ? html`
        

` : null}
` : null}
{ // Click on overlay or close button: for (const item of event.composedPath()) { if (item.classList && item.classList.contains("asset-editor-content")) return; } dispatch("SET_ASSET_EDITOR", { type: null, text: null }) }}>
${ { "bitmap": html``, "sequencer": html``, "map": html``, [undefined]: "" }[state.editor] }
` const sampleMenuItem = sample => html` ${sample.name} ` const editableName = (state) => html` ` const drawFile = (file, i, state) => { const [ name, text ] = file; const setText = () => { if (state.stale && !confirm("You have unsaved changes! Are you sure you want to switch files?")) return; state.staleRun = true; const games = Object.fromEntries(state.savedGames); const text = games[name]; const cur = state.codemirror.state.doc.toString(); state.newDocument = true; dispatch("SET_EDITOR_TEXT", { text: "", range: [0, cur.length] }); dispatch("RUN"); state.newDocument = true; dispatch("SET_EDITOR_TEXT", { text, range: [0, 0] }); dispatch("RENDER"); window.localStorage.setItem("last-game", name); } const deleteFile = (e) => { if (e.stopPropagation) e.stopPropagation(); if (e.preventDefault) e.preventDefault(); e.cancelBubble = true; e.returnValue = false; const toSave = state.savedGames.filter( ([ fileName, text ]) => { return fileName !== name; }) window.localStorage.setItem("puzzle-lab", JSON.stringify(toSave) ); if (!confirm(`Do you want to delete: ${name}?`)) return; state.savedGames = toSave; dispatch("RENDER"); return false; } const fullText = state.codemirror.state.doc.toString(); const matches = fullText.matchAll(/(map|bitmap|tune)`[\s\S]*?`/g); for (const match of matches) { const index = match.index; state.codemirror.foldRange(index, index+1); } return html`
${name.slice(0, 15)}${name.length > 15 ? "..." : ""}
x
` } const newFile = (state) => { if (!state.codemirror) return ""; const setText = () => { if (state.stale && !confirm("You have unsaved changes! Are you sure you want to create a new file?")) return; state.staleRun = true; const text = `/* @title: game_name @author: your_name */ const player = "p"; setLegend( [ player, bitmap\` ................ ................ .......000...... .......0.0...... ......0..0...... ......0...0.0... ....0003.30.0... ....0.0...000... ....0.05550..... ......0...0..... .....0....0..... .....0...0...... ......000....... ......0.0....... .....00.00...... ................\`] ); setSolids([]); let level = 0; const levels = [ map\` p. ..\`, ]; setMap(levels[level]); setPushables({ [ player ]: [], }); onInput("s", () => { getFirst(player).y += 1 }); afterInput(() => { }); `; const cur = state.codemirror.state.doc.toString(); state.newDocument = true; dispatch("SET_EDITOR_TEXT", { text: "", range: [0, cur.length] }); dispatch("RUN"); state.newDocument = true; dispatch("SET_EDITOR_TEXT", { text, range: [0, 0] }); dispatch("RENDER"); } const fullText = state.codemirror.state.doc.toString(); const matches = fullText.matchAll(/(map|bitmap|tune)`[\s\S]*?`/g); for (const match of matches) { const index = match.index; state.codemirror.foldRange(index, index+1); } return html`
new game
` } const menu = (state) => html`