From 39d9b949e9e8013d46f11bf541819fbf81b2f88c Mon Sep 17 00:00:00 2001 From: FantasyPvP <80643031+FantasyPvP@users.noreply.github.com> Date: Sat, 23 Nov 2024 21:34:54 +0000 Subject: [PATCH] reorganised some stuff and started coding another game --- src/lib.rs | 1 - src/system/kernel/render.rs | 2 +- src/user/bin/{ => apps}/calc/calc.rs | 0 src/user/bin/{ => apps}/calc/functions.rs | 0 src/user/bin/apps/calc/mod.rs | 4 + src/user/bin/{ => apps}/editor.rs | 0 src/user/bin/{ => apps}/grapher.rs | 0 src/user/bin/apps/mod.rs | 4 + src/user/bin/{ => apps}/tasks.rs | 0 src/user/bin/calc/mod.rs | 5 - src/user/bin/games/crystalrpg/effect.rs | 25 ++ src/user/bin/games/crystalrpg/game.rs | 10 + src/user/bin/games/crystalrpg/items/armour.rs | 23 ++ src/user/bin/games/crystalrpg/items/mod.rs | 12 + .../bin/games/crystalrpg/items/potions.rs | 0 .../bin/games/crystalrpg/items/weapons.rs | 0 src/user/bin/games/crystalrpg/map.rs | 10 + src/user/bin/games/crystalrpg/mod.rs | 8 +- src/user/bin/games/crystalrpg/player.rs | 43 +++ src/user/bin/games/mod.rs | 3 +- src/user/bin/games/{paper_rs => }/paper.rs | 6 +- src/user/bin/games/paper_rs/mod.rs | 4 - src/user/bin/games/pong.rs | 5 +- src/user/bin/{ => games}/tetris.rs | 0 src/user/bin/mod.rs | 17 +- src/user/bin/shell.rs | 122 ++++---- src/user/bin/shellrewrite.rs | 274 +++++++++--------- src/user/bin/{ => utils}/crystalfetch.rs | 4 +- src/user/bin/{ => utils}/gigachad_detector.rs | 0 src/user/bin/utils/mod.rs | 3 + src/user/bin/{ => utils}/rickroll.rs | 0 31 files changed, 350 insertions(+), 235 deletions(-) rename src/user/bin/{ => apps}/calc/calc.rs (100%) rename src/user/bin/{ => apps}/calc/functions.rs (100%) create mode 100644 src/user/bin/apps/calc/mod.rs rename src/user/bin/{ => apps}/editor.rs (100%) rename src/user/bin/{ => apps}/grapher.rs (100%) create mode 100644 src/user/bin/apps/mod.rs rename src/user/bin/{ => apps}/tasks.rs (100%) delete mode 100644 src/user/bin/calc/mod.rs create mode 100644 src/user/bin/games/crystalrpg/effect.rs create mode 100644 src/user/bin/games/crystalrpg/game.rs create mode 100644 src/user/bin/games/crystalrpg/items/armour.rs create mode 100644 src/user/bin/games/crystalrpg/items/mod.rs create mode 100644 src/user/bin/games/crystalrpg/items/potions.rs create mode 100644 src/user/bin/games/crystalrpg/items/weapons.rs create mode 100644 src/user/bin/games/crystalrpg/map.rs create mode 100644 src/user/bin/games/crystalrpg/player.rs rename src/user/bin/games/{paper_rs => }/paper.rs (98%) delete mode 100644 src/user/bin/games/paper_rs/mod.rs rename src/user/bin/{ => games}/tetris.rs (100%) rename src/user/bin/{ => utils}/crystalfetch.rs (96%) rename src/user/bin/{ => utils}/gigachad_detector.rs (100%) create mode 100644 src/user/bin/utils/mod.rs rename src/user/bin/{ => utils}/rickroll.rs (100%) diff --git a/src/lib.rs b/src/lib.rs index 3633e6e..0a317d8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,6 @@ pub mod system; pub mod user; pub use system::std as std; pub use user::bin::*; -use crate::calc::Calculator; #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/src/system/kernel/render.rs b/src/system/kernel/render.rs index a4eb726..a2b9fdd 100644 --- a/src/system/kernel/render.rs +++ b/src/system/kernel/render.rs @@ -306,8 +306,8 @@ impl Renderer { self.screen_ref.chars[i][j].write(*col); } } + self.internal_set_cursor_position(self.col_pos as u8, BUFFER_HEIGHT as u8 - 1); } - self.internal_set_cursor_position(self.col_pos as u8, BUFFER_HEIGHT as u8 - 1); } } diff --git a/src/user/bin/calc/calc.rs b/src/user/bin/apps/calc/calc.rs similarity index 100% rename from src/user/bin/calc/calc.rs rename to src/user/bin/apps/calc/calc.rs diff --git a/src/user/bin/calc/functions.rs b/src/user/bin/apps/calc/functions.rs similarity index 100% rename from src/user/bin/calc/functions.rs rename to src/user/bin/apps/calc/functions.rs diff --git a/src/user/bin/apps/calc/mod.rs b/src/user/bin/apps/calc/mod.rs new file mode 100644 index 0000000..32471fa --- /dev/null +++ b/src/user/bin/apps/calc/mod.rs @@ -0,0 +1,4 @@ +mod functions; +mod calc; + +pub use calc::Calculator; \ No newline at end of file diff --git a/src/user/bin/editor.rs b/src/user/bin/apps/editor.rs similarity index 100% rename from src/user/bin/editor.rs rename to src/user/bin/apps/editor.rs diff --git a/src/user/bin/grapher.rs b/src/user/bin/apps/grapher.rs similarity index 100% rename from src/user/bin/grapher.rs rename to src/user/bin/apps/grapher.rs diff --git a/src/user/bin/apps/mod.rs b/src/user/bin/apps/mod.rs new file mode 100644 index 0000000..dd51267 --- /dev/null +++ b/src/user/bin/apps/mod.rs @@ -0,0 +1,4 @@ +pub mod calc; +pub mod editor; +pub mod grapher; +pub mod tasks; \ No newline at end of file diff --git a/src/user/bin/tasks.rs b/src/user/bin/apps/tasks.rs similarity index 100% rename from src/user/bin/tasks.rs rename to src/user/bin/apps/tasks.rs diff --git a/src/user/bin/calc/mod.rs b/src/user/bin/calc/mod.rs deleted file mode 100644 index 488441b..0000000 --- a/src/user/bin/calc/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -//pub mod calc; -mod functions; -pub mod calc; - -pub use calc::*; diff --git a/src/user/bin/games/crystalrpg/effect.rs b/src/user/bin/games/crystalrpg/effect.rs new file mode 100644 index 0000000..97b1b14 --- /dev/null +++ b/src/user/bin/games/crystalrpg/effect.rs @@ -0,0 +1,25 @@ +pub struct Effect { + pub EffectType: EffectType, + pub potency: i32, + pub duration: Option, +} + +pub enum EffectType { + Poison, + Regeneration, + + Harming, + Healing, + + Speed, + Slowness, + Stunned, + Confused, + + Strength, + Weakness, + + OnFire, + + Invisible, +} \ No newline at end of file diff --git a/src/user/bin/games/crystalrpg/game.rs b/src/user/bin/games/crystalrpg/game.rs new file mode 100644 index 0000000..8970d0f --- /dev/null +++ b/src/user/bin/games/crystalrpg/game.rs @@ -0,0 +1,10 @@ +use hashbrown::HashMap; + +use crate::user::lib::geometry::Position; +use super::{map::Map, player::Player}; + +pub struct Game { + pub score: u32, + pub player: Player, + pub map: Map, +} \ No newline at end of file diff --git a/src/user/bin/games/crystalrpg/items/armour.rs b/src/user/bin/games/crystalrpg/items/armour.rs new file mode 100644 index 0000000..bb9bab2 --- /dev/null +++ b/src/user/bin/games/crystalrpg/items/armour.rs @@ -0,0 +1,23 @@ +pub struct Helmet { + name: &'static str, + lore: &'static str, + stats: ArmourStats, +} + +pub struct Chestplate { + name: &'static str, + lore: &'static str, + stats: ArmourStats, +} + +pub struct Boots { + name: &'static str, + lore: &'static str, + stats: ArmourStats, +} + +pub struct ArmourStats { + defence: i32, + health_bonus: i32, + mana_bonus: i32, +} diff --git a/src/user/bin/games/crystalrpg/items/mod.rs b/src/user/bin/games/crystalrpg/items/mod.rs new file mode 100644 index 0000000..370eea5 --- /dev/null +++ b/src/user/bin/games/crystalrpg/items/mod.rs @@ -0,0 +1,12 @@ + +pub trait Item { + fn name(&self) -> &str; + fn description(&self) -> &str; + + fn sell_price(&self) -> i32; + fn buy_price(&self) -> i32; +} + +pub mod armour; +pub mod weapons; +pub mod potions; diff --git a/src/user/bin/games/crystalrpg/items/potions.rs b/src/user/bin/games/crystalrpg/items/potions.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/user/bin/games/crystalrpg/items/weapons.rs b/src/user/bin/games/crystalrpg/items/weapons.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/user/bin/games/crystalrpg/map.rs b/src/user/bin/games/crystalrpg/map.rs new file mode 100644 index 0000000..3e0068e --- /dev/null +++ b/src/user/bin/games/crystalrpg/map.rs @@ -0,0 +1,10 @@ +use hashbrown::HashMap; + +pub struct Map { + tiles: HashMap<(i32, i32), Tile> +} + +pub enum Tile { + Empty, + Wall, +} \ No newline at end of file diff --git a/src/user/bin/games/crystalrpg/mod.rs b/src/user/bin/games/crystalrpg/mod.rs index 6f6ff5b..bf434cd 100644 --- a/src/user/bin/games/crystalrpg/mod.rs +++ b/src/user/bin/games/crystalrpg/mod.rs @@ -1 +1,7 @@ -mod entity; \ No newline at end of file +mod entity; +mod player; +mod map; +mod effect; +mod items; + +pub mod game; diff --git a/src/user/bin/games/crystalrpg/player.rs b/src/user/bin/games/crystalrpg/player.rs new file mode 100644 index 0000000..7f13198 --- /dev/null +++ b/src/user/bin/games/crystalrpg/player.rs @@ -0,0 +1,43 @@ +use alloc::{boxed::Box, string::String, vec::Vec}; + +use super::{effect::Effect, items::{armour::{Boots, Chestplate, Helmet}, Item}}; + +pub struct Player { + pub name: String, + + pub health: f64, + pub max_health: f64, + + pub mana: f64, + pub max_mana: f64, + + pub defence: f64, + pub agility: f64, + + pub stamina: f64, + pub max_stamina: f64, + + pub level: f64, + pub experience: f64, + pub skill_points: f64, + + pub helmet: Option, + pub chestplate: Option, + pub boots: Option, + + pub inventory: [Box; 20], + + pub effects: Vec, +} + +impl Player { + const BASE_MAX_HEALTH: f64 = 100.0; + const BASE_MAX_MANA: f64 = 100.0; + const BASE_MAX_STAMINA: f64 = 100.0; + + const BASE_DAMAGE: f64 = 0.0; + const BASE_DEFENCE: f64 = 0.0; + const BASE_AGILITY: f64 = 0.0; + + const BASE_LEVEL : f64 = 1.0; +} \ No newline at end of file diff --git a/src/user/bin/games/mod.rs b/src/user/bin/games/mod.rs index 784b6f9..bbb4b23 100644 --- a/src/user/bin/games/mod.rs +++ b/src/user/bin/games/mod.rs @@ -3,4 +3,5 @@ pub mod gameoflife; pub mod crystalrpg; pub mod pong; pub mod snake; -pub mod paper_rs; \ No newline at end of file +pub mod paper; +pub mod tetris; \ No newline at end of file diff --git a/src/user/bin/games/paper_rs/paper.rs b/src/user/bin/games/paper.rs similarity index 98% rename from src/user/bin/games/paper_rs/paper.rs rename to src/user/bin/games/paper.rs index 2ee35e0..9752af1 100644 --- a/src/user/bin/games/paper_rs/paper.rs +++ b/src/user/bin/games/paper.rs @@ -1,9 +1,9 @@ use core::any::Any; -use alloc::{boxed::Box, format, string::String, vec::Vec, vec}; +use alloc::{boxed::Box, format, string::String, vec::Vec}; use async_trait::async_trait; -use crate::{std::{self, application::{Application, Error}, io::{Color, ColorCode, Display, KeyStroke, Stdin}, render::{ColouredChar, Dimensions, Frame, Position, RenderError}, time}, user::{bin::games::asteroids::Game, lib::libgui::cg_core::CgComponent}}; +use crate::{std::{self, application::{Application, Error}, io::{Color, ColorCode, Display, KeyStroke, Stdin}, render::{ColouredChar, Dimensions, Frame, Position, RenderError}, time}, user::lib::libgui::cg_core::CgComponent}; #[derive(Copy, Clone)] @@ -48,7 +48,7 @@ impl Application for GameBoard { } } - async fn run(&mut self, args: Vec) -> Result<(), Error> { + async fn run(&mut self, _args: Vec) -> Result<(), Error> { let _display = Display::borrow(); 'outer: loop { diff --git a/src/user/bin/games/paper_rs/mod.rs b/src/user/bin/games/paper_rs/mod.rs deleted file mode 100644 index dc79c47..0000000 --- a/src/user/bin/games/paper_rs/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -/// this game is basically a ripoff of paper.io -pub mod paper; - -pub use paper::GameBoard; \ No newline at end of file diff --git a/src/user/bin/games/pong.rs b/src/user/bin/games/pong.rs index 7f1345a..d5d3a54 100644 --- a/src/user/bin/games/pong.rs +++ b/src/user/bin/games/pong.rs @@ -4,7 +4,6 @@ use alloc::vec::Vec; use core::any::Any; use async_trait::async_trait; use crate::std::application::{Application, Error}; -use crate::std; use crate::std::render::{BUFFER_HEIGHT, BUFFER_WIDTH, ColorCode, ColouredChar, Dimensions, Frame, Position, RenderError}; use crate::std::io::{Color, Display, KeyStroke, Stdin}; use crate::std::time::Timer; @@ -27,7 +26,7 @@ impl Application for Game { } async fn run(&mut self, _: Vec) -> Result<(), Error> { - let d = Display::borrow(); + let _d = Display::borrow(); let mut update_time = Timer::new(0.1); @@ -124,7 +123,7 @@ impl CgComponent for Game { fn render(&self) -> Result { let mut frame = Frame::new(Dimensions::new(0, 0), Dimensions::new(80, 25))?; - for y in (0..5) { + for y in 0..5 { frame.write(Position::new(self.player1.pos.x, self.player1.pos.y + y -2), ColouredChar::coloured('▓', ColorCode::new(Color::Cyan, Color::Black))).unwrap(); frame.write(Position::new(self.player2.pos.x, self.player2.pos.y + y -2), ColouredChar::coloured('▓', ColorCode::new(Color::Cyan, Color::Black))).unwrap(); } diff --git a/src/user/bin/tetris.rs b/src/user/bin/games/tetris.rs similarity index 100% rename from src/user/bin/tetris.rs rename to src/user/bin/games/tetris.rs diff --git a/src/user/bin/mod.rs b/src/user/bin/mod.rs index 4dbb3b8..20c0d95 100644 --- a/src/user/bin/mod.rs +++ b/src/user/bin/mod.rs @@ -1,14 +1,5 @@ - -pub mod calc; -pub mod crystalfetch; -pub mod rickroll; +pub mod apps; +pub mod games; +pub mod utils; pub mod shell; -pub mod tasks; -pub mod editor; -mod gigachad_detector; - -//mod shellrewrite; - -mod grapher; - -mod games; \ No newline at end of file +pub mod shellrewrite; \ No newline at end of file diff --git a/src/user/bin/shell.rs b/src/user/bin/shell.rs index 5a216ce..a11f0b9 100644 --- a/src/user/bin/shell.rs +++ b/src/user/bin/shell.rs @@ -1,30 +1,56 @@ +// External crates use lazy_static::lazy_static; use spin::Mutex; +use vga::{ + writers::{PrimitiveDrawing, GraphicsWriter, Graphics640x480x16}, + colors::Color16, +}; -use alloc::{boxed::Box, format, string::{String, ToString}, vec, vec::Vec}; -use vga::writers::{PrimitiveDrawing}; +// Standard library +use alloc::{ + boxed::Box, + format, + string::{String, ToString}, + vec, + vec::Vec, +}; +// Internal crates use crate::{ printerr, println, -}; - -use crate::std::{ - application::{Application, Error, Exit}, - time::{timer, wait}, - io::{ - Color, write, Screen, Stdin, Serial, KeyStroke + std::{ + application::{Application, Error, Exit}, + time::{timer, wait}, + io::{Color, write, Screen, Stdin, Serial, KeyStroke, Display}, }, -}; -use crate::std::io::Display; - -use crate::user::{ - lib::libgui::{ - cg_core::{CgComponent, CgKeyboardCapture}, - cg_widgets::CgDialog, + user::{ + lib::libgui::{ + cg_core::{CgComponent, CgKeyboardCapture}, + cg_widgets::CgDialog, + }, + bin::{ + apps::{ + calc::Calculator, + editor::Editor, + grapher::Grapher, + tasks::Tasks, + }, + games::{ + asteroids::Game as AsteroidsGame, + gameoflife::GameOfLife, + paper::GameBoard, + pong::Game as PongGame, + snake::Game as SnakeGame, + // tetris::TetrisEngine, + }, + utils::{ + crystalfetch::CrystalFetch, + gigachad_detector::GigachadDetector, + rickroll::Rickroll, + }, + }, }, - bin::*, - bin::games::*, }; lazy_static! { @@ -42,7 +68,7 @@ pub async fn command_handler() { pub async fn eventloop() { println!("running!"); - let mut fetch = crystalfetch::CrystalFetch::new(); + let mut fetch = CrystalFetch::new(); let string = String::from(" "); let mut vec: Vec = Vec::new(); vec.push(string); @@ -99,21 +125,21 @@ async fn exec() -> Result<(), Error> { match cmd.as_str() { "calculate" | "calc" | "solve" => { - let mut cmd = calc::Calculator::new(); + let mut cmd = Calculator::new(); cmd.run(args).await?; } "rickroll" => { - let mut cmd = rickroll::Rickroll::new(); + let mut cmd = Rickroll::new(); cmd.run(args).await?; } "crystalfetch" => { - let mut cmd = crystalfetch::CrystalFetch::new(); + let mut cmd = CrystalFetch::new(); cmd.run(args).await?; } "tasks" => { - let mut cmd = tasks::Tasks::new(); + let mut cmd = Tasks::new(); cmd.run(args).await?; } "VGA" => { @@ -126,20 +152,20 @@ async fn exec() -> Result<(), Error> { mode.draw_line((80, 60), (120, 420), Color16::Cyan); } "graph" => { - grapher::Grapher::new().run(args).await?; + Grapher::new().run(args).await?; } "games/snake" => { - snake::Game::new().run(args).await?; + SnakeGame::new().run(args).await?; } "games/asteroids" => { - let mut asteroid_game = asteroids::Game::new(); + let mut asteroid_game = AsteroidsGame::new(); asteroid_game.run(args).await?; } "games/pong" => { - pong::Game::new().run(args).await?; + PongGame::new().run(args).await?; } "games/paper.rs" => { - let mut game = paper_rs::GameBoard::new(); + let mut game = GameBoard::new(); game.run(args).await?; } "serial" => { @@ -147,34 +173,24 @@ async fn exec() -> Result<(), Error> { println!("{}", c); } "games/gameoflife" => { - let mut game = gameoflife::GameOfLife::new(); + let mut game = GameOfLife::new(); game.run(Vec::new()).await?; } "games/tetris" => { - // let mut game = tetris::TetrisEngine::new(); + // let mut game = TetrisEngine::new(); // game.run(Vec::new()).await?; } "gigachad?" => { - let mut detector = gigachad_detector::GigachadDetector::new(); + let mut detector = GigachadDetector::new(); detector.run(args).await?; } "editor" => { - let mut editor = editor::Editor::new(); + let mut editor = Editor::new(); editor.run(args).await?; } - "wait" => { - if args.len() != 1 { - return Err(Error::CommandFailed("exactly one argument must be provided".to_string())) - } - if let Ok(time) = args[0].parse::() { - wait(time as f64); - println!("waited for {}s", time); - } - } - // direct OS functions (not applications) "echo" => { println!( @@ -351,25 +367,3 @@ async fn setup_ui() { // } // } } - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/user/bin/shellrewrite.rs b/src/user/bin/shellrewrite.rs index 17dfd1d..95e542b 100644 --- a/src/user/bin/shellrewrite.rs +++ b/src/user/bin/shellrewrite.rs @@ -1,158 +1,158 @@ -// importing libraries -use async_trait::async_trait; -use lazy_static::lazy_static; -use spin::Mutex; -use x86_64::instructions::interrupts; +// // importing libraries +// use async_trait::async_trait; +// use lazy_static::lazy_static; +// use spin::Mutex; +// use x86_64::instructions::interrupts; -use alloc::{boxed::Box, string::{String, ToString}, vec, vec::Vec}; +// use alloc::{boxed::Box, string::{String, ToString}, vec, vec::Vec}; -use crate::{ - kernel::tasks::{executor::Executor, Task}, - std::application::{Application, Error}, - std::io::{print, println, Stdin, Screen}, - user::bin::*, -}; -use crate::std::io::{Color, write}; -use crate::user::bin::gigachad_detector::GigachadDetector; +// use crate::{ +// kernel::tasks::{executor::Executor, Task}, +// std::application::{Application, Error}, +// std::io::{print, println, Stdin, Screen}, +// user::bin::*, +// }; +// use crate::std::io::{Color, write}; +// use crate::user::bin::gigachad_detector::GigachadDetector; -use super::*; +// use super::*; -// [ CRYSTAL SHELL ] -// the purpose of this module is to provide a basic unix shell like experience for the user -// to interact with the OS -// this is a rewrite of my original shell. -// this shell should support: -// - browsing the virtual filesystem -// - executing programs -// - basic arithmetic -// - chained execution ( multiple commands linked together) eg: '5 + 5 | echo' which calculates -// the result of 5 + 5 and then sends the result to an echo command which prints it to console +// // [ CRYSTAL SHELL ] +// // the purpose of this module is to provide a basic unix shell like experience for the user +// // to interact with the OS +// // this is a rewrite of my original shell. +// // this shell should support: +// // - browsing the virtual filesystem +// // - executing programs +// // - basic arithmetic +// // - chained execution ( multiple commands linked together) eg: '5 + 5 | echo' which calculates +// // the result of 5 + 5 and then sends the result to an echo command which prints it to console -/// starts the shell -/// this function should be directly called by main.rs or by an init system +// /// starts the shell +// /// this function should be directly called by main.rs or by an init system -fn run_task(task_name: String, args: Vec) -> Result<(), String> { - Ok(()) -} +// fn run_task(task_name: String, args: Vec) -> Result<(), String> { +// Ok(()) +// } -pub async fn userspace() -> Result<(), String> { - let mut executor = Executor::new(); +// pub async fn userspace() -> Result<(), String> { +// let mut executor = Executor::new(); - let mut shell = Shell::new(); - shell.run(vec![]).await.unwrap(); +// let mut shell = Shell::new(); +// shell.run(vec![]).await.unwrap(); - Ok(()) -} +// Ok(()) +// } -struct Shell { - history: Vec, -} +// struct Shell { +// history: Vec, +// } -#[async_trait] -impl Application for Shell { - fn new() -> Shell { - Shell { - history: Vec::new(), - } - } - async fn run(&mut self, _: Vec) -> Result<(), Error> { - loop { - self.prompt(); - let input = Stdin::readline().await; - let (cmd, args) = self.parse_args(input).unwrap(); - self.run_cmd(cmd, args).await.unwrap(); - } - } -} +// #[async_trait] +// impl Application for Shell { +// fn new() -> Shell { +// Shell { +// history: Vec::new(), +// } +// } +// async fn run(&mut self, _: Vec) -> Result<(), Error> { +// loop { +// self.prompt(); +// let input = Stdin::readline().await; +// let (cmd, args) = self.parse_args(input).unwrap(); +// self.run_cmd(cmd, args).await.unwrap(); +// } +// } +// } -impl Shell { - fn prompt(&mut self) { - write(format_args!("\n Crystal> "), (Color::Cyan, Color::Black)); - } +// impl Shell { +// fn prompt(&mut self) { +// write(format_args!("\n Crystal> "), (Color::Cyan, Color::Black)); +// } - // fn exec R>(command: T) -> Result { // this command runs when a shell command is executed - // Ok(command()) - // } - async fn run_cmd(&mut self, cmd: String, args: Vec) -> Result<(), Error> { - match cmd.as_str() { - "calculate" | "calc" | "solve" => { - let mut cmd = calc::Calculator::new(); - cmd.run(args).await?; - } - "rickroll" => { - let mut cmd = rickroll::Rickroll::new(); - cmd.run(args).await?; - } - "crystalfetch" => { - let mut cmd = crystalfetch::CrystalFetch::new(); - cmd.run(args).await?; - } - "tasks" => { - let mut cmd = tasks::Tasks::new(); - cmd.run(args).await?; - } - "play" => { - let mut gameloop = crystal_rpg::init::GameLoop::new(); - gameloop.run(args).await?; - } - "echo" => { - println!( - "Crystal: '{}'", - " ".join(args) - ) - } - "clear" => { - Screen::clear(); - } - "print" => { - use crate::std::os::OS; - let x: String = OS.lock().version.clone(); - println!("{}", x); - } - "snake" => { - let mut game = snake::Game::new(); - game.run(Vec::new()).await?; - } - "gigachad?" => { - let mut gigachad_detector = GigachadDetector::new(); - gigachad_detector.run(args).await?; - } - "test_features" => { - use crate::std::random::Random; - println!("{}", Random::int(0, 10)); - } - _ => { - return Err(Error::UnknownCommand( - "command not yet implemented".to_string(), - )) - } - } - Ok(()) - } - fn parse_args(&self, command: String) -> Result<(String, Vec), String> { - let mut args: Vec = Vec::new(); +// // fn exec R>(command: T) -> Result { // this command runs when a shell command is executed +// // Ok(command()) +// // } +// async fn run_cmd(&mut self, cmd: String, args: Vec) -> Result<(), Error> { +// match cmd.as_str() { +// "calculate" | "calc" | "solve" => { +// let mut cmd = calc::Calculator::new(); +// cmd.run(args).await?; +// } +// "rickroll" => { +// let mut cmd = rickroll::Rickroll::new(); +// cmd.run(args).await?; +// } +// "crystalfetch" => { +// let mut cmd = crystalfetch::CrystalFetch::new(); +// cmd.run(args).await?; +// } +// "tasks" => { +// let mut cmd = tasks::Tasks::new(); +// cmd.run(args).await?; +// } +// "play" => { +// let mut gameloop = crystal_rpg::init::GameLoop::new(); +// gameloop.run(args).await?; +// } +// "echo" => { +// println!( +// "Crystal: '{}'", +// " ".join(args) +// ) +// } +// "clear" => { +// Screen::clear(); +// } +// "print" => { +// use crate::std::os::OS; +// let x: String = OS.lock().version.clone(); +// println!("{}", x); +// } +// "snake" => { +// let mut game = snake::Game::new(); +// game.run(Vec::new()).await?; +// } +// "gigachad?" => { +// let mut gigachad_detector = GigachadDetector::new(); +// gigachad_detector.run(args).await?; +// } +// "test_features" => { +// use crate::std::random::Random; +// println!("{}", Random::int(0, 10)); +// } +// _ => { +// return Err(Error::UnknownCommand( +// "command not yet implemented".to_string(), +// )) +// } +// } +// Ok(()) +// } +// fn parse_args(&self, command: String) -> Result<(String, Vec), String> { +// let mut args: Vec = Vec::new(); - for arg in command.split(" ").collect::>() { - match arg { - "" => {} - x => args.push(x.to_string()), - } - } +// for arg in command.split(" ").collect::>() { +// match arg { +// "" => {} +// x => args.push(x.to_string()), +// } +// } - let cmd: String; - if args.len() > 0 { - cmd = args[0].clone(); - args.remove(0); - } - else { - return Err("command was empty.".to_string()); - }; +// let cmd: String; +// if args.len() > 0 { +// cmd = args[0].clone(); +// args.remove(0); +// } +// else { +// return Err("command was empty.".to_string()); +// }; - Ok((cmd, args)) - } -} +// Ok((cmd, args)) +// } +// } diff --git a/src/user/bin/crystalfetch.rs b/src/user/bin/utils/crystalfetch.rs similarity index 96% rename from src/user/bin/crystalfetch.rs rename to src/user/bin/utils/crystalfetch.rs index c363799..15cbaa2 100644 --- a/src/user/bin/crystalfetch.rs +++ b/src/user/bin/utils/crystalfetch.rs @@ -8,8 +8,8 @@ use crate::std::{ }; use crate::println; -const _CRYSTAL_LOGO: &str = - "\n $$$$$$\\ $$\\ $$\\ $$$$$$\\ $$$$$$\\ +const _CRYSTAL_LOGO: &str ="\n + $$$$$$\\ $$\\ $$\\ $$$$$$\\ $$$$$$\\ $$ __$$\\ $$ | $$ $$ __$$\\$$ __$$\\ $$ / \\__|$$$$$$\\ $$\\ $$\\ $$$$$$$\\$$$$$$\\ $$$$$$\\ $$ $$ / $$ $$ / \\__| $$ | $$ __$$\\$$ | $$ $$ _____\\_$$ _| \\____$$\\$$ $$ | $$ \\$$$$$$\\ diff --git a/src/user/bin/gigachad_detector.rs b/src/user/bin/utils/gigachad_detector.rs similarity index 100% rename from src/user/bin/gigachad_detector.rs rename to src/user/bin/utils/gigachad_detector.rs diff --git a/src/user/bin/utils/mod.rs b/src/user/bin/utils/mod.rs new file mode 100644 index 0000000..81f0ffe --- /dev/null +++ b/src/user/bin/utils/mod.rs @@ -0,0 +1,3 @@ +pub mod crystalfetch; +pub mod gigachad_detector; +pub mod rickroll; \ No newline at end of file diff --git a/src/user/bin/rickroll.rs b/src/user/bin/utils/rickroll.rs similarity index 100% rename from src/user/bin/rickroll.rs rename to src/user/bin/utils/rickroll.rs