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

Refactors #14

Merged
merged 18 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
40 changes: 19 additions & 21 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Rust

on:
push:
branches: [ "dev" ]
branches: ["dev"]
pull_request:
branches: [ "dev" ]
branches: ["dev"]

env:
CARGO_TERM_COLOR: always
Expand All @@ -14,28 +14,26 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: macos-latest
target: aarch64-apple-darwin
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: windows-latest
target: x86_64-pc-windows-msvc
os: [macos-latest, ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2

- name: Build in release mode
run: cargo build --release --verbose

steps:
- uses: actions/checkout@v4
- uses: swatinem/rust-cache@v2
- name: Run tests
run: cargo test --verbose

- name: Build in release mode
run: cargo build --release --target ${{ matrix.target }} --verbose
- name: Run cargo fmt
run: cargo fmt --all --check

- name: Run tests
run: cargo test --target ${{ matrix.target }} --verbose
- name: Run cargo clippy
run: cargo clippy --all-targets

- name: Upload executable
uses: actions/upload-artifact@v4
with:
name: tuna-man_${{ matrix.os }}
path: target/${{ matrix.target }}/release/tuna-man*
- name: Upload executable
uses: actions/upload-artifact@v4
with:
name: tuna-man_${{ matrix.os }}
path: target/release/tuna-man*
2 changes: 1 addition & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
name = "tuna-man"
version = "0.1.0"
version = "0.2.1"
edition = "2021"
license = "GPL-3.0-or-later"
description = "No-bullshit, lightweight, Tournament Manager with a cli."
# documentation = "https://docs.rs/tuna-man"
repository = "https://codeberg.org/jark/tuna-man"
authors = ["Jeromos Kovács <iitsnotme214@proton.me>"]

[dependencies]
clap = { version = "4.5.21", features = ["derive"] }
Expand Down
1 change: 1 addition & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::tournament::format;
use std::path::PathBuf;

#[derive(clap::Parser, Clone, Debug, PartialEq, Eq)]
#[command(version, about, long_about)]
pub struct Args {
/// Path to file with participants: '<player/team>,<class>' syntax, where <class> is optional
pub file: PathBuf,
Expand Down
32 changes: 6 additions & 26 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use args::Args;
use clap::Parser;
use tournament::{backend, format, Tournament};
use tournament::{format, Tournament};

/// argument parsing
mod args;
Expand All @@ -9,41 +9,21 @@ mod tournament;

fn main() -> std::io::Result<()> {
let args = Args::parse();
// let format: Box<dyn format::Format<backend::Cli>> = match args.format {
// format::Supported::SingleElemination => Box::new(format::SingleElemination::default()),
// format::Supported::DoubleElemination => Box::new(format::DoubleElemination::default()),
// format::Supported::RoundRobin => todo!(),
// format::Supported::SwissSystem => todo!(),
// };
// new tournament, communicate with the user via the cli
let backend = backend::Cli;
// let format = args.format.to_format();
match args.format {
format::Supported::SingleElemination => {
Tournament::new(backend, format::SingleElemination::default())
.players_from_path(&args.file)?
.run(args);
Tournament::new(format::SingleElemination::default()).execute(args)
}
format::Supported::DoubleElemination => {
Tournament::new(backend, format::DoubleElemination::default())
.players_from_path(&args.file)?
.run(args);
Tournament::new(format::DoubleElemination::default()).execute(args)
}
format::Supported::RoundRobin => {
Tournament::new(backend, format::RoundRobin::default())
.players_from_path(&args.file)?
.run(args);
Tournament::new(format::RoundRobin::default()).execute(args)
}
format::Supported::SwissSystem => {
Tournament::new(backend, format::SwissSystem::default())
.players_from_path(&args.file)?
.run(args);
Tournament::new(format::SwissSystem::default()).execute(args)
}
}
// let mut tournament = Tournament::new(backend::Cli, format).players_from_path(args.file)?;

// players.save();

Ok(())

// TODO: ratatui ui
// let mut terminal = ratatui::try_init()?;
Expand Down
58 changes: 18 additions & 40 deletions src/tournament.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use backend::Backend;
use format::Format;
use players::Players;
use std::path::Path;

/// how we interact with the user
pub mod backend;
/// # the format of the tournament
///
/// ## available formats:
Expand All @@ -23,20 +20,19 @@ pub mod tests;

/// The whole [`Tournament`] with all the [`Players`] and [`Duel`]s
#[derive(Clone, Debug, PartialEq, Eq, Default)]
pub struct Tournament<B: Backend, F: Format<B>> {
pub struct Tournament<F: Format> {
format: F,
/// the [`backend::Backend`] to use
_backend: B,
}

impl<B: Backend, F: Format<B>> Tournament<B, F> {
// pub fn with_tables(self, tables: &[Table]) -> Self {
// Self {
// tables: tables.into(),
// ..self
// }
// }

impl<F: Format> Tournament<F> {
pub fn new(format: F) -> Self {
Self { format }
}
/// execute the Tournament with options from `args`
pub fn execute(self, args: crate::args::Args) -> std::io::Result<()> {
self.players_from_path(&args.file)?.run(args);
Ok(())
}
/// run the whole Tournament
pub fn run(mut self, args: crate::args::Args) {
let no_shuffle = args.shuffle.never() || args.shuffle.initially();
Expand All @@ -51,13 +47,13 @@ impl<B: Backend, F: Format<B>> Tournament<B, F> {
while !self.is_end() {
// winner branch duels this round
println!("\n\n\n\nRound {round}.\n");
self.print_status();
self.format.print_status();
self.play_next_round(no_shuffle);

round += 1;
}

let mut knocked = self.results();
let mut knocked = self.format.results();
// printing results
println!("\nTournament ended in {round} rounds, Results:");
println!("\n\nPODIUM\n------\n");
Expand All @@ -69,20 +65,6 @@ impl<B: Backend, F: Format<B>> Tournament<B, F> {
println!("{}. place: {player}", place + 4);
}
}
/// print the current status
pub fn print_status(&self) {
self.format.print_status();
}
pub fn new(backend: B, format: F) -> Self {
Self {
_backend: backend,
format,
}
}
/// results in reversed order
pub fn results(self) -> Players {
self.format.results()
}
/// `self` but with `players`
pub fn with_players(mut self, players: Players) -> Self {
assert!(
Expand All @@ -104,32 +86,28 @@ impl<B: Backend, F: Format<B>> Tournament<B, F> {
}
/// play the next round
pub fn play_next_round(&mut self, standard: bool) {
B::play_round(self, standard);
self.format.play_round(standard);
}
// pub fn execute(
// &mut self,
// term: &mut ratatui::Terminal<impl ratatui::backend::Backend>,
// ) -> std::io::Result<()> {
// todo!("app logic");
// loop {
// term.draw(|f| self.ui(f))?;

// if let Event::Key(key) = event::read()? {
// if key.kind != KeyEventKind::Press {
// continue;
// }
// match key.code {
// KeyCode::Char('q') | KeyCode::Esc => break,
// KeyCode::Char('j') | KeyCode::Down => todo!(),
// KeyCode::Char('k') | KeyCode::Up => todo!(),
// KeyCode::Char('r') => todo!(),
// KeyCode::Char('n') | KeyCode::Char('l') | KeyCode::Right => todo!(),
// KeyCode::Char('p') | KeyCode::Char('h') | KeyCode::Left => todo!(),
// KeyCode::Char('R') | KeyCode::Backspace => todo!(),
// KeyCode::Char('r') => restart(),
// KeyCode::Char('l') | KeyCode::Right => cursor.right(),
// KeyCode::Char('h') | KeyCode::Left => cursor.left(),
// KeyCode::Char('j') | KeyCode::Down => cursor.down(),
// KeyCode::Char('k') | KeyCode::Up => cursor.up(),
// _ => {}
// }
// } else {
// // resize and restart
// }
// }
// Ok(())
Expand Down
57 changes: 0 additions & 57 deletions src/tournament/backend.rs

This file was deleted.

Loading