add console clearing, allow use of console within itself

This commit is contained in:
Reimar 2025-10-13 10:47:36 +02:00
parent 5cf909b867
commit 213b495fe8
6 changed files with 14 additions and 8 deletions

View File

@ -80,7 +80,7 @@
</div>
<div id="console">
<pre><code id="console-code">Karlkode 1.0</code></pre>
<pre id="console-code"></pre>
<input
id="console-input"
type="text"
@ -101,7 +101,7 @@
<pre
id="editor"
>
const lib = karlkoder.lib();
export const lib = karlkoder.lib();
lib.clear("green");

View File

@ -15,6 +15,7 @@ export class CodeRunner {
async run() {
this.isRunning = true;
this.console.clear();
this.console.log("Running code...");
this.codeStopper.start();
@ -57,7 +58,7 @@ export class CodeRunner {
}
// Evaluate code
const func = new Function(`"use strict";return ${code}`);
const func = new Function(`"use strict";let console=playgroundConsole;return ${code}`);
try {
const result = func();

View File

@ -40,7 +40,7 @@ export class Gamelib {
try {
loopFunction(deltaT);
} catch (error) {
this.console.log(error);
this.console.error(error);
}
}, 16);

View File

@ -19,6 +19,10 @@ const playgroundConsole = new PlaygroundConsole(
document.querySelector("#console-code"),
);
window.addEventListener('DOMContentLoaded', () => {
playgroundConsole.log("Karlkode 1.0");
});
const codeStopper = new CodeStopper();
const spriteProvider = new SpriteProvider();

View File

@ -31,4 +31,8 @@ export class PlaygroundConsole {
el.textContent = "" + text;
this.elem.appendChild(el);
}
clear() {
this.elem.textContent = "";
}
}

View File

@ -351,11 +351,8 @@ footer {
transition: border-color 200ms ease-in-out;
}
#project-name:hover, #project-name:active {
#project-name:hover, #project-name:focus {
border-color: white;
}
#project-name:focus {
outline: none;
}