fix(save-editor): guard cycleMove against undefined moves in catalog

Closes #1403
This commit is contained in:
Yunus Emre Umar
2026-08-16 16:11:32 +03:00
parent 1151c188a7
commit 393a1013e4
+9 -4
View File
@@ -430,7 +430,7 @@ function Ops.setDv(S, mon, key, value)
end end
function Ops.cycleMove(S, mon, slot) function Ops.cycleMove(S, mon, slot)
if not mon then return false end if not mon or not (S.cat and S.cat.moves and #S.cat.moves > 0) then return false end
local moves = S.cat.moves local moves = S.cat.moves
local current = mon.moves and mon.moves[slot] and mon.moves[slot].id local current = mon.moves and mon.moves[slot] and mon.moves[slot].id
local idx = 0 local idx = 0
@@ -439,9 +439,14 @@ function Ops.cycleMove(S, mon, slot)
if id == current then idx = i break end if id == current then idx = i break end
end end
end end
local nextId = moves[(idx % #moves) + 1] for step = 1, #moves do
MonOps.setMove(S.data, mon, slot, nextId) local nextId = moves[((idx + step - 1) % #moves) + 1]
return Ops.mark(S, ("Move %d set to %s"):format(slot, nextId)) if S.data and S.data.moves and S.data.moves[nextId] then
MonOps.setMove(S.data, mon, slot, nextId)
return Ops.mark(S, ("Move %d set to %s"):format(slot, nextId))
end
end
return false
end end
function Ops.clearMove(S, mon, slot) function Ops.clearMove(S, mon, slot)