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

Страница интерфейса MediaWiki
(Ahahahahha изменил модель содержимого страницы Шаблон:Test/Revamp.js с «вики-текст» на «JavaScript»)
Метка: изменение модели содержимого
Нет описания правки
Строка 1: Строка 1:
document.addEventListener("DOMContentLoaded", function () {
// Getting elements
    const ammo1 = document.querySelector(".AmmoTest1");
const actionCheckboxes = document.querySelectorAll('.action-checkbox');
    const ammo2 = document.querySelector(".AmmoTest2");
const modifierCheckboxes = document.querySelectorAll('.modifier-checkbox');
    const damageDisplay = document.querySelector(".WeaponSummary");
const totalEchoesDisplay = document.getElementById('total-echoes');
    let selectedAmmo = null;
const totalMultiplierDisplay = document.getElementById('total-multiplier');
    const damageValue = 20; // Фиксированный урон
const rankDisplay = document.getElementById('rank');
const powerInput = document.getElementById('power-input');
const enableAllModifiersButton = document.getElementById('enable-all-modifiers-button');


    function updateDamageDisplay() {
// Variables to store Echo values
        if (selectedAmmo) {
let totalEchoes = 0;
            damageDisplay.textContent = `Урон: ${damageValue}`;
let powerEchoes = 0;
            damageDisplay.classList.add("updated");
 
            setTimeout(() => damageDisplay.classList.remove("updated"), 400);
// Tooltip functionality
         } else {
let tooltip = document.createElement('div');
            damageDisplay.textContent = "Урон: 0";
tooltip.classList.add('tooltip');
         }
document.body.appendChild(tooltip);
 
function showTooltip(event) {
    const description = event.target.dataset.description;
    if (description) {
        tooltip.textContent = description;
         tooltip.style.display = 'block';
         updateTooltipPosition(event);
     }
     }
}


    function selectAmmo(ammo) {
function hideTooltip() {
        if (selectedAmmo === ammo) {
    tooltip.style.display = 'none';
            selectedAmmo.classList.remove("active");
}
            selectedAmmo = null;
 
        } else {
function updateTooltipPosition(event) {
            if (selectedAmmo) {
    tooltip.style.left = `${event.pageX + 10}px`;
                selectedAmmo.classList.remove("active");
    tooltip.style.top = `${event.pageY + 10}px`;
            }
}
            selectedAmmo = ammo;
 
            selectedAmmo.classList.add("active");
// Add hover event listeners to modifier checkboxes with descriptions
         }
modifierCheckboxes.forEach(checkbox => {
        updateDamageDisplay();
    if (checkbox.dataset.description) {
        checkbox.addEventListener('mouseenter', showTooltip);
        checkbox.addEventListener('mousemove', updateTooltipPosition);
         checkbox.addEventListener('mouseleave', hideTooltip);
     }
     }
});
// Update the total Echoes based on actions completed
function updateTotalEchoes() {
    totalEchoes = 0; // Reset the total Echoes to start fresh


     ammo1.addEventListener("click", function () {
     // Loop through all action checkboxes and sum their Echo values if checked
         if (!ammo1.classList.contains("disabled")) {
    actionCheckboxes.forEach(checkbox => {
             selectAmmo(ammo1);
         if (checkbox.checked) {
            ammo2.classList.toggle("disabled", selectedAmmo !== null);
             totalEchoes += parseFloat(checkbox.dataset.echo) || 0;
         }
         }
     });
     });


     ammo2.addEventListener("click", function () {
     // Add the power Echoes
         if (!ammo2.classList.contains("disabled")) {
    totalEchoes += powerEchoes;
             selectAmmo(ammo2);
 
            ammo1.classList.toggle("disabled", selectedAmmo !== null);
    // 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;
}
// 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
});
});

Версия от 00:34, 4 февраля 2025

// Getting elements
const actionCheckboxes = document.querySelectorAll('.action-checkbox');
const modifierCheckboxes = document.querySelectorAll('.modifier-checkbox');
const totalEchoesDisplay = document.getElementById('total-echoes');
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;
let powerEchoes = 0;

// Tooltip functionality
let tooltip = document.createElement('div');
tooltip.classList.add('tooltip');
document.body.appendChild(tooltip);

function showTooltip(event) {
    const description = event.target.dataset.description;
    if (description) {
        tooltip.textContent = description;
        tooltip.style.display = 'block';
        updateTooltipPosition(event);
    }
}

function hideTooltip() {
    tooltip.style.display = 'none';
}

function updateTooltipPosition(event) {
    tooltip.style.left = `${event.pageX + 10}px`;
    tooltip.style.top = `${event.pageY + 10}px`;
}

// Add hover event listeners to modifier checkboxes with descriptions
modifierCheckboxes.forEach(checkbox => {
    if (checkbox.dataset.description) {
        checkbox.addEventListener('mouseenter', showTooltip);
        checkbox.addEventListener('mousemove', updateTooltipPosition);
        checkbox.addEventListener('mouseleave', hideTooltip);
    }
});

// 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
    actionCheckboxes.forEach(checkbox => {
        if (checkbox.checked) {
            totalEchoes += parseFloat(checkbox.dataset.echo) || 0;
        }
    });

    // Add the power Echoes
    totalEchoes += powerEchoes;

    // 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;
}

// 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
});