Fix loading race
This commit is contained in:
parent
643abafca1
commit
c8af5b4506
3 changed files with 42 additions and 78 deletions
18
load.js
18
load.js
|
@ -4,6 +4,7 @@ const DB_VERSION = 43;
|
|||
let db;
|
||||
let reload = false;
|
||||
let load_complete = false;
|
||||
let load_in_progress = false;
|
||||
let items;
|
||||
let sets;
|
||||
let itemMap;
|
||||
|
@ -62,6 +63,11 @@ function clean_item(item) {
|
|||
item.skillpoints = [item.str, item.dex, item.int, item.def, item.agi];
|
||||
item.has_negstat = item.str < 0 || item.dex < 0 || item.int < 0 || item.def < 0 || item.agi < 0;
|
||||
item.reqs = [item.strReq, item.dexReq, item.intReq, item.defReq, item.agiReq];
|
||||
for (let i = 0; i < 5; ++i) {
|
||||
if (item.reqs[i] === undefined) {
|
||||
item.reqs[i] = 0;
|
||||
}
|
||||
}
|
||||
if (item.slots === undefined) {
|
||||
item.slots = 0
|
||||
}
|
||||
|
@ -138,8 +144,18 @@ function load_init(init_func) {
|
|||
load_local(init_func);
|
||||
}
|
||||
else {
|
||||
console.log("Using new data...")
|
||||
if (load_in_progress) {
|
||||
while (!load_complete) {
|
||||
sleep(100);
|
||||
}
|
||||
init_func();
|
||||
}
|
||||
else {
|
||||
// Not 100% safe... whatever!
|
||||
load_in_progress = true
|
||||
load(init_func);
|
||||
console.log("Using new data...")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
35
load3.js
35
load3.js
|
@ -4,6 +4,7 @@ const DB_VERSION = 44;
|
|||
let db;
|
||||
let reload = false;
|
||||
let load_complete = false;
|
||||
let load_in_progress = false;
|
||||
let items;
|
||||
let sets;
|
||||
let itemMap;
|
||||
|
@ -14,9 +15,9 @@ let itemLists = new Map();
|
|||
* Load item set from local DB. Calls init() on success.
|
||||
*/
|
||||
async function load_local(init_func) {
|
||||
let get_tx = db.transaction(['item_db', 'set_db'], 'readonly');
|
||||
let sets_store = get_tx.objectStore('set_db');
|
||||
let get_store = get_tx.objectStore('item_db');
|
||||
let get_tx = db.transaction(['item3_db', 'set3_db'], 'readonly');
|
||||
let sets_store = get_tx.objectStore('set3_db');
|
||||
let get_store = get_tx.objectStore('item3_db');
|
||||
let request = get_store.getAll();
|
||||
request.onerror = function(event) {
|
||||
console.log("Could not read local item db...");
|
||||
|
@ -96,12 +97,12 @@ async function load(init_func) {
|
|||
// await clear_sets.clear();
|
||||
// await clear_tx.complete;
|
||||
|
||||
let add_tx = db.transaction(['item_db', 'set_db'], 'readwrite');
|
||||
let add_tx = db.transaction(['item3_db', 'set3_db'], 'readwrite');
|
||||
add_tx.onabort = function(e) {
|
||||
console.log(e);
|
||||
console.log("Not enough space...");
|
||||
};
|
||||
let items_store = add_tx.objectStore('item_db');
|
||||
let items_store = add_tx.objectStore('item3_db');
|
||||
let add_promises = [];
|
||||
for (const item of items) {
|
||||
clean_item(item);
|
||||
|
@ -111,7 +112,7 @@ async function load(init_func) {
|
|||
};
|
||||
add_promises.push(req);
|
||||
}
|
||||
let sets_store = add_tx.objectStore('set_db');
|
||||
let sets_store = add_tx.objectStore('set3_db');
|
||||
for (const set in sets) {
|
||||
add_promises.push(sets_store.add(sets[set], set));
|
||||
}
|
||||
|
@ -130,7 +131,7 @@ function load_init(init_func) {
|
|||
init_func();
|
||||
return;
|
||||
}
|
||||
let request = window.indexedDB.open('item_db', DB_VERSION);
|
||||
let request = window.indexedDB.open('item3_db', DB_VERSION);
|
||||
|
||||
request.onerror = function() {
|
||||
console.log("DB failed to open...");
|
||||
|
@ -143,8 +144,18 @@ function load_init(init_func) {
|
|||
load_local(init_func);
|
||||
}
|
||||
else {
|
||||
console.log("Using new data...")
|
||||
if (load_in_progress) {
|
||||
while (!load_complete) {
|
||||
sleep(100);
|
||||
}
|
||||
init_func();
|
||||
}
|
||||
else {
|
||||
// Not 100% safe... whatever!
|
||||
load_in_progress = true
|
||||
load(init_func);
|
||||
console.log("Using new data...")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,20 +165,20 @@ function load_init(init_func) {
|
|||
let db = e.target.result;
|
||||
|
||||
try {
|
||||
db.deleteObjectStore('item_db');
|
||||
db.deleteObjectStore('item3_db');
|
||||
}
|
||||
catch (error) {
|
||||
console.log("Could not delete item DB. This is probably fine");
|
||||
}
|
||||
try {
|
||||
db.deleteObjectStore('set_db');
|
||||
db.deleteObjectStore('set3_db');
|
||||
}
|
||||
catch (error) {
|
||||
console.log("Could not delete set DB. This is probably fine");
|
||||
}
|
||||
|
||||
db.createObjectStore('item_db');
|
||||
db.createObjectStore('set_db');
|
||||
db.createObjectStore('item3_db');
|
||||
db.createObjectStore('set3_db');
|
||||
|
||||
console.log("DB setup complete...");
|
||||
}
|
||||
|
|
63
powder3.js
63
powder3.js
|
@ -1,63 +0,0 @@
|
|||
let powderIDs = new Map();
|
||||
let powderNames = new Map();
|
||||
let _powderID = 0;
|
||||
for (const x of skp_elements) {
|
||||
for (let i = 1; i <= 6; ++i) {
|
||||
// Support both upper and lowercase, I guess.
|
||||
powderIDs.set(x.toUpperCase()+i, _powderID);
|
||||
powderIDs.set(x+i, _powderID);
|
||||
powderNames.set(_powderID, x+i);
|
||||
_powderID++;
|
||||
}
|
||||
}
|
||||
|
||||
// Ordering: [dmgMin, dmgMax, convert, defPlus, defMinus (+6 mod 5)]
|
||||
class Powder {
|
||||
constructor(min, max, convert, defPlus, defMinus) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.convert = convert;
|
||||
this.defPlus = defPlus;
|
||||
this.defMinus = defMinus;
|
||||
}
|
||||
}
|
||||
function _p(a,b,c,d,e) { return new Powder(a,b,c,d,e); } //bruh moment
|
||||
|
||||
let powderStats = [
|
||||
_p(3,6,17,2,1), _p(5,8,21,4,2), _p(6,10,25,8,3), _p(7,10,31,14,5), _p(9,11,38,22,9), _p(11,13,46,30,13),
|
||||
_p(1,8,9,3,1), _p(1,12,11,5,1), _p(2,15,13,9,2), _p(3,15,17,14,4), _p(4,17,22,20,7), _p(5,20,28,28,10),
|
||||
_p(3,4,13,3,1), _p(4,6,15,6,1), _p(5,8,17,11,2), _p(6,8,21,18,4), _p(7,10,26,28,7), _p(9,11,32,40,10),
|
||||
_p(2,5,14,3,1), _p(4,8,16,5,2), _p(5,9,19,9,3), _p(6,9,24,16,5), _p(8,10,30,25,9), _p(10,12,37,36,13),
|
||||
_p(2,6,11,3,1), _p(3,10,14,6,2), _p(4,11,17,10,3), _p(5,11,22,16,5), _p(7,12,28,24,9), _p(8,14,35,34,13)
|
||||
];
|
||||
|
||||
class PowderIngredient {
|
||||
constructor(durability, skpReq) {
|
||||
this.durability = durability;
|
||||
this.skpReq = skpReq;
|
||||
}
|
||||
}
|
||||
function _pi(a,b) { return new PowderIngredient(a,b)}
|
||||
|
||||
let powderIngreds = [
|
||||
_pi(-35,0),_pi(-52.5,0),_pi(-70,10),_pi(-91,20),_pi(-112,28),_pi(-133,36)
|
||||
];
|
||||
//Ordering: [weapon special name, weapon special effects, armor special name, armor special effects]
|
||||
class PowderSpecial{
|
||||
constructor(wSpName, wSpEff, aSpName, aSpEff, cap){
|
||||
this.weaponSpecialName = wSpName;
|
||||
this.weaponSpecialEffects = wSpEff;
|
||||
this.armorSpecialName = aSpName;
|
||||
this.armorSpecialEffects = aSpEff;
|
||||
this.cap = cap;
|
||||
}
|
||||
}
|
||||
function _ps(a,b,c,d,e) { return new PowderSpecial(a,b,c,d,e); } //bruh moment
|
||||
|
||||
let powderSpecialStats = [
|
||||
_ps("Quake",new Map([["Radius",[4.4,4.9,5.4,5.9,6.4]], ["Damage",[155,220,285,350,415]] ]),"Rage",new Map([ ["Damage", [0.3,0.4,0.5,0.7,1.0]],["Description", "% " + "\u2764" + " Missing"] ]),400), //e
|
||||
_ps("Chain Lightning",new Map([ ["Chains", [5,6,7,8,9]], ["Damage", [200,225,250,275,300]] ]),"Kill Streak",new Map([ ["Damage", [3,4.5,6,7.5,9]],["Duration", [5,5,5,5,5]],["Description", "Mob Killed"] ]),200), //t
|
||||
_ps("Curse",new Map([ ["Duration", [7,7.5,8,8.5,9]],["Damage Boost", [90,120,150,180,210]] ]),"Concentration",new Map([ ["Damage", [1,2,3,4,5]],["Duration",[1,1,1,1,1]],["Description", "Mana Used"] ]),150), //w
|
||||
_ps("Courage",new Map([ ["Duration", [6,6.5,7,7.5,8]],["Damage", [75,87.5,100,112.5,125]],["Damage Boost", [70,90,110,130,150]] ]),"Endurance",new Map([ ["Damage", [2,3,4,5,6]],["Duration", [8,8,8,8,8]],["Description", "Hit Taken"] ]),200), //f
|
||||
_ps("Wind Prison",new Map([ ["Duration", [3,3.5,4,4.5,5]],["Damage Boost", [400,450,500,550,600]],["Knockback", [8,12,16,20,24]] ]),"Dodge",new Map([ ["Damage",[2,3,4,5,6]],["Duration",[2,3,4,5,6]],["Description","Near Mobs"] ]),150) //a
|
||||
];
|
Loading…
Add table
Reference in a new issue