From ee4196e4c040c779775079aa2dead63a9f1741de Mon Sep 17 00:00:00 2001 From: Joshua Sigona Date: Sat, 14 Aug 2021 16:38:33 +0900 Subject: [PATCH] Added skill tree skill data editing. --- src/skilltree/skillTreeEditor.js | 55 ++++++++++++++++++++++++------ src/skilltree/skillTreeSelector.js | 5 ++- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/skilltree/skillTreeEditor.js b/src/skilltree/skillTreeEditor.js index d709aaf..3760bb9 100644 --- a/src/skilltree/skillTreeEditor.js +++ b/src/skilltree/skillTreeEditor.js @@ -20,6 +20,16 @@ function SkillTreeEditor(p) { const [gridPaddingY,setGridPaddingY] = useState(10) const [renderedInputs,setRenderedInputs] = useState([]) const [skillLines,setSkillLines] = useState([]) + const [skillData,setSkillData] = useState([]) + + function GetSkills(x,y) { + var filtered = skillData.filter((skill)=>Number(skill[0])===x&&Number(skill[1])===y) + if (filtered.length>0) { + return filtered[0] + } else { + return "" + } + } useEffect(()=>{ setClassList(p.GetData("class",undefined,undefined,true)) @@ -30,12 +40,19 @@ function SkillTreeEditor(p) { var keys = Object.keys(skillTreeData) for (var id of keys) { //console.log(cl+"/"+skillTreeData[id].class_id) - if (skillTreeData[id].class_id==cl) { + if (Number(skillTreeData[id].class_id)===Number(cl)) { var data = skillTreeData[id].data.split(',') + var skill = skillTreeData[id].skill_data.split(';') setSkillLines(data) + setSkillData(skill) setDimensionX(data[0].length) setDimensionY(data.length) setLineColor(skillTreeData[id].line_color) + setLineWidth(skillTreeData[id].line_width) + setGridSizeX(skillTreeData[id].gridsizex) + setGridSizeY(skillTreeData[id].gridsizey) + setGridPaddingX(skillTreeData[id].gridpaddingx) + setGridPaddingY(skillTreeData[id].gridpaddingy) } } },[skillTreeData,cl]) @@ -73,12 +90,28 @@ function SkillTreeEditor(p) { string[y] = stringLine.join('') setSkillLines(string) } - } ADJUSTMENT={ADJUSTMENT} x={x} y={y} gridSizeX={gridSizeX} gridSizeY={gridSizeY} padX={padX} padY={padY}/>) + } skill={GetSkills(x,y)} skillCallback={(x,y,skill)=>{ + var newSkillData = [...skillData] + var found=false + var newSkill = x+","+y+","+skill + for (var s in newSkillData) { + var split = newSkillData[s].split(',') + if (Number(split[0])===Number(x)&&Number(split[1])===Number(y)) { + newSkillData[s]=newSkill + found=true + break; + } + } + if (!found) { + newSkillData.push(newSkill) + } + setSkillData(newSkillData) + }} ADJUSTMENT={ADJUSTMENT} x={x} y={y} gridSizeX={gridSizeX} gridSizeY={gridSizeY} padX={padX} padY={padY}/>) } } } setRenderedInputs(controls) - },[skillLines,gridSizeX,gridSizeY,gridPaddingX,gridPaddingY,cl,dimensionY,dimensionX]) + },[skillLines,gridSizeX,gridSizeY,gridPaddingX,gridPaddingY,cl,dimensionY,dimensionX,skillData]) return <> {setLineColor(f.currentTarget.value)}}/> - {setLineWidth(f.currentTarget.value)}}/> - {setDimensionX(f.currentTarget.value)}}/> - {setDimensionY(f.currentTarget.value)}}/> - {setGridSizeX(f.currentTarget.value)}}/> - {setGridSizeY(f.currentTarget.value)}}/> - {setGridPaddingX(f.currentTarget.value)}}/> - {setGridPaddingY(f.currentTarget.value)}}/> + {setLineColor(f.currentTarget.value)}}/> + {setLineWidth(f.currentTarget.value)}}/> + {setDimensionX(f.currentTarget.value)}}/> + {setDimensionY(f.currentTarget.value)}}/> + {setGridSizeX(f.currentTarget.value)}}/> + {setGridSizeY(f.currentTarget.value)}}/> + {setGridPaddingX(f.currentTarget.value)}}/> + {setGridPaddingY(f.currentTarget.value)}}/> diff --git a/src/skilltree/skillTreeSelector.js b/src/skilltree/skillTreeSelector.js index 6cb0943..7ef2b1d 100644 --- a/src/skilltree/skillTreeSelector.js +++ b/src/skilltree/skillTreeSelector.js @@ -2,7 +2,6 @@ import { useEffect, useState } from 'react' function SkillTreeSelector(p) { - const [selectedSkill,setSelectedSkill] = useState(undefined) const [skillList,setSkillList] = useState([]) useEffect(()=>{ @@ -15,8 +14,8 @@ function SkillTreeSelector(p) { ) } - {p.defaultValue==='□'&&{p.skillCallback(p.x,p.y,f.currentTarget.value)}} value={p.skill.split(",")[2]}> + {["",...Object.keys((skillList)).filter((skill)=>skillList[skill].class_id===p.cl)].map((skill)=>)} }