2024-02-23 21:12:14 +00:00
|
|
|
function updateBreedingUsage() {
|
2024-02-24 19:30:47 +00:00
|
|
|
// Get the selected monster from the dropdown
|
|
|
|
var selectedMonster = document.getElementById("monsterDropdown").value;
|
2024-02-23 21:12:14 +00:00
|
|
|
|
2024-02-24 19:30:47 +00:00
|
|
|
// Fetch data from the API
|
|
|
|
fetch(`/api/breeding/usage/${selectedMonster}`)
|
2024-02-23 21:12:14 +00:00
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => {
|
2024-02-24 19:30:47 +00:00
|
|
|
// Update the HTML with the list of offspring monsters
|
|
|
|
renderOffspringList(data.used_in);
|
2024-02-23 21:12:14 +00:00
|
|
|
})
|
|
|
|
.catch(error => console.error('Error fetching data:', error));
|
2024-02-24 19:30:47 +00:00
|
|
|
}
|
2024-02-23 21:12:14 +00:00
|
|
|
|
2024-02-24 19:30:47 +00:00
|
|
|
function renderOffspringList(usageData) {
|
|
|
|
var offspringContainer = document.getElementById("offspringContainer");
|
2024-02-23 21:12:14 +00:00
|
|
|
|
2024-02-24 19:30:47 +00:00
|
|
|
// Clear previous HTML content
|
|
|
|
offspringContainer.innerHTML = "<h2 class='text-xl font-bold'>Used to Breed: </h2><ul class='list-disc'>";
|
2024-02-23 21:12:14 +00:00
|
|
|
|
2024-02-24 19:30:47 +00:00
|
|
|
// Create a Set to store unique offspring monsters
|
|
|
|
var uniqueOffspringSet = new Set();
|
|
|
|
|
|
|
|
// Add unique offspring to the Set
|
|
|
|
usageData.forEach(item => {
|
|
|
|
uniqueOffspringSet.add(item.offspring);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Create and append HTML for each unique offspring
|
|
|
|
uniqueOffspringSet.forEach(offspring => {
|
2024-04-27 23:34:59 +00:00
|
|
|
var offspringHTML = `<li class='font-bold text-left marker:text-slate-400 text-green-300'>
|
2024-02-24 19:30:47 +00:00
|
|
|
${offspring}
|
|
|
|
</li>`;
|
2024-02-23 21:12:14 +00:00
|
|
|
offspringContainer.innerHTML += offspringHTML;
|
2024-02-24 19:30:47 +00:00
|
|
|
});
|
2024-02-23 21:12:14 +00:00
|
|
|
|
2024-02-24 19:30:47 +00:00
|
|
|
// Close the unordered list
|
|
|
|
offspringContainer.innerHTML += "</ul>";
|
|
|
|
}
|