From 59fe208f5f3dd445d063a28cac21eebaa124fd6c Mon Sep 17 00:00:00 2001 From: Chris kerr Date: Tue, 30 Jan 2024 20:17:15 -0500 Subject: [PATCH] breeding iframe showing (bad) data --- app.py | 69 +++++++++++++++++++++++++++++++++++++++++ static/js/index.js | 30 +++++++++++------- static/style/output.css | 25 ++++++--------- templates/breeding.html | 40 ++++++++++++++++++++++++ templates/index.html | 55 ++++++++++++++++++++------------ 5 files changed, 172 insertions(+), 47 deletions(-) create mode 100644 templates/breeding.html diff --git a/app.py b/app.py index 1933f12..5eddec6 100644 --- a/app.py +++ b/app.py @@ -113,5 +113,74 @@ def monster_info(monster_name): ) +# Update the breeding route +@app.route("/breeding") +def breeding(): + # Get all monsters for dropdown + cursor = g.db.cursor() + cursor.execute("SELECT DISTINCT name FROM monsters") + monsters = [row[0] for row in cursor.fetchall()] + + # Pass the monsters to the breeding template + return render_template("breeding.html", monsters=monsters) + + +# Add this route for fetching breeding combinations +@app.route("/get_breeding_combinations") +def get_breeding_combinations(): + selected_monster = request.args.get("monster") + if not selected_monster: + return jsonify({"error": "Invalid input"}) + + base_combinations = get_base_combinations(selected_monster) + mate_combinations = get_mate_combinations(selected_monster) + + return jsonify( + {"base_combinations": base_combinations, "mate_combinations": mate_combinations} + ) + + +# Function to get base breeding combinations +def get_base_combinations(selected_monster): + cursor = g.db.cursor() + + # Fetch breed IDs based on the selected monster as a base + cursor.execute( + """ + SELECT breeds.target + FROM breeds + JOIN breed_requirements ON breeds.id = breed_requirements.breed_id + WHERE breed_requirements.requirement_type = 'base' + AND breed_requirements.requirement_value = ? + """, + (selected_monster,), + ) + + base_combinations = cursor.fetchall() + + return [row[0] for row in base_combinations] + + +# Function to get mate breeding combinations +def get_mate_combinations(selected_monster): + cursor = g.db.cursor() + + # Fetch breed IDs based on the selected monster as a mate + cursor.execute( + """ + SELECT breeds.target + FROM breeds + JOIN breed_requirements ON breeds.id = breed_requirements.breed_id + WHERE breed_requirements.requirement_type = 'mate' + AND breed_requirements.requirement_value = ? + """, + (selected_monster,), + ) + + mate_combinations = cursor.fetchall() + + return [row[0] for row in mate_combinations] + + if __name__ == "__main__": app.run(debug=True) diff --git a/static/js/index.js b/static/js/index.js index 2fc7ed7..21f6642 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -1,13 +1,12 @@ -// static/js/app.js - document.addEventListener("DOMContentLoaded", function () { const familyDropdown = document.getElementById("familyDropdown"); const monsterDropdown = document.getElementById("monsterDropdown"); - const iframe = document.getElementById("monsterIframe"); + const monsterIframe = document.getElementById("monsterIframe"); + const breedingIframe = document.getElementById("breedingIframe"); - // Initialize dropdowns and iframe + // Initialize dropdowns and iframes updateMonstersDropdown(); - updateIframe(); + updateIframes(); // Fetch families data from the server fetch("/get_families") @@ -15,17 +14,17 @@ document.addEventListener("DOMContentLoaded", function () { .then(data => { populateDropdown(familyDropdown, data); updateMonstersDropdown(); - updateIframe(); + updateIframes(); }) .catch(error => console.error("Error fetching families:", error)); familyDropdown.addEventListener("change", function () { updateMonstersDropdown(); - updateIframe(); + updateIframes(); }); monsterDropdown.addEventListener("change", function () { - updateIframe(); + updateIframes(); }); function populateDropdown(dropdown, data) { @@ -51,17 +50,24 @@ document.addEventListener("DOMContentLoaded", function () { .catch(error => console.error("Error fetching monsters:", error)); } - function updateIframe() { + function updateIframes() { const selectedFamily = familyDropdown.value; const selectedMonster = monsterDropdown.value; - // Update iframe src based on selected family and monster - const iframeSrc = selectedMonster + // Update monsterIframe src based on selected family and monster + const monsterIframeSrc = selectedMonster ? `/monster/${selectedMonster}` : selectedFamily ? `/monster/${selectedFamily}` : "about:blank"; - iframe.src = iframeSrc; + monsterIframe.src = monsterIframeSrc; + + // Update breedingIframe src based on the selected monster + const breedingIframeSrc = selectedMonster + ? `/get_breeding_combinations?monster=${selectedMonster}` + : "about:blank"; + + breedingIframe.src = breedingIframeSrc; } }); diff --git a/static/style/output.css b/static/style/output.css index aebde0f..5020404 100644 --- a/static/style/output.css +++ b/static/style/output.css @@ -544,6 +544,10 @@ video { position: static; } +.col-span-1 { + grid-column: span 1 / span 1; +} + .m-4 { margin: 1rem; } @@ -564,14 +568,18 @@ video { margin-top: 1rem; } -.mt-8 { - margin-top: 2rem; +.flex { + display: flex; } .grid { display: grid; } +.h-auto { + height: auto; +} + .w-auto { width: auto; } @@ -592,19 +600,10 @@ video { border-radius: 0.375rem; } -.border { - border-width: 1px; -} - .border-2 { border-width: 2px; } -.border-gray-400 { - --tw-border-opacity: 1; - border-color: rgb(156 163 175 / var(--tw-border-opacity)); -} - .border-teal-500 { --tw-border-opacity: 1; border-color: rgb(20 184 166 / var(--tw-border-opacity)); @@ -628,10 +627,6 @@ video { padding: 1rem; } -.p-8 { - padding: 2rem; -} - .font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; } diff --git a/templates/breeding.html b/templates/breeding.html new file mode 100644 index 0000000..d118a4e --- /dev/null +++ b/templates/breeding.html @@ -0,0 +1,40 @@ + + + + + + + + Breeding Combinations + + + +

Breeding Combinations

+ +
+ {% if selected_monster %} +

+ Breeding Combinations for {{ selected_monster.name }} +

+
+
+

Base Combinations

+
    + {% for combination in selected_monster.base_combinations %} +
  • {{ combination.target }}
  • + {% endfor %} +
+
+
+

Mate Combinations

+
    + {% for combination in selected_monster.mate_combinations %} +
  • {{ combination.target }}
  • + {% endfor %} +
+
+
+ {% endif %} +
+ + diff --git a/templates/index.html b/templates/index.html index ef8a7ab..9ce5494 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,32 +1,47 @@ - - - + + + DWM APP - + - - -

Welcome to the Dragon Warrior Monsters 2 App

+ + +

+ Welcome to the Dragon Warrior Monsters 2 App +

- - + + - - + + +
+ - + +
- +