asajs 4.0.4 → 4.0.6-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
@@ -19,3 +19,6 @@ export function isOctalChar(char) {
19
19
  export function isCompileBinding(input) {
20
20
  return input.startsWith("[") && input.endsWith("]");
21
21
  }
22
+ export function isHasBinding(input) {
23
+ return /#\w+/.test(input);
24
+ }
@@ -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,
@@ -40,6 +40,8 @@ export function Lexer(input, start = 0, end) {
40
40
  case "/":
41
41
  case "%":
42
42
  case "^":
43
+ case "?":
44
+ case ":":
43
45
  tokens.push(makeToken(input, TokenKind.OPERATOR, index));
44
46
  break;
45
47
  case "(":
@@ -3,6 +3,7 @@ import { BindingType } from "../../types/enums/BindingType.js";
3
3
  import { FunctionMap } from "./Function.js";
4
4
  import { Lexer } from "./Lexer.js";
5
5
  import { RandomBindingString } from "../../components/Utils.js";
6
+ import { isHasBinding } from "./Checker.js";
6
7
  export class Parser {
7
8
  input;
8
9
  cache;
@@ -26,7 +27,7 @@ export class Parser {
26
27
  }
27
28
  static intToBin(input) {
28
29
  const bindings = [];
29
- const rtn = RandomBindingString(16);
30
+ const rtn = RandomBindingString();
30
31
  for (let i = 0; i < 30; i++) {
31
32
  bindings.push({
32
33
  source: `(${input} / ${2 ** i} - (${input} / ${2 ** (i + 1)}) * 2)`,
@@ -60,11 +61,56 @@ export class Parser {
60
61
  return this.tokens[this.tokens.length - 1];
61
62
  }
62
63
  parseExpression() {
63
- return this.parseOrExpression();
64
+ return this.parseBinaryExpression();
65
+ }
66
+ parseBinaryExpression() {
67
+ let left = this.parseOrExpression(), current;
68
+ while ((current = this.at()) && current.kind === TokenKind.OPERATOR && current.value === "?") {
69
+ this.eat();
70
+ let middle = this.parseExpression(), right;
71
+ if ((current = this.at()) && current.kind === TokenKind.OPERATOR && current.value === ":") {
72
+ this.eat();
73
+ right = this.parseExpression();
74
+ }
75
+ else
76
+ this.expect(TokenKind.OPERATOR, "Unexpected token!");
77
+ let leftBind, middleBind, rightBind;
78
+ if (isHasBinding(left)) {
79
+ leftBind = RandomBindingString();
80
+ this.genBindings.push({
81
+ source: `((0 + ${left}) > 0)`,
82
+ target: leftBind,
83
+ });
84
+ }
85
+ else
86
+ this.expect(TokenKind.WORD, "Unexpected token!");
87
+ if (isHasBinding(middle)) {
88
+ middleBind = RandomBindingString();
89
+ this.genBindings.push({
90
+ source: middle,
91
+ target: middleBind,
92
+ });
93
+ }
94
+ else
95
+ this.expect(TokenKind.WORD, "Unexpected token!");
96
+ if (isHasBinding(right)) {
97
+ rightBind = RandomBindingString();
98
+ this.genBindings.push({
99
+ source: right,
100
+ target: rightBind,
101
+ });
102
+ }
103
+ else
104
+ this.expect(TokenKind.WORD, "Unexpected token!");
105
+ const ifTrueExpression = `(('prefix' + ${leftBind} + ${middleBind}) - ('prefixfalse' + ${middleBind})) - 'prefixtrue')`;
106
+ const ifFalseExpression = `(('prefix' + ${leftBind} + ${rightBind}) - ('prefixtrue' + ${rightBind})) - 'prefixfalse')`;
107
+ return `(${ifTrueExpression} + ${ifFalseExpression})`;
108
+ }
109
+ return left;
64
110
  }
65
111
  parseOrExpression() {
66
112
  let left = this.parseAndExpression(), current;
67
- while ((current = this.at()) && this.at().kind === TokenKind.OPERATOR && current.value === "||") {
113
+ while ((current = this.at()) && current.kind === TokenKind.OPERATOR && current.value === "||") {
68
114
  this.eat();
69
115
  left = `(${left} or ${this.parseAndExpression()})`;
70
116
  }
@@ -72,7 +118,7 @@ export class Parser {
72
118
  }
73
119
  parseAndExpression() {
74
120
  let left = this.parseComparisonExpression(), current;
75
- while ((current = this.at()) && this.at().kind === TokenKind.OPERATOR && current.value === "&&") {
121
+ while ((current = this.at()) && current.kind === TokenKind.OPERATOR && current.value === "&&") {
76
122
  this.eat();
77
123
  left = `(${left} and ${this.parseComparisonExpression()})`;
78
124
  }
@@ -81,7 +127,7 @@ export class Parser {
81
127
  parseComparisonExpression() {
82
128
  let left = this.parseAdditiveExpression(), current;
83
129
  while ((current = this.at()) &&
84
- this.at().kind === TokenKind.OPERATOR &&
130
+ current.kind === TokenKind.OPERATOR &&
85
131
  ["==", ">", "<", ">=", "<=", "!="].includes(current.value)) {
86
132
  const operator = this.eat();
87
133
  const right = this.parseAdditiveExpression();
@@ -106,7 +152,7 @@ export class Parser {
106
152
  parseAdditiveExpression() {
107
153
  let left = this.parseMultiplicativeExpression(), current;
108
154
  while ((current = this.at()) &&
109
- this.at()?.kind === TokenKind.OPERATOR &&
155
+ current?.kind === TokenKind.OPERATOR &&
110
156
  ["+", "-"].includes(current.value)) {
111
157
  const operator = this.eat();
112
158
  const right = this.parseMultiplicativeExpression();
@@ -117,7 +163,7 @@ export class Parser {
117
163
  parseMultiplicativeExpression() {
118
164
  let left = this.parseBitwiseLogicExpression(), current;
119
165
  while ((current = this.at()) &&
120
- this.at()?.kind === TokenKind.OPERATOR &&
166
+ current?.kind === TokenKind.OPERATOR &&
121
167
  ["*", "/", "%"].includes(current.value)) {
122
168
  const operator = this.eat();
123
169
  const right = this.parsePrimaryExpression();
@@ -126,7 +172,7 @@ export class Parser {
126
172
  if (this.cache.has(cacheStr)) {
127
173
  return (left = this.cache.get(cacheStr));
128
174
  }
129
- const ret = RandomBindingString(16);
175
+ const ret = RandomBindingString();
130
176
  this.genBindings.push({
131
177
  source: `(${left} - (${left} / ${right} * ${right}))`,
132
178
  target: ret,
@@ -143,6 +143,14 @@ export function getGamedataPath() {
143
143
  }
144
144
  }
145
145
  }
146
+ case "linux": {
147
+ const gamedata = path.join(process.env.HOME, "\\.local\\share\\mcpelauncher\\games\\com.mojang");
148
+ if (fs.existsSync(gamedata))
149
+ return (pathinfo.gamepath = gamedata);
150
+ else {
151
+ return (pathinfo.gamepath = path.join(process.env.HOME, "\\.var\\app\\io.mrarm.mcpelauncher\\data\\mcpelauncher\\games\\com.mojang"));
152
+ }
153
+ }
146
154
  default: {
147
155
  console.warn(`Your platform is not supported the install feature yet! \nYour OS version: ${os.version()}`);
148
156
  }
@@ -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) {