Skip to content

Commit b7df1f1

Browse files
stirbyS1M0N38
authored andcommitted
computed reorder index
1 parent ddf3ca4 commit b7df1f1

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/lua/log.lua

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,20 @@ function LOG.hook_hand_rearrange()
228228
end
229229

230230
if order_changed then
231-
-- TODO: compute the rearrangement from previous_order and current_order
232-
-- and use as the arguments to the rearrange_hand API call
233-
-- So remove previous_order and current_order and use cards
234-
-- Then remove sendInfoMessage calls
235-
local arguments = {
236-
previous_order = previous_order,
237-
current_order = current_order,
238-
}
239-
local name = "rearrange_hand"
240-
sendInfoMessage("Hand rearranged - cards reordered", "LOG")
241-
sendInfoMessage("Before: " .. json.encode(previous_order), "LOG")
242-
sendInfoMessage("After: " .. json.encode(current_order), "LOG")
243-
LOG.write(name, arguments)
231+
-- Compute rearrangement to interpret the action
232+
-- Map every card-id → its position in the old list
233+
local lookup = {}
234+
for pos, card_id in ipairs(previous_order) do
235+
lookup[card_id] = pos - 1 -- zero-based for the API
236+
end
237+
238+
-- Walk the new order and translate
239+
local cards = {}
240+
for pos, card_id in ipairs(current_order) do
241+
cards[pos] = lookup[card_id]
242+
end
243+
244+
LOG.write("rearrange_hand", { cards = cards })
244245
end
245246
end
246247

0 commit comments

Comments
 (0)