@bornengine/engine 0.5.0 → 0.5.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/ui/api.ts +45 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bornengine/engine",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "BornEngine: native TypeScript game engine compiled by Perry",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
package/src/ui/api.ts CHANGED
@@ -34,24 +34,48 @@ function colorValues(color: Color): number[] {
34
34
  return [color.r, color.g, color.b, color.a];
35
35
  }
36
36
 
37
+ function sendUiCommand(
38
+ backend: UiBackendId,
39
+ opcode: number,
40
+ id: UiId,
41
+ args: number[],
42
+ text: string,
43
+ ): void {
44
+ bloom_ui_command(
45
+ backend,
46
+ opcode,
47
+ id,
48
+ args[0] ?? 0,
49
+ args[1] ?? 0,
50
+ args[2] ?? 0,
51
+ args[3] ?? 0,
52
+ text as any,
53
+ );
54
+ }
55
+
56
+ function sendUiScratchCommand(
57
+ backend: UiBackendId,
58
+ opcode: number,
59
+ id: UiId,
60
+ values: number[],
61
+ text: string,
62
+ ): void {
63
+ bloom_ui_scratch_reset(backend);
64
+ for (const value of values) bloom_ui_scratch_push_f64(backend, value);
65
+ bloom_ui_scratch_command(backend, opcode, id, values.length, text as any);
66
+ }
67
+
68
+ function injectUiText(text: string): void {
69
+ bloom_ui_inject_text(text as any);
70
+ }
71
+
37
72
  export function createUiApi(backend: UiBackendId): UiApi {
38
- function command(opcode: number, id: UiId, args: number[] = [], text = ''): void {
39
- bloom_ui_command(
40
- backend,
41
- opcode,
42
- id,
43
- args[0] ?? 0,
44
- args[1] ?? 0,
45
- args[2] ?? 0,
46
- args[3] ?? 0,
47
- text as any,
48
- );
73
+ function command(opcode: number, id: UiId, args: number[] = [], text?: string): void {
74
+ sendUiCommand(backend, opcode, id, args, text ?? '');
49
75
  }
50
76
 
51
- function scratchCommand(opcode: number, id: UiId, values: number[], text = ''): void {
52
- bloom_ui_scratch_reset(backend);
53
- for (const value of values) bloom_ui_scratch_push_f64(backend, value);
54
- bloom_ui_scratch_command(backend, opcode, id, values.length, text as any);
77
+ function scratchCommand(opcode: number, id: UiId, values: number[], text?: string): void {
78
+ sendUiScratchCommand(backend, opcode, id, values, text ?? '');
55
79
  }
56
80
 
57
81
  function response(id: UiId): UiResponse {
@@ -97,7 +121,7 @@ export function createUiApi(backend: UiBackendId): UiApi {
97
121
  checkbox(id, label, checked) {
98
122
  command(UiOpcode.Checkbox, id, [checked ? 1 : 0], label);
99
123
  const result = response(id);
100
- return result.present ? result.value > 0.5 : checked;
124
+ return result.present && result.changed ? result.value > 0.5 : checked;
101
125
  },
102
126
  radioButton(id, label, selected) {
103
127
  command(UiOpcode.RadioButton, id, [selected ? 1 : 0], label);
@@ -106,23 +130,23 @@ export function createUiApi(backend: UiBackendId): UiApi {
106
130
  sliderFloat(id, label, value, min, max) {
107
131
  command(UiOpcode.SliderFloat, id, [value, min, max], label);
108
132
  const result = response(id);
109
- return result.present ? result.value : value;
133
+ return result.present && result.changed ? result.value : value;
110
134
  },
111
135
  sliderInt(id, label, value, min, max) {
112
136
  command(UiOpcode.SliderInt, id, [value, min, max], label);
113
137
  const result = response(id);
114
- return result.present ? Math.round(result.value) : value;
138
+ return result.present && result.changed ? Math.round(result.value) : value;
115
139
  },
116
140
  dragFloat(id, prefix, value, speed = 0.1, min = Number.NaN, max = Number.NaN) {
117
141
  command(UiOpcode.DragFloat, id, [value, speed, min, max], prefix);
118
142
  const result = response(id);
119
- return result.present ? result.value : value;
143
+ return result.present && result.changed ? result.value : value;
120
144
  },
121
145
  textEditSingleline(id, label, value) {
122
146
  command(UiOpcode.Label, 0, [], label);
123
147
  command(UiOpcode.TextEdit, id, [], value);
124
148
  const result = response(id);
125
- return result.present ? result.text : value;
149
+ return result.present && result.changed ? result.text : value;
126
150
  },
127
151
  beginCombo(id, label, selectedText) {
128
152
  command(UiOpcode.Label, 0, [], label);
@@ -210,7 +234,7 @@ export function createUiApi(backend: UiBackendId): UiApi {
210
234
  isAvailable() { return bloom_ui_is_available(backend) > 0.5; },
211
235
  wantsPointerInput() { return bloom_ui_wants_input(backend, 0) > 0.5; },
212
236
  wantsKeyboardInput() { return bloom_ui_wants_input(backend, 1) > 0.5; },
213
- injectText(text) { bloom_ui_inject_text(text as any); },
237
+ injectText(text) { injectUiText(text); },
214
238
  };
215
239
  return api;
216
240
  }