Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mix #8

Merged
merged 12 commits into from
Sep 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: various
Jeromos Kovacs committed Sep 28, 2024
commit 5d20f0d3ffbaa26ff1e060f567289c99899ce4d9
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
.cgoltui.log
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -12,4 +12,6 @@ categories = ["games"]

[dependencies]
fastrand = "2.1.1"
fern = "0.6.2"
log = "0.4.22"
ratatui = "0.28.1"
32 changes: 13 additions & 19 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
use crate::{shapes, Universe, DEF_DUR};
use ratatui::crossterm::terminal;
use crate::{shapes, Area, Universe, DEF_DUR};
use std::time::Duration;

pub struct App {
pub universe: Universe,
pub i: usize,
pub poll_t: Duration,
pub paused: bool,
pub wh: (u16, u16),
pub area: Area,
}
impl Default for App {
fn default() -> Self {
let i = 0;
let wh = terminal::size().expect("couldn't get terminal size");
App {
wh,
universe: shapes::get(wh, i).unwrap(),
i,
area: Area::default(),
universe: Universe::default(),
i: 0,
poll_t: DEF_DUR,
paused: false,
}
}
}
impl App {
pub fn new(wh: u16) -> Self {
pub fn new(area: Area) -> Self {
let i = 0;
App {
wh,
universe: shapes::get(wh, i).unwrap(),
area,
universe: shapes::get(area, i).unwrap(),
i,
poll_t: DEF_DUR,
paused: false,
@@ -36,10 +33,6 @@ impl App {
// pub fn render_universe(&self) {
// println!("{}", self.universe);
// }
pub fn set_wh(&mut self) {
let wh = size().expect("couldn't get terminal size");
self.wh = (wh.1 + 10) * 3;
}

pub fn play_pause(&mut self, prev_poll_t: &mut Duration) {
if self.paused {
@@ -51,8 +44,9 @@ impl App {
self.paused = !self.paused;
}
pub fn restart(&mut self) {
self.universe =
shapes::get(self.wh, self.i).expect("display area is too small to fit current shape");
self.universe = shapes::get(self.area, self.i)
.inspect_err(|e| log::error!("{e:?}"))
.expect("display area is too small to fit current shape");
}

pub fn tick(&mut self) {
@@ -84,7 +78,7 @@ impl App {
} else {
self.i += 1;
}
if let Ok(shape) = shapes::get(self.wh, self.i) {
if let Ok(shape) = shapes::get(self.area, self.i) {
self.universe = shape;
} else {
eprintln!("couldn't switch to next shape");
@@ -96,7 +90,7 @@ impl App {
} else {
self.i = shapes::N as usize - 1;
}
if let Ok(shape) = shapes::get(self.wh, self.i) {
if let Ok(shape) = shapes::get(self.area, self.i) {
self.universe = shape;
} else {
eprintln!("couldn't switch to previous shape");
Loading