Add overlay and save to building locking #763

This commit is contained in:
Daniël van Noord
2021-07-25 14:09:37 +02:00
parent 4fe07ba1d3
commit f59972892b
7 changed files with 50 additions and 22 deletions

View File

@@ -1,13 +0,0 @@
/**
* This function toggle the locked state of a building
* @param {number} index Index of the row to change
*/
export default function ToggleBuildingLock(index) {
if (l(`productLock${index}`).innerHTML === 'Unlocked') {
l(`productLock${index}`).innerHTML = 'Locked';
l(`row${index}`).children[3].style.pointerEvents = 'none';
} else {
l(`productLock${index}`).innerHTML = 'Unlocked';
l(`row${index}`).children[3].style.pointerEvents = 'auto';
}
}

View File

@@ -1,17 +1,17 @@
import ToggleBuildingLock from './ToggleBuildingLock';
import toggleBuildingLock from './toggleBuildingLock';
/**
* This function adds a lock button to the "building view" in the middle section
*/
export default function CreateBuildingLockButtons() {
export default function createBuildingLockButtons() {
Object.keys(l('rows').children).forEach((index) => {
const productButtons = l('rows').children[index].children[1];
const button = document.createElement('div');
button.id = `productLock${Number(index) + 1}`;
button.className = 'productButton';
button.innerHTML = 'Unlocked';
button.innerHTML = 'Lock';
button.onclick = function () {
ToggleBuildingLock(Number(index) + 1);
toggleBuildingLock(Number(index) + 1);
};
productButtons.appendChild(button);
});

View File

@@ -0,0 +1,23 @@
/**
* This function toggle the locked state of a building
* @param {number} index Index of the row to change
*/
export default function toggleBuildingLock(index) {
if (l(`productLock${index}`).innerHTML === 'Lock') {
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.lockedMinigames.push(
index.toString(),
);
l(`row${index}`).style.pointerEvents = 'none';
l(`row${index}`).style.opacity = '0.4';
l(`productLock${index}`).innerHTML = 'Unlock';
l(`productLock${index}`).style.pointerEvents = 'auto';
} else {
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.lockedMinigames =
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.lockedMinigames.filter(
(value) => value !== index.toString(),
);
l(`productLock${index}`).innerHTML = 'Lock';
l(`row${index}`).style.pointerEvents = 'auto';
l(`row${index}`).style.opacity = '1';
}
}