Browse Source

getting currency to update; getting day count to update

Justin Gilman 3 weeks ago
parent
commit
781d4ef17b
3 changed files with 58 additions and 11 deletions
  1. 20 10
      data/potions.json
  2. 35 1
      game.js
  3. 3 0
      ui/gamestatusui.js

+ 20 - 10
data/potions.json

@@ -9,7 +9,8 @@
         "title": "Pumpkin Spice Latte",
         "properties": ["Tasty","Basic","Spooky"],
         "model": "models/bottle_C_brown.gltf.glb",
-        "color": {"r": 0.8, "g": 0.3, "b": 0.0}
+        "color": {"r": 0.8, "g": 0.3, "b": 0.0},
+        "value": 100
     },
     {
         "name": "wildendraught",
@@ -21,7 +22,8 @@
         "title": "Wildendraught",
         "properties": ["Feral","Unhinged","Carbonated"],
         "model": "models/bottle_B_green.gltf.glb",
-        "color": {"r": 0.1, "g": 0.8, "b": 0.1}
+        "color": {"r": 0.1, "g": 0.8, "b": 0.1},
+        "value": 100
     },
     {
         "name": "spooksauce",
@@ -33,7 +35,8 @@
         "title": "Spooksauce",
         "properties": ["Haunting","Creepy","Sweet"],
         "model": "models/bottle_A_purple.gltf.glb",
-        "color": {"r": 0.7, "g": 0.1, "b": 0.6}
+        "color": {"r": 0.7, "g": 0.1, "b": 0.6},
+        "value": 100
     },
     {
         "name": "carrot-juice",
@@ -45,7 +48,8 @@
         "title": "Carrot Juice",
         "properties": ["Confusing","Unusual","Disturbing"],
         "model": "models/bottle_A_brown.gltf.glb",
-        "color": {"r": 0.7, "g": 0.5, "b": 0.1}
+        "color": {"r": 0.7, "g": 0.5, "b": 0.1},
+        "value": 100
     },
     {
         "name": "sanguis-damnum",
@@ -57,7 +61,8 @@
         "title": "Sanguis Damnum",
         "properties": ["Coppery","Thick","Hot"],
         "model": "models/bottle_C_purple.gltf.glb",
-        "color": {"r": 0.5, "g": 0.1, "b": 0.5}
+        "color": {"r": 0.5, "g": 0.1, "b": 0.5},
+        "value": 100
     },
     {
         "name": "freshie",
@@ -69,7 +74,8 @@
         "title": "Freshie",
         "properties": ["Umami","Invigorating","Yum"],
         "model": "models/bottle_B_purple.gltf.glb",
-        "color": {"r": 0.7, "g": 0.2, "b": 0.9}
+        "color": {"r": 0.7, "g": 0.2, "b": 0.9},
+        "value": 100
     },
     {
         "name": "corpsicle",
@@ -81,7 +87,8 @@
         "title": "Corpsicle",
         "properties": ["Meaty","Pulpy","Moldy"],
         "model": "models/bottle_A_blue.gltf.glb",
-        "color": {"r": 0.0, "g": 0.1, "b": 0.4}
+        "color": {"r": 0.0, "g": 0.1, "b": 0.4},
+        "value": 100
     },
     {
         "name": "healthy-greens",
@@ -93,7 +100,8 @@
         "title": "Healthy Greens",
         "properties": ["Healthy","Crisp","Verdant"],
         "model": "models/bottle_C_green.gltf.glb",
-        "color": {"r": 0.0, "g": 0.8, "b": 0.2}
+        "color": {"r": 0.0, "g": 0.8, "b": 0.2},
+        "value": 100
     },
     {
         "name": "not-poison",
@@ -105,7 +113,8 @@
         "title": "Not Poison",
         "properties": ["Bitter","Almond","Intense"],
         "model": "models/bottle_A_green.gltf.glb",
-        "color": {"r": 0.2, "g": 0.8, "b": 0.2}
+        "color": {"r": 0.2, "g": 0.8, "b": 0.2},
+        "value": 100
     },
     {
         "name": "fungus-amongus",
@@ -117,6 +126,7 @@
         "title": "Fungus Amongus",
         "properties": ["Sour", "Vile","Suspicious"],
         "model": "models/bottle_C_blue.gltf.glb",
-        "color": {"r": 0.4, "g": 0.4, "b": 0.8}
+        "color": {"r": 0.4, "g": 0.4, "b": 0.8},
+        "value": 100
     }
 ]

+ 35 - 1
game.js

@@ -27,7 +27,7 @@ import * as ingredientInfo from './data/ingredients.json'
 import * as potionInfo from './data/potions.json'
 import Shopper from './shopper.js'
 import { buildCanvasText } from './library/canvastext.js'
-import { hideGameStatusUI } from './ui/gamestatusui.js'
+import { hideGameStatusUI, updateGameStatusUI } from './ui/gamestatusui.js'
 
 export const GAME_SAVE_KEY = "spookonomics-v1"
 const raycast = new THREE.Raycaster()
@@ -232,6 +232,15 @@ export function addValueToSave(container, key, value) {
     localStorage.setItem(`${GAME_SAVE_KEY}-${key}`, JSON.stringify(container))
 }
 
+export function addAmountToSave(key, value) {
+    let amount = parseInt(localStorage.getItem(`${GAME_SAVE_KEY}-${key}`)) ?? 0
+    console.log('reading from save', amount)
+    amount += value
+
+    localStorage.setItem(`${GAME_SAVE_KEY}-${key}`, amount)
+    return amount
+}
+
 export function removeValueFromSave(container, key, value) {
     let containerString = localStorage.getItem(`${GAME_SAVE_KEY}-${key}`)
     if (!containerString) {
@@ -250,6 +259,12 @@ export function clearSaveData(stageData) {
     stageData.potionInventory = []
     localStorage.setItem(`${GAME_SAVE_KEY}-potion-stocked`, JSON.stringify([]))
     stageData.potionStocked = []
+
+    stageData.currency = 100
+    localStorage.setItem(`${GAME_SAVE_KEY}-currency`, stageData.currency)
+
+    stageData.currentDay = 1
+    localStorage.setItem(`${GAME_SAVE_KEY}-currentday`, stageData.currentDay)
 }
 
 export function loadSaveData(stageData) {
@@ -270,6 +285,18 @@ export function loadSaveData(stageData) {
         stageData.potionStocked = JSON.parse(potionsStockedString)
         stageData.potionStocked.sort()
     }
+
+    stageData.currency = localStorage.getItem(`${GAME_SAVE_KEY}-currency`)
+    if (!stageData.currency) {
+        localStorage.setItem(`${GAME_SAVE_KEY}-currency`, 100)
+        stageData.currency = 100
+    }
+
+    stageData.currentDay = localStorage.getItem(`${GAME_SAVE_KEY}-currentday`)
+    if (!stageData.currentDay) {
+        localStorage.setItem(`${GAME_SAVE_KEY}-currentday`, 1)
+        stageData.currentDay = 1
+    }
 }
 
 export async function init(inGame) {
@@ -708,6 +735,8 @@ export async function init(inGame) {
     brewUI(game, stageData)
     shopUI(game, stageData)
 
+    updateGameStatusUI(game, stageData)
+
 
     stageData.beginBrew = () => { beginBrew(game, stageData) }
     stageData.beginSell = () => { beginSell(game, stageData) }
@@ -922,6 +951,9 @@ export function onClick() {
                                             updatePotionShelfDisplay()
                                             firstCustomer.acceptPotion()
                                             stageData.soundEffects['audio/cash-register.ogg'].play()
+                                            console.log(`getting money: ${potion.potionData.value}`)
+                                            stageData.currency = addAmountToSave("currency", potion.potionData.value)
+                                            updateGameStatusUI(game, stageData)
                                             //move money from customer to chest
                                             //add money to save data
                                             //move customer out of room
@@ -1142,6 +1174,8 @@ function nextCustomer() {
 
     if (stageData.customers.length == 0) {
         stageData.isSellingPotions = false
+        stageData.currentDay = addAmountToSave("currentday", 1)
+        updateGameStatusUI(game, stageData)
     } else {
         stageData.customers[0].showDesire()
         if (stageData.potionStocked.length < 1) {

+ 3 - 0
ui/gamestatusui.js

@@ -11,5 +11,8 @@ export function hideGameStatusUI(game, stageData) {
 }
 
 export function updateGameStatusUI(game, stageData) {
+    console.log("updating game currency", stageData.currency)
+    document.getElementById("currency-progress").value = stageData.currency
 
+    document.getElementById("current-day-text").innerHTML = `day ${stageData.currentDay}`
 }