Compare commits

..

4 Commits

1 changed files with 24 additions and 6 deletions

View File

@ -335,8 +335,14 @@ fn render(window: *seizer.Window) !void {
}
{
const is_selected = selected_deck != null and selected_deck.? == &draw_pile;
const is_hovered = hovered_deck != null and hovered_deck.? == &draw_pile;
const color = if (is_hovered) [4]u8{ 0xA0, 0xFF, 0xA0, 0xFF } else [4]u8{ 0xFF, 0xFF, 0xFF, 0xFF };
const color = if (is_selected)
[4]u8{ 0xFF, 0xA0, 0xA0, 0xFF }
else if (is_hovered)
[4]u8{ 0xA0, 0xFF, 0xA0, 0xFF }
else
[4]u8{ 0xFF, 0xFF, 0xFF, 0xFF };
var pos = [2]f32{ @floatFromInt(margin), @floatFromInt(margin) };
pos[0] += board_offset[0];
@ -466,7 +472,12 @@ pub fn doSelectOrPlace(pressed: bool) !void {
if ((empty and ace) or (suit_matches and is_next_rank)) {
foundation.ensureUnusedCapacity(gpa, 1) catch continue;
foundation.appendAssumeCapacity(selected_deck.?.pop());
hovered_card = indexOfTopOfStack(hovered_deck.?.items);
hovered_card = if (hovered_deck.? == &drawn_cards)
hovered_deck.?.items.len -| 1
else
indexOfTopOfStack(hovered_deck.?.items);
cards_moved = true;
break;
}
@ -475,9 +486,13 @@ pub fn doSelectOrPlace(pressed: bool) !void {
}
}
try history.append(gpa, snapshot);
if (cards_moved) {
try history.append(gpa, snapshot);
}
selected_deck = null;
} else {
var cards_moved = false;
const snapshot = try Snapshot.initFromCurrentGlobalState();
if (selected_deck) |selected| move_from_selected_to_hovered: {
const selected_substack = selected.items[selected_card..];
@ -492,7 +507,7 @@ pub fn doSelectOrPlace(pressed: bool) !void {
hovered.appendSliceAssumeCapacity(selected_substack);
selected.shrinkRetainingCapacity(selected.items.len - selected_substack.len);
hovered_card = indexOfTopOfStack(hovered_deck.?.items);
try history.append(gpa, snapshot);
cards_moved = true;
break :move_from_selected_to_hovered;
}
@ -513,7 +528,7 @@ pub fn doSelectOrPlace(pressed: bool) !void {
foundation.ensureUnusedCapacity(gpa, 1) catch continue;
foundation.appendAssumeCapacity(selected_deck.?.pop());
hovered_card = indexOfTopOfStack(hovered_deck.?.items);
try history.append(gpa, snapshot);
cards_moved = true;
break :move_from_selected_to_hovered;
}
}
@ -523,7 +538,7 @@ pub fn doSelectOrPlace(pressed: bool) !void {
}
if (hovered.items[hovered.items.len - 1].rank - 1 != selected_substack[0].rank or
hovered.items[hovered.items.len - 1].suit == selected_substack[0].suit)
hovered.items[hovered.items.len - 1].suit.color() == selected_substack[0].suit.color())
{
break :move_from_selected_to_hovered;
}
@ -531,6 +546,9 @@ pub fn doSelectOrPlace(pressed: bool) !void {
hovered.appendSliceAssumeCapacity(selected_substack);
selected.shrinkRetainingCapacity(selected.items.len - selected_substack.len);
hovered_card = indexOfTopOfStack(hovered_deck.?.items);
cards_moved = true;
}
if (cards_moved) {
try history.append(gpa, snapshot);
}
selected_deck = null;