Frontend skill tree editor complete

master
Joshua Sigona 3 years ago
parent 8a6b37c352
commit f3c78bd5ba
  1. 4
      src/App.js
  2. 37
      src/skilltree/skillTreeEditor.js
  3. 14
      src/skilltree/skillTreeSelector.js

@ -755,6 +755,8 @@ function App() {
function GetData(table,row,col,id){ function GetData(table,row,col,id){
if (row===undefined) {row=''}
if (col===undefined) {col=''}
var data = id?DATAID:DATA var data = id?DATAID:DATA
return data!==undefined?data[table]!==undefined?data[table][row]!==undefined?data[table][row][col]!==undefined?data[table][row][col]:data[table][row]:data[table]:data:"no data" return data!==undefined?data[table]!==undefined?data[table][row]!==undefined?data[table][row][col]!==undefined?data[table][row][col]:data[table][row]:data[table]:data:"no data"
} }
@ -832,7 +834,7 @@ function App() {
</Route> </Route>
<Route path={process.env.PUBLIC_URL+"/skilltree"}> <Route path={process.env.PUBLIC_URL+"/skilltree"}>
<Box title="Skill Tree"> <Box title="Skill Tree">
<SkillTreeEditor/> <SkillTreeEditor GetData={GetData}/>
</Box> </Box>
</Route> </Route>
<Route path="/"> <Route path="/">

@ -1,11 +1,14 @@
import { SkillTree } from "./skillTree"; import { SkillTree } from "./skillTree";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { SkillTreeSelector } from "./skillTreeSelector"; import { SkillTreeSelector } from "./skillTreeSelector";
import axios from "axios";
function SkillTreeEditor(p) { function SkillTreeEditor(p) {
const ADJUSTMENT = [-32,-32] const ADJUSTMENT = [-32,-32]
const [classList,setClassList] = useState([])
const [cl,setCl] = useState(0)
const [lineColor,setLineColor] = useState("#000000") const [lineColor,setLineColor] = useState("#000000")
const [lineWidth,setLineWidth] = useState(3) const [lineWidth,setLineWidth] = useState(3)
const [dimensionX,setDimensionX] = useState(6) const [dimensionX,setDimensionX] = useState(6)
@ -23,13 +26,36 @@ function SkillTreeEditor(p) {
" □─□┼□", //└ ┘ ┴ " □─□┼□", //└ ┘ ┴
" □ "]) " □ "])
useEffect(()=>{
setClassList(p.GetData("class",undefined,undefined,true))
},[p.GetData])
useEffect(()=>{
setCl(Object.keys(classList)[0])
},[classList])
useEffect(()=>{
var skillTreeString = [...skillLines]
while (skillTreeString.length<dimensionY) {
skillTreeString.push(" ".repeat(dimensionX))
}
for (var line=0;line<skillTreeString.length;line++) {
if (skillTreeString[line].length<dimensionX) {
skillTreeString[line]+=" ".repeat(dimensionX-skillTreeString[line].length)
}
}
setSkillLines(skillTreeString)
},[dimensionX,dimensionY])
useEffect(()=>{ useEffect(()=>{
var controls = [] var controls = []
for (var x=0;x<dimensionX;x++) { for (var y=0;y<skillLines.length;y++) {
for (var y=0;y<dimensionY;y++) { for (var x=0;x<skillLines[y].length;x++) {
var padX = x!==0?gridPaddingX*x:0 var padX = x!==0?gridPaddingX*x:0
var padY = y!==0?gridPaddingY*y:0 var padY = y!==0?gridPaddingY*y:0
controls.push(<SkillTreeSelector defaultValue={skillLines[y][x]} callback={(char,x,y)=>{ controls.push(<SkillTreeSelector GetData={p.GetData} cl={Number(cl)} defaultValue={skillLines[y][x]} callback={(char,x,y)=>{
var string = [...skillLines] var string = [...skillLines]
var stringLine = string[y].split('') var stringLine = string[y].split('')
stringLine[x] = char stringLine[x] = char
@ -40,7 +66,7 @@ function SkillTreeEditor(p) {
} }
} }
setRenderedInputs(controls) setRenderedInputs(controls)
},[skillLines,dimensionX,dimensionY,gridSizeX,gridSizeY,gridPaddingX,gridPaddingY]) },[skillLines,gridSizeX,gridSizeY,gridPaddingX,gridPaddingY,cl])
return <> return <>
<div style={{width:"800px",position:"relative",left:"300px"}}> <div style={{width:"800px",position:"relative",left:"300px"}}>
@ -49,6 +75,9 @@ function SkillTreeEditor(p) {
skillLines={skillLines} skillLines={skillLines}
/> />
{renderedInputs.map((control)=>control)} {renderedInputs.map((control)=>control)}
<select value={cl} onChange={(f)=>{setCl(f.currentTarget.value)}}>
{Object.keys(classList).map((c)=><option value={c}>{c+" - "+classList[c].name}</option>)}
</select>
<input type="color" value={lineColor} onChange={(f)=>{setLineColor(f.currentTarget.value)}}/> <input type="color" value={lineColor} onChange={(f)=>{setLineColor(f.currentTarget.value)}}/>
<input type="number" value={lineWidth} onChange={(f)=>{setLineWidth(f.currentTarget.value)}}/> <input type="number" value={lineWidth} onChange={(f)=>{setLineWidth(f.currentTarget.value)}}/>
<input type="number" value={dimensionX} onChange={(f)=>{setDimensionX(f.currentTarget.value)}}/> <input type="number" value={dimensionX} onChange={(f)=>{setDimensionX(f.currentTarget.value)}}/>

@ -2,17 +2,23 @@ import { useEffect, useState } from 'react'
function SkillTreeSelector(p) { function SkillTreeSelector(p) {
const [char,setChar] = useState(p.defaultValue) const [selectedSkill,setSelectedSkill] = useState(undefined)
const [skillList,setSkillList] = useState([])
useEffect(()=>{ useEffect(()=>{
p.callback(char,Number(p.x),Number(p.y)) setSkillList(p.GetData("class_skill"))
},[char]) },[p.cl])
return <select onChange={(f)=>{setChar(f.currentTarget.value)}} style={{position:"absolute",left:p.ADJUSTMENT[0]+(p.x*p.gridSizeX+p.padX+p.gridSizeX/2),top:p.ADJUSTMENT[1]+(p.y*p.gridSizeY+p.padY+p.gridSizeY/2)}} value={char}> return <>
<select onChange={(f)=>{p.callback(f.currentTarget.value,Number(p.x),Number(p.y))}} style={{position:"absolute",left:p.ADJUSTMENT[0]+(p.x*p.gridSizeX+p.padX+p.gridSizeX/2),top:p.ADJUSTMENT[1]+(p.y*p.gridSizeY+p.padY+p.gridSizeY/2)}} value={p.defaultValue}>
{[' ','─','│','□','┌','└','┐','┘','┬','┴','├','┤','┼'].map((ch)=> {[' ','─','│','□','┌','└','┐','┘','┬','┴','├','┤','┼'].map((ch)=>
<option value={ch}>{ch}</option>) <option value={ch}>{ch}</option>)
} }
</select> </select>
{p.defaultValue==='□'&&<select style={{width:"64px",position:"absolute",left:p.ADJUSTMENT[0]+(p.x*p.gridSizeX+p.padX+p.gridSizeX/2),top:p.ADJUSTMENT[1]+(p.y*p.gridSizeY+p.padY+p.gridSizeY/2)+28}} onChange={(f)=>{setSelectedSkill(f.currentTarget.value)}} value={selectedSkill}>
{Object.keys((skillList)).filter((skill)=>skillList[skill].class_id===p.cl).map((skill)=><option value={skillList[skill].id}>{skillList[skill].name}</option>)}
</select>}
</>
} }

Loading…
Cancel
Save