Skip to content

Commit

Permalink
Rename tentative to tentatives
Browse files Browse the repository at this point in the history
  • Loading branch information
yescallop committed Nov 19, 2024
1 parent 9aa6f06 commit 636153e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion client/src/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ impl DialogImpl for ConfirmDialog {
Confirm::Submit(_, Some(_)) => "Place two stones?",
Confirm::Pass(None) => "Place no stone and pass?",
Confirm::Pass(Some(_)) => "Place one stone and pass?",
Confirm::Claim(tentative, ..) => match tentative.len() {
Confirm::Claim(tentatives, ..) => match tentatives.len() {
// TODO: Inform the user if they're claiming a win for the opponent?
0 => "Claim a win?",
1 => "Place one stone and claim a win?",
Expand Down
26 changes: 13 additions & 13 deletions client/src/game_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub fn GameView(
#[prop(optional)] view_center: RwSignal<Point>,
#[prop(optional)] cursor_pos: RwSignal<Option<Point>>,
#[prop(optional)] phantom_pos: RwSignal<Option<Point>>,
#[prop(optional)] tentative_pos: RwSignal<ArrayVec<[Point; 2]>>,
#[prop(optional)] tentatives_pos: RwSignal<ArrayVec<[Point; 2]>>,
#[prop(optional)] win_claim: RwSignal<Option<WinClaim>>,
) -> impl IntoView {
let disabled = Memo::new(move |_| disabled());
Expand Down Expand Up @@ -268,7 +268,7 @@ pub fn GameView(
// are enough tentative stones, the move is automatically submitted.
let hit_cursor = move |cursor: Point| {
let phantom = phantom_pos.get();
let mut tentative = tentative_pos.get();
let mut tentatives = tentatives_pos.get();

if calc().board_to_view_pos(cursor).is_none() {
return;
Expand All @@ -292,7 +292,7 @@ pub fn GameView(

if record.write_untracked().with_temp_placements(
stone,
&tentative,
&tentatives,
|record| record.test_winning_row(p, dir).is_some(),
) {
WinClaim::Ready(p, dir)
Expand All @@ -316,18 +316,18 @@ pub fn GameView(
return;
}

if let Some(i) = tentative.iter().position(|&p| p == cursor) {
phantom_pos.set(Some(tentative.remove(i)));
tentative_pos.set(tentative);
if let Some(i) = tentatives.iter().position(|&p| p == cursor) {
phantom_pos.set(Some(tentatives.remove(i)));
tentatives_pos.set(tentatives);
} else if phantom == Some(cursor) {
phantom_pos.set(None);
tentative.push(cursor);
tentative_pos.set(tentative);
tentatives.push(cursor);
tentatives_pos.set(tentatives);

if tentative.len() == record.read().max_stones_to_play() {
if tentatives.len() == record.read().max_stones_to_play() {
on_event(Event::Submit);
}
} else if tentative.len() < record.read().max_stones_to_play() {
} else if tentatives.len() < record.read().max_stones_to_play() {
phantom_pos.set(Some(cursor));
}
};
Expand Down Expand Up @@ -884,7 +884,7 @@ pub fn GameView(
}

// Draw the tentative stones.
for p in tentative_pos
for p in tentatives_pos
.get_untracked()
.into_iter()
.filter_map(|p| calc.board_to_view_pos(p))
Expand Down Expand Up @@ -957,15 +957,15 @@ pub fn GameView(

// Clear phantom, tentatives and win claim if the record or the stone changed.
*phantom_pos.write_untracked() = None;
*tentative_pos.write_untracked() = ArrayVec::new();
*tentatives_pos.write_untracked() = ArrayVec::new();
*win_claim.write_untracked() = None;

changed.notify();
});

Effect::new(move || {
phantom_pos.track();
tentative_pos.track();
tentatives_pos.track();
win_claim.track();

changed.notify();
Expand Down
24 changes: 12 additions & 12 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn App() -> impl IntoView {
let record = RwSignal::new(Record::new());
let stone = RwSignal::new(None::<Stone>);

let tentative_pos = RwSignal::new(ArrayVec::new());
let tentatives_pos = RwSignal::new(ArrayVec::new());
let win_claim = RwSignal::new(None);

let game_id = RwSignal::new(String::new());
Expand Down Expand Up @@ -349,12 +349,12 @@ pub fn App() -> impl IntoView {
match ev {
Event::Menu => show_game_menu_dialog(),
Event::Submit => {
let tentative = tentative_pos.get();
let tentatives = tentatives_pos.get();
let claim = win_claim.get();
if online() {
confirm(match claim {
Some(WinClaim::Ready(p, dir)) => Confirm::Claim(tentative, p, dir),
_ => match tentative[..] {
Some(WinClaim::Ready(p, dir)) => Confirm::Claim(tentatives, p, dir),
_ => match tentatives[..] {
[] => Confirm::Pass(None),
[p] if record.read().has_past() => Confirm::Pass(Some(p)),
[p] => Confirm::Submit(p, None),
Expand All @@ -366,12 +366,12 @@ pub fn App() -> impl IntoView {
let mut record = record.write();

if let Some(WinClaim::Ready(p, dir)) = claim {
if !tentative.is_empty() {
record.make_move(Move::Place(tentative[0], tentative.get(1).copied()));
if !tentatives.is_empty() {
record.make_move(Move::Place(tentatives[0], tentatives.get(1).copied()));
}
record.make_move(Move::Win(p, dir));
} else {
record.make_move(match tentative[..] {
record.make_move(match tentatives[..] {
[] => Move::Pass,
[p] => Move::Place(p, None),
[p1, p2] => Move::Place(p1, Some(p2)),
Expand Down Expand Up @@ -532,11 +532,11 @@ pub fn App() -> impl IntoView {
Confirm::Submit(p1, p2) => send(ClientMessage::Place(p1, p2)),
Confirm::Pass(None) => send(ClientMessage::Pass),
Confirm::Pass(Some(p)) => send(ClientMessage::Place(p, None)),
Confirm::Claim(tentative, p, dir) => {
if !tentative.is_empty() {
Confirm::Claim(tentatives, p, dir) => {
if !tentatives.is_empty() {
send(ClientMessage::Place(
tentative[0],
tentative.get(1).copied(),
tentatives[0],
tentatives.get(1).copied(),
));
}
send(ClientMessage::ClaimWin(p, dir));
Expand Down Expand Up @@ -586,7 +586,7 @@ pub fn App() -> impl IntoView {
stone=stone.read_only()
disabled=move || !dialog_entries.read().is_empty()
on_event=on_event
tentative_pos=tentative_pos
tentatives_pos=tentatives_pos
win_claim=win_claim
/>
<For each=move || dialog_entries.get() key=|entry| entry.id let(DialogEntry { id, dialog })>
Expand Down

0 comments on commit 636153e

Please sign in to comment.