-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
93 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// @ts-check | ||
|
||
const obj = editor.createObject(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
}); |