From b47d041a99c8186061e433e47abad46b15162a9a Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Tue, 19 Dec 2023 22:09:11 +0100 Subject: [PATCH 1/3] turn off codemirror search --- src/EditorSetup.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EditorSetup.ts b/src/EditorSetup.ts index aff82d7..556ebf3 100644 --- a/src/EditorSetup.ts +++ b/src/EditorSetup.ts @@ -20,7 +20,7 @@ import { HighlightStyle, } from "@codemirror/language"; import { defaultKeymap, historyKeymap, history } from "@codemirror/commands"; -import { searchKeymap, highlightSelectionMatches } from "@codemirror/search"; +import { highlightSelectionMatches } from "@codemirror/search"; import { autocompletion, closeBrackets, @@ -259,7 +259,7 @@ export const editorSetup: Extension = (() => [ highlightActiveLine(), highlightSelectionMatches(), keymap.of([ - ...searchKeymap, + // ...searchKeymap, ...closeBracketsKeymap, ...defaultKeymap, ...historyKeymap, From 70cf7f2562725cc4cbcb5747f0c8bb6981cacfe4 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Tue, 19 Dec 2023 22:27:08 +0100 Subject: [PATCH 2/3] remove global variables madness --- src/API.ts | 45 ++----------------------- src/documentation/patterns/variables.ts | 22 +++++------- 2 files changed, 11 insertions(+), 56 deletions(-) diff --git a/src/API.ts b/src/API.ts index 856e697..645977d 100644 --- a/src/API.ts +++ b/src/API.ts @@ -131,9 +131,11 @@ export class UserAPI { public onceEvaluator: boolean = true; load: samples; + public global: { [key: string]: any }; constructor(public app: Editor) { this.MidiConnection = new MidiConnection(this, app.settings); + this.global = {}; } _loadUniverseFromInterface = (universe: string) => { @@ -1045,49 +1047,6 @@ export class UserAPI { this._drunk.toggleWrap(wrap); }; - // ============================================================= - // Variable related functions - // ============================================================= - - public variable = (a: number | string, b?: any): any => { - /** - * Sets or returns the value of a variable internal to API. - * - * @param a - The name of the variable - * @param b - [optional] The value to set the variable to - * @returns The value of the variable - */ - if (typeof a === "string" && b === undefined) { - return this.variables[a]; - } else { - this.variables[a] = b; - return this.variables[a]; - } - }; - v = this.variable; - - public delete_variable = (name: string): void => { - /** - * Deletes a variable internal to API. - * - * @param name - The name of the variable to delete - */ - delete this.variables[name]; - }; - dv = this.delete_variable; - - public clear_variables = (): void => { - /** - * Clears all variables internal to API. - * - * @remarks - * This function will delete all variables without warning. - * Use with caution. - */ - this.variables = {}; - }; - cv = this.clear_variables; - // ============================================================= // Randomness functions // ============================================================= diff --git a/src/documentation/patterns/variables.ts b/src/documentation/patterns/variables.ts index 489d816..5c79b95 100644 --- a/src/documentation/patterns/variables.ts +++ b/src/documentation/patterns/variables.ts @@ -7,20 +7,15 @@ export const variables = (application: Editor): string => { # Variables -By default, each script is independant from each other. Scripts live in their own bubble and you cannot get or set variables affecting a script from any other script. +By default, each script is independant from each other. The variables defined in **script 1** are not available in **script 2**, etc. Moreover, they are overriden everytime the file is evaluated. It means that you cannot store any state or share information. However, you can use global variables to make that possible. -**However**, everybody knows that global variables are cool and should be used everywhere. Global variables are an incredibely powerful tool to radically alter a composition in a few lines of code. +There is a global object that you can use to store and retrieve information. It is a simple key/value store. You can store any type of data in it: -- variable(a: number | string, b?: any): if only one argument is provided, the value of the variable will be returned through its name, denoted by the first argument. If a second argument is used, it will be saved as a global variable under the name of the first argument. - - delete_variable(name: string): deletes a global variable from storage. - - clear_variables(): clear **ALL** variables. **This is a destructive operation**! - -**Note:** since this example is running in the documentation, we cannot take advantage of the multiple scripts paradigm. Try to send a variable from the global file to the local file n°6. - ${makeExample( "Setting a global variable", ` -v('my_cool_variable', 2) +// This is script n°3 +global.my_variable = 2 `, true, )} @@ -28,15 +23,16 @@ v('my_cool_variable', 2) ${makeExample( "Getting that variable back and printing!", ` -// Note that we just use one argument -log(v('my_cool_variable')) +// This is script n°4 +log(global.my_variable) `, - false, + true, )} +Now your scripts can share information with each other! ## Counter and iterators - + You will often need to use iterators and/or counters to index over data structures (getting a note from a list of notes, etc...). There are functions ready to be used for this. Each script also comes with its own iterator that you can access using the i variable. **Note:** the script iteration count is **not** resetted between sessions. It will continue to increase the more you play, even if you just picked up an old project. - counter(name: number | string, limit?: number, step?: number): reads the value of the counter name. You can also call this function using the dollar symbol: $. From 6f886ecc104dab2116c393177ed97be75f5a5d66 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Tue, 19 Dec 2023 23:10:05 +0100 Subject: [PATCH 3/3] fix deploy build --- src/API.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/API.ts b/src/API.ts index 645977d..ceb5670 100644 --- a/src/API.ts +++ b/src/API.ts @@ -113,7 +113,6 @@ export class UserAPI { * function destined to the user should be placed here. */ - private variables: { [key: string]: any } = {}; public codeExamples: { [key: string]: string } = {}; private counters: { [key: string]: any } = {}; private _drunk: DrunkWalk = new DrunkWalk(-100, 100, false); @@ -1708,7 +1707,7 @@ export class UserAPI { for (let value = start; value <= end; value += step) { result.push(value); } - } else if((end > start && step < 0) || (end < start && step > 0)) { + } else if ((end > start && step < 0) || (end < start && step > 0)) { for (let value = start; value >= end; value -= step) { result.push(parseFloat(value.toFixed(countPlaces(step)))); }