@wonderlandengine/editor-api 1.2.0-dev.0 → 1.2.0-dev.1
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/dist/data.d.ts +1 -1
- package/dist/data.js +1 -1
- package/dist/native.d.ts +6 -1
- package/dist/tools.d.ts +2 -0
- package/dist/tools.js +2 -1
- package/dist/ui.d.ts +53 -6
- package/dist/ui.js +68 -23
- package/package.json +2 -2
package/dist/data.d.ts
CHANGED
@@ -624,7 +624,7 @@ export declare class LanguageResource {
|
|
624
624
|
};
|
625
625
|
}
|
626
626
|
/**
|
627
|
-
*
|
627
|
+
* Access to Wonderland Editor's data.
|
628
628
|
*
|
629
629
|
* Hold control and hover any field in Wonderland Editor to see its JSON path.
|
630
630
|
* The path is equivalent to how you find the matching chain of properties.
|
package/dist/data.js
CHANGED
@@ -622,7 +622,7 @@ export class LanguageResource {
|
|
622
622
|
strings = {};
|
623
623
|
}
|
624
624
|
/**
|
625
|
-
*
|
625
|
+
* Access to Wonderland Editor's data.
|
626
626
|
*
|
627
627
|
* Hold control and hover any field in Wonderland Editor to see its JSON path.
|
628
628
|
* The path is equivalent to how you find the matching chain of properties.
|
package/dist/native.d.ts
CHANGED
@@ -7,14 +7,19 @@ interface NativeToolsAPI {
|
|
7
7
|
}
|
8
8
|
interface NativeUiAPI {
|
9
9
|
freeImage(id: number): void;
|
10
|
-
loadImage(
|
10
|
+
loadImage(data: ArrayBuffer): [number, number];
|
11
11
|
text(text: string): void;
|
12
12
|
label(text: string): void;
|
13
13
|
button(label: string): boolean;
|
14
14
|
image(id: number, width: number, height: number): boolean;
|
15
15
|
inputText(label: string, value: string): string | null;
|
16
|
+
checkbox(label: string, value: boolean): boolean | null;
|
17
|
+
colorEdit4(label: string, value: Float32Array): boolean;
|
16
18
|
dummy(width: number, height: number): void;
|
17
19
|
sameLine(offset: number): void;
|
20
|
+
separator(): void;
|
21
|
+
beginGroup(): void;
|
22
|
+
endGroup(): void;
|
18
23
|
}
|
19
24
|
declare global {
|
20
25
|
function _wl_internalBinding(moduleName: 'tools'): NativeToolsAPI;
|
package/dist/tools.d.ts
CHANGED
package/dist/tools.js
CHANGED
package/dist/ui.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
1
2
|
/** Image to be used in the {@ref Ui}. */
|
2
3
|
export declare class UiImage {
|
3
4
|
_id: number;
|
@@ -17,7 +18,7 @@ export declare const label: (text: string) => void;
|
|
17
18
|
* @example
|
18
19
|
* In a draw function of a plugin, use as follows:
|
19
20
|
* ```ts
|
20
|
-
* if(
|
21
|
+
* if(ui.button('Click me!')) {
|
21
22
|
* console.log('You clicked the button.');
|
22
23
|
* }
|
23
24
|
* ```
|
@@ -33,21 +34,67 @@ export declare const button: (label: string) => boolean;
|
|
33
34
|
* In a draw function of a plugin, use as follows:
|
34
35
|
* ```ts
|
35
36
|
* this.thumbnail = null;
|
36
|
-
*
|
37
|
+
* loadImage(fs.readFileSync("cache/plugins/my-plugin/downloads/thumbnail.png"))
|
37
38
|
* .then((img) => this.thumbnail = img);
|
38
39
|
* ```
|
39
40
|
*
|
40
41
|
* @see image()
|
41
42
|
*/
|
42
|
-
export declare function
|
43
|
+
export declare function loadImage(data: ArrayBuffer | Buffer): Promise<UiImage>;
|
43
44
|
export declare function image(image: UiImage, width: number, height: number): boolean;
|
44
45
|
/**
|
45
46
|
* Text input field.
|
46
47
|
*
|
47
|
-
* @
|
48
|
-
*
|
48
|
+
* @param label Label to display next to the field.
|
49
|
+
* @param value Current value to set the field to.
|
50
|
+
* @returns The new string value when changed by the user this frame, otherwise `null`.
|
51
|
+
*
|
52
|
+
* @example
|
53
|
+
* s = ui.inputText("change this:", s) || s;
|
49
54
|
*/
|
50
55
|
export declare const inputText: (label: string, value: string) => string | null;
|
51
|
-
|
56
|
+
/**
|
57
|
+
* Checkbox.
|
58
|
+
*
|
59
|
+
* @param label Label to display next to the checkbox.
|
60
|
+
* @param value Current value to set the checkbox to.
|
61
|
+
* @returns The new boolean value when changed by the user this frame, otherwise `null`.
|
62
|
+
*
|
63
|
+
* @example
|
64
|
+
* const n = ui.checkbox("change this:", myBool);
|
65
|
+
* if(n !== null) myBool = n;
|
66
|
+
*/
|
67
|
+
export declare const checkbox: (label: string, value: boolean) => boolean | null;
|
68
|
+
/**
|
69
|
+
* Color picker for RGBA color.
|
70
|
+
*
|
71
|
+
* @param label Label to display next to the picker.
|
72
|
+
* @param value Value to be in-place edited.
|
73
|
+
* @returns `true` if changed by the user this frame, `false` otherwise.
|
74
|
+
*
|
75
|
+
* @example
|
76
|
+
* const col = new Float32Array(4);
|
77
|
+
* if(ui.colorEdit4("My color:", col)) {
|
78
|
+
* console.log("Changed!");
|
79
|
+
* }
|
80
|
+
*/
|
81
|
+
export declare const colorEdit4: (label: string, value: Float32Array) => boolean;
|
82
|
+
/**
|
83
|
+
* Dummy element (space).
|
84
|
+
*
|
85
|
+
* @param width Width of the dummy element
|
86
|
+
* @param height Height of the dummy element
|
87
|
+
*/
|
52
88
|
export declare const dummy: (width: number, height: number) => void;
|
89
|
+
/**
|
90
|
+
* Draw next widget on the same line.
|
91
|
+
*
|
92
|
+
* @param offset Offset on the x axis.
|
93
|
+
*/
|
53
94
|
export declare const sameLine: (offset: number) => void;
|
95
|
+
/** Separator line. */
|
96
|
+
export declare const separator: () => void;
|
97
|
+
/** Begin a widget group. */
|
98
|
+
export declare const beginGroup: () => void;
|
99
|
+
/** End a widget group. */
|
100
|
+
export declare const endGroup: () => void;
|
package/dist/ui.js
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { awaitJob } from './tools.js';
|
1
2
|
const ui = _wl_internalBinding('ui');
|
2
3
|
/** Image to be used in the {@ref Ui}. */
|
3
4
|
export class UiImage {
|
@@ -23,7 +24,7 @@ export const label = ui.label.bind(ui);
|
|
23
24
|
* @example
|
24
25
|
* In a draw function of a plugin, use as follows:
|
25
26
|
* ```ts
|
26
|
-
* if(
|
27
|
+
* if(ui.button('Click me!')) {
|
27
28
|
* console.log('You clicked the button.');
|
28
29
|
* }
|
29
30
|
* ```
|
@@ -39,41 +40,85 @@ export const button = ui.button.bind(ui);
|
|
39
40
|
* In a draw function of a plugin, use as follows:
|
40
41
|
* ```ts
|
41
42
|
* this.thumbnail = null;
|
42
|
-
*
|
43
|
+
* loadImage(fs.readFileSync("cache/plugins/my-plugin/downloads/thumbnail.png"))
|
43
44
|
* .then((img) => this.thumbnail = img);
|
44
45
|
* ```
|
45
46
|
*
|
46
47
|
* @see image()
|
47
48
|
*/
|
48
|
-
export function
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
49
|
+
export async function loadImage(data) {
|
50
|
+
if (!(data instanceof ArrayBuffer)) {
|
51
|
+
const converted = new Uint8Array(data.byteLength);
|
52
|
+
for (let i = 0; i < data.byteLength; ++i) {
|
53
|
+
converted[i] = data[i];
|
54
|
+
}
|
55
|
+
data = converted.buffer;
|
56
|
+
}
|
57
|
+
/* Wrapper around a GL::Texture. People will be tempted calling
|
58
|
+
* this in weird places, so better just throw it on the JobSystem
|
59
|
+
* for the MainThread and spread it over time. */
|
60
|
+
const [job, imageId] = ui.loadImage(data);
|
61
|
+
await awaitJob(job);
|
62
|
+
return new UiImage(imageId);
|
61
63
|
}
|
62
64
|
export function image(image, width, height) {
|
63
|
-
|
64
|
-
|
65
|
+
/* Since ImGui expects GL::Texture, we load the image for the user
|
66
|
+
* from filepath. Avoids them pulling in pngjs and other mistakes */
|
65
67
|
return ui.image(image._id, width, height);
|
66
68
|
}
|
67
69
|
/**
|
68
70
|
* Text input field.
|
69
71
|
*
|
70
|
-
* @
|
71
|
-
*
|
72
|
+
* @param label Label to display next to the field.
|
73
|
+
* @param value Current value to set the field to.
|
74
|
+
* @returns The new string value when changed by the user this frame, otherwise `null`.
|
75
|
+
*
|
76
|
+
* @example
|
77
|
+
* s = ui.inputText("change this:", s) || s;
|
72
78
|
*/
|
73
79
|
export const inputText = ui.inputText.bind(ui);
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
80
|
+
/**
|
81
|
+
* Checkbox.
|
82
|
+
*
|
83
|
+
* @param label Label to display next to the checkbox.
|
84
|
+
* @param value Current value to set the checkbox to.
|
85
|
+
* @returns The new boolean value when changed by the user this frame, otherwise `null`.
|
86
|
+
*
|
87
|
+
* @example
|
88
|
+
* const n = ui.checkbox("change this:", myBool);
|
89
|
+
* if(n !== null) myBool = n;
|
90
|
+
*/
|
91
|
+
export const checkbox = ui.checkbox.bind(ui);
|
92
|
+
/**
|
93
|
+
* Color picker for RGBA color.
|
94
|
+
*
|
95
|
+
* @param label Label to display next to the picker.
|
96
|
+
* @param value Value to be in-place edited.
|
97
|
+
* @returns `true` if changed by the user this frame, `false` otherwise.
|
98
|
+
*
|
99
|
+
* @example
|
100
|
+
* const col = new Float32Array(4);
|
101
|
+
* if(ui.colorEdit4("My color:", col)) {
|
102
|
+
* console.log("Changed!");
|
103
|
+
* }
|
104
|
+
*/
|
105
|
+
export const colorEdit4 = ui.colorEdit4.bind(ui);
|
106
|
+
/**
|
107
|
+
* Dummy element (space).
|
108
|
+
*
|
109
|
+
* @param width Width of the dummy element
|
110
|
+
* @param height Height of the dummy element
|
111
|
+
*/
|
78
112
|
export const dummy = ui.dummy.bind(ui);
|
113
|
+
/**
|
114
|
+
* Draw next widget on the same line.
|
115
|
+
*
|
116
|
+
* @param offset Offset on the x axis.
|
117
|
+
*/
|
79
118
|
export const sameLine = ui.sameLine.bind(ui);
|
119
|
+
/** Separator line. */
|
120
|
+
export const separator = ui.separator.bind(ui);
|
121
|
+
/** Begin a widget group. */
|
122
|
+
export const beginGroup = ui.beginGroup.bind(ui);
|
123
|
+
/** End a widget group. */
|
124
|
+
export const endGroup = ui.endGroup.bind(ui);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@wonderlandengine/editor-api",
|
3
|
-
"version": "1.2.0-dev.
|
3
|
+
"version": "1.2.0-dev.1",
|
4
4
|
"description": "Wonderland Engine's Editor API for plugins - very experimental.",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"module": "./dist/index.js",
|
@@ -31,7 +31,7 @@
|
|
31
31
|
"pretty": "prettier --config ./prettierrc.json --write ./src",
|
32
32
|
"doc": "typedoc --entryPoints ./src/index.ts --tsconfig tsconfig.json --json ./doc.json",
|
33
33
|
"json-diff": "npm run defaults && npx json-diff ../../src/WonderlandEditor/defaults.json defaults.json",
|
34
|
-
"
|
34
|
+
"prepack": "npm run build"
|
35
35
|
},
|
36
36
|
"peerDependencies": {},
|
37
37
|
"devDependencies": {
|