MediaWiki:Test/Revamp.js: различия между версиями

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показано 9 промежуточных версий этого же участника)
Строка 1: Строка 1:
// Getting elements
document.addEventListener("DOMContentLoaded", function() {
const actionCheckboxes = document.querySelectorAll('.action-checkbox');
    const weaponSelect = document.getElementById('weapon-select');
const modifierCheckboxes = document.querySelectorAll('.modifier-checkbox');
    const bulletSelect = document.getElementById('bullet-select');
const totalEchoesDisplay = document.getElementById('total-echoes');
    const dpsDisplay = document.getElementById('dps-display');
const totalMultiplierDisplay = document.getElementById('total-multiplier');
const rankDisplay = document.getElementById('rank');
const powerInput = document.getElementById('power-input');
const enableAllModifiersButton = document.getElementById('enable-all-modifiers-button');


// Variables to store Echo values
    // Проверка наличия элементов
let totalEchoes = 0;
    if (!weaponSelect || !bulletSelect || !dpsDisplay) {
let powerEchoes = 0;
        console.error("Один из элементов интерфейса не найден!");
 
        return;
// Tooltip functionality
    }
let tooltip = document.createElement('div');
tooltip.classList.add('tooltip');
document.body.appendChild(tooltip);


function showTooltip(event) {
     const WEAPONS = {
     const description = event.target.dataset.description;
         'Vulpaka': { fireRate: 6.6 },
    if (description) {
     };
         tooltip.textContent = description;
        tooltip.style.display = 'block';
        updateTooltipPosition(event);
     }
}


function hideTooltip() {
    const BULLETS = {
    tooltip.style.display = 'none';
        'VulpakaBalls': { damage: 5 },
}
    };


function updateTooltipPosition(event) {
     let currentWeapon = weaponSelect.value || Object.keys(WEAPONS)[0];
     tooltip.style.left = `${event.pageX + 10}px`;
     let currentBullet = bulletSelect.value || Object.keys(BULLETS)[0];
     tooltip.style.top = `${event.pageY + 10}px`;
}


// Add hover event listeners to modifier checkboxes with descriptions
    function calculateDPS() {
modifierCheckboxes.forEach(checkbox => {
        const weapon = WEAPONS[currentWeapon] || { fireRate: 0 };
    if (checkbox.dataset.description) {
        const bullet = BULLETS[currentBullet] || { damage: 0 };
         checkbox.addEventListener('mouseenter', showTooltip);
          
         checkbox.addEventListener('mousemove', updateTooltipPosition);
         const dps = bullet.damage * weapon.fireRate;
         checkbox.addEventListener('mouseleave', hideTooltip);
         dpsDisplay.textContent = dps.toFixed(1);
     }
     }
});
// Update the total Echoes based on actions completed
function updateTotalEchoes() {
    totalEchoes = 0; // Reset the total Echoes to start fresh


     // Loop through all action checkboxes and sum their Echo values if checked
     weaponSelect.addEventListener('change', function() {
    actionCheckboxes.forEach(checkbox => {
        currentWeapon = this.value;
        if (checkbox.checked) {
         calculateDPS();
            totalEchoes += parseFloat(checkbox.dataset.echo) || 0;
         }
     });
     });


     // Add the power Echoes
     bulletSelect.addEventListener('change', function() {
    totalEchoes += powerEchoes;
        currentBullet = this.value;
 
         calculateDPS();
    // Apply the multiplier
    const totalMultiplier = calculateTotalMultiplier();
    const finalEchoes = totalEchoes * totalMultiplier;
 
    // Update displays
    totalEchoesDisplay.textContent = totalEchoes.toFixed(2); // Show total echoes without multiplier
    totalMultiplierDisplay.textContent = `x${totalMultiplier.toFixed(1)} (Final: ${finalEchoes.toFixed(2)})`;
 
    // Update rank display (using totalEchoes and finalEchoes)
    updateRank(totalEchoes, finalEchoes);
}
 
// Calculate the total multiplier based on selected modifiers
function calculateTotalMultiplier() {
    let totalMultiplier = 1.0;
 
    modifierCheckboxes.forEach(checkbox => {
         if (checkbox.checked) {
            totalMultiplier += parseFloat(checkbox.dataset.modifier) || 0;
        }
     });
     });


     return totalMultiplier;
     // Первоначальный расчёт
}
     calculateDPS();
 
// Update power Echoes based on the power input value
function updatePowerEchoes() {
     let powerLevel = parseFloat(powerInput.value) || 0; // Ensure power input is valid number
 
    // Cap the powerLevel to a maximum of 20
    if (powerLevel > 20) {
        powerLevel = 20;
        powerInput.value = 20; // Update the input field value
    }
 
    powerEchoes = powerLevel * 0.75; // 0.75 Echo per power
    updateTotalEchoes(); // Recalculate the echoes whenever power input changes
}
 
// Update the rank based on total Echoes (without multiplier) and final Echoes (with multiplier)
function updateRank(totalEchoes, finalEchoes) {
    let rank = 'E';
 
    if (finalEchoes >= 441 && totalEchoes >= 140) {
        rank = 'W'; // W rank requires both final echoes >= 441 and total echoes >= 140
    } else if (totalEchoes >= 140) {
        rank = 'S';
    } else if (totalEchoes >= 112) {
        rank = 'A';
    } else if (totalEchoes >= 87) {
        rank = 'B';
    } else if (totalEchoes >= 60) {
        rank = 'C';
    } else if (totalEchoes >= 30) {
        rank = 'D';
    }
 
    rankDisplay.textContent = rank;
}
 
// Add event listeners to all action checkboxes
actionCheckboxes.forEach(checkbox => {
    checkbox.addEventListener('change', updateTotalEchoes);
});
 
// Add event listeners to all modifier checkboxes
modifierCheckboxes.forEach(checkbox => {
    checkbox.addEventListener('change', updateTotalEchoes);
});
 
// Add event listener to the power input field to update automatically
powerInput.addEventListener('input', updatePowerEchoes);
 
// Reset functionality - clear all data and redirect to registration page
const resetButton = document.getElementById('reset-button');
resetButton.addEventListener('click', function() {
    localStorage.removeItem('characterName');
    localStorage.removeItem('characterRace');
    window.location.href = 'register.html'; // Redirect to registration page
});
 
// Upload progress functionality - image upload and display
const uploadButton = document.getElementById('upload-progress-button');
const uploadInput = document.getElementById('upload-input');
const uploadedImage = document.getElementById('uploaded-image');
const progressDetails = document.getElementById('progress-details');
 
uploadButton.addEventListener('click', function() {
    uploadInput.click(); // Trigger file input
});
 
uploadInput.addEventListener('change', function(event) {
    const file = event.target.files[0];
    if (file) {
        const reader = new FileReader();
        reader.onload = function(e) {
            uploadedImage.src = e.target.result;
            uploadedImage.style.display = 'block'; // Show the uploaded image
        };
        reader.readAsDataURL(file); // Convert the image file to base64 and display it
 
        // Display progress details with character name, rank, and echoes
        const characterName = localStorage.getItem('characterName');
        const characterRace = localStorage.getItem('characterRace');
        const totalEchoes = totalEchoesDisplay.textContent;
        const rank = rankDisplay.textContent;
 
        progressDetails.textContent = `
            Character Name: ${characterName}
            Race: ${characterRace}
            Total Echoes: ${totalEchoes}
            Rank: ${rank}
        `;
    }
});
 
// "Enable All Modifiers" functionality
enableAllModifiersButton.addEventListener('click', function() {
    const allChecked = Array.from(modifierCheckboxes).every(checkbox => checkbox.checked);
 
    if (allChecked) {
        // If all are checked, uncheck all and change the button text to "Enable All Modifiers"
        modifierCheckboxes.forEach(checkbox => {
            checkbox.checked = false;
        });
        enableAllModifiersButton.textContent = 'Enable All Modifiers';
    } else {
        // If not all are checked, check all and change the button text to "Disable All Modifiers"
        modifierCheckboxes.forEach(checkbox => {
            checkbox.checked = true;
        });
        enableAllModifiersButton.textContent = 'Disable All Modifiers';
    }
   
    updateTotalEchoes(); // Recalculate the echoes after enabling/disabling all modifiers
});
});

Текущая версия от 20:03, 17 февраля 2025

document.addEventListener("DOMContentLoaded", function() {
    const weaponSelect = document.getElementById('weapon-select');
    const bulletSelect = document.getElementById('bullet-select');
    const dpsDisplay = document.getElementById('dps-display');

    // Проверка наличия элементов
    if (!weaponSelect || !bulletSelect || !dpsDisplay) {
        console.error("Один из элементов интерфейса не найден!");
        return;
    }

    const WEAPONS = {
        'Vulpaka': { fireRate: 6.6 },
    };

    const BULLETS = {
        'VulpakaBalls': { damage: 5 },
    };

    let currentWeapon = weaponSelect.value || Object.keys(WEAPONS)[0];
    let currentBullet = bulletSelect.value || Object.keys(BULLETS)[0];

    function calculateDPS() {
        const weapon = WEAPONS[currentWeapon] || { fireRate: 0 };
        const bullet = BULLETS[currentBullet] || { damage: 0 };
        
        const dps = bullet.damage * weapon.fireRate;
        dpsDisplay.textContent = dps.toFixed(1);
    }

    weaponSelect.addEventListener('change', function() {
        currentWeapon = this.value;
        calculateDPS();
    });

    bulletSelect.addEventListener('change', function() {
        currentBullet = this.value;
        calculateDPS();
    });

    // Первоначальный расчёт
    calculateDPS();
});