Added some more comments and updated code arrangement

This commit is contained in:
IM23a-spirgif
2024-11-07 15:24:11 +01:00
parent 894ae41efc
commit e75510dd8f
+2 -13
View File
@@ -188,7 +188,7 @@ function updateModifiedWeaponStats(damage, rpm, reloadTime) {
<th>Modified Reload Time</th> <th>Modified Reload Time</th>
<th>DPS</th> <th>DPS</th>
<th>DPM</th> <th>DPM</th>
<th>Average DPS</th> <!-- New Column for Average DPS --> <th>Average DPS</th>
</tr> </tr>
<tr> <tr>
<td>${selectedWeapon.name}</td> <td>${selectedWeapon.name}</td>
@@ -198,7 +198,7 @@ function updateModifiedWeaponStats(damage, rpm, reloadTime) {
<td>${reloadTime.toFixed(2)} seconds</td> <td>${reloadTime.toFixed(2)} seconds</td>
<td id="dps-value"></td> <td id="dps-value"></td>
<td id="dpm-value"></td> <td id="dpm-value"></td>
<td id="average-dps-value"></td> <!-- Cell for Average DPS --> <td id="average-dps-value"></td>
</tr> </tr>
</table> </table>
`; `;
@@ -541,12 +541,9 @@ function filterOperatives() {
const input = document.getElementById('operative-search').value.toLowerCase(); const input = document.getElementById('operative-search').value.toLowerCase();
const operativeSelect = document.getElementById('operative-select'); const operativeSelect = document.getElementById('operative-select');
const options = operativeSelect.getElementsByTagName('option'); const options = operativeSelect.getElementsByTagName('option');
let firstVisibleOption = null; // Track the first matching option let firstVisibleOption = null; // Track the first matching option
for (let i = 0; i < options.length; i++) { for (let i = 0; i < options.length; i++) {
const optionText = options[i].textContent || options[i].innerText; const optionText = options[i].textContent || options[i].innerText;
// Check if the option matches the search query // Check if the option matches the search query
if (optionText.toLowerCase().indexOf(input) > -1) { if (optionText.toLowerCase().indexOf(input) > -1) {
options[i].style.display = ''; // Show matching option options[i].style.display = ''; // Show matching option
@@ -557,7 +554,6 @@ function filterOperatives() {
options[i].style.display = 'none'; // Hide non-matching option options[i].style.display = 'none'; // Hide non-matching option
} }
} }
// Automatically select the first visible matching option // Automatically select the first visible matching option
if (firstVisibleOption) { if (firstVisibleOption) {
operativeSelect.value = firstVisibleOption.value; operativeSelect.value = firstVisibleOption.value;
@@ -570,14 +566,11 @@ function filterOperatives() {
function createGunTypeCheckboxes() { function createGunTypeCheckboxes() {
const gunTypeFiltersContainer = document.getElementById('gun-type-filters'); const gunTypeFiltersContainer = document.getElementById('gun-type-filters');
gunTypeFiltersContainer.innerHTML = ''; // Clear existing checkboxes gunTypeFiltersContainer.innerHTML = ''; // Clear existing checkboxes
const gunTypesSet = new Set(); // Use a Set to store unique gun types from the weapon data const gunTypesSet = new Set(); // Use a Set to store unique gun types from the weapon data
// Extract unique gun types from the weapon data // Extract unique gun types from the weapon data
weapons.forEach(weapon => { weapons.forEach(weapon => {
weapon.guntype.forEach(type => gunTypesSet.add(type)); // Add each gun type to the Set weapon.guntype.forEach(type => gunTypesSet.add(type)); // Add each gun type to the Set
}); });
// Create checkboxes for each unique gun type // Create checkboxes for each unique gun type
gunTypesSet.forEach(gunType => { gunTypesSet.forEach(gunType => {
const label = document.createElement('label'); const label = document.createElement('label');
@@ -585,21 +578,18 @@ function createGunTypeCheckboxes() {
input.type = 'checkbox'; input.type = 'checkbox';
input.value = gunType; input.value = gunType;
input.className = 'gun-type-checkbox'; input.className = 'gun-type-checkbox';
// Add event listener to filter weapons when checkbox is checked/unchecked // Add event listener to filter weapons when checkbox is checked/unchecked
input.addEventListener('change', () => { input.addEventListener('change', () => {
const selectedCheckboxes = Array.from(document.querySelectorAll('.gun-type-checkbox:checked')); const selectedCheckboxes = Array.from(document.querySelectorAll('.gun-type-checkbox:checked'));
selectedGunTypes = selectedCheckboxes.map(checkbox => checkbox.value); selectedGunTypes = selectedCheckboxes.map(checkbox => checkbox.value);
filterWeapons(); // Re-filter weapons based on the selected gun types filterWeapons(); // Re-filter weapons based on the selected gun types
}); });
label.appendChild(input); label.appendChild(input);
label.appendChild(document.createTextNode(gunType)); label.appendChild(document.createTextNode(gunType));
gunTypeFiltersContainer.appendChild(label); gunTypeFiltersContainer.appendChild(label);
gunTypeFiltersContainer.appendChild(document.createElement('br')); gunTypeFiltersContainer.appendChild(document.createElement('br'));
}); });
} }
// Attach event listeners to the search inputs // Attach event listeners to the search inputs
document.getElementById('weapon-search').addEventListener('keyup', filterWeapons); document.getElementById('weapon-search').addEventListener('keyup', filterWeapons);
document.getElementById('operative-search').addEventListener('keyup', filterOperatives); document.getElementById('operative-search').addEventListener('keyup', filterOperatives);
@@ -608,7 +598,6 @@ document.querySelectorAll('#guntype-filters input').forEach(checkbox => {
checkbox.addEventListener('change', filterWeapons); checkbox.addEventListener('change', filterWeapons);
}); });
// Call the fetch function to load the data and populate the dropdown on page load // Call the fetch function to load the data and populate the dropdown on page load
fetchWeaponsData(); fetchWeaponsData();
fetchModifiers(); fetchModifiers();