blink background

This commit is contained in:
2023-08-02 21:10:07 +02:00
parent 72dba1a581
commit 035328cf13
2 changed files with 49 additions and 8 deletions

View File

@ -18,6 +18,7 @@ const sound = (value: any) => ({
export class UserAPI {
variables: { [key: string]: any } = {}
iterators: { [key: string]: any } = {}
MidiConnection: MidiConnection = new MidiConnection()
strudelSound = webaudioOutput()
load: samples
@ -100,6 +101,34 @@ export class UserAPI {
this.MidiConnection.panic()
}
// =============================================================
// Iterator related functions
// =============================================================
public iterator(name: string, limit?: number, step?: number) {
// Check if iterator already exists
if (!(name in this.iterators)) {
// Create new iterator with default step of 1
this.iterators[name] = {
value: 0,
step: step ?? 1,
limit
};
} else {
// Increment existing iterator by step value
this.iterators[name].value += this.iterators[name].step;
// Check for limit overshoot
if (this.iterators[name].limit !== undefined &&
this.iterators[name].value > this.iterators[name].limit) {
this.iterators[name].value = 0;
}
}
// Return current iterator value
return this.iterators[name].value;
}
// =============================================================
// Variable related functions
// =============================================================

View File

@ -208,6 +208,7 @@ export class Editor {
event.preventDefault();
// const code = this.getCodeBlock();
this.currentFile.candidate = this.view.state.doc.toString();
this.flashBackground('#2d313d', 200)
// tryEvaluate(this, this.currentFile);
}
@ -218,6 +219,7 @@ export class Editor {
) {
event.preventDefault(); // Prevents the addition of a new line
this.currentFile.candidate = this.view.state.doc.toString();
this.flashBackground('#2d313d', 200)
// const code = this.getSelectedLines();
}
@ -413,8 +415,6 @@ export class Editor {
if (svg.classList.contains("text-orange-300")) {
svg.classList.remove("text-orange-300");
button.classList.remove("text-orange-300");
console.log(svg.classList)
console.log(button.classList)
}
});
button.children[0].classList.remove('text-white');
@ -499,11 +499,7 @@ export class Editor {
updateEditorView(): void {
// Remove everything from the editor
this.view.dispatch({
changes: {
from: 0,
to: this.view.state.doc.toString().length,
insert: "",
},
changes: { from: 0, to: this.view.state.doc.toString().length, insert: '', },
});
// Insert something
@ -653,6 +649,22 @@ export class Editor {
document.getElementById("modal")!.classList.add("invisible");
document.getElementById("modal-buffers")!.classList.add("invisible");
}
flashBackground(color: string, duration: number) {
// Set the flashing color
this.view.dom.style.backgroundColor = color;
const gutters = this.view.dom.getElementsByClassName("cm-gutter");
Array.from(gutters).forEach(gutter => gutter.style.backgroundColor = color);
// Reset to original color after duration
setTimeout(() => {
this.view.dom.style.backgroundColor = "";
Array.from(gutters).forEach(gutter => gutter.style.backgroundColor = "");
}, duration);
}
}
const app = new Editor();
@ -682,10 +694,10 @@ document.getElementById("start-button")!.addEventListener("click", startClock);
// When the user leaves the page, all the universes should be saved in the localStorage
window.addEventListener("beforeunload", () => {
event.preventDefault();
event.returnValue = "";
// Iterate over all local files and set the candidate to the committed
app.currentFile.candidate = app.view.state.doc.toString();
app.currentFile.committed = app.view.state.doc.toString();
app.settings.saveApplicationToLocalStorage(app.universes, app.settings);
app.clock.stop()
return null;
});