From 31fd1a2f01b9c1d092bc38a8c4ca8ed0dc2da3aa Mon Sep 17 00:00:00 2001 From: ferricles Date: Tue, 26 Jul 2022 11:37:08 -0700 Subject: [PATCH] change Build internal item repr to include separate tomes array, allow bitvec to append using other bitvec (untested) --- js/build.js | 15 +++++++-------- js/build_encode_decode.js | 10 +++++++++- js/builder_graph.js | 6 ++++-- js/utils.js | 11 ++++++++++- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/js/build.js b/js/build.js index 6211e43..476c3cd 100644 --- a/js/build.js +++ b/js/build.js @@ -11,17 +11,15 @@ class Build{ * @description Construct a build. * @param {Number} level : Level of the player. * @param {String[]} equipment : List of equipment names that make up the build. - * In order: boots, Chestplate, Leggings, Boots, Ring1, Ring2, Brace, Neck, Weapon. - * @param {Number[]} powders : Powder application. List of lists of integers (powder IDs). - * In order: boots, Chestplate, Leggings, Boots, Weapon. - * @param {Object[]} inputerrors : List of instances of error-like classes. + * In order: boots, Chestplate, Leggings, Boots, Ring1, Ring2, Brace, Neck * * @param {Object[]} tomes: List of tomes. * In order: 2x Weapon Mastery Tome, 4x Armor Mastery Tome, 1x Guild Tome. * 2x Slaying Mastery Tome, 2x Dungeoneering Mastery Tome, 2x Gathering Mastery Tome are in game, but do not have "useful" stats (those that affect damage calculations or building) + * + * @param {Object} weapon: Weapon. */ - constructor(level, items, weapon){ - + constructor(level, equipment, tomes, weapon){ if (level < 1) { //Should these be constants? this.level = 1; } else if (level > 106) { @@ -36,9 +34,10 @@ class Build{ document.getElementById("level-choice").value = this.level; this.availableSkillpoints = levelToSkillPoints(this.level); - this.equipment = items; + this.equipment = equipment; + this.tomes = tomes; this.weapon = weapon; - this.items = this.equipment.concat([this.weapon]); + this.items = this.equipment.concat(tomes, [this.weapon]); // return [equip_order, best_skillpoints, final_skillpoints, best_total]; // calc skillpoints requires statmaps only diff --git a/js/build_encode_decode.js b/js/build_encode_decode.js index ffb2c7f..2c280b7 100644 --- a/js/build_encode_decode.js +++ b/js/build_encode_decode.js @@ -233,7 +233,15 @@ function encodeBuild(build, powders, skillpoints, atree, atree_state) { // [flag to indicate if tomes are included (0/1)] // [if set: 7 sequential tome IDs, each 6 bits unsigned] - + if (build.tomes.length > 0) { + build_bits.append(1, 1); + //decoding will assume that tomes has length of 7. + for (const tome of build.tomes) { + build_bits.append(tome.id, 6); + } + } else { + build_bits.append(0, 1); + } // ATREE diff --git a/js/builder_graph.js b/js/builder_graph.js index 73caa07..39b32b7 100644 --- a/js/builder_graph.js +++ b/js/builder_graph.js @@ -397,7 +397,9 @@ class BuildAssembleNode extends ComputeNode { input_map.get('ring1-input'), input_map.get('ring2-input'), input_map.get('bracelet-input'), - input_map.get('necklace-input'), + input_map.get('necklace-input') + ]; + let tomes = [ input_map.get('weaponTome1-input'), input_map.get('weaponTome2-input'), input_map.get('armorTome1-input'), @@ -419,7 +421,7 @@ class BuildAssembleNode extends ComputeNode { if (all_none && !location.hash) { return null; } - return new Build(level, equipments, weapon); + return new Build(level, equipments, tomes, weapon); } } diff --git a/js/utils.js b/js/utils.js index de6d781..1b552d7 100644 --- a/js/utils.js +++ b/js/utils.js @@ -373,10 +373,19 @@ Base64 = (function () { } } else if (data instanceof BitVector) { //fill to end of curr int of existing bv + let other_pos = (32 - (pos % 32)) % 32; + this.bits[curr_idx] |= data.slice(0, other_pos); + curr_idx += 1; //fill full ints + while (other_pos + 32 < data.length) { + this.bits[curr_idx] = data.slice(other_pos, other_pos + 32); + curr_idx += 1; + other_pos += 32; + } - //fill from "rest of" length/bv + //fill from "rest of" length/bv + this.bits[curr_idx] = data.slice(other_pos, data.length); } else { throw new TypeError("BitVector must be appended with a Number or a B64 String"); }