File tree Expand file tree Collapse file tree 1 file changed +14
-13
lines changed
Expand file tree Collapse file tree 1 file changed +14
-13
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments