Tightly couple ATK and HP values

This commit is contained in:
Justin Edmund 2023-01-14 18:59:34 -08:00
parent 9041683a6c
commit dd8f1906e8
2 changed files with 30 additions and 5 deletions

View file

@ -66,6 +66,9 @@ const RingSelect = (props: Props) => {
} }
function receiveRingValues(index: number, left: number, right: number) { function receiveRingValues(index: number, left: number, right: number) {
if (index == 1 || index == 2) {
setSyncedRingValues(index, right)
} else {
setRings({ setRings({
...rings, ...rings,
[index]: { [index]: {
@ -74,6 +77,26 @@ const RingSelect = (props: Props) => {
}, },
}) })
} }
}
function setSyncedRingValues(index: 1 | 2, value: number) {
const atkValues = (dataSet(1)[0] as ItemSkill).values ?? []
const hpValues = (dataSet(2)[0] as ItemSkill).values ?? []
let found = index === 1 ? atkValues.indexOf(value) : hpValues.indexOf(value)
setRings({
...rings,
1: {
modifier: rings[1].modifier,
strength: atkValues[found],
},
2: {
modifier: rings[2].modifier,
strength: hpValues[found],
},
})
}
return ( return (
<div className="Rings"> <div className="Rings">

View file

@ -57,6 +57,10 @@ const SelectWithInput = ({
setCurrentItemValue(rightSelectValue) setCurrentItemValue(rightSelectValue)
}, [leftSelectValue, rightSelectValue]) }, [leftSelectValue, rightSelectValue])
useEffect(() => {
if (currentItemSkill) sendValues(currentItemSkill.id, currentItemValue)
}, [currentItemSkill, currentItemValue])
// Methods: UI state management // Methods: UI state management
function changeOpen(side: 'left' | 'right') { function changeOpen(side: 'left' | 'right') {
if (side === 'left' && !leftSelectDisabled) { if (side === 'left' && !leftSelectDisabled) {
@ -111,13 +115,11 @@ const SelectWithInput = ({
const skill = dataSet.find((sk) => sk.id === value) const skill = dataSet.find((sk) => sk.id === value)
setCurrentItemSkill(skill) setCurrentItemSkill(skill)
setCurrentItemValue(0) setCurrentItemValue(0)
sendValues(leftSelectValue, rightSelectValue)
} }
function handleRightSelectChange(rawValue: string) { function handleRightSelectChange(rawValue: string) {
const value = parseFloat(rawValue) const value = parseFloat(rawValue)
setCurrentItemValue(value) setCurrentItemValue(value)
sendValues(leftSelectValue, rightSelectValue)
} }
return ( return (