From 991f726fa1fbcf4c93a087312b9d6e7af7dfe1d8 Mon Sep 17 00:00:00 2001 From: 0ceanSlim Date: Fri, 2 Feb 2024 10:03:55 -0500 Subject: [PATCH] refactored monster information to stats --- app.py | 38 ++++++++++++------------- static/js/indexListener.js | 13 +++++++-- templates/{monsters.html => stats.html} | 3 +- 3 files changed, 31 insertions(+), 23 deletions(-) rename templates/{monsters.html => stats.html} (96%) diff --git a/app.py b/app.py index b167524..f18bc0c 100644 --- a/app.py +++ b/app.py @@ -62,10 +62,10 @@ def get_monsters(): @app.route("/monster/") -def monster_info(monster_name): +def monster_stats(monster_name): cursor = g.db.cursor() - # Retrieve monster information from the database based on name + # Retrieve monster stats from the database based on name cursor.execute( """ SELECT @@ -81,39 +81,39 @@ def monster_info(monster_name): (monster_name,), ) - monster_info = cursor.fetchone() + monster_stats = cursor.fetchone() - if monster_info is None: + if monster_stats is None: abort(404) # Retrieve skills for the monster - cursor.execute("SELECT skill FROM skills WHERE monster_id = ?", (monster_info[0],)) + cursor.execute("SELECT skill FROM skills WHERE monster_id = ?", (monster_stats[0],)) skills = [row[0] for row in cursor.fetchall()] # Retrieve spawn locations for the monster cursor.execute( "SELECT map, description FROM spawn_locations WHERE monster_id = ?", - (monster_info[0],), + (monster_stats[0],), ) spawn_locations = [ {"map": row[0], "description": row[1]} for row in cursor.fetchall() ] return render_template( - "monsters.html", + "stats.html", monster={ - "id": monster_info[0], - "name": monster_info[1], - "family": monster_info[2], - "in_story": "Yes" if monster_info[3] else "No", - "agl": monster_info[4], - "int": monster_info[5], - "maxlvl": monster_info[6], - "atk": monster_info[7], - "mp": monster_info[8], - "exp": monster_info[9], - "hp": monster_info[10], - "def": monster_info[11], + "id": monster_stats[0], + "name": monster_stats[1], + "family": monster_stats[2], + "in_story": "Yes" if monster_stats[3] else "No", + "agl": monster_stats[4], + "int": monster_stats[5], + "maxlvl": monster_stats[6], + "atk": monster_stats[7], + "mp": monster_stats[8], + "exp": monster_stats[9], + "hp": monster_stats[10], + "def": monster_stats[11], "skills": skills, "spawn_locations": spawn_locations, }, diff --git a/static/js/indexListener.js b/static/js/indexListener.js index 836f859..08fa315 100644 --- a/static/js/indexListener.js +++ b/static/js/indexListener.js @@ -1,11 +1,15 @@ document.addEventListener("DOMContentLoaded", function () { const familyDropdown = document.getElementById("familyDropdown"); const monsterDropdown = document.getElementById("monsterDropdown"); + // Implementing Family Icon Grid in place of family dropdown + //const familyGrid = document.getElementById("familyGrid") - // Initialize dropdowns and iframes + // Initialize dropdowns updateMonstersDropdown(); + // Initialize Family Grid(); + // populateFamilyGrid(); - // Fetch families data from the server + // Fetch families data from the server and populate families dropdown fetch("/get_families") .then(response => response.json()) .then(data => { @@ -13,6 +17,7 @@ document.addEventListener("DOMContentLoaded", function () { }) .catch(error => console.error("Error fetching families:", error)); + // Listeners for Dropdown Changes familyDropdown.addEventListener("change", function () { updateMonstersDropdown(); }); @@ -21,5 +26,9 @@ document.addEventListener("DOMContentLoaded", function () { updateIframes(); }); + // Listener for a click on the one of the family icons + //familyGrid.addEventListener("on click", function() { + // updateMonsterGrid(); // Need a function for this too... + //}); }); diff --git a/templates/monsters.html b/templates/stats.html similarity index 96% rename from templates/monsters.html rename to templates/stats.html index 68592ee..19f8ca8 100644 --- a/templates/monsters.html +++ b/templates/stats.html @@ -3,11 +3,10 @@ - Monster Information + Monster Stats -

Monster Information

{{ monster.name }}

Family: {{ monster.family }}