Skip to content

Commit

Permalink
scripting stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed Jan 30, 2025
1 parent c50829b commit 7f669cf
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 18 deletions.
3 changes: 3 additions & 0 deletions scripts/CreateCircle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @ts-check

const obj = editor.createObject(1);
15 changes: 15 additions & 0 deletions scripts/DeselectRandom.js
Original file line number Diff line number Diff line change
@@ -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`);
7 changes: 0 additions & 7 deletions scripts/OhNo.js

This file was deleted.

71 changes: 68 additions & 3 deletions scripts/Std.ts
Original file line number Diff line number Diff line change
@@ -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<K extends keyof EditorEventListeners>(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;
15 changes: 7 additions & 8 deletions scripts/Worker.js
Original file line number Diff line number Diff line change
@@ -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}`);
}
});

0 comments on commit 7f669cf

Please sign in to comment.