Make encoding method backwards compatible and export the lowest version encoding possible (up to 4)
This commit is contained in:
parent
f8d90b347e
commit
ac636c9498
3 changed files with 80 additions and 179 deletions
|
@ -221,11 +221,8 @@ function init_maps() {
|
|||
["accessory", "bracelet", "No Bracelet"],
|
||||
["accessory", "necklace", "No Necklace"],
|
||||
["weapon", "dagger", "No Weapon"],
|
||||
["tome", "weaponTome", "No Weapon Tome"],
|
||||
["tome", "armorTome", "No Armour Tome"],
|
||||
["tome", "guildTome", "No Guild Tome"]
|
||||
];
|
||||
for (let i = 0; i < 12; i++) {
|
||||
for (let i = 0; i < noneItems.length; i++) {
|
||||
let item = Object();
|
||||
item.slots = 0;
|
||||
item.category = noneItems[i][0];
|
||||
|
|
|
@ -339,7 +339,7 @@ class Build{
|
|||
} else {
|
||||
try {
|
||||
let weaponTome1 = getCustomFromHash(tomes[0]) ? getCustomFromHash(tomes[0]) : undefined;
|
||||
if (weaponTome1.statMap.get("type") !== "weaponTome1") {
|
||||
if (weaponTome1.statMap.get("type") !== "weaponTome") {
|
||||
throw new Error("Not a Weapon Tome");
|
||||
}
|
||||
if (this.weaponTome1.get("custom")) {
|
||||
|
@ -358,7 +358,7 @@ class Build{
|
|||
} else {
|
||||
try {
|
||||
let weaponTome2 = getCustomFromHash(tomes[1]) ? getCustomFromHash(tomes[1]) : undefined;
|
||||
if (weaponTome2.statMap.get("type") !== "weaponTome2") {
|
||||
if (weaponTome2.statMap.get("type") !== "weaponTome") {
|
||||
throw new Error("Not a Weapon Tome");
|
||||
}
|
||||
if (this.weaponTome2.get("custom")) {
|
||||
|
@ -377,7 +377,7 @@ class Build{
|
|||
} else {
|
||||
try {
|
||||
let armorTome1 = getCustomFromHash(tomes[2]) ? getCustomFromHash(tomes[2]) : undefined;
|
||||
if (armorTome1.statMap.get("type") !== "armorTome1") {
|
||||
if (armorTome1.statMap.get("type") !== "armorTome") {
|
||||
throw new Error("Not an Armor Tome");
|
||||
}
|
||||
if (this.armorTome1.get("custom")) {
|
||||
|
@ -396,7 +396,7 @@ class Build{
|
|||
} else {
|
||||
try {
|
||||
let armorTome2 = getCustomFromHash(tomes[3]) ? getCustomFromHash(tomes[3]) : undefined;
|
||||
if (armorTome2.statMap.get("type") !== "armorTome2") {
|
||||
if (armorTome2.statMap.get("type") !== "armorTome") {
|
||||
throw new Error("Not an Armor Tome");
|
||||
}
|
||||
if (this.armorTome2.get("custom")) {
|
||||
|
@ -415,7 +415,7 @@ class Build{
|
|||
} else {
|
||||
try {
|
||||
let armorTome3 = getCustomFromHash(tomes[4]) ? getCustomFromHash(tomes[4]) : undefined;
|
||||
if (armorTome3.statMap.get("type") !== "armorTome3") {
|
||||
if (armorTome3.statMap.get("type") !== "armorTome") {
|
||||
throw new Error("Not an Armor Tome");
|
||||
}
|
||||
if (this.armorTome3.get("custom")) {
|
||||
|
@ -434,7 +434,7 @@ class Build{
|
|||
} else {
|
||||
try {
|
||||
let armorTome4 = getCustomFromHash(tomes[5]) ? getCustomFromHash(tomes[5]) : undefined;
|
||||
if (armorTome4.statMap.get("type") !== "armorTome4") {
|
||||
if (armorTome4.statMap.get("type") !== "armorTome") {
|
||||
throw new Error("Not an Armor Tome");
|
||||
}
|
||||
if (this.armorTome4.get("custom")) {
|
||||
|
|
240
js/sq2builder.js
240
js/sq2builder.js
|
@ -137,7 +137,7 @@ function parsePowdering(powder_info) {
|
|||
}
|
||||
powdering[i] = powders;
|
||||
}
|
||||
return powdering;
|
||||
return [powdering, powder_info];
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -155,8 +155,10 @@ function decodeBuild(url_tag) {
|
|||
let skillpoints = [0, 0, 0, 0, 0];
|
||||
let level = 106;
|
||||
|
||||
version_number = parseInt(version)
|
||||
//equipment (items)
|
||||
if (version === "0" || version === "1" || version === "2" || version === "3") {
|
||||
// TODO: use filters
|
||||
if (version_number < 4) {
|
||||
let equipments = info[1];
|
||||
for (let i = 0; i < 9; ++i ) {
|
||||
let equipment_str = equipments.slice(i*3,i*3+3);
|
||||
|
@ -164,7 +166,7 @@ function decodeBuild(url_tag) {
|
|||
}
|
||||
info[1] = equipments.slice(27);
|
||||
}
|
||||
if (version === "4") {
|
||||
else if (version_number == 4) {
|
||||
let info_str = info[1];
|
||||
let start_idx = 0;
|
||||
for (let i = 0; i < 9; ++i ) {
|
||||
|
@ -180,7 +182,7 @@ function decodeBuild(url_tag) {
|
|||
}
|
||||
info[1] = info_str.slice(start_idx);
|
||||
}
|
||||
if (version === "5") {
|
||||
else if (version_number <= 6) {
|
||||
let info_str = info[1];
|
||||
let start_idx = 0;
|
||||
for (let i = 0; i < 9; ++i ) {
|
||||
|
@ -199,46 +201,17 @@ function decodeBuild(url_tag) {
|
|||
}
|
||||
info[1] = info_str.slice(start_idx);
|
||||
}
|
||||
if (version === "6") {
|
||||
let info_str = info[1];
|
||||
let start_idx = 0;
|
||||
for (let i = 0; i < 9; ++i ) {
|
||||
if (info_str.slice(start_idx,start_idx+3) === "CR-") {
|
||||
equipment[i] = info_str.slice(start_idx, start_idx+20);
|
||||
start_idx += 20;
|
||||
} else if (info_str.slice(start_idx+3,start_idx+6) === "CI-") {
|
||||
let len = Base64.toInt(info_str.slice(start_idx,start_idx+3));
|
||||
equipment[i] = info_str.slice(start_idx+3,start_idx+3+len);
|
||||
start_idx += (3+len);
|
||||
} else {
|
||||
let equipment_str = info_str.slice(start_idx, start_idx+3);
|
||||
equipment[i] = getItemNameFromID(Base64.toInt(equipment_str));
|
||||
start_idx += 3;
|
||||
}
|
||||
}
|
||||
//tomes!
|
||||
for (let i = 0; i < 7; ++i) {
|
||||
let tome_str = info_str.charAt(start_idx);
|
||||
tomes[i] = getTomeNameFromID(Base64.toInt(tome_str));
|
||||
start_idx += 1;
|
||||
}
|
||||
info[1] = info_str.slice(start_idx);
|
||||
|
||||
//tome values do not appear in anything before v6.
|
||||
for (let i in tomes) {
|
||||
setValue(tomeInputs[i], tomes[i]);
|
||||
}
|
||||
}
|
||||
//constant in all versions
|
||||
for (let i in equipment) {
|
||||
setValue(equipmentInputs[i], equipment[i]);
|
||||
}
|
||||
|
||||
//level, skill point assignments, and powdering
|
||||
if (version === "1") {
|
||||
if (version_number == 1) {
|
||||
let powder_info = info[1];
|
||||
powdering = parsePowdering(powder_info);
|
||||
} else if (version === "2") {
|
||||
let res = parsePowdering(powder_info);
|
||||
powdering = res[0];
|
||||
} else if (version_number == 2) {
|
||||
save_skp = true;
|
||||
let skillpoint_info = info[1].slice(0, 10);
|
||||
for (let i = 0; i < 5; ++i ) {
|
||||
|
@ -246,8 +219,9 @@ function decodeBuild(url_tag) {
|
|||
}
|
||||
|
||||
let powder_info = info[1].slice(10);
|
||||
powdering = parsePowdering(powder_info);
|
||||
} else if (version === "3" || version === "4" || version === "5" || version === "6"){
|
||||
let res = parsePowdering(powder_info);
|
||||
powdering = res[0];
|
||||
} else if (version_number <= 6){
|
||||
level = Base64.toInt(info[1].slice(10,12));
|
||||
setValue("level-choice",level);
|
||||
save_skp = true;
|
||||
|
@ -258,8 +232,22 @@ function decodeBuild(url_tag) {
|
|||
|
||||
let powder_info = info[1].slice(12);
|
||||
|
||||
powdering = parsePowdering(powder_info);
|
||||
let res = parsePowdering(powder_info);
|
||||
powdering = res[0];
|
||||
info[1] = res[1];
|
||||
}
|
||||
// Tomes.
|
||||
if (version == 6) {
|
||||
//tome values do not appear in anything before v6.
|
||||
for (let i = 0; i < 7; ++i) {
|
||||
let tome_str = info[1].charAt(i);
|
||||
for (let i in tomes) {
|
||||
setValue(tomeInputs[i], getTomeNameFromID(Base64.toInt(tome_str)));
|
||||
}
|
||||
}
|
||||
info[1] = info[1].slice(7);
|
||||
}
|
||||
|
||||
for (let i in powderInputs) {
|
||||
setValue(powderInputs[i], powdering[i]);
|
||||
}
|
||||
|
@ -276,141 +264,57 @@ function encodeBuild() {
|
|||
let build_string;
|
||||
|
||||
//V6 encoding - Tomes
|
||||
if (player_build.items.length == 16 && player_build.tomes) {
|
||||
build_string = "6_";
|
||||
build_version = 4;
|
||||
build_string = "";
|
||||
tome_string = "";
|
||||
|
||||
let crafted_idx = 0;
|
||||
let custom_idx = 0;
|
||||
for (const item of player_build.items) {
|
||||
let crafted_idx = 0;
|
||||
let custom_idx = 0;
|
||||
for (const item of player_build.items) {
|
||||
|
||||
if (item.get("custom")) {
|
||||
let custom = "CI-"+encodeCustom(player_build.customItems[custom_idx],true);
|
||||
build_string += Base64.fromIntN(custom.length, 3) + custom;
|
||||
custom_idx += 1;
|
||||
} else if (item.get("crafted")) {
|
||||
build_string += "CR-"+encodeCraft(player_build.craftedItems[crafted_idx]);
|
||||
crafted_idx += 1;
|
||||
} else if (item.get("category") === "tome") {
|
||||
build_string += Base64.fromIntN(item.get("id"), 1);
|
||||
} else {
|
||||
build_string += Base64.fromIntN(item.get("id"), 3);
|
||||
}
|
||||
}
|
||||
|
||||
for (const skp of skp_order) {
|
||||
build_string += Base64.fromIntN(getValue(skp + "-skp"), 2); // Maximum skillpoints: 2048
|
||||
}
|
||||
build_string += Base64.fromIntN(player_build.level, 2);
|
||||
for (const _powderset of player_build.powders) {
|
||||
let n_bits = Math.ceil(_powderset.length / 6);
|
||||
build_string += Base64.fromIntN(n_bits, 1); // Hard cap of 378 powders.
|
||||
// Slice copy.
|
||||
let powderset = _powderset.slice();
|
||||
while (powderset.length != 0) {
|
||||
let firstSix = powderset.slice(0,6).reverse();
|
||||
let powder_hash = 0;
|
||||
for (const powder of firstSix) {
|
||||
powder_hash = (powder_hash << 5) + 1 + powder; // LSB will be extracted first.
|
||||
}
|
||||
build_string += Base64.fromIntN(powder_hash, 5);
|
||||
powderset = powderset.slice(6);
|
||||
if (item.get("custom")) {
|
||||
let custom = "CI-"+encodeCustom(player_build.customItems[custom_idx],true);
|
||||
build_string += Base64.fromIntN(custom.length, 3) + custom;
|
||||
custom_idx += 1;
|
||||
build_version = Math.max(build_version, 5);
|
||||
} else if (item.get("crafted")) {
|
||||
build_string += "CR-"+encodeCraft(player_build.craftedItems[crafted_idx]);
|
||||
crafted_idx += 1;
|
||||
} else if (item.get("category") === "tome") {
|
||||
let tome_id = item.get("id");
|
||||
if (tome_id <= 60) {
|
||||
// valid normal tome. ID 61-63 is for NONE tomes.
|
||||
build_version = Math.max(build_version, 6);
|
||||
}
|
||||
tome_string += Base64.fromIntN(tome_id, 1);
|
||||
} else {
|
||||
build_string += Base64.fromIntN(item.get("id"), 3);
|
||||
}
|
||||
}
|
||||
|
||||
return build_string;
|
||||
for (const skp of skp_order) {
|
||||
build_string += Base64.fromIntN(getValue(skp + "-skp"), 2); // Maximum skillpoints: 2048
|
||||
}
|
||||
build_string += Base64.fromIntN(player_build.level, 2);
|
||||
for (const _powderset of player_build.powders) {
|
||||
let n_bits = Math.ceil(_powderset.length / 6);
|
||||
build_string += Base64.fromIntN(n_bits, 1); // Hard cap of 378 powders.
|
||||
// Slice copy.
|
||||
let powderset = _powderset.slice();
|
||||
while (powderset.length != 0) {
|
||||
let firstSix = powderset.slice(0,6).reverse();
|
||||
let powder_hash = 0;
|
||||
for (const powder of firstSix) {
|
||||
powder_hash = (powder_hash << 5) + 1 + powder; // LSB will be extracted first.
|
||||
}
|
||||
build_string += Base64.fromIntN(powder_hash, 5);
|
||||
powderset = powderset.slice(6);
|
||||
}
|
||||
}
|
||||
build_string += tome_string;
|
||||
|
||||
return build_version.toString() + "_" + build_string;
|
||||
}
|
||||
/* For reference in development - V5 and V4 encoding schemes */
|
||||
// //V5 encoding - Custom Items
|
||||
// if (player_build.customItems.length > 0) {
|
||||
// build_string = "5_";
|
||||
// let crafted_idx = 0;
|
||||
// let custom_idx = 0;
|
||||
// for (const item of player_build.items) {
|
||||
// //skip tomes (do we skip them?)
|
||||
// if (item.category === "tome") {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// if (item.get("custom")) {
|
||||
// let custom = "CI-"+encodeCustom(player_build.customItems[custom_idx],true);
|
||||
// build_string += Base64.fromIntN(custom.length, 3) + custom;
|
||||
// custom_idx += 1;
|
||||
// } else if (item.get("crafted")) {
|
||||
// build_string += "CR-"+encodeCraft(player_build.craftedItems[crafted_idx]);
|
||||
// crafted_idx += 1;
|
||||
// } else {
|
||||
// build_string += Base64.fromIntN(item.get("id"), 3);
|
||||
// }
|
||||
// }
|
||||
|
||||
// for (const skp of skp_order) {
|
||||
// build_string += Base64.fromIntN(getValue(skp + "-skp"), 2); // Maximum skillpoints: 2048
|
||||
// }
|
||||
// build_string += Base64.fromIntN(player_build.level, 2);
|
||||
// for (const _powderset of player_build.powders) {
|
||||
// let n_bits = Math.ceil(_powderset.length / 6);
|
||||
// build_string += Base64.fromIntN(n_bits, 1); // Hard cap of 378 powders.
|
||||
// // Slice copy.
|
||||
// let powderset = _powderset.slice();
|
||||
// while (powderset.length != 0) {
|
||||
// let firstSix = powderset.slice(0,6).reverse();
|
||||
// let powder_hash = 0;
|
||||
// for (const powder of firstSix) {
|
||||
// powder_hash = (powder_hash << 5) + 1 + powder; // LSB will be extracted first.
|
||||
// }
|
||||
// build_string += Base64.fromIntN(powder_hash, 5);
|
||||
// powderset = powderset.slice(6);
|
||||
// }
|
||||
// }
|
||||
// } else { //v4 encoding
|
||||
// build_string = "4_";
|
||||
// let crafted_idx = 0;
|
||||
// for (const item of player_build.items) {
|
||||
// //skip tomes for now
|
||||
// if (item.get("category") === "tome") {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// if (item.get("crafted")) {
|
||||
// build_string += "-"+encodeCraft(player_build.craftedItems[crafted_idx]);
|
||||
// crafted_idx += 1;
|
||||
// } else {
|
||||
// build_string += Base64.fromIntN(item.get("id"), 3);
|
||||
// }
|
||||
// }
|
||||
|
||||
// for (const skp of skp_order) {
|
||||
// build_string += Base64.fromIntN(getValue(skp + "-skp"), 2); // Maximum skillpoints: 2048
|
||||
// }
|
||||
// build_string += Base64.fromIntN(player_build.level, 2);
|
||||
// for (const _powderset of player_build.powders) {
|
||||
// let n_bits = Math.ceil(_powderset.length / 6);
|
||||
// build_string += Base64.fromIntN(n_bits, 1); // Hard cap of 378 powders.
|
||||
// // Slice copy.
|
||||
// let powderset = _powderset.slice();
|
||||
// while (powderset.length != 0) {
|
||||
// let firstSix = powderset.slice(0,6).reverse();
|
||||
// let powder_hash = 0;
|
||||
// for (const powder of firstSix) {
|
||||
// powder_hash = (powder_hash << 5) + 1 + powder; // LSB will be extracted first.
|
||||
// }
|
||||
// build_string += Base64.fromIntN(powder_hash, 5);
|
||||
// powderset = powderset.slice(6);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// this.equipment = [ this.helmet, this.chestplate, this.leggings, this.boots, this.ring1, this.ring2, this.bracelet, this.necklace ];
|
||||
// let build_string = "3_" + Base64.fromIntN(player_build.helmet.get("id"), 3) +
|
||||
// Base64.fromIntN(player_build.chestplate.get("id"), 3) +
|
||||
// Base64.fromIntN(player_build.leggings.get("id"), 3) +
|
||||
// Base64.fromIntN(player_build.boots.get("id"), 3) +
|
||||
// Base64.fromIntN(player_build.ring1.get("id"), 3) +
|
||||
// Base64.fromIntN(player_build.ring2.get("id"), 3) +
|
||||
// Base64.fromIntN(player_build.bracelet.get("id"), 3) +
|
||||
// Base64.fromIntN(player_build.necklace.get("id"), 3) +
|
||||
// Base64.fromIntN(player_build.weapon.get("id"), 3);
|
||||
return "";
|
||||
}
|
||||
|
||||
function calculateBuild(save_skp, skp){
|
||||
|
|
Loading…
Add table
Reference in a new issue