asajs 4.0.4 → 4.0.5-indev

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/config.d.ts CHANGED
@@ -7,6 +7,7 @@ export interface Config {
7
7
  importToPreview?: boolean
8
8
  autoEnable?: boolean
9
9
  gdkUserId?: string
10
+ fixInventoryItemRenderer?: boolean
10
11
  }
11
12
  packinfo?: {
12
13
  name?: string
@@ -1,4 +1,6 @@
1
1
  import { AnimationKeyframe } from "../components/AnimationKeyframe.js";
2
+ import { BagBinding } from "../types/enums/BagBinding.js";
3
+ import { config } from "./Configuration.js";
2
4
  export function FormatProperties(properties) {
3
5
  const property_bag = {};
4
6
  for (const key in properties) {
@@ -8,6 +10,9 @@ export function FormatProperties(properties) {
8
10
  delete properties[key];
9
11
  }
10
12
  }
13
+ if (config.compiler?.fixInventoryItemRenderer && property_bag[BagBinding.ITEM_ID_AUX]) {
14
+ property_bag[BagBinding.ITEM_ID_AUX] = `(${property_bag[BagBinding.ITEM_ID_AUX]} / 1)`;
15
+ }
11
16
  if (properties.anchor) {
12
17
  properties.anchor_from = properties.anchor_to = properties.anchor;
13
18
  delete properties.anchor;
@@ -2,7 +2,7 @@ import { RandomBindingString } from "../../components/Utils.js";
2
2
  import { defaultFunctions } from "./Function.js";
3
3
  export function intToBin(input) {
4
4
  const { abs, negabs } = defaultFunctions;
5
- const ret = RandomBindingString(16);
5
+ const ret = RandomBindingString();
6
6
  const bindings = [];
7
7
  // negative bit
8
8
  bindings.push({
@@ -15,7 +15,7 @@ export function intToBin(input) {
15
15
  };
16
16
  }
17
17
  export function binToInt(input) {
18
- const ret = RandomBindingString(16);
18
+ const ret = RandomBindingString();
19
19
  const bindings = [];
20
20
  const nevBind = (input + "0");
21
21
  // Is reverse to positive
@@ -1,8 +1,5 @@
1
1
  import { RandomBindingString } from "../../components/Utils.js";
2
2
  export const FunctionMap = new Map();
3
- function callFn(name, ...args) {
4
- return FunctionMap.get(name)(...args);
5
- }
6
3
  export const defaultFunctions = {
7
4
  /**
8
5
  * Returns the absolute value of a number (the value without regard to whether it is positive or negative). For example, the absolute value of -5 is the same as the absolute value of 5.
@@ -10,7 +7,7 @@ export const defaultFunctions = {
10
7
  * @returns
11
8
  */
12
9
  abs: number => {
13
- const randomBinding = RandomBindingString(16);
10
+ const randomBinding = RandomBindingString();
14
11
  return {
15
12
  genBindings: [{ source: `((-1 + (${number} > 0) * 2) * ${number})`, target: randomBinding }],
16
13
  value: randomBinding,
@@ -22,7 +19,7 @@ export const defaultFunctions = {
22
19
  * @returns
23
20
  */
24
21
  negabs: number => {
25
- const randomBinding = RandomBindingString(16);
22
+ const randomBinding = RandomBindingString();
26
23
  return {
27
24
  genBindings: [{ source: `((-1 + (${number} < 0) * 2) * ${number})`, target: randomBinding }],
28
25
  value: randomBinding,
@@ -34,37 +31,88 @@ export const defaultFunctions = {
34
31
  * @returns
35
32
  */
36
33
  new: expression => {
37
- const randomBinding = RandomBindingString(16);
34
+ const randomBinding = RandomBindingString();
38
35
  return {
39
36
  genBindings: [{ source: expression, target: randomBinding }],
40
37
  value: randomBinding,
41
38
  };
42
39
  },
43
- /**
44
- * Returns the square root of a number.
45
- * @param number
46
- * @returns
47
- */
48
- sqrt: number => {
49
- const rtn = RandomBindingString(16), $1 = RandomBindingString(16), $2 = RandomBindingString(16);
50
- const { genBindings: absValue, value: absRtn } = callFn("abs", number);
40
+ sqrt: input => {
41
+ const ret = RandomBindingString();
42
+ const isNegative = RandomBindingString();
43
+ const isLowerThanTwo = RandomBindingString();
44
+ const next = RandomBindingString();
45
+ const nextEqualOrGreaterThan = RandomBindingString();
46
+ const isNextEqualOrGreaterThanRet = `(${nextEqualOrGreaterThan} * ${ret})`;
47
+ const isNotNextEqualOrGreaterThanRet = `((not ${nextEqualOrGreaterThan}) * ${next})`;
48
+ const lowerThanTwoPart = `(${isLowerThanTwo} * ${input})`;
49
+ const notLowerThanTwoPart = `((not ${isLowerThanTwo}) * (${isNextEqualOrGreaterThanRet} + ${isNotNextEqualOrGreaterThanRet}))`;
50
+ const negativePart = `(${isNegative} * -1)`;
51
+ const notNegativePart = `((not ${isNegative}) * (${lowerThanTwoPart} + ${notLowerThanTwoPart}))`;
52
+ return {
53
+ genBindings: [
54
+ {
55
+ source: `(${input} < 0)`,
56
+ target: isNegative,
57
+ },
58
+ {
59
+ source: `(${input} < 2)`,
60
+ target: isLowerThanTwo,
61
+ },
62
+ {
63
+ source: input,
64
+ target: ret,
65
+ },
66
+ {
67
+ source: `(${ret} + ${input} / ${ret}) / 2`,
68
+ target: next,
69
+ },
70
+ {
71
+ source: `(${next} = ${ret}) or (${next} > ${ret})`,
72
+ target: nextEqualOrGreaterThan,
73
+ },
74
+ {
75
+ source: `${negativePart} + ${notNegativePart}`,
76
+ target: ret,
77
+ },
78
+ ],
79
+ value: ret,
80
+ };
81
+ },
82
+ cache_value: (cache_binding, override_binding, is_read) => {
83
+ return {
84
+ value: `((${is_read} * ${cache_binding}) + ((not ${is_read}) * ${override_binding}))`,
85
+ };
86
+ },
87
+ vector_length: (x, y, z) => {
88
+ const newBind = defaultFunctions.new(`${y} * ${y} + ${x} * ${x} + ${z} * ${z}`);
89
+ const sqrtBind = defaultFunctions.sqrt(newBind.value);
90
+ return {
91
+ genBindings: [newBind.genBindings[0], ...sqrtBind.genBindings],
92
+ value: sqrtBind.value,
93
+ };
94
+ },
95
+ strlen: str => {
96
+ if (!/\#\w+/.test(str))
97
+ throw new Error("Invalid string");
98
+ const count = RandomBindingString();
99
+ const inputStr = RandomBindingString();
51
100
  return {
52
101
  genBindings: [
53
102
  {
54
- source: `${number} * 100 / 2`,
55
- target: $1,
103
+ source: `0 * (${str} = 'a')`,
104
+ target: count,
56
105
  },
57
- ...absValue,
58
106
  {
59
- source: `${absRtn} > 1`,
60
- target: $2,
107
+ source: `'a' + ${str}`,
108
+ target: inputStr,
61
109
  },
62
110
  {
63
- source: `(${number} < 0) * -1 + (${number} > -1) * (${$2} * ((${rtn} + ${number} / ${rtn}) / 2) + (not ${$2}) * ${rtn})`,
64
- target: rtn,
111
+ source: `${count} + (not ((('%.' + (${count} + 1) + 's') * ${inputStr}) = ${inputStr}))`,
112
+ target: count,
65
113
  },
66
114
  ],
67
- value: rtn,
115
+ value: count,
68
116
  };
69
117
  },
70
118
  /**
@@ -74,6 +122,7 @@ export const defaultFunctions = {
74
122
  */
75
123
  translatable: key => {
76
124
  return {
125
+ genBindings: [],
77
126
  value: `'%' + ${key}`,
78
127
  };
79
128
  },
@@ -96,7 +145,7 @@ export const defaultFunctions = {
96
145
  * @returns
97
146
  */
98
147
  bind: (value, bait) => {
99
- const ret = RandomBindingString(16);
148
+ const ret = RandomBindingString();
100
149
  if (!bait) {
101
150
  throw new Error("Bait is required");
102
151
  }
@@ -111,7 +160,7 @@ export const defaultFunctions = {
111
160
  * @returns
112
161
  */
113
162
  int: input => {
114
- const ret = RandomBindingString(16);
163
+ const ret = RandomBindingString();
115
164
  return {
116
165
  genBindings: [{ source: `${input}`, target: ret }],
117
166
  value: ret,
@@ -26,7 +26,7 @@ export class Parser {
26
26
  }
27
27
  static intToBin(input) {
28
28
  const bindings = [];
29
- const rtn = RandomBindingString(16);
29
+ const rtn = RandomBindingString();
30
30
  for (let i = 0; i < 30; i++) {
31
31
  bindings.push({
32
32
  source: `(${input} / ${2 ** i} - (${input} / ${2 ** (i + 1)}) * 2)`,
@@ -126,7 +126,7 @@ export class Parser {
126
126
  if (this.cache.has(cacheStr)) {
127
127
  return (left = this.cache.get(cacheStr));
128
128
  }
129
- const ret = RandomBindingString(16);
129
+ const ret = RandomBindingString();
130
130
  this.genBindings.push({
131
131
  source: `(${left} - (${left} / ${right} * ${right}))`,
132
132
  target: ret,
@@ -56,7 +56,7 @@ export function ResolveBinding(cache, ...bindings) {
56
56
  };
57
57
  }
58
58
  else {
59
- const ret = RandomBindingString(16);
59
+ const ret = RandomBindingString();
60
60
  cache.set(mapkey, ret);
61
61
  result.push({
62
62
  source_property_name: token.value,
@@ -127,7 +127,7 @@ export function RandomString(length, base = 32) {
127
127
  }
128
128
  return out.join("");
129
129
  }
130
- export function RandomBindingString(length, base = 32) {
130
+ export function RandomBindingString(length = 16, base = 32) {
131
131
  return `#${RandomString(length, base)}`;
132
132
  }
133
133
  export function GetItemByAuxID(auxID) {