@wonderlandengine/editor-api 1.2.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/dist/data.d.ts +671 -0
- package/dist/data.js +669 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +14 -0
- package/dist/native.d.ts +24 -0
- package/dist/native.js +1 -0
- package/dist/tools.d.ts +24 -0
- package/dist/tools.js +42 -0
- package/dist/ui.d.ts +53 -0
- package/dist/ui.js +79 -0
- package/package.json +46 -0
package/dist/native.d.ts
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
import { EditorData } from './data.js';
|
2
|
+
interface NativeToolsAPI {
|
3
|
+
packageProject(destDir?: string): number;
|
4
|
+
loadFile(filename: string): number;
|
5
|
+
loadScene(filename: string, parent?: string): number;
|
6
|
+
awaitJob(jobId: number, cb: (success: boolean) => void): void;
|
7
|
+
}
|
8
|
+
interface NativeUiAPI {
|
9
|
+
freeImage(id: number): void;
|
10
|
+
loadImage(path: string, cb: (id: number) => void): void;
|
11
|
+
text(text: string): void;
|
12
|
+
label(text: string): void;
|
13
|
+
button(label: string): boolean;
|
14
|
+
image(id: number, width: number, height: number): boolean;
|
15
|
+
inputText(label: string, value: string): string | null;
|
16
|
+
dummy(width: number, height: number): void;
|
17
|
+
sameLine(offset: number): void;
|
18
|
+
}
|
19
|
+
declare global {
|
20
|
+
function _wl_internalBinding(moduleName: 'tools'): NativeToolsAPI;
|
21
|
+
function _wl_internalBinding(moduleName: 'ui'): NativeUiAPI;
|
22
|
+
function _wl_internalBinding(moduleName: 'data'): EditorData;
|
23
|
+
}
|
24
|
+
export {};
|
package/dist/native.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/dist/tools.d.ts
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
/**
|
2
|
+
* Package the current project
|
3
|
+
* @param destDir Destination directory into which to package, default `'<project-root>/deploy'`.
|
4
|
+
* @returns Promise with that is rejected on package failure.
|
5
|
+
*/
|
6
|
+
export declare function packageProject(destDir?: string): Promise<void>;
|
7
|
+
/**
|
8
|
+
* Load a file into current scene
|
9
|
+
*
|
10
|
+
* @param path Path to file to load
|
11
|
+
* @returns Promise with that is rejected on load failure.
|
12
|
+
*/
|
13
|
+
export declare function loadFile(path: string): Promise<void>;
|
14
|
+
/**
|
15
|
+
* Load a scene file into current scene
|
16
|
+
*
|
17
|
+
* @param path Path to file to load
|
18
|
+
* @param options.parent Parent object to parent the scene to. `null`, `undefined` and `""` indicate
|
19
|
+
* scene root.
|
20
|
+
* @returns Promise with that is rejected on load failure.
|
21
|
+
*/
|
22
|
+
export declare function loadScene(path: string, options: {
|
23
|
+
parent?: string;
|
24
|
+
}): Promise<void>;
|
package/dist/tools.js
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
const tools = _wl_internalBinding('tools');
|
2
|
+
function awaitJob(jobId) {
|
3
|
+
return new Promise((resolve, reject) => {
|
4
|
+
tools.awaitJob(jobId, (success) => {
|
5
|
+
if (success)
|
6
|
+
resolve();
|
7
|
+
else
|
8
|
+
reject();
|
9
|
+
});
|
10
|
+
});
|
11
|
+
}
|
12
|
+
/**
|
13
|
+
* Package the current project
|
14
|
+
* @param destDir Destination directory into which to package, default `'<project-root>/deploy'`.
|
15
|
+
* @returns Promise with that is rejected on package failure.
|
16
|
+
*/
|
17
|
+
export function packageProject(destDir) {
|
18
|
+
const job = tools.packageProject(destDir);
|
19
|
+
return awaitJob(job);
|
20
|
+
}
|
21
|
+
/**
|
22
|
+
* Load a file into current scene
|
23
|
+
*
|
24
|
+
* @param path Path to file to load
|
25
|
+
* @returns Promise with that is rejected on load failure.
|
26
|
+
*/
|
27
|
+
export function loadFile(path) {
|
28
|
+
const job = tools.loadFile(path);
|
29
|
+
return awaitJob(job);
|
30
|
+
}
|
31
|
+
/**
|
32
|
+
* Load a scene file into current scene
|
33
|
+
*
|
34
|
+
* @param path Path to file to load
|
35
|
+
* @param options.parent Parent object to parent the scene to. `null`, `undefined` and `""` indicate
|
36
|
+
* scene root.
|
37
|
+
* @returns Promise with that is rejected on load failure.
|
38
|
+
*/
|
39
|
+
export function loadScene(path, options) {
|
40
|
+
const job = tools.loadScene(path, options.parent);
|
41
|
+
return awaitJob(job);
|
42
|
+
}
|
package/dist/ui.d.ts
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
/** Image to be used in the {@ref Ui}. */
|
2
|
+
export declare class UiImage {
|
3
|
+
_id: number;
|
4
|
+
constructor(id: number);
|
5
|
+
/** Manually mark this image as no longer needed */
|
6
|
+
free(): void;
|
7
|
+
}
|
8
|
+
/** Simple text */
|
9
|
+
export declare const text: (text: string) => void;
|
10
|
+
/** Label for the next UI element */
|
11
|
+
export declare const label: (text: string) => void;
|
12
|
+
/**
|
13
|
+
* Simple button
|
14
|
+
* @param label Label for the button.
|
15
|
+
* @returns `true` when pressed this frame.
|
16
|
+
*
|
17
|
+
* @example
|
18
|
+
* In a draw function of a plugin, use as follows:
|
19
|
+
* ```ts
|
20
|
+
* if(WLE.button('Click me!')) {
|
21
|
+
* console.log('You clicked the button.');
|
22
|
+
* }
|
23
|
+
* ```
|
24
|
+
*/
|
25
|
+
export declare const button: (label: string) => boolean;
|
26
|
+
/**
|
27
|
+
* Load a ui image. Any format supported by the editor is supported.
|
28
|
+
*
|
29
|
+
* @param filepath Path to the file.
|
30
|
+
* @returns Promise with the loaded UiImage
|
31
|
+
*
|
32
|
+
* @example
|
33
|
+
* In a draw function of a plugin, use as follows:
|
34
|
+
* ```ts
|
35
|
+
* this.thumbnail = null;
|
36
|
+
* loadUiImage("cache/plugins/my-plugin/downloads/thumbnail.png")
|
37
|
+
* .then((img) => this.thumbnail = img);
|
38
|
+
* ```
|
39
|
+
*
|
40
|
+
* @see image()
|
41
|
+
*/
|
42
|
+
export declare function loadUiImage(filepath: string): Promise<UiImage>;
|
43
|
+
export declare function image(image: UiImage, width: number, height: number): boolean;
|
44
|
+
/**
|
45
|
+
* Text input field.
|
46
|
+
*
|
47
|
+
* @usage
|
48
|
+
* s = ui.inputText("change this:", s) || s;
|
49
|
+
*/
|
50
|
+
export declare const inputText: (label: string, value: string) => string | null;
|
51
|
+
export declare function inputColor4(label: string, value: ArrayLike<number>): boolean;
|
52
|
+
export declare const dummy: (width: number, height: number) => void;
|
53
|
+
export declare const sameLine: (offset: number) => void;
|
package/dist/ui.js
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
const ui = _wl_internalBinding('ui');
|
2
|
+
/** Image to be used in the {@ref Ui}. */
|
3
|
+
export class UiImage {
|
4
|
+
_id = -1;
|
5
|
+
constructor(id) {
|
6
|
+
this._id = id;
|
7
|
+
}
|
8
|
+
/** Manually mark this image as no longer needed */
|
9
|
+
free() {
|
10
|
+
if (this._id >= 0)
|
11
|
+
ui.freeImage(this._id);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
/** Simple text */
|
15
|
+
export const text = ui.text.bind(ui);
|
16
|
+
/** Label for the next UI element */
|
17
|
+
export const label = ui.label.bind(ui);
|
18
|
+
/**
|
19
|
+
* Simple button
|
20
|
+
* @param label Label for the button.
|
21
|
+
* @returns `true` when pressed this frame.
|
22
|
+
*
|
23
|
+
* @example
|
24
|
+
* In a draw function of a plugin, use as follows:
|
25
|
+
* ```ts
|
26
|
+
* if(WLE.button('Click me!')) {
|
27
|
+
* console.log('You clicked the button.');
|
28
|
+
* }
|
29
|
+
* ```
|
30
|
+
*/
|
31
|
+
export const button = ui.button.bind(ui);
|
32
|
+
/**
|
33
|
+
* Load a ui image. Any format supported by the editor is supported.
|
34
|
+
*
|
35
|
+
* @param filepath Path to the file.
|
36
|
+
* @returns Promise with the loaded UiImage
|
37
|
+
*
|
38
|
+
* @example
|
39
|
+
* In a draw function of a plugin, use as follows:
|
40
|
+
* ```ts
|
41
|
+
* this.thumbnail = null;
|
42
|
+
* loadUiImage("cache/plugins/my-plugin/downloads/thumbnail.png")
|
43
|
+
* .then((img) => this.thumbnail = img);
|
44
|
+
* ```
|
45
|
+
*
|
46
|
+
* @see image()
|
47
|
+
*/
|
48
|
+
export function loadUiImage(filepath) {
|
49
|
+
// Wrapper around a GL::Texture. People will be tempted calling
|
50
|
+
// this in weird places, so better just throw it on the JobSystem
|
51
|
+
// for the MainThread and spread it over time.
|
52
|
+
return new Promise((resolve, reject) => {
|
53
|
+
ui.loadImage(filepath, (id) => {
|
54
|
+
if (id < 0) {
|
55
|
+
reject();
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
resolve(new UiImage(id));
|
59
|
+
});
|
60
|
+
});
|
61
|
+
}
|
62
|
+
export function image(image, width, height) {
|
63
|
+
// Since ImGui expects GL::Texture, we load the image for the user
|
64
|
+
// from filepath. Avoids them pulling in pngjs and other mistakes
|
65
|
+
return ui.image(image._id, width, height);
|
66
|
+
}
|
67
|
+
/**
|
68
|
+
* Text input field.
|
69
|
+
*
|
70
|
+
* @usage
|
71
|
+
* s = ui.inputText("change this:", s) || s;
|
72
|
+
*/
|
73
|
+
export const inputText = ui.inputText.bind(ui);
|
74
|
+
export function inputColor4(label, value) {
|
75
|
+
// We can in-place edit Float32Array, probably even number array
|
76
|
+
return false;
|
77
|
+
}
|
78
|
+
export const dummy = ui.dummy.bind(ui);
|
79
|
+
export const sameLine = ui.sameLine.bind(ui);
|
package/package.json
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
{
|
2
|
+
"name": "@wonderlandengine/editor-api",
|
3
|
+
"version": "1.2.0-dev.0",
|
4
|
+
"description": "Wonderland Engine's Editor API for plugins - very experimental.",
|
5
|
+
"main": "./dist/index.js",
|
6
|
+
"module": "./dist/index.js",
|
7
|
+
"types": "./dist/index.d.ts",
|
8
|
+
"type": "module",
|
9
|
+
"exports": {
|
10
|
+
".": "./dist/index.js"
|
11
|
+
},
|
12
|
+
"repository": {
|
13
|
+
"type": "git",
|
14
|
+
"url": "git+https://github.com/WonderlandEngine/api.git"
|
15
|
+
},
|
16
|
+
"keywords": [
|
17
|
+
"webxr",
|
18
|
+
"wonderland",
|
19
|
+
"components"
|
20
|
+
],
|
21
|
+
"author": "Wonderland GmbH",
|
22
|
+
"license": "MIT",
|
23
|
+
"bugs": {
|
24
|
+
"url": "https://discord.wonderlandengine.com/"
|
25
|
+
},
|
26
|
+
"homepage": "https://wonderlandengine.com/editor/plugins/",
|
27
|
+
"scripts": {
|
28
|
+
"build": "tsc",
|
29
|
+
"build:watch": "tsc --watch",
|
30
|
+
"defaults": "npm run build && npm run doc && node scripts/generate-defaults.mjs ./doc.json",
|
31
|
+
"pretty": "prettier --config ./prettierrc.json --write ./src",
|
32
|
+
"doc": "typedoc --entryPoints ./src/index.ts --tsconfig tsconfig.json --json ./doc.json",
|
33
|
+
"json-diff": "npm run defaults && npx json-diff ../../src/WonderlandEditor/defaults.json defaults.json",
|
34
|
+
"prepublishOnly": "npm run build"
|
35
|
+
},
|
36
|
+
"peerDependencies": {},
|
37
|
+
"devDependencies": {
|
38
|
+
"@types/node": "^18.11.9",
|
39
|
+
"prettier": "^2.8.0",
|
40
|
+
"typedoc": "^0.23.21",
|
41
|
+
"typescript": "^4.9.3"
|
42
|
+
},
|
43
|
+
"files": [
|
44
|
+
"dist"
|
45
|
+
]
|
46
|
+
}
|