diff --git a/scripts/CreateCircle.js b/scripts/CreateCircle.js new file mode 100644 index 0000000..02060d4 --- /dev/null +++ b/scripts/CreateCircle.js @@ -0,0 +1,3 @@ +// @ts-check + +const obj = editor.createObject(1); diff --git a/scripts/DeselectRandom.js b/scripts/DeselectRandom.js new file mode 100644 index 0000000..310ba06 --- /dev/null +++ b/scripts/DeselectRandom.js @@ -0,0 +1,15 @@ +// @ts-check + +/// @name Deselect random +/// @by HJfod + +const objs = editor.getSelectedObjects(); +print(`Selected objects: ${objs.length}`); +let count = 0; +for (const obj of objs) { + if (Math.random() > 0.5) { + obj.selected = false; + count += 1; + } +} +print(`Deselected ${count} objects`); diff --git a/scripts/OhNo.js b/scripts/OhNo.js deleted file mode 100644 index 571ad5f..0000000 --- a/scripts/OhNo.js +++ /dev/null @@ -1,7 +0,0 @@ -// @ts-check - -const objs = editor.getSelectedObjects(); -print(`selected objects: ${objs.length}`); -for (const obj of objs) { - print(`id: ${obj.id}`); -} diff --git a/scripts/Std.ts b/scripts/Std.ts index b40fc84..ce680d8 100644 --- a/scripts/Std.ts +++ b/scripts/Std.ts @@ -1,9 +1,74 @@ -declare interface GameObject { +declare interface Metadata { + name: string, + by: string, +} + +declare interface EditorEventListeners { + "select": (objs: GameObject[]) => void, +} + +/** + * Represents an object in the editor + */ +declare class GameObject { + /** + * The ID of the object. See [Colon's level](https://gdbrowser.com/99784974) + * for a list of all object IDs. This property is not modifiable; if you + * want to convert an object to a different type, use {@link Editor.createObject} + * and transfer the properties you want over to the new one + */ readonly id: number; + /** + * The X-coordinate of the object. Modifying this property will move the + * object. Note that for performance reasons, you should use + * {@link Editor.moveObjectsBy} instead if you are moving large amounts of + * objects + */ + x: number; + /** + * The X-coordinate of the object. Modifying this property will move the + * object. Note that for performance reasons, you should use + * {@link Editor.moveObjectsBy} instead if you are moving large amounts of + * objects + */ + y: number; + /** + * Whether this object is selected or not. Modifying this property will + * select/deselect the object + */ + selected: boolean; } -declare interface Editor { +/** + * Interface for interacting with the level editor + */ +declare class Editor { + /** + * Get the currently selected objects + */ getSelectedObjects(): GameObject[]; + /** + * Move the specified objects by the specified amount of units relative to + * their current position + * @param objs Objects to move + * @param amount Amount to move relative to the objects' current position, + * in (X, Y) coordinates + */ + moveObjectsBy(objs: GameObject[], amount: [number, number]): void; + /** + * Create a new object in the editor. The object is placed at (0, 0) (the bottom left starting corner) + * @param id The ID of the object to create. See [Colon's level](https://gdbrowser.com/99784974) for a list of all object IDs + */ + createObject(id: number): GameObject; + + addEventListener(event: K, onEvent: EditorEventListeners[K]): void; } +/** + * Interface for interacting with the level editor, such as getting selected objects or creating new ones + */ declare const editor: Editor; -declare function print(msg: string): void; +/** + * Output messages to the script run window + * @param msgs Message(s) to output + */ +declare function print(...msgs: any[]): void; diff --git a/scripts/Worker.js b/scripts/Worker.js index 91d1f33..ae53ddb 100644 --- a/scripts/Worker.js +++ b/scripts/Worker.js @@ -1,13 +1,12 @@ +// @ts-check -function deselectRandom(objs) { - for (obj of objs) { - if (Math.random() > 0.5) { - obj.deselect(); - } - } -} +/// @name Log on select +/// @by HJfod +/// @worker // This is just an idea editor.addEventListener("select", objs => { - deselectRandom(objs); + for (const obj of objs) { + print(`Selected ${obj}`); + } });