diff --git a/solitaire.lua b/solitaire.lua index 5b69ae3..4f94cf8 100644 --- a/solitaire.lua +++ b/solitaire.lua @@ -279,67 +279,23 @@ function update() end mouse_pos={mx,my} - local hover=card_at_point(mx,my) - local location=location_at_point(mx,my) + local mouse_hover=card_at_point(mx,my) + local mouse_location=location_at_point(mx,my) if mouse_moved then c_hover=nil end + if mright or c_back then hand=nil end + if c_hover then if #stacks[c_hover[1]]~=0 then - hover=c_hover + update_selected(c_sel, c_sel_last, c_hover, nil) elseif #stacks[c_hover[1]]==0 then - location=c_hover + update_selected(c_sel, c_sel_last, nil, c_hover) end + else + update_selected(mleft, mleft_last, mouse_hover, mouse_location) end - local left=false - if mleft or c_sel then - left=true - end - - local right=false - if mright or c_back then - right=true - end - - if right then hand=nil end - - if not last_left and hover then - if not exhausted and hover[1]==1 and left then - hand=nil - draw_cards_to(stacks[1],stacks[2],3) - if #stacks[1]==0 then - exhausted=true - end - elseif hand and hover and - hand[1]==hover[1] and hand[2]==hover[2] and left - then - for i=3,6 do - if move_sel(hand, {i,#stacks[i]}) then - break - end - end - hand=nil - elseif hand and hover and left then - move_sel(hand,hover) - hand=nil - elseif not hand and left then - if sel_can_move(hover) then - stacks[hover[1]][hover[2]].state=2 - hand={hover[1],hover[2]} - end - elseif stacks[hover[1]][hover[2]].state==0 then - if sel_can_move(hover) then - for i=hover[2],#stacks[hover[1]] do - stacks[hover[1]][i].state=1 - end - end - end - end - if left and location and hand then - move_sel(hand,location) - hand=nil - end for j,stack in ipairs(stacks) do local stack=stacks[j] local stackx=0 @@ -380,7 +336,8 @@ function update() end if clear_count==0 then is_clearing=false end end - last_left=left + mleft_last=mleft + c_sel_last=c_sel if should_check_for_win then local has_won=true @@ -396,6 +353,45 @@ function update() end end +function update_selected(select_input, last_select_input, hovered, location) + if not last_select_input and hovered then + if not exhausted and hovered[1]==1 and select_input then + hand=nil + draw_cards_to(stacks[1],stacks[2],3) + if #stacks[1]==0 then + exhausted=true + end + elseif hand and hovered and + hand[1]==hovered[1] and hand[2]==hovered[2] and select_input + then + for i=3,6 do + if move_sel(hand, {i,#stacks[i]}) then + break + end + end + hand=nil + elseif hand and hovered and select_input then + move_sel(hand,hovered) + hand=nil + elseif not hand and select_input then + if sel_can_move(hovered) then + stacks[hovered[1]][hovered[2]].state=2 + hand={hovered[1],hovered[2]} + end + elseif hovered and stacks[hovered[1]][hovered[2]].state==0 then + if sel_can_move(hovered) then + for i=hovered[2],#stacks[hovered[1]] do + stacks[hovered[1]][i].state=1 + end + end + end + end + if select_input and location and hand then + move_sel(hand,location) + hand=nil + end +end + function check_has_won() local has_won=true for i=3,6 do