diff --git a/PointBuy/scriptsPointBuy.js b/PointBuy/scriptsPointBuy.js index 8890558..1228401 100644 --- a/PointBuy/scriptsPointBuy.js +++ b/PointBuy/scriptsPointBuy.js @@ -1,22 +1,27 @@ document.addEventListener('DOMContentLoaded', () => { + guncelle(); + document.getElementById('race').addEventListener('change', guncelle); + document.getElementById('background').addEventListener('change', guncelle); + document.getElementById('class').addEventListener('change', guncelle); + + + document.getElementById('race').addEventListener('change', calculateSkillSlots); + document.getElementById('background').addEventListener('change', calculateSkillSlots); + document.getElementById('class').addEventListener('change', calculateSkillSlots); const form = document.getElementById('character-form'); + const raceForm = document.getElementById('race-form'); const statInputs = form.querySelectorAll('input[type="number"]'); const totalPointsElement = document.getElementById('total-points'); const submitBtn = document.getElementById('submit-btn'); const resetBtn = document.getElementById('reset-btn'); - let totalPoints = 0; + document.querySelectorAll('input[type="number"]').forEach(input => { + input.addEventListener('input', guncelle); + }); - let stats = { - str: 10, - dex: 10, - con: 10, - int: 10, - wis: 10, - cha: 10 - }; + let totalPoints = 0; - const statBonuses = { + let statBonuses = { strB: 0, dexB: 0, conB: 0, @@ -36,6 +41,26 @@ document.addEventListener('DOMContentLoaded', () => { 15: 9 }; + const raceBonuses = { + Select: {strB: 0, dexB: 0, conB: 0, intB: 0, wisB: 0, chaB: 0}, + Human: {strB: 1, dexB: 1, conB: 1, intB: 1, wisB: 1, chaB: 1}, + + "Elf(Ulu)": {strB: 0, dexB: 2, conB: 0, intB: 1, wisB: 0, chaB: 0}, + "Elf(Or)": {strB: 0, dexB: 2, conB: 0, intB: 0, wisB: 1, chaB: 0}, + "Elf(Drow)": {strB: 0, dexB: 2, conB: 0, intB: 0, wisB: 0, chaB: 1}, + "Dwarf(Dağ)": {strB: 2, dexB: 0, conB: 2, intB: 0, wisB: 0, chaB: 0}, + "Dwarf(Tepe)": {strB: 0, dexB: 0, conB: 2, intB: 0, wisB: 1, chaB: 0}, + "Halfling(Tez)": {strB: 0, dexB: 2, conB: 0, intB: 0, wisB: 0, chaB: 1}, + "Halfling(Tık)": {strB: 0, dexB: 2, conB: 1, intB: 0, wisB: 0, chaB: 0}, + Dragonborn: {strB: 2, dexB: 0, conB: 0, intB: 0, wisB: 0, chaB: 1}, + "Gnome(Kaya)": {strB: 0, dexB: 0, conB: 1, intB: 2, wisB: 0, chaB: 0}, + "Gnome(Or)": {strB: 0, dexB: 1, conB: 0, intB: 2, wisB: 0, chaB: 0}, + Tiefling: {strB: 0, dexB: 0, conB: 0, intB: 1, wisB: 0, chaB: 2}, + + "Yarı-Orc": {strB: 2, dexB: 0, conB: 1, intB: 0, wisB: 0, chaB: 0}, + }; + + const calculateStatCost = (stat) => { return statCostTable[stat] || 0; }; @@ -68,6 +93,17 @@ document.addEventListener('DOMContentLoaded', () => { }); }; + const updateRaceBonuses = (race) => { + const bonuses = raceBonuses[race] || {strB: 0, dexB: 0, conB: 0, intB: 0, wisB: 0, chaB: 0}; + statBonuses = bonuses; + Object.keys(bonuses).forEach(key => { + console.log(`Updating ${key.split('B')[0]}-racial with value ${bonuses[key]}`); // Hangi bonusun güncellendiğini kontrol edin + document.getElementById(`${key.split('B')[0]}-racial`).textContent = bonuses[key]; + }); + updateTotalsAndModifiers(); + guncelle(); + }; + statInputs.forEach(input => { input.addEventListener('change', () => { if (input.value < 8) input.value = 8; @@ -77,21 +113,527 @@ document.addEventListener('DOMContentLoaded', () => { }); }); + raceForm.addEventListener('change', (event) => { + const selectedRace = event.target.value; + console.log(`Selected race: ${selectedRace}`); // Burada seçilen ırkı konsola yazdırın + updateRaceBonuses(selectedRace); + }); resetBtn.addEventListener('click', () => { statInputs.forEach(input => input.value = 8); + updateRaceBonuses('select'); // Default race olarak "human" seçebilirsiniz calculatePointsRemaining(); updateTotalsAndModifiers(); }); form.addEventListener('submit', (event) => { event.preventDefault(); - // Karakter oluşturma işlemleri burada yapılabilir alert('Character created successfully!'); form.reset(); + updateRaceBonuses('select'); calculatePointsRemaining(); updateTotalsAndModifiers(); }); calculatePointsRemaining(); updateTotalsAndModifiers(); + updateRaceBonuses('Select'); // Sayfa yüklendiğinde varsayılan ırkı ayarla +}); +// ------------------------------RACE İNFO----------------------------------- + +const raceInfo = { + Human: { + title: "İnsan", + description: "
${info.description}
`; + } else { + raceInfoDiv.classList.add('hidden'); + raceInfoDiv.classList.remove('visible'); + raceInfoDiv.innerHTML = ''; + } + } +}; + +document.getElementById('race').addEventListener('change', updateRaceInfo); + +// -------------------------------BACKGROUND İNFO----------------------------------- + +const backgroundInfoDiv = document.getElementById("background-info"); + +const backgroundInfo = { + Soldier: { + title: "Asker", + description: "${info.description}
`; + } else { + backgroundInfoDiv.classList.add('hidden'); + backgroundInfoDiv.innerHTML = ''; + } + } +}; + +document.getElementById('background').addEventListener('change', updateBackgroundInfo); + +// ------------------------------CLASS İNFO----------------------------------- + +const classInfoDiv = document.getElementById("class-info"); + +const classInfo = { + Barbarian: { + title: "Barbar", + description: "${info.description}
`; + } else { + classInfoDiv.classList.add('hidden'); + classInfoDiv.classList.remove('visible'); + classInfoDiv.innerHTML = ''; + } + } +}; + + +document.getElementById('class').addEventListener('change', updateClassInfo); + +// -------------------------------SKİLL SLOT----------------------------------------------- + +let remainingSkillSlots = 0; + +const skillSlotEksi = () => { + if (remainingSkillSlots < 0) { + document.getElementById('skill-slot-eksi').classList.remove('hidden'); + } else { + document.getElementById('skill-slot-eksi').classList.add('hidden'); + } +} +function calculateSkillSlots() { + let skillSlots = 0; // Yerel skillSlots değişkeni + + const selectedClass = document.getElementById('class').value; + if (selectedClass === 'Barbarian') { + skillSlots += 2; + } else if (selectedClass === 'Bard') { + skillSlots += 3; + } else if (selectedClass === 'Cleric') { + skillSlots += 2; + }else if (selectedClass === 'Druid') { + skillSlots += 2; + }else if (selectedClass === 'Fighter') { + skillSlots += 2; + }else if (selectedClass === 'Monk') { + skillSlots += 2; + }else if (selectedClass === 'Paladin') { + skillSlots += 2; + }else if (selectedClass === 'Ranger') { + skillSlots += 3; + }else if (selectedClass === 'Rogue') { + skillSlots += 4; + }else if (selectedClass === 'Sorcerer') { + skillSlots += 2; + }else if (selectedClass === 'Warlock') { + skillSlots += 2; + }else if (selectedClass === 'Wizard') { + skillSlots += 2; + } + + + const selectedBackground = document.getElementById('background').value; + const backgroundsWithBonus = [ + 'Criminal', 'FolkHero', 'Sage', 'Soldier', + 'Denizci', 'DenizciKorsan', 'GosteriAdamı', 'GosteriAdamiGladyator', + 'LocaZanaatkari', 'LocaZanaatkariTuccar', 'Munzevi', 'Murit', + 'SokakCocugu', 'Soylu', 'SoyluSovalye', 'Suclu', 'SucluAjan', + 'Yabanci', 'Sarlatan' + ]; + + if (backgroundsWithBonus.includes(selectedBackground)) { + skillSlots += 2; + } + + + remainingSkillSlots = skillSlots; // remainingSkillSlots güncelle + updateRemainingSkillSlots(); // remainingSkillSlots metnini güncelle +}; +const updateRemainingSkillSlots = () => { + document.getElementById('skill-slots').innerText = `Kalan Skill Yuvası: ${remainingSkillSlots}`; // Hesaplanan skillSlots değerini güncelle + skillSlotEksi(); +}; + +let strMod = 0; +let dexMod = 0; +let conMod = 0; +let intMod = 0; +let wisMod = 0; +let chaMod = 0; + +const hesaplanmisBonus = () => { + strMod = parseInt(document.getElementById('str-modifier').textContent, 10) || 0; + dexMod = parseInt(document.getElementById('dex-modifier').textContent, 10) || 0; + conMod = parseInt(document.getElementById('con-modifier').textContent, 10) || 0; + intMod = parseInt(document.getElementById('int-modifier').textContent, 10) || 0; + wisMod = parseInt(document.getElementById('wis-modifier').textContent, 10) || 0; + chaMod = parseInt(document.getElementById('cha-modifier').textContent, 10) || 0; +}; + +const skillBonuses = { + athletics: 0, + acrobatics: 0, + sleightOfHand: 0, + stealth: 0, + history: 0, + religion: 0, + investigation: 0, + nature: 0, + arcana: 0, + animalHandling: 0, + insight: 0, + medicine: 0, + perception: 0, + survival: 0, + deception: 0, + persuasion: 0, + performance: 0, + intimidation: 0, +}; + +const skillBonuslariGuncelle = () => { + skillBonuses.athletics = strMod; + skillBonuses.acrobatics = dexMod; + skillBonuses.stealth = dexMod; + skillBonuses.sleightOfHand = dexMod; + skillBonuses.history = intMod; + skillBonuses.religion = intMod; + skillBonuses.investigation = intMod; + skillBonuses.nature = intMod; + skillBonuses.arcana = intMod; + skillBonuses.animalHandling = wisMod; + skillBonuses.insight = wisMod; + skillBonuses.medicine = wisMod; + skillBonuses.perception = wisMod; + skillBonuses.survival = wisMod; + skillBonuses.deception = chaMod; + skillBonuses.persuasion = chaMod; + skillBonuses.performance = chaMod; + skillBonuses.intimidation = chaMod; +}; +const updateStatsAndSkills = () => { + skillBonuslariGuncelle(); + hesaplanmisBonus(); + document.getElementById('athletics').innerHTML = skillBonuses.athletics; + document.getElementById('acrobatics').innerHTML = skillBonuses.acrobatics; + document.getElementById('stealth').innerHTML = skillBonuses.stealth; + document.getElementById('sleightOfHand').innerHTML = skillBonuses.sleightOfHand; + document.getElementById('history').innerHTML = skillBonuses.history; + document.getElementById('religion').innerHTML = skillBonuses.religion; + document.getElementById('investigation').innerHTML = skillBonuses.investigation; + document.getElementById('nature').innerHTML = skillBonuses.nature; + document.getElementById('arcana').innerHTML = skillBonuses.arcana; + document.getElementById('animalHandling').innerHTML = skillBonuses.animalHandling; + document.getElementById('insight').innerHTML = skillBonuses.insight; + document.getElementById('medicine').innerHTML = skillBonuses.medicine; + document.getElementById('perception').innerHTML = skillBonuses.perception; + document.getElementById('survival').innerHTML = skillBonuses.survival; + document.getElementById('deception').innerHTML = skillBonuses.deception; + document.getElementById('persuasion').innerHTML = skillBonuses.persuasion; + document.getElementById('performance').innerHTML = skillBonuses.performance; + document.getElementById('intimidation').innerHTML = skillBonuses.intimidation; + }; + +const toggleBonus = (skillId, buttonId, skillBonusKey, statName) => { + const button = document.getElementById(buttonId); + const statModifier = parseInt(document.getElementById(`${statName}-modifier`).textContent, 10) || 0; + let skillTotal = statModifier + (skillBonuses[skillBonusKey] || 0); + skillTotal = statModifier + if (button.classList.contains('active')) { + button.classList.remove('active'); + skillTotal = statModifier; + remainingSkillSlots += 1; + } else { + button.classList.add('active'); + skillTotal = statModifier + 2; // Buton aktif olduğunda +2 bonus eklenir + remainingSkillSlots -= 1; + } + + document.getElementById(skillId).textContent = skillTotal; + updateRemainingSkillSlots(); + skillBonuslariGuncelle(); +}; + + +const resetAllButtons = () => { + const skillButtons = document.querySelectorAll('.skillButton'); + skillButtons.forEach(button => { + button.classList.remove('active'); + }); +}; + +// Fonksiyonları window nesnesine atama +window.toggleBonusAthletics = () => toggleBonus('athletics', 'But-athletics', 'athletics', 'str'); +window.toggleBonusAcrobatics = () => toggleBonus('acrobatics', 'But-acrobatics', 'acrobatics', 'dex'); +window.toggleBonusSleightOfHand = () => toggleBonus('sleightOfHand', 'But-sleightOfHand', 'sleightOfHand', 'dex'); +window.toggleBonusStealth = () => toggleBonus('stealth', 'But-stealth', 'stealth', 'dex'); +window.toggleBonusHistory = () => toggleBonus('history', 'But-history', 'history', 'int'); +window.toggleBonusReligion = () => toggleBonus('religion', 'But-religion', 'religion', 'int'); +window.toggleBonusInvestigation = () => toggleBonus('investigation', 'But-investigation', 'investigation', 'int'); +window.toggleBonusNature = () => toggleBonus('nature', 'But-nature', 'nature', 'int'); +window.toggleBonusArcana = () => toggleBonus('arcana', 'But-arcana', 'arcana', 'int'); +window.toggleBonusAnimalHandling = () => toggleBonus('animalHandling', 'But-animalHandling', 'animalHandling', 'wis'); +window.toggleBonusInsight = () => toggleBonus('insight', 'But-insight', 'insight', 'wis'); +window.toggleBonusMedicine = () => toggleBonus('medicine', 'But-medicine', 'medicine', 'wis'); +window.toggleBonusPerception = () => toggleBonus('perception', 'But-perception', 'perception', 'wis'); +window.toggleBonusSurvival = () => toggleBonus('survival', 'But-survival', 'survival', 'wis'); +window.toggleBonusDeception = () => toggleBonus('deception', 'But-deception', 'deception', 'cha'); +window.toggleBonusPersuasion = () => toggleBonus('persuasion', 'But-persuasion', 'persuasion', 'cha'); +window.toggleBonusPerformance = () => toggleBonus('performance', 'But-performance', 'performance', 'cha'); +window.toggleBonusIntimidation = () => toggleBonus('intimidation', 'But-intimidation', 'intimidation', 'cha'); + +document.getElementById('class').addEventListener('change', () => { + resetAllButtons(); + calculateSkillSlots(); }); + +document.getElementById('background').addEventListener('change', () => { + resetAllButtons(); + calculateSkillSlots(); +}); + +calculateSkillSlots(); // Başlangıçta çağrılır + +// -------------------------------POİNT BUY----------------------------------------------- + + + +const guncelle = () => { + hesaplanmisBonus(); + skillBonuslariGuncelle(); + updateStatsAndSkills(); +}; + +// -------------------------------MENÜ---------------------------------- +const toggleMenu = () => { + const menu = document.getElementById('hamburger-menu'); + if (menu.classList.contains('hidden')) { + menu.classList.remove('hidden'); + menu.classList.add('visible'); + } else { + menu.classList.remove('visible'); + menu.classList.add('hidden'); + } +}; + +document.addEventListener('click', (event) => { + const menu = document.getElementById('hamburger-menu'); + const menuIcon = document.querySelector('.menu-icon'); + + if (menu.contains(event.target) || menuIcon.contains(event.target)) { + return; + } + + if (menu.classList.contains('visible')) { + menu.classList.remove('visible'); + menu.classList.add('hidden'); + } +});