fast72 commited on
Commit
3ea6c37
·
verified ·
1 Parent(s): ffc5d88

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +112 -30
index.js CHANGED
@@ -13,14 +13,11 @@ const fruits = [
13
  ["Pumpkin", 8, 3400, 80], ["Apple", 3, 275, 50], ["Bamboo", 4, 4000, 35], ["Coconut", 14, 400, 70],
14
  ["Cactus", 7, 3400, 100], ["Dragon Fruit", 12, 4750, 100], ["Mango", 15, 6500, 200], ["Grape", 3, 7850, 200],
15
  ["Mushroom", 25, 151000, 220], ["Pepper", 5, 8000, 200], ["Cacao", 8, 12000, 250], ["Beanstalk", 10, 28000, 300],
16
- ["Ember Lily", 12, 66666, 450], ["Sugar Apple", 9, 48000, 200], ["Burning Bud", 12, 65000, 500], ["Cauliflower", 5, 50, 150],
17
- ["Rafflesia", 8, 3500, 80], ["Green Apple", 3, 300, 200], ["Avocado", 6.5, 350, 300], ["Banana", 1.5, 2000, 100],
18
- ["Pineapple", 3, 2000, 70], ["Kiwi", 5, 2750, 300], ["Bell Pepper", 8, 5500, 325], ["Prickly Pear", 7, 7000, 375],
19
- ["Loquat", 6.5, 8000, 200], ["Pitcher Plant", 12, 32000, 275], ["Feijoa", 10, 13000, 400], ["Wild Carrot", 1.3, 25000, 100],
20
- ["Pear", 3, 20000, 120], ["Cantaloupe", 5.5, 34000, 250], ["Parasol Flower", 6, 200000, 350],
21
- ["Rosy Delight", 10, 69000, 450], ["Elephant Ears", 18, 77000, 500], ["Delphinium", 0.3, 24000, 100],
22
- ["Lily of the Valley", 6, 49120, 400], ["Traveler's Fruit", 15, 59000, 500], ["Peace Lily", 0.6, 24000, 100],
23
- ["Aloe Vera", 5.5, 69000, 350], ["Guanabana", 4, 72500, 400], ["Chocolate Carrot", 0.275, 11000, 100],
24
  ["Red Lollipop", 4, 50000, 65], ["Blue Lollipop", 1, 50000, 65], ["Candy Sunflower", 1.5, 80000, 85],
25
  ["Easter Egg", 3, 2500, 20], ["Candy Blossom", 3, 100000, 40], ["Peach", 2, 300, 70], ["Raspberry", 0.75, 100, 70],
26
  ["Papaya", 3, 1000, 60], ["Banana", 1.5, 1750, 100], ["Passionfruit", 3, 3550, 40], ["Soul Fruit", 25, 7750, 200],
@@ -28,49 +25,134 @@ const fruits = [
28
  ["Purple Cabbage", 5, 500, 70], ["Lemon", 1, 350, 50], ["Pink Tulip", 0.05, 850, 55], ["Cranberry", 1, 3500, 50],
29
  ["Durian", 8, 7500, 200], ["Eggplant", 5, 12000, 220], ["Lotus", 20, 35000, 650], ["Venus Fly Trap", 10, 85000, 650],
30
  ["Nightshade", 0.5, 3500, 100], ["Glowshroom", 0.75, 300, 100], ["Mint", 1, 5250, 150], ["Moonflower", 2, 9500, 200],
31
- ["Starfruit", 3, 15000, 250], ["Moonglow", 7, 25000, 400], ["Moon Blossom", 3, 66666, 400],
32
- ["Crimson Vine", 1, 1250, 100], ["Moon Melon", 8, 18000, 300], ["Blood Banana", 1.5, 6000, 200],
33
- ["Celestiberry", 2, 10000, 200], ["Moon Mango", 15, 50000, 300], ["Rose", 1, 5000, 100],
34
- ["Foxglove", 2, 20000, 250], ["Lilac", 3, 35000, 250], ["Pink Lily", 6, 65000, 400],
35
- ["Purple Dahlia", 12, 75000, 400], ["Sunflower", 16.5, 160000, 600], ["Lavender", 0.275, 25000, 90],
36
- ["Nectarshade", 0.8, 50000, 100], ["Nectarine", 3, 48000, 200], ["Hive Fruit", 8, 62000, 300],
37
- ["Manuka Flower", 0.3, 25000, 200], ["Dandelion", 4, 50000, 300], ["Lumira", 6, 85000, 350],
38
- ["Honeysuckle", 12, 100000, 400], ["Crocus", 0.275, 30000, 150], ["Succulent", 5, 25000, 175],
39
  ["Violet Corn", 3, 50000, 250], ["Bendboo", 18, 155000, 275], ["Cocovine", 14, 66666, 275],
40
  ["Dragon Pepper", 6, 88888, 300], ["Bee Balm", 1, 18000, 200], ["Nectar Thorn", 7, 44444, 350],
41
- ["Suncoil", 10, 80000, 400], ["Noble Flower", 5, 20000, 250], ["Ice Cream Bean", 4, 4500, 200],
42
- ["Lime", 1, 1000, 125], ["White Mulberry", 3, 3000, 200]
43
  ]
44
 
45
  const mutationMultiplier = {
46
  Dawnbound: 150, Voidtouched: 135, Disco: 125, Meteoric: 125, Galactic: 120,
47
- Celestial: 120, Shocked: 100, Alienlike: 100, Sundried: 85, Molten: 25,
48
- Zombified: 25, Paradisal: 100, Frozen: 10, Cooked: 10, Plasma: 5,
49
- Heavenly: 5, HoneyGlazed: 5, Twisted: 5, Burnt: 4, Bloodlit: 4,
50
  Verdant: 4, Pollinated: 3, Windstruck: 2, Wet: 2, Chilled: 2,
51
- Choc: 2, Moonlit: 2, Aurora: 90, Wiltproof: 4, Drenched: 5, Fried: 8, Cloudtouched: 5
52
  }
53
 
54
  const rarityMultiplier = { Normal: 1, Gold: 20, Rainbow: 50 }
55
 
56
- function clamp(v, min, max) {
57
- return Math.min(Math.max(v, min), max)
58
- }
59
 
60
  function calcValue(name, weight, rarity = "Normal", mutations = []) {
61
  const item = fruits.find(f => f[0] === name)
62
  if (!item) return "0¢"
63
- const totalMutation = mutations.reduce((t, m) => t * (mutationMultiplier[m] || 1), 1)
 
 
 
 
64
  const clamped = clamp(weight / item[1], 0.95, 1e8)
65
- const value = Math.round((item[2] * totalMutation * (rarityMultiplier[rarity] || 1)) * (clamped * clamped))
66
- return value.toLocaleString("en-US") + "¢"
 
67
  }
68
 
69
  app.get("/", (req, res) => {
70
  const fruitOptions = fruits.map(f => f[0]).sort().map(name => `<option value="${name}">${name}</option>`).join("")
71
  const mutationOptions = Object.keys(mutationMultiplier).map(m => `<option value="${m}">${m}</option>`).join("")
72
  const rarityOptions = ["Normal", "Gold", "Rainbow"].map(r => `<option value="${r}">${r}</option>`).join("")
73
- res.send(`<!DOCTYPE html><html><head><meta charset='UTF-8'><meta name='viewport' content='width=device-width, initial-scale=1.0'><title>Calculator</title></head><body><form id='form'><label>Fruit<select name='fruit'>${fruitOptions}</select></label><label>Weight<input type='number' name='weight' step='0.01'></label><label>Rarity<select name='rarity'>${rarityOptions}</select></label><label>Mutations<select name='mutations' multiple size='10'>${mutationOptions}</select></label><button type='submit'>Calculate</button></form><div id='result'></div><script>document.getElementById('form').onsubmit = async e => {e.preventDefault();const form = e.target;const data = new URLSearchParams();data.append('fruit', form.fruit.value);data.append('weight', form.weight.value);data.append('rarity', form.rarity.value);Array.from(form.mutations.selectedOptions).forEach(o => data.append('mutations', o.value));const res = await fetch('/calc', {method: 'POST',headers: {'Content-Type': 'application/x-www-form-urlencoded'},body: data});const json = await res.json();document.getElementById('result').innerText = json.value}</script></body></html>`)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  })
75
 
76
  app.post("/calc", (req, res) => {
@@ -81,4 +163,4 @@ app.post("/calc", (req, res) => {
81
  res.json({ value: result })
82
  })
83
 
84
- app.listen(port, () => console.log(`http://localhost:${port}`))
 
13
  ["Pumpkin", 8, 3400, 80], ["Apple", 3, 275, 50], ["Bamboo", 4, 4000, 35], ["Coconut", 14, 400, 70],
14
  ["Cactus", 7, 3400, 100], ["Dragon Fruit", 12, 4750, 100], ["Mango", 15, 6500, 200], ["Grape", 3, 7850, 200],
15
  ["Mushroom", 25, 151000, 220], ["Pepper", 5, 8000, 200], ["Cacao", 8, 12000, 250], ["Beanstalk", 10, 28000, 300],
16
+ ["Ember Lily", 12, 66666, 450], ["Sugar Apple", 9, 48000, 200], ["Pineapple", 3, 2000, 70], ["Cauliflower", 5, 40, 150],
17
+ ["Green Apple", 3, 300, 200], ["Banana", 1.5, 2000, 100], ["Avocado", 6.5, 350, 300], ["Kiwi", 5, 2750, 300],
18
+ ["Bell Pepper", 8, 5500, 325], ["Prickly Pear", 7, 7000, 375], ["Feijoa", 10, 13000, 400], ["Loquat", 6.5, 8000, 200],
19
+ ["Wild Carrot", 0.3, 25000, 100], ["Pear", 3, 20000, 120], ["Cantaloupe", 5.5, 34000, 250], ["Parasol Flower", 6, 200000, 350],
20
+ ["Rosy Delight", 10, 69000, 450], ["Elephant Ears", 18, 77000, 500], ["Chocolate Carrot", 0.275, 11000, 100],
 
 
 
21
  ["Red Lollipop", 4, 50000, 65], ["Blue Lollipop", 1, 50000, 65], ["Candy Sunflower", 1.5, 80000, 85],
22
  ["Easter Egg", 3, 2500, 20], ["Candy Blossom", 3, 100000, 40], ["Peach", 2, 300, 70], ["Raspberry", 0.75, 100, 70],
23
  ["Papaya", 3, 1000, 60], ["Banana", 1.5, 1750, 100], ["Passionfruit", 3, 3550, 40], ["Soul Fruit", 25, 7750, 200],
 
25
  ["Purple Cabbage", 5, 500, 70], ["Lemon", 1, 350, 50], ["Pink Tulip", 0.05, 850, 55], ["Cranberry", 1, 3500, 50],
26
  ["Durian", 8, 7500, 200], ["Eggplant", 5, 12000, 220], ["Lotus", 20, 35000, 650], ["Venus Fly Trap", 10, 85000, 650],
27
  ["Nightshade", 0.5, 3500, 100], ["Glowshroom", 0.75, 300, 100], ["Mint", 1, 5250, 150], ["Moonflower", 2, 9500, 200],
28
+ ["Starfruit", 3, 15000, 250], ["Moonglow", 7, 25000, 400], ["Moon Blossom", 3, 66666, 400], ["Crimson Vine", 1, 1250, 100],
29
+ ["Moon Melon", 8, 18000, 300], ["Blood Banana", 1.5, 6000, 200], ["Celestiberry", 2, 10000, 200],
30
+ ["Moon Mango", 15, 50000, 300], ["Rose", 1, 5000, 100], ["Foxglove", 2, 20000, 250], ["Lilac", 3, 35000, 250],
31
+ ["Pink Lily", 6, 65000, 400], ["Purple Dahlia", 12, 75000, 400], ["Sunflower", 16.5, 160000, 600],
32
+ ["Lavender", 0.275, 25000, 90], ["Nectarshade", 0.8, 50000, 100], ["Nectarine", 3, 48000, 200],
33
+ ["Hive Fruit", 8, 62000, 300], ["Manuka Flower", 0.3, 25000, 200], ["Dandelion", 4, 50000, 300],
34
+ ["Lumira", 6, 85000, 350], ["Honeysuckle", 12, 100000, 400], ["Crocus", 0.275, 30000, 150], ["Succulent", 5, 25000, 175],
 
35
  ["Violet Corn", 3, 50000, 250], ["Bendboo", 18, 155000, 275], ["Cocovine", 14, 66666, 275],
36
  ["Dragon Pepper", 6, 88888, 300], ["Bee Balm", 1, 18000, 200], ["Nectar Thorn", 7, 44444, 350],
37
+ ["Suncoil", 10, 80000, 400], ["Noble Flower", 5, 20000, 250], ["Traveler's Fruit", 2, 20000, 250],
38
+ ["Ice Cream Bean", 4, 4500, 200], ["Lime", 1, 1000, 125]
39
  ]
40
 
41
  const mutationMultiplier = {
42
  Dawnbound: 150, Voidtouched: 135, Disco: 125, Meteoric: 125, Galactic: 120,
43
+ Celestial: 120, Shocked: 100, Alienlike: 100, Paradisal: 100, Aurora: 90, Sundried: 85, Molten: 25,
44
+ Zombified: 25, Frozen: 10, Cooked: 10, Fried: 8, Plasma: 5,
45
+ Heavenly: 5, HoneyGlazed: 5, Twisted: 5, Cloudtouched: 5, Drenched: 5, Burnt: 4, Bloodlit: 4, Wiltproof: 4,
46
  Verdant: 4, Pollinated: 3, Windstruck: 2, Wet: 2, Chilled: 2,
47
+ Choc: 2, Moonlit: 2,
48
  }
49
 
50
  const rarityMultiplier = { Normal: 1, Gold: 20, Rainbow: 50 }
51
 
52
+ function clamp(v, min, max) { return Math.min(Math.max(v, min), max) }
53
+
54
+ function format(n) { return n.toLocaleString("en-US") + "¢" }
55
 
56
  function calcValue(name, weight, rarity = "Normal", mutations = []) {
57
  const item = fruits.find(f => f[0] === name)
58
  if (!item) return "0¢"
59
+ let mutationMult = 1
60
+ for (const m of mutations) {
61
+ mutationMult += (mutationMultiplier[m] || 1) - 1
62
+ }
63
+ mutationMult = Math.max(1, mutationMult)
64
  const clamped = clamp(weight / item[1], 0.95, 1e8)
65
+ const mult = (rarityMultiplier[rarity] || 1) * mutationMult
66
+ const value = Math.round(item[2] * mult * (clamped * clamped) + 1)
67
+ return format(value)
68
  }
69
 
70
  app.get("/", (req, res) => {
71
  const fruitOptions = fruits.map(f => f[0]).sort().map(name => `<option value="${name}">${name}</option>`).join("")
72
  const mutationOptions = Object.keys(mutationMultiplier).map(m => `<option value="${m}">${m}</option>`).join("")
73
  const rarityOptions = ["Normal", "Gold", "Rainbow"].map(r => `<option value="${r}">${r}</option>`).join("")
74
+ res.send(`
75
+ <!DOCTYPE html>
76
+ <html lang='en'>
77
+ <head>
78
+ <meta charset='UTF-8'>
79
+ <meta name='viewport' content='width=device-width, initial-scale=1.0'>
80
+ <title>Price Calculator</title>
81
+ <script src="https://cdn.tailwindcss.com"></script>
82
+ <style>
83
+ .fade-in { animation: fadeIn 0.6s ease-in-out; }
84
+ @keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
85
+ select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg fill='white' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M10 12l-4-4h8l-4 4z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; background-size: 1rem; }
86
+ </style>
87
+ </head>
88
+ <body class="bg-gradient-to-br from-[#0f0f1a] to-[#0c1b2a] text-white flex items-center justify-center min-h-screen px-4">
89
+ <div class="w-full max-w-lg fade-in">
90
+ <h1 class="text-3xl font-bold text-center mb-4 text-blue-300">Grow a Garden</h1>
91
+ <h2 class="text-lg text-center text-blue-400 mb-6">Calculate your fruit's price</h2>
92
+ <form id="form" class="bg-[#1a1d2c] p-6 rounded-2xl shadow-xl space-y-4">
93
+ <div>
94
+ <label class="block mb-1 text-sm">Fruit</label>
95
+ <select name="fruit" id="fruit" required class="w-full p-3 rounded bg-[#2c3144] text-white focus:outline-none focus:ring-2 focus:ring-blue-400">${fruitOptions}</select>
96
+ </div>
97
+ <div>
98
+ <label class="block mb-1 text-sm">Weight (kg)</label>
99
+ <input name="weight" type="number" step="0.01" placeholder="0.00" required class="w-full p-3 rounded bg-[#2c3144] text-white focus:outline-none focus:ring-2 focus:ring-blue-400">
100
+ </div>
101
+ <div>
102
+ <label class="block mb-1 text-sm">Rarity</label>
103
+ <select name="rarity" id="rarity" required class="w-full p-3 rounded bg-[#2c3144] text-white focus:outline-none focus:ring-2 focus:ring-blue-400">${rarityOptions}</select>
104
+ </div>
105
+ <div>
106
+ <label class="block mb-1 text-sm">Mutations</label>
107
+ <select name="mutations" id="mutations" multiple size="6" class="w-full p-3 rounded bg-[#2c3144] text-white focus:outline-none focus:ring-2 focus:ring-blue-400">${mutationOptions}</select>
108
+ </div>
109
+ <button type="submit" class="w-full bg-blue-500 hover:bg-blue-600 p-3 rounded font-bold transition-all">Calculate</button>
110
+ <div id="result" class="text-center text-blue-300 font-semibold"></div>
111
+ </form>
112
+ </div>
113
+ <script>
114
+ document.getElementById("form").onsubmit = async e => {
115
+ e.preventDefault()
116
+ const form = e.target
117
+ const data = new URLSearchParams()
118
+ const fruit = form.fruit.value
119
+ const rarity = form.rarity.value.trim()
120
+ data.append("fruit", fruit)
121
+ data.append("weight", form.weight.value)
122
+ data.append("rarity", rarity)
123
+
124
+ let selected = Array.from(form.mutations.selectedOptions).map(o => o.value)
125
+ if (selected.includes("Frozen") || (selected.includes("Wet") && selected.includes("Chilled"))) {
126
+ selected = selected.filter(m => !["Wet", "Chilled"].includes(m))
127
+ if (!selected.includes("Frozen")) selected.push("Frozen")
128
+ }
129
+ if (selected.includes("Sundried") && selected.includes("Verdant")) {
130
+ selected = selected.filter(m => !["Sundried", "Verdant"].includes(m))
131
+ selected.push("Paradisal")
132
+ }
133
+ if (selected.includes("Cooked")) {
134
+ selected = selected.filter(m => m !== "Burnt")
135
+ }
136
+ if (selected.includes("Burnt")) {
137
+ selected = selected.filter(m => m !== "Cooked")
138
+ }
139
+
140
+ selected.forEach(m => data.append("mutations", m))
141
+
142
+ const res = await fetch("/calc", {
143
+ method: "POST",
144
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
145
+ body: data
146
+ })
147
+
148
+ const json = await res.json()
149
+ const output = json.value ? \`<p>Total: <span class='text-blue-400'>\${json.value}</span></p>\` : \`<p class='text-red-400'>Invalid input</p>\`
150
+ document.getElementById("result").innerHTML = output
151
+ }
152
+ </script>
153
+ </body>
154
+ </html>
155
+ `)
156
  })
157
 
158
  app.post("/calc", (req, res) => {
 
163
  res.json({ value: result })
164
  })
165
 
166
+ app.listen(port)