reorganised some stuff and started coding another game
This commit is contained in:
@@ -20,7 +20,6 @@ pub mod system;
|
|||||||
pub mod user;
|
pub mod user;
|
||||||
pub use system::std as std;
|
pub use system::std as std;
|
||||||
pub use user::bin::*;
|
pub use user::bin::*;
|
||||||
use crate::calc::Calculator;
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
|||||||
@@ -306,8 +306,8 @@ impl Renderer {
|
|||||||
self.screen_ref.chars[i][j].write(*col);
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
mod functions;
|
||||||
|
mod calc;
|
||||||
|
|
||||||
|
pub use calc::Calculator;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
pub mod calc;
|
||||||
|
pub mod editor;
|
||||||
|
pub mod grapher;
|
||||||
|
pub mod tasks;
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
//pub mod calc;
|
|
||||||
mod functions;
|
|
||||||
pub mod calc;
|
|
||||||
|
|
||||||
pub use calc::*;
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
pub struct Effect {
|
||||||
|
pub EffectType: EffectType,
|
||||||
|
pub potency: i32,
|
||||||
|
pub duration: Option<i32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum EffectType {
|
||||||
|
Poison,
|
||||||
|
Regeneration,
|
||||||
|
|
||||||
|
Harming,
|
||||||
|
Healing,
|
||||||
|
|
||||||
|
Speed,
|
||||||
|
Slowness,
|
||||||
|
Stunned,
|
||||||
|
Confused,
|
||||||
|
|
||||||
|
Strength,
|
||||||
|
Weakness,
|
||||||
|
|
||||||
|
OnFire,
|
||||||
|
|
||||||
|
Invisible,
|
||||||
|
}
|
||||||
@@ -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,
|
||||||
|
}
|
||||||
@@ -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,
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
use hashbrown::HashMap;
|
||||||
|
|
||||||
|
pub struct Map {
|
||||||
|
tiles: HashMap<(i32, i32), Tile>
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Tile {
|
||||||
|
Empty,
|
||||||
|
Wall,
|
||||||
|
}
|
||||||
@@ -1 +1,7 @@
|
|||||||
mod entity;
|
mod entity;
|
||||||
|
mod player;
|
||||||
|
mod map;
|
||||||
|
mod effect;
|
||||||
|
mod items;
|
||||||
|
|
||||||
|
pub mod game;
|
||||||
|
|||||||
@@ -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<Helmet>,
|
||||||
|
pub chestplate: Option<Chestplate>,
|
||||||
|
pub boots: Option<Boots>,
|
||||||
|
|
||||||
|
pub inventory: [Box<dyn Item>; 20],
|
||||||
|
|
||||||
|
pub effects: Vec<Effect>,
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -3,4 +3,5 @@ pub mod gameoflife;
|
|||||||
pub mod crystalrpg;
|
pub mod crystalrpg;
|
||||||
pub mod pong;
|
pub mod pong;
|
||||||
pub mod snake;
|
pub mod snake;
|
||||||
pub mod paper_rs;
|
pub mod paper;
|
||||||
|
pub mod tetris;
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
use core::any::Any;
|
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 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)]
|
#[derive(Copy, Clone)]
|
||||||
@@ -48,7 +48,7 @@ impl Application for GameBoard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run(&mut self, args: Vec<String>) -> Result<(), Error> {
|
async fn run(&mut self, _args: Vec<String>) -> Result<(), Error> {
|
||||||
let _display = Display::borrow();
|
let _display = Display::borrow();
|
||||||
|
|
||||||
'outer: loop {
|
'outer: loop {
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
/// this game is basically a ripoff of paper.io
|
|
||||||
pub mod paper;
|
|
||||||
|
|
||||||
pub use paper::GameBoard;
|
|
||||||
@@ -4,7 +4,6 @@ use alloc::vec::Vec;
|
|||||||
use core::any::Any;
|
use core::any::Any;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use crate::std::application::{Application, Error};
|
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::render::{BUFFER_HEIGHT, BUFFER_WIDTH, ColorCode, ColouredChar, Dimensions, Frame, Position, RenderError};
|
||||||
use crate::std::io::{Color, Display, KeyStroke, Stdin};
|
use crate::std::io::{Color, Display, KeyStroke, Stdin};
|
||||||
use crate::std::time::Timer;
|
use crate::std::time::Timer;
|
||||||
@@ -27,7 +26,7 @@ impl Application for Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn run(&mut self, _: Vec<String>) -> Result<(), Error> {
|
async fn run(&mut self, _: Vec<String>) -> Result<(), Error> {
|
||||||
let d = Display::borrow();
|
let _d = Display::borrow();
|
||||||
|
|
||||||
let mut update_time = Timer::new(0.1);
|
let mut update_time = Timer::new(0.1);
|
||||||
|
|
||||||
@@ -124,7 +123,7 @@ impl CgComponent for Game {
|
|||||||
fn render(&self) -> Result<Frame, RenderError> {
|
fn render(&self) -> Result<Frame, RenderError> {
|
||||||
let mut frame = Frame::new(Dimensions::new(0, 0), Dimensions::new(80, 25))?;
|
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.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();
|
frame.write(Position::new(self.player2.pos.x, self.player2.pos.y + y -2), ColouredChar::coloured('▓', ColorCode::new(Color::Cyan, Color::Black))).unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-13
@@ -1,14 +1,5 @@
|
|||||||
|
pub mod apps;
|
||||||
pub mod calc;
|
pub mod games;
|
||||||
pub mod crystalfetch;
|
pub mod utils;
|
||||||
pub mod rickroll;
|
|
||||||
pub mod shell;
|
pub mod shell;
|
||||||
pub mod tasks;
|
pub mod shellrewrite;
|
||||||
pub mod editor;
|
|
||||||
mod gigachad_detector;
|
|
||||||
|
|
||||||
//mod shellrewrite;
|
|
||||||
|
|
||||||
mod grapher;
|
|
||||||
|
|
||||||
mod games;
|
|
||||||
+58
-64
@@ -1,30 +1,56 @@
|
|||||||
|
// External crates
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
|
use vga::{
|
||||||
|
writers::{PrimitiveDrawing, GraphicsWriter, Graphics640x480x16},
|
||||||
|
colors::Color16,
|
||||||
|
};
|
||||||
|
|
||||||
use alloc::{boxed::Box, format, string::{String, ToString}, vec, vec::Vec};
|
// Standard library
|
||||||
use vga::writers::{PrimitiveDrawing};
|
use alloc::{
|
||||||
|
boxed::Box,
|
||||||
|
format,
|
||||||
|
string::{String, ToString},
|
||||||
|
vec,
|
||||||
|
vec::Vec,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Internal crates
|
||||||
use crate::{
|
use crate::{
|
||||||
printerr,
|
printerr,
|
||||||
println,
|
println,
|
||||||
};
|
std::{
|
||||||
|
application::{Application, Error, Exit},
|
||||||
use crate::std::{
|
time::{timer, wait},
|
||||||
application::{Application, Error, Exit},
|
io::{Color, write, Screen, Stdin, Serial, KeyStroke, Display},
|
||||||
time::{timer, wait},
|
|
||||||
io::{
|
|
||||||
Color, write, Screen, Stdin, Serial, KeyStroke
|
|
||||||
},
|
},
|
||||||
};
|
user::{
|
||||||
use crate::std::io::Display;
|
lib::libgui::{
|
||||||
|
cg_core::{CgComponent, CgKeyboardCapture},
|
||||||
use crate::user::{
|
cg_widgets::CgDialog,
|
||||||
lib::libgui::{
|
},
|
||||||
cg_core::{CgComponent, CgKeyboardCapture},
|
bin::{
|
||||||
cg_widgets::CgDialog,
|
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! {
|
lazy_static! {
|
||||||
@@ -42,7 +68,7 @@ pub async fn command_handler() {
|
|||||||
pub async fn eventloop() {
|
pub async fn eventloop() {
|
||||||
println!("running!");
|
println!("running!");
|
||||||
|
|
||||||
let mut fetch = crystalfetch::CrystalFetch::new();
|
let mut fetch = CrystalFetch::new();
|
||||||
let string = String::from(" ");
|
let string = String::from(" ");
|
||||||
let mut vec: Vec<String> = Vec::new();
|
let mut vec: Vec<String> = Vec::new();
|
||||||
vec.push(string);
|
vec.push(string);
|
||||||
@@ -99,21 +125,21 @@ async fn exec() -> Result<(), Error> {
|
|||||||
|
|
||||||
match cmd.as_str() {
|
match cmd.as_str() {
|
||||||
"calculate" | "calc" | "solve" => {
|
"calculate" | "calc" | "solve" => {
|
||||||
let mut cmd = calc::Calculator::new();
|
let mut cmd = Calculator::new();
|
||||||
cmd.run(args).await?;
|
cmd.run(args).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
"rickroll" => {
|
"rickroll" => {
|
||||||
let mut cmd = rickroll::Rickroll::new();
|
let mut cmd = Rickroll::new();
|
||||||
cmd.run(args).await?;
|
cmd.run(args).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
"crystalfetch" => {
|
"crystalfetch" => {
|
||||||
let mut cmd = crystalfetch::CrystalFetch::new();
|
let mut cmd = CrystalFetch::new();
|
||||||
cmd.run(args).await?;
|
cmd.run(args).await?;
|
||||||
}
|
}
|
||||||
"tasks" => {
|
"tasks" => {
|
||||||
let mut cmd = tasks::Tasks::new();
|
let mut cmd = Tasks::new();
|
||||||
cmd.run(args).await?;
|
cmd.run(args).await?;
|
||||||
}
|
}
|
||||||
"VGA" => {
|
"VGA" => {
|
||||||
@@ -126,20 +152,20 @@ async fn exec() -> Result<(), Error> {
|
|||||||
mode.draw_line((80, 60), (120, 420), Color16::Cyan);
|
mode.draw_line((80, 60), (120, 420), Color16::Cyan);
|
||||||
}
|
}
|
||||||
"graph" => {
|
"graph" => {
|
||||||
grapher::Grapher::new().run(args).await?;
|
Grapher::new().run(args).await?;
|
||||||
}
|
}
|
||||||
"games/snake" => {
|
"games/snake" => {
|
||||||
snake::Game::new().run(args).await?;
|
SnakeGame::new().run(args).await?;
|
||||||
}
|
}
|
||||||
"games/asteroids" => {
|
"games/asteroids" => {
|
||||||
let mut asteroid_game = asteroids::Game::new();
|
let mut asteroid_game = AsteroidsGame::new();
|
||||||
asteroid_game.run(args).await?;
|
asteroid_game.run(args).await?;
|
||||||
}
|
}
|
||||||
"games/pong" => {
|
"games/pong" => {
|
||||||
pong::Game::new().run(args).await?;
|
PongGame::new().run(args).await?;
|
||||||
}
|
}
|
||||||
"games/paper.rs" => {
|
"games/paper.rs" => {
|
||||||
let mut game = paper_rs::GameBoard::new();
|
let mut game = GameBoard::new();
|
||||||
game.run(args).await?;
|
game.run(args).await?;
|
||||||
}
|
}
|
||||||
"serial" => {
|
"serial" => {
|
||||||
@@ -147,34 +173,24 @@ async fn exec() -> Result<(), Error> {
|
|||||||
println!("{}", c);
|
println!("{}", c);
|
||||||
}
|
}
|
||||||
"games/gameoflife" => {
|
"games/gameoflife" => {
|
||||||
let mut game = gameoflife::GameOfLife::new();
|
let mut game = GameOfLife::new();
|
||||||
game.run(Vec::new()).await?;
|
game.run(Vec::new()).await?;
|
||||||
}
|
}
|
||||||
"games/tetris" => {
|
"games/tetris" => {
|
||||||
// let mut game = tetris::TetrisEngine::new();
|
// let mut game = TetrisEngine::new();
|
||||||
// game.run(Vec::new()).await?;
|
// game.run(Vec::new()).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
"gigachad?" => {
|
"gigachad?" => {
|
||||||
let mut detector = gigachad_detector::GigachadDetector::new();
|
let mut detector = GigachadDetector::new();
|
||||||
detector.run(args).await?;
|
detector.run(args).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
"editor" => {
|
"editor" => {
|
||||||
let mut editor = editor::Editor::new();
|
let mut editor = Editor::new();
|
||||||
editor.run(args).await?;
|
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::<u64>() {
|
|
||||||
wait(time as f64);
|
|
||||||
println!("waited for {}s", time);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// direct OS functions (not applications)
|
// direct OS functions (not applications)
|
||||||
"echo" => {
|
"echo" => {
|
||||||
println!(
|
println!(
|
||||||
@@ -351,25 +367,3 @@ async fn setup_ui() {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+137
-137
@@ -1,158 +1,158 @@
|
|||||||
// importing libraries
|
// // importing libraries
|
||||||
use async_trait::async_trait;
|
// use async_trait::async_trait;
|
||||||
use lazy_static::lazy_static;
|
// use lazy_static::lazy_static;
|
||||||
use spin::Mutex;
|
// use spin::Mutex;
|
||||||
use x86_64::instructions::interrupts;
|
// 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::{
|
// use crate::{
|
||||||
kernel::tasks::{executor::Executor, Task},
|
// kernel::tasks::{executor::Executor, Task},
|
||||||
std::application::{Application, Error},
|
// std::application::{Application, Error},
|
||||||
std::io::{print, println, Stdin, Screen},
|
// std::io::{print, println, Stdin, Screen},
|
||||||
user::bin::*,
|
// user::bin::*,
|
||||||
};
|
// };
|
||||||
use crate::std::io::{Color, write};
|
// use crate::std::io::{Color, write};
|
||||||
use crate::user::bin::gigachad_detector::GigachadDetector;
|
// use crate::user::bin::gigachad_detector::GigachadDetector;
|
||||||
|
|
||||||
use super::*;
|
// use super::*;
|
||||||
|
|
||||||
// [ CRYSTAL SHELL ]
|
// // [ CRYSTAL SHELL ]
|
||||||
// the purpose of this module is to provide a basic unix shell like experience for the user
|
// // the purpose of this module is to provide a basic unix shell like experience for the user
|
||||||
// to interact with the OS
|
// // to interact with the OS
|
||||||
// this is a rewrite of my original shell.
|
// // this is a rewrite of my original shell.
|
||||||
// this shell should support:
|
// // this shell should support:
|
||||||
// - browsing the virtual filesystem
|
// // - browsing the virtual filesystem
|
||||||
// - executing programs
|
// // - executing programs
|
||||||
// - basic arithmetic
|
// // - basic arithmetic
|
||||||
// - chained execution ( multiple commands linked together) eg: '5 + 5 | echo' which calculates
|
// // - 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
|
// // the result of 5 + 5 and then sends the result to an echo command which prints it to console
|
||||||
|
|
||||||
|
|
||||||
/// starts the shell
|
// /// starts the shell
|
||||||
/// this function should be directly called by main.rs or by an init system
|
// /// this function should be directly called by main.rs or by an init system
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn run_task(task_name: String, args: Vec<String>) -> Result<(), String> {
|
// fn run_task(task_name: String, args: Vec<String>) -> Result<(), String> {
|
||||||
Ok(())
|
// Ok(())
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub async fn userspace() -> Result<(), String> {
|
// pub async fn userspace() -> Result<(), String> {
|
||||||
let mut executor = Executor::new();
|
// let mut executor = Executor::new();
|
||||||
|
|
||||||
let mut shell = Shell::new();
|
// let mut shell = Shell::new();
|
||||||
shell.run(vec![]).await.unwrap();
|
// shell.run(vec![]).await.unwrap();
|
||||||
|
|
||||||
Ok(())
|
// Ok(())
|
||||||
}
|
// }
|
||||||
|
|
||||||
struct Shell {
|
// struct Shell {
|
||||||
history: Vec<String>,
|
// history: Vec<String>,
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[async_trait]
|
// #[async_trait]
|
||||||
impl Application for Shell {
|
// impl Application for Shell {
|
||||||
fn new() -> Shell {
|
// fn new() -> Shell {
|
||||||
Shell {
|
// Shell {
|
||||||
history: Vec::new(),
|
// history: Vec::new(),
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
async fn run(&mut self, _: Vec<String>) -> Result<(), Error> {
|
// async fn run(&mut self, _: Vec<String>) -> Result<(), Error> {
|
||||||
loop {
|
// loop {
|
||||||
self.prompt();
|
// self.prompt();
|
||||||
let input = Stdin::readline().await;
|
// let input = Stdin::readline().await;
|
||||||
let (cmd, args) = self.parse_args(input).unwrap();
|
// let (cmd, args) = self.parse_args(input).unwrap();
|
||||||
self.run_cmd(cmd, args).await.unwrap();
|
// self.run_cmd(cmd, args).await.unwrap();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
impl Shell {
|
// impl Shell {
|
||||||
fn prompt(&mut self) {
|
// fn prompt(&mut self) {
|
||||||
write(format_args!("\n Crystal> "), (Color::Cyan, Color::Black));
|
// write(format_args!("\n Crystal> "), (Color::Cyan, Color::Black));
|
||||||
}
|
// }
|
||||||
|
|
||||||
// fn exec<R, T: Fn() -> R>(command: T) -> Result<R, Error> { // this command runs when a shell command is executed
|
// // fn exec<R, T: Fn() -> R>(command: T) -> Result<R, Error> { // this command runs when a shell command is executed
|
||||||
// Ok(command())
|
// // Ok(command())
|
||||||
// }
|
// // }
|
||||||
async fn run_cmd(&mut self, cmd: String, args: Vec<String>) -> Result<(), Error> {
|
// async fn run_cmd(&mut self, cmd: String, args: Vec<String>) -> Result<(), Error> {
|
||||||
match cmd.as_str() {
|
// match cmd.as_str() {
|
||||||
"calculate" | "calc" | "solve" => {
|
// "calculate" | "calc" | "solve" => {
|
||||||
let mut cmd = calc::Calculator::new();
|
// let mut cmd = calc::Calculator::new();
|
||||||
cmd.run(args).await?;
|
// cmd.run(args).await?;
|
||||||
}
|
// }
|
||||||
"rickroll" => {
|
// "rickroll" => {
|
||||||
let mut cmd = rickroll::Rickroll::new();
|
// let mut cmd = rickroll::Rickroll::new();
|
||||||
cmd.run(args).await?;
|
// cmd.run(args).await?;
|
||||||
}
|
// }
|
||||||
"crystalfetch" => {
|
// "crystalfetch" => {
|
||||||
let mut cmd = crystalfetch::CrystalFetch::new();
|
// let mut cmd = crystalfetch::CrystalFetch::new();
|
||||||
cmd.run(args).await?;
|
// cmd.run(args).await?;
|
||||||
}
|
// }
|
||||||
"tasks" => {
|
// "tasks" => {
|
||||||
let mut cmd = tasks::Tasks::new();
|
// let mut cmd = tasks::Tasks::new();
|
||||||
cmd.run(args).await?;
|
// cmd.run(args).await?;
|
||||||
}
|
// }
|
||||||
"play" => {
|
// "play" => {
|
||||||
let mut gameloop = crystal_rpg::init::GameLoop::new();
|
// let mut gameloop = crystal_rpg::init::GameLoop::new();
|
||||||
gameloop.run(args).await?;
|
// gameloop.run(args).await?;
|
||||||
}
|
// }
|
||||||
"echo" => {
|
// "echo" => {
|
||||||
println!(
|
// println!(
|
||||||
"Crystal: '{}'",
|
// "Crystal: '{}'",
|
||||||
" ".join(args)
|
// " ".join(args)
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
"clear" => {
|
// "clear" => {
|
||||||
Screen::clear();
|
// Screen::clear();
|
||||||
}
|
// }
|
||||||
"print" => {
|
// "print" => {
|
||||||
use crate::std::os::OS;
|
// use crate::std::os::OS;
|
||||||
let x: String = OS.lock().version.clone();
|
// let x: String = OS.lock().version.clone();
|
||||||
println!("{}", x);
|
// println!("{}", x);
|
||||||
}
|
// }
|
||||||
"snake" => {
|
// "snake" => {
|
||||||
let mut game = snake::Game::new();
|
// let mut game = snake::Game::new();
|
||||||
game.run(Vec::new()).await?;
|
// game.run(Vec::new()).await?;
|
||||||
}
|
// }
|
||||||
"gigachad?" => {
|
// "gigachad?" => {
|
||||||
let mut gigachad_detector = GigachadDetector::new();
|
// let mut gigachad_detector = GigachadDetector::new();
|
||||||
gigachad_detector.run(args).await?;
|
// gigachad_detector.run(args).await?;
|
||||||
}
|
// }
|
||||||
"test_features" => {
|
// "test_features" => {
|
||||||
use crate::std::random::Random;
|
// use crate::std::random::Random;
|
||||||
println!("{}", Random::int(0, 10));
|
// println!("{}", Random::int(0, 10));
|
||||||
}
|
// }
|
||||||
_ => {
|
// _ => {
|
||||||
return Err(Error::UnknownCommand(
|
// return Err(Error::UnknownCommand(
|
||||||
"command not yet implemented".to_string(),
|
// "command not yet implemented".to_string(),
|
||||||
))
|
// ))
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
Ok(())
|
// Ok(())
|
||||||
}
|
// }
|
||||||
fn parse_args(&self, command: String) -> Result<(String, Vec<String>), String> {
|
// fn parse_args(&self, command: String) -> Result<(String, Vec<String>), String> {
|
||||||
let mut args: Vec<String> = Vec::new();
|
// let mut args: Vec<String> = Vec::new();
|
||||||
|
|
||||||
for arg in command.split(" ").collect::<Vec<&str>>() {
|
// for arg in command.split(" ").collect::<Vec<&str>>() {
|
||||||
match arg {
|
// match arg {
|
||||||
"" => {}
|
// "" => {}
|
||||||
x => args.push(x.to_string()),
|
// x => args.push(x.to_string()),
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
let cmd: String;
|
// let cmd: String;
|
||||||
if args.len() > 0 {
|
// if args.len() > 0 {
|
||||||
cmd = args[0].clone();
|
// cmd = args[0].clone();
|
||||||
args.remove(0);
|
// args.remove(0);
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
return Err("command was empty.".to_string());
|
// return Err("command was empty.".to_string());
|
||||||
};
|
// };
|
||||||
|
|
||||||
Ok((cmd, args))
|
// Ok((cmd, args))
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ use crate::std::{
|
|||||||
};
|
};
|
||||||
use crate::println;
|
use crate::println;
|
||||||
|
|
||||||
const _CRYSTAL_LOGO: &str =
|
const _CRYSTAL_LOGO: &str ="\n
|
||||||
"\n $$$$$$\\ $$\\ $$\\ $$$$$$\\ $$$$$$\\
|
$$$$$$\\ $$\\ $$\\ $$$$$$\\ $$$$$$\\
|
||||||
$$ __$$\\ $$ | $$ $$ __$$\\$$ __$$\\
|
$$ __$$\\ $$ | $$ $$ __$$\\$$ __$$\\
|
||||||
$$ / \\__|$$$$$$\\ $$\\ $$\\ $$$$$$$\\$$$$$$\\ $$$$$$\\ $$ $$ / $$ $$ / \\__|
|
$$ / \\__|$$$$$$\\ $$\\ $$\\ $$$$$$$\\$$$$$$\\ $$$$$$\\ $$ $$ / $$ $$ / \\__|
|
||||||
$$ | $$ __$$\\$$ | $$ $$ _____\\_$$ _| \\____$$\\$$ $$ | $$ \\$$$$$$\\
|
$$ | $$ __$$\\$$ | $$ $$ _____\\_$$ _| \\____$$\\$$ $$ | $$ \\$$$$$$\\
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
pub mod crystalfetch;
|
||||||
|
pub mod gigachad_detector;
|
||||||
|
pub mod rickroll;
|
||||||
Reference in New Issue
Block a user