Skip to content

Commit

Permalink
improvements: various
Browse files Browse the repository at this point in the history
Make the linter (including clippy) happy, improve some text, and other things.
  • Loading branch information
wooster0 committed Oct 23, 2022
1 parent 1d6c962 commit 9852de2
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ As an alternative to the editor you can generate `.yaya` grids using [@AaronErha

## Command line arguments

The program takes a single number for a squared grid size, two numbers for a width and height or the filename of a `.yaya` grid file.
The program takes a single number for a squared grid size, two numbers for width and height, or the filename of a `.yaya` grid file to load a custom user-made grid.

```shell
yayagram # a random 5x5 grid
Expand Down
4 changes: 2 additions & 2 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Editor {
// but does the file for it still exist?
if !Path::new(&self.filename).exists() {
match self.new_writer(builder) {
Ok(writer) => (writer),
Ok(writer) => writer,
Err(err) => {
return Err(err);
}
Expand All @@ -144,7 +144,7 @@ impl Editor {
None => {
// This is the first time we are saving the grid
match self.new_writer(builder) {
Ok(writer) => (writer),
Ok(writer) => writer,
Err(err) => {
return Err(err);
}
Expand Down
5 changes: 3 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ pub fn r#loop(terminal: &mut Terminal, builder: &mut Builder) -> State {
State::Solved(_) => break state,
State::Exit(instant) => {
if let Some(instant) = instant {
if instant.elapsed().as_secs() > 60 {
// If the player played for more than 1 minute, the game is considered to have some kind of value to the player,
if instant.elapsed().as_secs() >= 30 {
// If the player stayed for half a minute,
// the game is considered to have some kind of value to the player,
// so we make sure the player really wants to exit.

let confirmed =
Expand Down
8 changes: 6 additions & 2 deletions src/event/input/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,12 @@ fn resize_grid(
// Temporarily set the builder grid size back to the old size to render the confirmation alert properly.
let new_grid_size = builder.grid.size;
builder.grid.size = original_grid_size;
let confirmed =
window::confirmation_prompt(terminal, builder, alert, "new random grid in this size");
let confirmed = window::confirmation_prompt(
terminal,
builder,
alert,
"load new random grid in this size",
);
builder.grid.size = new_grid_size;

if confirmed {
Expand Down
12 changes: 5 additions & 7 deletions src/event/input/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ pub fn await_fitting_size(
} else {
unreachable!()
};
let message = format!(
"Please increase window {} or decrease text size (Ctrl and -)",
length
);
let message =
format!("Please increase window {length} or decrease text size (Ctrl and -)");
terminal.write(&message);
terminal.flush();

Expand Down Expand Up @@ -157,7 +155,7 @@ pub fn await_dropped_grid_file_path(
Ok(path)
}

/// Draws an alert asking the user to confirm the given thing and returns whether the user confirmed the action.
/// Draws an alert asking the user to confirm the given verb and returns whether the user confirmed the action.
///
/// Despite the alert saying that Esc cancels, every other key apart from Enter will cancel as well.
///
Expand All @@ -166,9 +164,9 @@ pub fn confirmation_prompt(
terminal: &mut Terminal,
builder: &mut Builder,
alert: &mut Option<Alert>,
thing_to_confirm: &str,
verb_to_confirm: &str,
) -> bool {
let message = format!("Press Enter to confirm {}. Esc to cancel", thing_to_confirm).into();
let message = format!("Press Enter to {}; Esc to cancel", verb_to_confirm).into();
alert::draw(terminal, builder, alert, message);

// We could also just ignore `Event::Mouse(_)` in the loop below but disabling mouse capture changes the pointer icon
Expand Down
2 changes: 1 addition & 1 deletion src/grid/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl Builder {
// In the future it might be helpful to take a look at the market share of Windows 10 or 11 and decide by that.
//
// In this regard, for good Windows terminal compatibility,
// I generally recommend limiting yourself to characters listed on https://en.wikipedia.org/wiki/Code_page_437
// I generally recommend sticking to the characters listed on https://en.wikipedia.org/wiki/Code_page_437
#[cfg(windows)]
terminal.write(" +");
}
Expand Down
6 changes: 3 additions & 3 deletions src/grid/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use terminal::{
Terminal,
};

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Cell {
/// An umarked cell.
Empty,
Expand All @@ -29,7 +29,7 @@ impl Default for Cell {

impl From<bool> for Cell {
fn from(filled: bool) -> Self {
filled.then(|| Cell::Filled).unwrap_or_default()
filled.then_some(Cell::Filled).unwrap_or_default()
}
}

Expand Down Expand Up @@ -317,7 +317,7 @@ impl CellPlacement {
} else {
self.measurement_point = Some(selected_cell_point);

State::Alert("Set second measurement point".into())
State::Alert("Press X to set second measurement point".into())
}
} else {
State::Continue
Expand Down
18 changes: 9 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ use terminal::{
Terminal,
};

// Things that could be implemented but might not be worth it:
// -A main menu
// -An interactive tutorial
// -Currently whole clue rows are grayed out once all cells for those clues have been solved
// Wishlist:
// - A main menu
// - An interactive tutorial
// - Currently whole clue rows are grayed out once all cells for those clues have been solved
// Make them gray out individually. (Maybe itertools' `pad_using` is helpful)
// -Ability to save records to a file and determine new records with that
// -Ability to continue after solving the puzzle/ability to play it again
// - Ability to save records to a file and determine new records with that
// - Ability to continue after solving the puzzle/ability to play it again

fn main() {
let code = match run() {
Ok(()) => 0,
Err(err) => {
eprintln!("{}", err);
eprintln!("{err}");
1
}
};
Expand All @@ -42,15 +42,15 @@ fn run() -> Result<(), Cow<'static, str>> {
Ok(Some(args::Arg::Help)) => {
println!(concat!(
"Play nonograms/picross in your terminal.\n",
"For the arguments please check <https://github.com/r00ster91/yayagram#command-line-arguments>."
"For command line arguments please visit <https://github.com/r00ster91/yayagram#command-line-arguments>."
));

return Ok(());
}
Ok(Some(args::Arg::Version)) => {
let version = env!("CARGO_PKG_VERSION");

println!("{}", version);
println!("{version}");

return Ok(());
}
Expand Down

0 comments on commit 9852de2

Please sign in to comment.