@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 CHANGED
@@ -624,7 +624,7 @@ export declare class LanguageResource {
624
624
  };
625
625
  }
626
626
  /**
627
- * @brief Access to Wonderland Editor's data
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
- * @brief Access to Wonderland Editor's data
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(path: string, cb: (id: number) => void): void;
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
@@ -1,3 +1,5 @@
1
+ /** @hidden */
2
+ export declare function awaitJob(jobId: number): Promise<void>;
1
3
  /**
2
4
  * Package the current project
3
5
  * @param destDir Destination directory into which to package, default `'<project-root>/deploy'`.
package/dist/tools.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const tools = _wl_internalBinding('tools');
2
- function awaitJob(jobId) {
2
+ /** @hidden */
3
+ export function awaitJob(jobId) {
3
4
  return new Promise((resolve, reject) => {
4
5
  tools.awaitJob(jobId, (success) => {
5
6
  if (success)
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(WLE.button('Click me!')) {
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
- * loadUiImage("cache/plugins/my-plugin/downloads/thumbnail.png")
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 loadUiImage(filepath: string): Promise<UiImage>;
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
- * @usage
48
- * s = ui.inputText("change this:", s) || s;
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
- export declare function inputColor4(label: string, value: ArrayLike<number>): boolean;
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(WLE.button('Click me!')) {
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
- * loadUiImage("cache/plugins/my-plugin/downloads/thumbnail.png")
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 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
- });
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
- // Since ImGui expects GL::Texture, we load the image for the user
64
- // from filepath. Avoids them pulling in pngjs and other mistakes
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
- * @usage
71
- * s = ui.inputText("change this:", s) || s;
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
- export function inputColor4(label, value) {
75
- // We can in-place edit Float32Array, probably even number array
76
- return false;
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.0",
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
- "prepublishOnly": "npm run build"
34
+ "prepack": "npm run build"
35
35
  },
36
36
  "peerDependencies": {},
37
37
  "devDependencies": {