overpy 9.6.2 → 9.6.3

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/overpy.js +49 -9
  2. package/package.json +1 -1
package/overpy.js CHANGED
@@ -38695,6 +38695,10 @@ ${scriptText}`, {
38695
38695
  setRulePrefixTemplateFilestack(_rulePrefixTemplateFilestack);
38696
38696
  return;
38697
38697
  }
38698
+ if (content2.startsWith("#!useVariableForCompressionAlphabet")) {
38699
+ setUseVariableForCompressionAlphabet(true);
38700
+ return;
38701
+ }
38698
38702
  if (content2.startsWith("#!debugElementCount")) {
38699
38703
  setDebugElementCount(true);
38700
38704
  return;
@@ -45143,8 +45147,9 @@ astParsingFunctions.__if__ = function(content) {
45143
45147
  }
45144
45148
  }
45145
45149
  }
45150
+ let isLoneIf = content.parent.childIndex === content.parent.children.length - 1 || content.parent.childIndex < content.parent.children.length - 1 && !["__elif__", "__else__"].includes(content.parent.children[content.parent.childIndex + 1].name);
45146
45151
  if (enableOptimization) {
45147
- if (content.children.length === 1 && (content.parent.childIndex === content.parent.children.length - 1 || content.parent.children[content.parent.childIndex + 1].name !== "__elif__" && content.parent.children[content.parent.childIndex + 1].name !== "__else__") && ["return", "loop", "__skip__"].includes(content.children[0].name)) {
45152
+ if (content.children.length === 1 && isLoneIf && ["return", "loop", "__skip__"].includes(content.children[0].name)) {
45148
45153
  if (currentRuleHasVariableGoto) {
45149
45154
  content.parent.children.splice(content.parent.childIndex + 1, 0, content.children[0], getAstForUselessInstruction());
45150
45155
  }
@@ -45166,7 +45171,7 @@ astParsingFunctions.__if__ = function(content) {
45166
45171
  makeChildrenUseless(content.children);
45167
45172
  }
45168
45173
  }
45169
- if (content.parent.childIndex === content.parent.children.length - 1 || content.parent.childIndex < content.parent.children.length - 1 && !["__elif__", "__else__"].includes(content.parent.children[content.parent.childIndex + 1].name)) {
45174
+ if (isLoneIf) {
45170
45175
  var includeEnd = true;
45171
45176
  if (enableOptimization && currentRuleEvent !== "__subroutine__" && content.parent.childIndex === content.parent.children.length - 1) {
45172
45177
  var root = content;
@@ -45182,6 +45187,16 @@ astParsingFunctions.__if__ = function(content) {
45182
45187
  }
45183
45188
  }
45184
45189
  }
45190
+ if (optimizeForSize2 && (content.args[0].name === "__not__" || content.children.length === 1 && includeEnd && ["__equals__", "__inequals__", "__greaterThan__", "__greaterThanOrEquals__", "__lessThan__", "__lessThanOrEquals__"].includes(content.args[0].name))) {
45191
+ let label = "__label_if_" + getUniqueNumber() + "__";
45192
+ content.parent.children.splice(content.parent.childIndex + 1, 0, ...content.children, new Ast2(label, [], [], "Label"), getAstForUselessInstruction());
45193
+ if (content.args[0].name === "__not__") {
45194
+ content.args[0] = content.args[0].args[0];
45195
+ } else {
45196
+ content.args[0] = astParsingFunctions.__not__(new Ast2("__not__", [content.args[0]]));
45197
+ }
45198
+ return new Ast2("__skipIf__", [content.args[0], new Ast2("__distanceTo__", [new Ast2(label, [], [], "Label")])]);
45199
+ }
45185
45200
  if (includeEnd) {
45186
45201
  content.parent.children.splice(content.parent.childIndex + 1, 0, getAstForEnd());
45187
45202
  }
@@ -45409,6 +45424,14 @@ astParsingFunctions.__negate__ = function(content) {
45409
45424
  };
45410
45425
 
45411
45426
  // src/compiler/functions/__not__.ts
45427
+ var inverseComparisonMapping = {
45428
+ "__equals__": "__inequals__",
45429
+ "__inequals__": "__equals__",
45430
+ "__greaterThan__": "__lessThanOrEquals__",
45431
+ "__greaterThanOrEquals__": "__lessThan__",
45432
+ "__lessThan__": "__greaterThanOrEquals__",
45433
+ "__lessThanOrEquals__": "__greaterThan__"
45434
+ };
45412
45435
  astParsingFunctions.__not__ = function(content) {
45413
45436
  if (enableOptimization) {
45414
45437
  if (isDefinitelyFalsy(content.args[0])) {
@@ -45426,6 +45449,9 @@ astParsingFunctions.__not__ = function(content) {
45426
45449
  if (content.args[0].name === ".isDead") {
45427
45450
  return new Ast2(".isAlive", [content.args[0].args[0]]);
45428
45451
  }
45452
+ if (content.args[0].name in inverseComparisonMapping) {
45453
+ return new Ast2(inverseComparisonMapping[content.args[0].name], content.args[0].args);
45454
+ }
45429
45455
  }
45430
45456
  return content;
45431
45457
  };
@@ -46845,16 +46871,18 @@ function compressToString(compressionInfo) {
46845
46871
  }
46846
46872
  function getDecompressionAst(compressedString, compressionInfo) {
46847
46873
  let { minDecimalPlace, maxDecimalPlace, offset, arrayType } = compressionInfo;
46874
+ let formulaAlphabet = useVariableForCompressionAlphabet ? "__compressionAlphabet__" : "x.last()";
46875
+ let formulaCompressedArray = useVariableForCompressionAlphabet ? `$compressedString.split(null[0])` : `[e.concat(${escapeString(alphabet2, false)}) for e in $compressedString.split(null[0])]`;
46848
46876
  if (arrayType === "number") {
46849
- let decompressionFormula = Array(Math.ceil((maxDecimalPlace - minDecimalPlace) / 2)).fill(0).map((x, i) => i).map((x) => `${Math.pow(100, x + minDecimalPlace / 2)}*x.last().strIndex(x[0].charAt(${x}))`).join(" + ");
46850
- return parseOpyMacro(`[${decompressionFormula} - ${offset} for x in [e.concat(${escapeString(alphabet2, false)}) for e in $compressedString.split(null[0])]]`, ["$compressedString"], [compressedString]);
46877
+ let decompressionFormula = Array(Math.ceil((maxDecimalPlace - minDecimalPlace) / 2)).fill(0).map((x, i) => i).map((x) => `${Math.pow(100, x + minDecimalPlace / 2)}*${formulaAlphabet}.strIndex(x.charAt(${x}))`).join(" + ");
46878
+ return parseOpyMacro(`[${decompressionFormula} - ${offset} for x in ${formulaCompressedArray}]`, ["$compressedString"], [compressedString]);
46851
46879
  } else {
46852
46880
  let decompressionFormulas = Array(3).fill(0).map((_, h) => {
46853
46881
  return Array(Math.ceil((maxDecimalPlace - minDecimalPlace) / 2)).fill(0).map((x, i) => i).map((x) => `
46854
- ${Math.pow(100, x + minDecimalPlace / 2)}*x.last().strIndex(x[0].charAt(${x + Math.ceil((maxDecimalPlace - minDecimalPlace) / 2) * h}))
46882
+ ${Math.pow(100, x + minDecimalPlace / 2)}*${formulaAlphabet}.strIndex(x.charAt(${x + Math.ceil((maxDecimalPlace - minDecimalPlace) / 2) * h}))
46855
46883
  `).join(" + ");
46856
46884
  });
46857
- return parseOpyMacro(`[vect(${decompressionFormulas[0]},${decompressionFormulas[2]},${decompressionFormulas[1]}) - vect(1,1,1)*${offset} for x in [e.concat(${escapeString(alphabet2, false)}) for e in $compressedString.split(null[0])]]`, ["$compressedString"], [compressedString]);
46885
+ return parseOpyMacro(`[vect(${decompressionFormulas[0]},${decompressionFormulas[2]},${decompressionFormulas[1]}) - vect(1,1,1)*${offset} for x in ${formulaCompressedArray}]`, ["$compressedString"], [compressedString]);
46858
46886
  }
46859
46887
  }
46860
46888
  astParsingFunctions.compressed = function(content) {
@@ -59649,7 +59677,10 @@ var valueFuncKw = (
59649
59677
  {
59650
59678
  "name": "condition",
59651
59679
  "description": "The mapping expression that is evaluated for each element of the copied array. Use the current array element value to reference the element of the array currently being considered.",
59652
- "type": "bool"
59680
+ "type": [
59681
+ "Object",
59682
+ "Array"
59683
+ ]
59653
59684
  }
59654
59685
  ],
59655
59686
  "isConstant": true,
@@ -64618,7 +64649,7 @@ function astRulesToWs(rules) {
64618
64649
  result += "}\n\n";
64619
64650
  incrementNbElements();
64620
64651
  let ruleElements = nbElements - elementsBefore;
64621
- if (debugElementCount) {
64652
+ if (debugElementCount && ruleElements > 1) {
64622
64653
  let { filePath } = getRuleFilePath(rule.fileStack);
64623
64654
  ruleElementCounts.push({ name: oldRuleName, file: filePath, elements: ruleElements });
64624
64655
  result = "//" + ruleElements + " element" + (ruleElements !== 1 ? "s" : "") + "\n" + result;
@@ -65636,6 +65667,9 @@ async function compile(content, language = "en-US", _rootPath = "", _mainFileNam
65636
65667
  if (replacementForEmptyString === "variable") {
65637
65668
  addVariable("__emptyString__", true, -1, getInternalFileStack(), tokenize("[].charAt(null)")[0].tokens);
65638
65669
  }
65670
+ if (useVariableForCompressionAlphabet) {
65671
+ addVariable("__compressionAlphabet__", true, -1, getInternalFileStack(), tokenize(escapeString(alphabet2, false))[0].tokens);
65672
+ }
65639
65673
  if (translationLanguages2.length > 0) {
65640
65674
  setTranslatedStrings(importFromPoFiles());
65641
65675
  }
@@ -69106,7 +69140,7 @@ Wrapping a string with \`___\` has the same caveats as putting a translated stri
69106
69140
  return: "String"
69107
69141
  },
69108
69142
  "compressed": {
69109
- "description": "Compresses in-place the specified array of numbers or vectors into a string, then returns the decompressed array. Strings take much fewer elements, so use this function if you are running out of elements.\n\nNote that numbers will get rounded to 3 decimal places, and vectors to 2 decimal places.\n\nThis function is only effective once the array has at least 18 vectors or 26 numbers.\n\nThis function can be more effective than `compress()` and `decompressNumbers()` / `decompressVectors()`, as it can apply optimizations if all numbers have a low amount of significant digits or if they are all positive.",
69143
+ "description": "Compresses in-place the specified array of numbers or vectors into a string, then returns the decompressed array. Strings take much fewer elements, so use this function if you are running out of elements.\n\nNote that numbers will get rounded to 3 decimal places, and vectors to 2 decimal places.\n\nThis function is only effective once the array has at least 5 vectors or 7 numbers (depending on the complexity; use `#!debugElementCount` to compare).\n\nThis function can be more effective than `compress()` and `decompressNumbers()` / `decompressVectors()`, as it can apply optimizations if all numbers have a low amount of significant digits or if they are all positive.",
69110
69144
  "args": [
69111
69145
  {
69112
69146
  "name": "array",
@@ -69721,6 +69755,8 @@ var rulePrefixTemplate = "";
69721
69755
  var setRulePrefixTemplate = (template) => rulePrefixTemplate = template;
69722
69756
  var rulePrefixTemplateFilestack = [];
69723
69757
  var setRulePrefixTemplateFilestack = (filestack) => rulePrefixTemplateFilestack = filestack;
69758
+ var useVariableForCompressionAlphabet = false;
69759
+ var setUseVariableForCompressionAlphabet = (use) => useVariableForCompressionAlphabet = use;
69724
69760
  var decompilerGotos;
69725
69761
  var resetDecompilerGotos = () => decompilerGotos = [];
69726
69762
  var nbTabs;
@@ -69800,6 +69836,7 @@ function resetGlobalVariables(language) {
69800
69836
  currentRulePrefix = "";
69801
69837
  rulePrefixTemplate = "";
69802
69838
  rulePrefixTemplateFilestack = [];
69839
+ useVariableForCompressionAlphabet = false;
69803
69840
  }
69804
69841
  var operatorPrecedence = {
69805
69842
  "=": 1,
@@ -72262,6 +72299,9 @@ You can specify \`noDetectionRule\` to not create the rule which sets the variab
72262
72299
  You can also specify \`noTlErr\` to have spectators view the default language when viewing a translated string (the \`__languageIndex__\` variable is now 0-indexed instead of 1-indexed). Keep in mind that, if translations aren't used properly, you may not see it if you playtest with the default language.
72263
72300
  `
72264
72301
  },
72302
+ "useVariableForCompressionAlphabet": {
72303
+ "description": `If enabled, the compression functions will use a global variable \`__compressionAlphabet__\` instead of a hardcoded string for the alphabet, which will save further elements.`
72304
+ },
72265
72305
  "extension": {
72266
72306
  "description": "You shouldn't be reading this. Contact Zezombye if you can see this.",
72267
72307
  "snippet": "You shouldn't be reading this. Contact Zezombye if you can see this."
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "url": "https://github.com/Zezombye/overpy"
8
8
  },
9
9
  "description": "High-level language for the Overwatch Workshop, with decompilation and compilation.",
10
- "version": "9.6.2",
10
+ "version": "9.6.3",
11
11
  "readme": "README.md",
12
12
  "keywords": [
13
13
  "overpy",