Merge pull request #2 from Bubobubobubobubo/two-clocks
blink background
This commit is contained in:
29
src/API.ts
29
src/API.ts
@ -18,6 +18,7 @@ const sound = (value: any) => ({
|
|||||||
export class UserAPI {
|
export class UserAPI {
|
||||||
|
|
||||||
variables: { [key: string]: any } = {}
|
variables: { [key: string]: any } = {}
|
||||||
|
iterators: { [key: string]: any } = {}
|
||||||
MidiConnection: MidiConnection = new MidiConnection()
|
MidiConnection: MidiConnection = new MidiConnection()
|
||||||
strudelSound = webaudioOutput()
|
strudelSound = webaudioOutput()
|
||||||
load: samples
|
load: samples
|
||||||
@ -100,6 +101,34 @@ export class UserAPI {
|
|||||||
this.MidiConnection.panic()
|
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
|
// Variable related functions
|
||||||
// =============================================================
|
// =============================================================
|
||||||
|
|||||||
28
src/main.ts
28
src/main.ts
@ -208,6 +208,7 @@ export class Editor {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
// const code = this.getCodeBlock();
|
// const code = this.getCodeBlock();
|
||||||
this.currentFile.candidate = this.view.state.doc.toString();
|
this.currentFile.candidate = this.view.state.doc.toString();
|
||||||
|
this.flashBackground('#2d313d', 200)
|
||||||
// tryEvaluate(this, this.currentFile);
|
// tryEvaluate(this, this.currentFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,6 +219,7 @@ export class Editor {
|
|||||||
) {
|
) {
|
||||||
event.preventDefault(); // Prevents the addition of a new line
|
event.preventDefault(); // Prevents the addition of a new line
|
||||||
this.currentFile.candidate = this.view.state.doc.toString();
|
this.currentFile.candidate = this.view.state.doc.toString();
|
||||||
|
this.flashBackground('#2d313d', 200)
|
||||||
// const code = this.getSelectedLines();
|
// const code = this.getSelectedLines();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,8 +415,6 @@ export class Editor {
|
|||||||
if (svg.classList.contains("text-orange-300")) {
|
if (svg.classList.contains("text-orange-300")) {
|
||||||
svg.classList.remove("text-orange-300");
|
svg.classList.remove("text-orange-300");
|
||||||
button.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');
|
button.children[0].classList.remove('text-white');
|
||||||
@ -499,11 +499,7 @@ export class Editor {
|
|||||||
updateEditorView(): void {
|
updateEditorView(): void {
|
||||||
// Remove everything from the editor
|
// Remove everything from the editor
|
||||||
this.view.dispatch({
|
this.view.dispatch({
|
||||||
changes: {
|
changes: { from: 0, to: this.view.state.doc.toString().length, insert: '', },
|
||||||
from: 0,
|
|
||||||
to: this.view.state.doc.toString().length,
|
|
||||||
insert: "",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Insert something
|
// Insert something
|
||||||
@ -653,6 +649,22 @@ export class Editor {
|
|||||||
document.getElementById("modal")!.classList.add("invisible");
|
document.getElementById("modal")!.classList.add("invisible");
|
||||||
document.getElementById("modal-buffers")!.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();
|
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
|
// When the user leaves the page, all the universes should be saved in the localStorage
|
||||||
window.addEventListener("beforeunload", () => {
|
window.addEventListener("beforeunload", () => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.returnValue = "";
|
|
||||||
// Iterate over all local files and set the candidate to the committed
|
// Iterate over all local files and set the candidate to the committed
|
||||||
app.currentFile.candidate = app.view.state.doc.toString();
|
app.currentFile.candidate = app.view.state.doc.toString();
|
||||||
app.currentFile.committed = app.view.state.doc.toString();
|
app.currentFile.committed = app.view.state.doc.toString();
|
||||||
app.settings.saveApplicationToLocalStorage(app.universes, app.settings);
|
app.settings.saveApplicationToLocalStorage(app.universes, app.settings);
|
||||||
app.clock.stop()
|
app.clock.stop()
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user