|
|
|
@ -134,19 +134,8 @@ const goShoppingBtn = document.querySelector('.go_shopping_btn'); |
|
|
|
const shoppingModal = document.querySelector('.shopping_modal'); |
|
|
|
const shoppingModal = document.querySelector('.shopping_modal'); |
|
|
|
const shoppingModalClose = document.querySelector('.shopping_modal_close'); |
|
|
|
const shoppingModalClose = document.querySelector('.shopping_modal_close'); |
|
|
|
|
|
|
|
|
|
|
|
const changePriceBtn = document.querySelector('.change_price_button'); |
|
|
|
const priceInlineInput = document.querySelector('.price_inline_input'); |
|
|
|
const priceModal = document.querySelector('.price_change_modal'); |
|
|
|
|
|
|
|
const priceModalClose = document.querySelector('.price_change_modal_close'); |
|
|
|
|
|
|
|
const priceInput = document.querySelector('.price_input'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const priceSaveBtn = document.querySelector('.price_change_save_btn'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const changeRecipeBtn = document.querySelector('.change_recipe_btn'); |
|
|
|
|
|
|
|
const recipeModal = document.querySelector('.recipe_modal'); |
|
|
|
|
|
|
|
const recipeModalClose = document.querySelector('.recipe_modal_close'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const startDayBtn = document.querySelector('.start_day_btn'); |
|
|
|
const startDayBtn = document.querySelector('.start_day_btn'); |
|
|
|
const recipeSaveBtn = document.querySelector('.recipe_save_btn'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Shopping modal - quantity inputs and dynamic pricing
|
|
|
|
// Shopping modal - quantity inputs and dynamic pricing
|
|
|
|
const shopQtyInputs = document.querySelectorAll('.shop_qty_input'); |
|
|
|
const shopQtyInputs = document.querySelectorAll('.shop_qty_input'); |
|
|
|
@ -203,87 +192,53 @@ if (goShoppingBtn) { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (changePriceBtn) { |
|
|
|
// Inline price editing
|
|
|
|
changePriceBtn.addEventListener('click', () => { |
|
|
|
if (priceInlineInput) { |
|
|
|
|
|
|
|
// Save price on blur or Enter
|
|
|
|
priceModal.classList.add('open'); |
|
|
|
function savePrice() { |
|
|
|
priceInput.focus(); |
|
|
|
const value = parseFloat(priceInlineInput.value) || 0; |
|
|
|
const priceInputLength = priceInput.value.length; |
|
|
|
const newState = set_price_per_cup(gameState, value); |
|
|
|
|
|
|
|
setState(newState); |
|
|
|
|
|
|
|
priceInlineInput.value = gameState.price_per_cup.toFixed(2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
priceInput.setSelectionRange(priceInputLength, priceInputLength); |
|
|
|
priceInlineInput.addEventListener('blur', savePrice); |
|
|
|
|
|
|
|
priceInlineInput.addEventListener('keydown', (e) => { |
|
|
|
|
|
|
|
if (e.key === 'Enter') { |
|
|
|
|
|
|
|
priceInlineInput.blur(); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
priceModalClose.addEventListener('click', () => { |
|
|
|
// Select all text on focus for easy editing
|
|
|
|
priceModal.classList.remove('open'); |
|
|
|
priceInlineInput.addEventListener('focus', () => { |
|
|
|
|
|
|
|
priceInlineInput.select(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
priceSaveBtn.addEventListener('click', () => { |
|
|
|
// Initialize with current value
|
|
|
|
const newState = set_price_per_cup(gameState, Number(priceInput.value)); |
|
|
|
priceInlineInput.value = gameState.price_per_cup.toFixed(2); |
|
|
|
setState(newState); |
|
|
|
|
|
|
|
priceModal.classList.remove('open'); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Recipe modal handlers
|
|
|
|
// Start Day button
|
|
|
|
const recipeInputs = document.querySelectorAll('.recipe_input'); |
|
|
|
if (startDayBtn) { |
|
|
|
const recipeCostValue = document.querySelector('.recipe_cost_value'); |
|
|
|
startDayBtn.addEventListener('click', startDay); |
|
|
|
|
|
|
|
|
|
|
|
// Base prices for cost breakdown (matches SupplyPricing tier 1 in game.js)
|
|
|
|
|
|
|
|
const basePrices = { lemons: 0.02, sugar: 0.01, ice: 0.01, cup: 0.01 }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function updateRecipeCost() { |
|
|
|
|
|
|
|
const lemons = parseInt(document.querySelector('.recipe_input[data-recipe="lemons"]').value) || 0; |
|
|
|
|
|
|
|
const sugar = parseInt(document.querySelector('.recipe_input[data-recipe="sugar"]').value) || 0; |
|
|
|
|
|
|
|
const ice = parseInt(document.querySelector('.recipe_input[data-recipe="ice"]').value) || 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update breakdown rows
|
|
|
|
|
|
|
|
document.querySelector('.recipe_cost_item[data-cost="lemons"]').textContent = '$' + (lemons * basePrices.lemons).toFixed(2); |
|
|
|
|
|
|
|
document.querySelector('.recipe_cost_item[data-cost="sugar"]').textContent = '$' + (sugar * basePrices.sugar).toFixed(2); |
|
|
|
|
|
|
|
document.querySelector('.recipe_cost_item[data-cost="ice"]').textContent = '$' + (ice * basePrices.ice).toFixed(2); |
|
|
|
|
|
|
|
document.querySelector('.recipe_cost_item[data-cost="cup"]').textContent = '$' + basePrices.cup.toFixed(2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update total
|
|
|
|
|
|
|
|
const result = calculate_cost_per_cup(gameState, { lemons, sugar, ice }); |
|
|
|
|
|
|
|
recipeCostValue.textContent = '$' + result.cost_per_cup.toFixed(2); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Update cost when recipe inputs change
|
|
|
|
// Recipe stepper buttons
|
|
|
|
recipeInputs.forEach(input => { |
|
|
|
document.querySelectorAll('.stepper_btn').forEach(btn => { |
|
|
|
input.addEventListener('input', updateRecipeCost); |
|
|
|
btn.addEventListener('click', () => { |
|
|
|
}); |
|
|
|
const ingredient = btn.dataset.ingredient; |
|
|
|
|
|
|
|
const isPlus = btn.classList.contains('stepper_plus'); |
|
|
|
if (changeRecipeBtn) { |
|
|
|
const currentValue = gameState.recipe[ingredient]; |
|
|
|
changeRecipeBtn.addEventListener('click', () => { |
|
|
|
const newValue = isPlus ? currentValue + 1 : Math.max(0, currentValue - 1); |
|
|
|
// Set inputs to current recipe values
|
|
|
|
|
|
|
|
document.querySelector('.recipe_input[data-recipe="lemons"]').value = gameState.recipe.lemons; |
|
|
|
|
|
|
|
document.querySelector('.recipe_input[data-recipe="sugar"]').value = gameState.recipe.sugar; |
|
|
|
|
|
|
|
document.querySelector('.recipe_input[data-recipe="ice"]').value = gameState.recipe.ice; |
|
|
|
|
|
|
|
updateRecipeCost(); |
|
|
|
|
|
|
|
recipeModal.classList.add('open'); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
recipeModalClose.addEventListener('click', () => { |
|
|
|
|
|
|
|
recipeModal.classList.remove('open'); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
recipeSaveBtn.addEventListener('click', () => { |
|
|
|
|
|
|
|
const lemons = parseInt(document.querySelector('.recipe_input[data-recipe="lemons"]').value) || 0; |
|
|
|
|
|
|
|
const sugar = parseInt(document.querySelector('.recipe_input[data-recipe="sugar"]').value) || 0; |
|
|
|
|
|
|
|
const ice = parseInt(document.querySelector('.recipe_input[data-recipe="ice"]').value) || 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const result = calculate_cost_per_cup(gameState, { lemons, sugar, ice }); |
|
|
|
const newRecipe = { ...gameState.recipe, [ingredient]: newValue }; |
|
|
|
|
|
|
|
const result = calculate_cost_per_cup(gameState, newRecipe); |
|
|
|
setState({ |
|
|
|
setState({ |
|
|
|
recipe: { lemons, sugar, ice }, |
|
|
|
recipe: newRecipe, |
|
|
|
cost_per_cup: result.cost_per_cup |
|
|
|
cost_per_cup: result.cost_per_cup |
|
|
|
}); |
|
|
|
}); |
|
|
|
recipeModal.classList.remove('open'); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Start Day button
|
|
|
|
|
|
|
|
if (startDayBtn) { |
|
|
|
|
|
|
|
startDayBtn.addEventListener('click', startDay); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Export for debugging in console
|
|
|
|
// Export for debugging in console
|
|
|
|
window.gameState = gameState; |
|
|
|
window.gameState = gameState; |
|
|
|
|