-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c00c03d
commit cab2785
Showing
7 changed files
with
153 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import react, { useEffect, useState } from "react"; | ||
import CharacterRepository from "../../repositories/CharacterRepository"; | ||
import SkillsRepository from "../../repositories/SkillsRepository"; | ||
|
||
export const SkillColumn = ({ level, classSkills, updater }) => { | ||
const [skillPointsMax, setSkillPointsMax] = useState(0) | ||
const [classsSkills, setClassSkills] = useState([]) | ||
const [levelSkills, setLevelSkills] = useState([]) | ||
const [spentPoints, setSpentPoints] = useState(0) | ||
|
||
useEffect(() => { | ||
CharacterRepository.get(level.characterId).then(res => setSkillPointsMax( | ||
Math.floor((res["int"] - 10) / 2) + level?.class?.skillPoints)) | ||
setClassSkills(classSkills) | ||
setLevelSkills(level.levelSkills.sort((a,b)=> a.skillId - b.skillId)) | ||
calcSpentPoints() | ||
}, [level]) | ||
|
||
useEffect(()=> { | ||
updater() | ||
},[]) | ||
|
||
const spendPoints = (evt,levelSkill) => { | ||
const copy = { ...levelSkill } | ||
copy.points = parseInt(evt.target.value) | ||
SkillsRepository.updateLevelSkill(copy) | ||
updater() | ||
} | ||
|
||
const calcSpentPoints = () => { | ||
let spent = 0 | ||
levelSkills.forEach(levelSkill => { | ||
spent += parseInt(document.querySelector(`#classLevel--${level.id}--skill${levelSkill.skillId}`)?.value) | ||
}) | ||
setSpentPoints(spent) | ||
} | ||
|
||
return <> | ||
<div className="flexdown"> | ||
<h3>{level.characterLevel}</h3> | ||
<h3>{skillPointsMax - spentPoints}</h3> | ||
<input className="classSkill"/> | ||
{levelSkills?.map(levelSkill => | ||
<input id={`classLevel--${level.characterLevel}--skill${levelSkill.skillId}`} | ||
defaultValue={levelSkill.points} | ||
onBlur={(evt)=>spendPoints(evt,levelSkill)} | ||
className={classsSkills&&classsSkills[levelSkill.skillId]?.classSkillProf?"classSkill":"crossClassSkill"}/>)} | ||
</div> | ||
</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters