Skip to content
Closed
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
569 changes: 193 additions & 376 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions kanash-components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ keywords = ["ratatui", "learning", "japanese", "TUI"]
rand = "0.9.0"
wana_kana = "4.0.0"
tui-rain = { git = "https://github.com/SuperJappie08/tui-rain.git", branch = "ratatui-0.30.0" }
rascii_art = "0.4.5"

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.3", features = ["wasm_js"] }
getrandom = { version = "0.4", features = ["wasm_js"] }
ratzilla = "0.3.0"
web-time = "1.1.0"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ratatui = "0.30.0"
ansi-to-tui = "8.0.1"
80 changes: 0 additions & 80 deletions kanash-components/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
use super::{home::HomeModel, kana::KanaModel, *};
use crate::helper::rain;

#[cfg(not(target_arch = "wasm32"))]
use ansi_to_tui::IntoText;
#[cfg(not(target_arch = "wasm32"))]
use rascii_art::{render_to, RenderOptions};

#[cfg(not(target_arch = "wasm32"))]
use ratatui::text::Text;
#[cfg(target_arch = "wasm32")]
use ratzilla::ratatui::text::Text;

#[derive(Debug, PartialEq, Eq)]
enum AppPage {
Home(HomeModel),
Expand All @@ -20,13 +10,9 @@ enum AppPage {
#[derive(Debug, PartialEq, Eq)]
pub struct App {
pub exit: bool,
background_widget: Box<Text<'static>>,
page: AppPage,
previous_height: u16,
disable_rain: bool,
pub disable_background: bool,
background_number: usize,
pub background_paths: Vec<String>,
}

impl Components for App {
Expand All @@ -36,12 +22,8 @@ impl Components for App {
Self {
exit: false,
page: AppPage::Home(home),
background_widget: Box::new(Text::default()),
previous_height: 0,
disable_rain: false,
disable_background: false,
background_paths: vec![],
background_number: 0,
}
}

Expand All @@ -66,32 +48,6 @@ impl Components for App {
return None;
}

if msg == Message::Home(HomeMessage::Background) {
match h.background_state {
BackgroundMode::Cycle => {
self.background_number += 1;
self.previous_height = 0;

if self.background_number + 1 == self.background_paths.len() {
h.key_helper_state = BackgroundMode::Disable
}

if self.background_number >= self.background_paths.len() {
self.disable_background = true;
self.background_number = 0;
h.background_state = BackgroundMode::Disable;
h.key_helper_state = BackgroundMode::Cycle;
}
}
BackgroundMode::Disable => {
h.background_state = BackgroundMode::Cycle;
self.disable_background = false;
}
}

return None;
}

if msg == Message::Home(HomeMessage::Up) || msg == Message::Home(HomeMessage::Down)
{
let response = h.update(msg.clone());
Expand Down Expand Up @@ -126,11 +82,6 @@ impl Components for App {
}

fn view(&mut self, frame: &mut Frame, elapsed: Duration) {
#[cfg(not(target_arch = "wasm32"))]
if !self.disable_background {
self.background(frame);
}

if !self.disable_rain {
rain::view(frame, elapsed);
}
Expand All @@ -141,34 +92,3 @@ impl Components for App {
}
}
}

#[cfg(not(target_arch = "wasm32"))]
impl App {
fn background(&mut self, frame: &mut Frame) {
let actual_height = frame.area().height;
if self.previous_height != actual_height {
self.write_background(actual_height.into());
self.previous_height = actual_height;
}

frame.render_widget((*self.background_widget).clone(), frame.area());
}

fn write_background(&mut self, height: u32) {
// needed because otherwise the render_to function take a while to overwrite the previous string
let mut buffer = String::new();

if !self.background_paths.is_empty() {
render_to(
self.background_paths[self.background_number].clone(),
&mut buffer,
&RenderOptions::new().height(height).colored(true),
)
.unwrap();
} else {
buffer = String::from("No asset directory")
}

self.background_widget = Box::new(buffer.into_text().unwrap().centered());
}
}
4 changes: 0 additions & 4 deletions kanash-components/src/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub enum BackgroundMode {
pub struct HomeModel {
page_list: Vec<String>,
state: ListState,
pub background_state: BackgroundMode,
pub key_helper_state: BackgroundMode,
}

Expand All @@ -39,7 +38,6 @@ pub enum HomeMessage {
Down,

RainFx,
Background,
}

impl Components for HomeModel {
Expand All @@ -54,7 +52,6 @@ impl Components for HomeModel {
"Learn Both".into(),
],
state: init_state,
background_state: BackgroundMode::Cycle,
key_helper_state: BackgroundMode::Cycle,
}
}
Expand All @@ -78,7 +75,6 @@ impl Components for HomeModel {
KeyCode::Char('j') | KeyCode::Down => Some(Message::Home(HomeMessage::Down)),
KeyCode::Char('k') | KeyCode::Up => Some(Message::Home(HomeMessage::Up)),
KeyCode::Char('x') => Some(Message::Home(HomeMessage::RainFx)),
KeyCode::Char('b') => Some(Message::Home(HomeMessage::Background)),
_ => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion kanash-components/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub use ratzilla::{event::KeyCode, web_sys::console};

use std::time::Duration;

use home::{BackgroundMode, HomeMessage, Mode};
use home::{HomeMessage, Mode};
use kana::KanaMessage;

pub struct ColorPalette;
Expand Down
1 change: 0 additions & 1 deletion kanash-ratzilla/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ kanash-components = { path = "../kanash-components/" }
ratzilla = "0.3.0"
tachyonfx = { version = "0.23.0", default-features = false, features = ["wasm"] }
tui-big-text = "0.8.1"
wasm-bindgen = "0.2.105"
web-time = "1.1.0"

[dev-dependencies]
Expand Down
4 changes: 0 additions & 4 deletions kanash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ keywords = ["ratatui", "learning", "japanese", "TUI"]
[dependencies]
kanash-components = { path = "../kanash-components/", version = "0.1.6" }
ratatui = "0.30.0"
wana_kana = "4.0.0"
tachyonfx = "0.23.0"
tui-big-text = "0.8.1"
ansi-to-tui = "8.0.1"
rascii_art = "0.4.5"
clap = { version = "4.5.56", features = ["derive"] }

[dev-dependencies]
crossterm = "0.29.0"
19 changes: 0 additions & 19 deletions kanash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,7 @@ use std::time::{Duration, Instant};
use tachyonfx::{fx, EffectRenderer, Interpolation};
use tui_big_text::{BigText, PixelSize};

use clap::Parser;

#[derive(Parser, Debug)]
struct Args {
/// Path to the assets directory
#[arg(short, long)]
path: Option<String>,
}

fn main() {
let arg = Args::parse();

let mut terminal = ratatui::init();

let mut fade_effect = fx::dissolve((20000, Interpolation::QuadOut));
Expand Down Expand Up @@ -60,7 +49,6 @@ fn main() {
.areas(bottom);

frame.render_widget(p, area);
// crate::components::helper::image::view(frame, "./assets/rezo.png".to_string(), img_area);
frame.render_widget(credit, img_area);
if start_time.elapsed() > Duration::from_secs(1) {
frame.render_effect(&mut fade_effect, area, tachyonfx::Duration::from_millis(33));
Expand All @@ -69,13 +57,6 @@ fn main() {
}

let mut app = App::new();
if let Some(path) = arg.path {
let assets = std::fs::read_dir(path)
.unwrap()
.map(|entry| entry.unwrap().path().to_str().unwrap().to_string())
.collect::<Vec<_>>();
app.background_paths = assets;
}

// Main app rendering
while !app.exit {
Expand Down
Loading