Skip to content
Snippets Groups Projects
Commit 8e944638 authored by Vrelnir's avatar Vrelnir
Browse files

Merge branch 'fixes' into 'dev'

Fix stray function getting into saves from vending machines

See merge request Vrelnir/degrees-of-lewdity!2159
parents 8cbe8214 f0821cf6
No related branches found
No related tags found
No related merge requests found
......@@ -48,22 +48,24 @@ function getDebuggingInfo() {
vaginatarget: V.vaginatarget,
});
}
for (let i = 0; i < EventSystem.count(); i++) {
for (let i = 0; i < V.NPCList.length; i++) {
const npc = V.NPCList[i];
const npcData = {
active: npc.active,
index: npc.index,
};
if (V.combat) {
Object.apply(npcData, {
mouth: npc.mouth,
penis: npc.penis,
lefthand: npc.lefthand,
righthand: npc.righthand,
vagina: npc.vagina,
});
if (npc.type) {
const npcData = {
active: npc.active,
index: npc.index,
};
if (V.combat) {
Object.apply(npcData, {
mouth: npc.mouth,
penis: npc.penis,
lefthand: npc.lefthand,
righthand: npc.righthand,
vagina: npc.vagina,
});
}
response["npc" + i] = npcData;
}
response["npc" + i] = npcData;
}
return response;
}
......
......@@ -55,6 +55,27 @@ const idb = (() => {
// this actually should never happen, but none can say that i'm not thourough
openRequest.onblocked = () => console.log("something went wrong");
/**
* scan and delete functions that wormed their way into story vars
* there should never be any functions in there, period.
*
* @param {object} target to scan
* @param {object} path to report
*/
function funNuke(target = V, path = "V") {
for (const key in target) {
const value = target[key];
const newPath = path !== false ? path + "." + key : false;
if (value && typeof value === "object") funNuke(value, newPath);
else if (typeof value === "function") {
// we've got a baddie
delete target[key];
if (path !== false) Errors.report("Corrupt variable detected, please report!", newPath);
}
}
}
window.funNuke = funNuke;
/**
* copy saves from localStorage into indexedDB, without regard to what's already in there
*
......@@ -171,14 +192,37 @@ const idb = (() => {
slot,
data: { id: Story.domId, title: Story.get(saveVars.passage || "Start").description(), date: Date.now(), metadata },
};
// open a request to set or replace an existing slot
const transactionRequest = db.transaction(["saves", "details"], "readwrite");
transactionRequest.objectStore("saves").delete(slot);
transactionRequest.objectStore("saves").add(savesItem);
transactionRequest.objectStore("details").delete(slot);
transactionRequest.objectStore("details").add(detailsItem);
return makePromise(transactionRequest);
// expect failures here
try {
// open a request to set or replace an existing slot
const transactionRequest = db.transaction(["saves", "details"], "readwrite");
transactionRequest.objectStore("saves").delete(slot);
transactionRequest.objectStore("saves").add(savesItem);
transactionRequest.objectStore("details").delete(slot);
transactionRequest.objectStore("details").add(detailsItem);
return makePromise(transactionRequest);
} catch {
// dispose of the possible functions in story vars and try again
funNuke();
saveObj.history.forEach(s => funNuke(s.variables, false));
try {
const transactionRequest = db.transaction(["saves", "details"], "readwrite");
transactionRequest.objectStore("saves").delete(slot);
transactionRequest.objectStore("saves").add(savesItem);
transactionRequest.objectStore("details").delete(slot);
transactionRequest.objectStore("details").add(detailsItem);
return makePromise(transactionRequest);
} catch {
// admit the defeat and go home
Errors.report("idb.setItem failure unknown. Couldn't complete the save in slot " + slot);
lock = false;
// return a promise, because some code down the line expects .then()
return new Promise(resolve => resolve(false));
}
}
}
/**
......
......@@ -2466,10 +2466,7 @@ You tell Briar you are not interested in <<his>> conditions.
You insert the money into the machine and a bottle of lube slides into a drawer. You take it.
<br><br>
<<set $money -= 3000>>
<<if !$player.inventory.sextoys.lube>>
<<set $player.inventory.sextoys.lube to []>>
<</if>>
<<set $player.inventory.sextoys.lube.push(clone(setup.sextoys[8]))>>
<<run window.sexShopOnBuyClick(8, false, false, false)>>
<<set $brothelVending.lube -=1>>
<<set $brothelVending.lubeSold +=1>>
<<link [[Back|Brothel Dressing Room]]>><<endevent>><</link>>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment