asajs 4.1.7 → 4.1.9

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.
@@ -9,6 +9,21 @@ export function FormatProperties(properties) {
9
9
  property_bag[key] = value;
10
10
  delete properties[key];
11
11
  }
12
+ if (key.startsWith("$")) {
13
+ const [varName, varType] = key.split("|");
14
+ if (!varType)
15
+ break;
16
+ switch (varType) {
17
+ case "d":
18
+ properties[`${varName}|default`] = value;
19
+ delete properties[key];
20
+ break;
21
+ case "default":
22
+ break;
23
+ default:
24
+ throw new Error("Invalid variable type");
25
+ }
26
+ }
12
27
  }
13
28
  if (config.compiler?.fixInventoryItemRenderer && property_bag[BagBinding.ITEM_ID_AUX]) {
14
29
  property_bag[BagBinding.ITEM_ID_AUX] = `(${property_bag[BagBinding.ITEM_ID_AUX]} / 1)`;
@@ -25,6 +25,9 @@ export function isHasBinding(input) {
25
25
  export function isBinding(input) {
26
26
  return /^#\w+$/.test(input);
27
27
  }
28
+ export function isVariable(input) {
29
+ return /^\$\w+$/.test(input);
30
+ }
28
31
  export function isNumber(input) {
29
32
  return /^[+-]?(?:\d+|\d+\.\d*|\.\d+)(?:[eE][+-]?\d+)?$/.test(input);
30
33
  }
@@ -1,6 +1,6 @@
1
- import { bs, RandomBindingString, RandomString, ResolveBinding } from "../../components/Utils.js";
1
+ import { bs, RandomBindingString, RandomString, ResolveBinding, vs } from "../../components/Utils.js";
2
2
  import { bindingFuntions } from "../Configuration.js";
3
- import { isBinding, isNumber, isString } from "./Checker.js";
3
+ import { isBinding, isNumber, isString, isVariable } from "./Checker.js";
4
4
  export const FunctionMap = new Map();
5
5
  export const defaultFunctions = {
6
6
  /**
@@ -224,6 +224,14 @@ export const defaultFunctions = {
224
224
  value: bs(input_binding),
225
225
  };
226
226
  },
227
+ vs: input_variable => {
228
+ if (!isVariable(input_variable))
229
+ throw new Error("Invalid input binding");
230
+ return {
231
+ doNotAddParentesis: true,
232
+ value: vs(input_variable),
233
+ };
234
+ },
227
235
  /**
228
236
  * Return a translatable string
229
237
  * @param key
@@ -201,15 +201,21 @@ export function bs(input) {
201
201
  }
202
202
  }
203
203
  export function vs(input) {
204
+ let [name, mode] = input.split("|");
205
+ input = name;
206
+ if (mode)
207
+ mode = "|" + mode;
208
+ else
209
+ mode = "";
204
210
  if (isNotObfuscate)
205
- return input;
211
+ return `${name}${mode}`;
206
212
  else {
207
213
  if (rndMap.has(input))
208
- return rndMap.get(input);
214
+ return `${rndMap.get(input)}${mode}`;
209
215
  else {
210
216
  const ret = RandomVariableBinding();
211
217
  rndMap.set(input, ret);
212
- return ret;
218
+ return `${ret}${mode}`;
213
219
  }
214
220
  }
215
221
  }
@@ -7,5 +7,6 @@ export declare function isOctalChar(char: string): boolean;
7
7
  export declare function isCompileBinding(input: string): boolean;
8
8
  export declare function isHasBinding(input: string): boolean;
9
9
  export declare function isBinding(input: string): boolean;
10
+ export declare function isVariable(input: string): boolean;
10
11
  export declare function isNumber(input: string): boolean;
11
12
  export declare function isString(input: string): boolean;
@@ -88,6 +88,10 @@ export declare const defaultFunctions: {
88
88
  doNotAddParentesis: true;
89
89
  value: `#${string}`;
90
90
  };
91
+ vs: (input_variable: string) => {
92
+ doNotAddParentesis: true;
93
+ value: `$${string}`;
94
+ };
91
95
  /**
92
96
  * Return a translatable string
93
97
  * @param key
@@ -17,7 +17,7 @@ export type Animation = anim.Animation<AnimType> | AnimationKeyframe<AnimType> |
17
17
  export type Array2<T> = [T, T];
18
18
  export type Array3<T> = [T, T, T];
19
19
  export type Array4<T> = [T, T, T, T];
20
- export type Value<T> = Variable | T;
20
+ export type Value<T> = Variable | Binding | T;
21
21
  export type AnimValue<T> = Value<T | Animation>;
22
22
  export type BindingItem = {
23
23
  ignored?: Value<boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asajs",
3
- "version": "4.1.7",
3
+ "version": "4.1.9",
4
4
  "description": "Create your Minecraft JSON-UI resource packs using JavaScript",
5
5
  "keywords": [
6
6
  "Minecraft",