Compare commits
3 Commits
e5de1c84cd
...
ce1a24217a
Author | SHA1 | Date | |
---|---|---|---|
ce1a24217a | |||
ecc55df373 | |||
8c0cf6c4c6 |
@ -11,23 +11,30 @@ def get_monster_stats():
|
|||||||
selected_monster = request.args.get("monster")
|
selected_monster = request.args.get("monster")
|
||||||
|
|
||||||
if selected_monster:
|
if selected_monster:
|
||||||
# Fetch specific stats for the monster
|
# Fetch specific stats for the monster
|
||||||
cursor.execute("""
|
query = """
|
||||||
SELECT
|
SELECT
|
||||||
name,
|
monsters.name,
|
||||||
agl AS agility,
|
monsters.agl AS agility,
|
||||||
int AS intelligence,
|
monsters.int AS intelligence,
|
||||||
maxlvl AS max_level,
|
monsters.maxlvl AS max_level,
|
||||||
exp AS experience,
|
monsters.exp AS experience,
|
||||||
hp AS health_points,
|
monsters.hp AS health_points,
|
||||||
atk AS attack,
|
monsters.atk AS attack,
|
||||||
def AS defense
|
monsters.def AS defense,
|
||||||
|
families.name AS family,
|
||||||
|
spawn_locations.map || ' - ' || spawn_locations.description AS location
|
||||||
FROM monsters
|
FROM monsters
|
||||||
WHERE LOWER(name) = LOWER(?)
|
LEFT JOIN families ON monsters.family_id = families.id
|
||||||
""", (selected_monster.lower(),))
|
LEFT JOIN spawn_locations ON monsters.id = spawn_locations.monster_id
|
||||||
|
WHERE LOWER(monsters.name) = LOWER(?)
|
||||||
|
"""
|
||||||
|
|
||||||
|
cursor.execute(query, (selected_monster.lower(),))
|
||||||
|
|
||||||
# Fetch the result and convert it to a dictionary
|
# Fetch the result and convert it to a dictionary
|
||||||
monster_stats = cursor.fetchone()
|
monster_stats = cursor.fetchone()
|
||||||
|
print("Result:", monster_stats)
|
||||||
|
|
||||||
if monster_stats:
|
if monster_stats:
|
||||||
# Map stat names to descriptive labels
|
# Map stat names to descriptive labels
|
||||||
@ -38,17 +45,19 @@ def get_monster_stats():
|
|||||||
"attack": "Attack",
|
"attack": "Attack",
|
||||||
"defense": "Defense",
|
"defense": "Defense",
|
||||||
"agility": "Agility",
|
"agility": "Agility",
|
||||||
"intelligence": "Intelligence"
|
"intelligence": "Intelligence",
|
||||||
}
|
"family": "Family",
|
||||||
|
"location": "Location"
|
||||||
|
}
|
||||||
|
|
||||||
# Create a new dictionary with descriptive stat names
|
# Create a new dictionary with descriptive stat names
|
||||||
formatted_stats = {
|
formatted_stats = {
|
||||||
"name": monster_stats[0],
|
"name": monster_stats[0],
|
||||||
**{stat_labels[key]: monster_stats[i + 1] for i, key in enumerate(["agility", "intelligence", "max_level", "experience", "health_points", "attack", "defense"])}
|
**{stat_labels[key]: monster_stats[i + 1] for i, key in enumerate(["agility", "intelligence", "max_level", "experience", "health_points", "attack", "defense", "family", "location"])}
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonify(formatted_stats)
|
return jsonify(formatted_stats)
|
||||||
else:
|
else:
|
||||||
return jsonify({"error": "Monster not found"}), 404
|
return jsonify({"error": "Monster not found"}), 404
|
||||||
else:
|
else:
|
||||||
return jsonify({"error": "Monster name not provided"}), 400
|
return jsonify({"error": "Monster name not provided"}), 400
|
||||||
|
@ -20,9 +20,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
|
|
||||||
monsterDropdown.addEventListener("change", function () {
|
monsterDropdown.addEventListener("change", function () {
|
||||||
updateIframes();
|
updateIframes();
|
||||||
});
|
|
||||||
|
|
||||||
monsterDropdown.addEventListener("change", function () {
|
|
||||||
updateMonsterStats();
|
updateMonsterStats();
|
||||||
|
updateMonsterName();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
16
static/js/updateMonsterName.js
Normal file
16
static/js/updateMonsterName.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
function updateMonsterName() {
|
||||||
|
// Get the selected monster from the dropdown
|
||||||
|
var selectedMonster = document.getElementById("monsterDropdown").value;
|
||||||
|
|
||||||
|
// Make an API request to get the stats for the selected monster
|
||||||
|
fetch(`/api/monster/stats?monster=${selectedMonster}`)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
// Update the HTML content with the monster name
|
||||||
|
var nameContainer = document.getElementById("monsterNameContainer");
|
||||||
|
nameContainer.innerHTML = `<h2>${data.name}</h2>`;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error("Error fetching monster name:", error);
|
||||||
|
});
|
||||||
|
}
|
@ -3,15 +3,12 @@ function updateMonsterStats() {
|
|||||||
var selectedMonster = document.getElementById("monsterDropdown").value;
|
var selectedMonster = document.getElementById("monsterDropdown").value;
|
||||||
|
|
||||||
// Make an API request to get the stats for the selected monster
|
// Make an API request to get the stats for the selected monster
|
||||||
// You can use fetch or any other method to make the API request
|
|
||||||
// Replace the API endpoint with the actual endpoint of your Flask app
|
|
||||||
fetch(`/api/monster/stats?monster=${selectedMonster}`)
|
fetch(`/api/monster/stats?monster=${selectedMonster}`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
// Update the HTML content with the monster stats
|
// Update the HTML content with the monster stats
|
||||||
var statsContainer = document.getElementById("monsterStatsContainer");
|
var statsContainer = document.getElementById("monsterStatsContainer");
|
||||||
statsContainer.innerHTML = `<h2>${data.name} Stats</h2>
|
statsContainer.innerHTML = `<p>Agility: ${data.Agility}</p>
|
||||||
<p>Agility: ${data.Agility}</p>
|
|
||||||
<p>Attack: ${data.Attack}</p>
|
<p>Attack: ${data.Attack}</p>
|
||||||
<p>Defense: ${data.Defense}</p>
|
<p>Defense: ${data.Defense}</p>
|
||||||
<p>Experience: ${data.Experience}</p>
|
<p>Experience: ${data.Experience}</p>
|
||||||
|
@ -28,6 +28,26 @@
|
|||||||
width="280"
|
width="280"
|
||||||
>
|
>
|
||||||
</iframe>
|
</iframe>
|
||||||
|
|
||||||
|
<div id="monsterNameContainer">
|
||||||
|
<!-- Monster name will be displayed here -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="monsterStatsContainer">
|
||||||
|
<!-- Monster stats will be displayed here -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="monsterLocationContainer">
|
||||||
|
<!-- Monster Location will be displayed here
|
||||||
|
TODO Add location to stats api -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="monsterFamilyContainer">
|
||||||
|
<!-- Monster Family will be displayed here
|
||||||
|
TODO Add family to stats api -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="grid items-center justify-center grid-cols-1 ml-4">
|
<div class="grid items-center justify-center grid-cols-1 ml-4">
|
||||||
<iframe
|
<iframe
|
||||||
id="monsterSpriteIframe"
|
id="monsterSpriteIframe"
|
||||||
@ -56,11 +76,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div id="monsterStatsContainer">
|
|
||||||
<!-- Monster stats will be displayed here -->
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<div class="mx-auto footer">
|
<div class="mx-auto footer">
|
||||||
<h2 class="m-2 text-2xl font-bold">About The App</h2>
|
<h2 class="m-2 text-2xl font-bold">About The App</h2>
|
||||||
|
Loading…
Reference in New Issue
Block a user