asajs 3.0.5 → 3.0.7

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 CHANGED
@@ -1,72 +1,72 @@
1
- # AsaJS
2
-
3
- A framework specifically designed for creating UI resource packs using JavaScript/TypeScript for Minecraft: Bedrock Edition, packed with many useful utilities!
4
-
5
- # Installation
6
-
7
- <p>To install it into your project, you need to have <b>Node.js</b> pre-installed to use it!</p>
8
-
9
- <p>You also need to create a project and use the following command to start using <b>AsaJS</b>:</p>
10
-
11
- ```batch
12
- npm install asajs
13
- ```
14
-
15
- <p>That command will add the AsaJS library to your project, and you can start using it.</p>
16
-
17
- # How to use
18
-
19
- <p>The syntax is very simple. If you just want to add a button to hide start screen, here is the code for that:</p>
20
-
21
- ```javascript
22
- import { Anchor, BindingName, UI, Vanilla } from "asajs";
23
-
24
- // Game start screen content
25
- const vanillaStartScreenContent = Vanilla.start.startScreenContent();
26
-
27
- // A custom start screen
28
- const ourStartScreenContent = UI.panel({ size: "100%" }).addChild(vanillaStartScreenContent);
29
-
30
- // Toggle for hide start screen
31
- const ourToggle = UI.extend(Vanilla.commonToggles.lightTextToggle(), {
32
- w: 84,
33
- h: 28,
34
- $button_text: "Hide Screen",
35
- $toggle_name: "hide_start_screen",
36
- $toggle_view_binding_name: "hide_start_screen_state",
37
- });
38
-
39
- // Add toggle to start screen content
40
- ourStartScreenContent.addChild(ourToggle, {
41
- anchor: Anchor.TopLeft,
42
- x: 5,
43
- y: 5,
44
- });
45
-
46
- vanillaStartScreenContent.override.addBindings([
47
- {
48
- binding_name: BindingName.ScreenNeedsRebuild,
49
- binding_name_override: "#bind_0",
50
- },
51
- {
52
- source_control_name: "hide_start_screen_state",
53
- source_property_name: "#toggle_state",
54
- target_property_name: "#bind_1",
55
- },
56
- {
57
- source_property_name: "[!#bind_0 && !#bind_1]",
58
- target_property_name: "#visible",
59
- },
60
- ]);
61
-
62
- // Modify start screen content
63
- Vanilla.start.startScreen({
64
- $screen_content: ourStartScreenContent.getPath(),
65
- });
66
- ```
67
-
68
- <p>And you just need to run the code you wrote, and here is the result:</p>
69
-
70
- <p align="center">
71
- <img width="750px" max-width="100%" src="resources/example_1.png" />
72
- </p>
1
+ # AsaJS
2
+
3
+ A framework specifically designed for creating UI resource packs using JavaScript/TypeScript for Minecraft: Bedrock Edition, packed with many useful utilities!
4
+
5
+ # Installation
6
+
7
+ <p>To install it into your project, you need to have <b>Node.js</b> pre-installed to use it!</p>
8
+
9
+ <p>You also need to create a project and use the following command to start using <b>AsaJS</b>:</p>
10
+
11
+ ```batch
12
+ npm install asajs
13
+ ```
14
+
15
+ <p>That command will add the AsaJS library to your project, and you can start using it.</p>
16
+
17
+ # How to use
18
+
19
+ <p>The syntax is very simple. If you just want to add a button to hide start screen, here is the code for that:</p>
20
+
21
+ ```javascript
22
+ import { Anchor, BindingName, UI, Vanilla } from "asajs";
23
+
24
+ // Game start screen content
25
+ const vanillaStartScreenContent = Vanilla.start.startScreenContent();
26
+
27
+ // A custom start screen
28
+ const ourStartScreenContent = UI.panel({ size: "100%" }).addChild(vanillaStartScreenContent);
29
+
30
+ // Toggle for hide start screen
31
+ const ourToggle = UI.extend(Vanilla.commonToggles.lightTextToggle(), {
32
+ w: 84,
33
+ h: 28,
34
+ $button_text: "Hide Screen",
35
+ $toggle_name: "hide_start_screen",
36
+ $toggle_view_binding_name: "hide_start_screen_state",
37
+ });
38
+
39
+ // Add toggle to start screen content
40
+ ourStartScreenContent.addChild(ourToggle, {
41
+ anchor: Anchor.TopLeft,
42
+ x: 5,
43
+ y: 5,
44
+ });
45
+
46
+ vanillaStartScreenContent.override.addBindings([
47
+ {
48
+ binding_name: BindingName.ScreenNeedsRebuild,
49
+ binding_name_override: "#bind_0",
50
+ },
51
+ {
52
+ source_control_name: "hide_start_screen_state",
53
+ source_property_name: "#toggle_state",
54
+ target_property_name: "#bind_1",
55
+ },
56
+ {
57
+ source_property_name: "[!#bind_0 && !#bind_1]",
58
+ target_property_name: "#visible",
59
+ },
60
+ ]);
61
+
62
+ // Modify start screen content
63
+ Vanilla.start.startScreen({
64
+ $screen_content: ourStartScreenContent.getPath(),
65
+ });
66
+ ```
67
+
68
+ <p>And you just need to run the code you wrote, and here is the result:</p>
69
+
70
+ <p align="center">
71
+ <img width="750px" max-width="100%" src="resources/example_1.png" />
72
+ </p>
@@ -52,19 +52,19 @@ function ReadProperties(properties) {
52
52
  properties.min_size = [properties.min_w || 0, properties.min_h || 0];
53
53
  delete properties.min_w;
54
54
  delete properties.min_h;
55
- } else if (properties.min_size !== void 0 && !Array.isArray(properties.min_size) && typeof properties.min_size === "string" && !properties.min_size.startsWith("$"))
55
+ } else if (properties.min_size !== void 0 && !Array.isArray(properties.min_size) && (typeof properties.min_size === "string" && !properties.min_size.startsWith("$") || typeof properties.min_size === "number"))
56
56
  properties.min_size = [properties.min_size, properties.min_size];
57
57
  if (properties.max_w || properties.max_h) {
58
58
  properties.max_size = [properties.max_w || 0, properties.max_h || 0];
59
59
  delete properties.max_w;
60
60
  delete properties.max_h;
61
- } else if (properties.max_size !== void 0 && !Array.isArray(properties.max_size) && typeof properties.max_size === "string" && !properties.max_size.startsWith("$"))
61
+ } else if (properties.max_size !== void 0 && !Array.isArray(properties.max_size) && (typeof properties.max_size === "string" && !properties.max_size.startsWith("$") || typeof properties.max_size === "number"))
62
62
  properties.max_size = [properties.max_size, properties.max_size];
63
63
  if (properties.w || properties.h) {
64
64
  properties.size = [properties.w || 0, properties.h || 0];
65
65
  delete properties.w;
66
66
  delete properties.h;
67
- } else if (properties.size !== void 0 && !Array.isArray(properties.size) && typeof properties.size === "string" && !properties.size.startsWith("$"))
67
+ } else if (properties.size !== void 0 && !Array.isArray(properties.size) && (typeof properties.size === "string" && !properties.size.startsWith("$") || typeof properties.size === "number"))
68
68
  properties.size = [properties.size, properties.size];
69
69
  if (properties.sound_path) {
70
70
  properties.sound_name = import_Sounds.SoundHandler.get(properties.sound_path);
@@ -29,6 +29,7 @@ var import_CurrentLine = require("../compilers/reader/CurrentLine");
29
29
  var import_Object = require("../compilers/reader/Object");
30
30
  var import_ReadBinding = require("../compilers/reader/ReadBinding");
31
31
  var import_ReadProperties = require("../compilers/reader/ReadProperties");
32
+ var import_MappingTypes = require("../types/enums/MappingTypes");
32
33
  var import_Class = require("./Class");
33
34
  var import_Random = require("./Random");
34
35
  var import_UI = require("./UI");
@@ -39,7 +40,9 @@ class Modify extends import_Class.Class {
39
40
  __publicField(this, "properties", {});
40
41
  __publicField(this, "controls");
41
42
  __publicField(this, "bindings");
43
+ __publicField(this, "button_mappings");
42
44
  __publicField(this, "variables");
45
+ __publicField(this, "anims");
43
46
  __publicField(this, "isValidPath");
44
47
  __publicField(this, "name", "");
45
48
  __publicField(this, "namespace", "");
@@ -89,6 +92,16 @@ class Modify extends import_Class.Class {
89
92
  else (this.bindings || (this.bindings = [])).push((0, import_ReadBinding.ReadBinding)(bindings, this.override));
90
93
  return this.override;
91
94
  },
95
+ addMapping: (mapping) => {
96
+ this.button_mappings || (this.button_mappings = []);
97
+ if (!mapping) return this.override;
98
+ if (Array.isArray(mapping)) mapping.forEach((v) => this.override.addMapping(v));
99
+ else {
100
+ mapping.mapping_type || (mapping.mapping_type = import_MappingTypes.MappingType.Global);
101
+ this.button_mappings.push(mapping);
102
+ }
103
+ return this.override;
104
+ },
92
105
  addVariables: (variables) => {
93
106
  this.variables || (this.variables = {});
94
107
  if (variables)
@@ -101,6 +114,11 @@ class Modify extends import_Class.Class {
101
114
  });
102
115
  return this.override;
103
116
  },
117
+ addAnimation: (animation, startIndex) => {
118
+ this.anims || (this.anims = []);
119
+ if (animation) this.anims.push(animation.getKeyIndex(startIndex || 0));
120
+ return this.override;
121
+ },
104
122
  searchBinding: (bindingName, controlName, targetBindingName) => {
105
123
  var _a, _b;
106
124
  for (let index = 0; index < (((_a = this.bindings) == null ? void 0 : _a.length) || 0); index++) {
@@ -236,16 +254,16 @@ class Modify extends import_Class.Class {
236
254
  getUI() {
237
255
  const code = (0, import_ReadProperties.ReadProperties)(this.properties);
238
256
  const modifications = [];
239
- for (const key of ["type", "controls", "bindings", "button_mappings"])
257
+ for (const key of ["type", "controls", "bindings", "button_mappings", "anims"])
240
258
  if (this[key]) code[key] = this[key];
241
- if (this.variables)
259
+ if (this.variables) code.variables;
260
+ if (this.variables && Object(this.variables).length !== 0)
242
261
  import_Object.Obj.forEach(this.variables, (k, v) => {
243
- (code.variables || (code.variables = [])).push({
262
+ code.variables.push({
244
263
  requires: k,
245
264
  ...v
246
265
  });
247
266
  });
248
- if (this.variables && Object.keys(this.variables).length === 0) code.variables || (code.variables = []);
249
267
  {
250
268
  if (this.modifyBindings) {
251
269
  modifications.push({
@@ -277,7 +277,8 @@ const _UI = class _UI {
277
277
  return name === this.name;
278
278
  }
279
279
  addChild(element, properties, name, callback) {
280
- if (!this.controls) this.controls = [];
280
+ this.controls || (this.controls = []);
281
+ if (!element) return this;
281
282
  name || (name = import_Random.Random.getName());
282
283
  if (this.isDuplicate(name)) {
283
284
  import_Log.Log.warning("".concat((0, import_CurrentLine.CurrentLine)(), " child element should have a unique name!"));
@@ -300,19 +301,37 @@ const _UI = class _UI {
300
301
  return this;
301
302
  }
302
303
  addBindings(bindings) {
304
+ this.bindings || (this.bindings = []);
305
+ if (!bindings) return this;
303
306
  if (Array.isArray(bindings)) for (const binding of bindings) this.addBindings(binding);
304
- else (this.bindings || (this.bindings = [])).push((0, import_ReadBinding.ReadBinding)(bindings, this));
307
+ else this.bindings.push((0, import_ReadBinding.ReadBinding)(bindings, this));
308
+ return this;
309
+ }
310
+ addMapping(mapping) {
311
+ this.button_mappings || (this.button_mappings = []);
312
+ if (!mapping) return this;
313
+ if (Array.isArray(mapping)) mapping.forEach((v) => this.addMapping(v));
314
+ else {
315
+ mapping.mapping_type || (mapping.mapping_type = import_MappingTypes.MappingType.Global);
316
+ this.button_mappings.push(mapping);
317
+ }
305
318
  return this;
306
319
  }
307
320
  addVariables(variables) {
308
321
  this.variables || (this.variables = {});
309
- import_Object.Obj.forEach(variables, (key, value) => {
310
- this.variables[key] = {
311
- ...import_Object.Obj.map(value, (k, v) => {
312
- return { key: k, value: (0, import_ReadProperties.ReadValue)(v) };
313
- })
314
- };
315
- });
322
+ if (variables)
323
+ import_Object.Obj.forEach(variables, (key, value) => {
324
+ this.variables[key] = {
325
+ ...import_Object.Obj.map(value, (k, v) => {
326
+ return { key: k, value: (0, import_ReadProperties.ReadValue)(v) };
327
+ })
328
+ };
329
+ });
330
+ return this;
331
+ }
332
+ addAnimation(animation, startIndex) {
333
+ this.anims || (this.anims = []);
334
+ if (animation) this.anims.push(animation.getKeyIndex(startIndex || 0));
316
335
  return this;
317
336
  }
318
337
  getUI() {
@@ -330,9 +349,10 @@ const _UI = class _UI {
330
349
  target_property_name: targetBinding
331
350
  });
332
351
  }
333
- if (this.variables)
352
+ if (this.variables) code.variables || (code.variables = []);
353
+ if (this.variables && Object(this.variables).length !== 0)
334
354
  import_Object.Obj.forEach(this.variables, (k, v) => {
335
- (code.variables || (code.variables = [])).push({
355
+ code.variables.push({
336
356
  requires: k,
337
357
  ...v
338
358
  });
@@ -355,18 +375,6 @@ const _UI = class _UI {
355
375
  properties
356
376
  });
357
377
  }
358
- addAnimation(animation, startIndex) {
359
- (this.anims || (this.anims = [])).push(animation.getKeyIndex(startIndex || 0));
360
- return this;
361
- }
362
- addMapping(mapping) {
363
- if (Array.isArray(mapping)) mapping.forEach((v) => this.addMapping(v));
364
- else {
365
- mapping.mapping_type || (mapping.mapping_type = import_MappingTypes.MappingType.Global);
366
- (this.button_mappings || (this.button_mappings = [])).push(mapping);
367
- }
368
- return this;
369
- }
370
378
  static apply() {
371
379
  }
372
380
  static bind() {