added submodule for custom python interpreter
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "CrystalPy"]
|
||||||
|
path = CrystalPy
|
||||||
|
url = git@github.com:FantasyPvP/CrystalPy.git
|
||||||
Generated
+2
@@ -4,6 +4,8 @@
|
|||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/crystalos_macros/src" isTestSource="false" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/crystalos_macros/target" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
|
|||||||
Submodule
+1
Submodule CrystalPy added at 0dfd92eca7
@@ -3,7 +3,7 @@ pub mod random;
|
|||||||
pub mod application;
|
pub mod application;
|
||||||
pub mod tasks;
|
pub mod tasks;
|
||||||
pub mod os;
|
pub mod os;
|
||||||
pub mod frame;
|
pub mod render;
|
||||||
pub mod time;
|
pub mod time;
|
||||||
pub mod syscall;
|
pub mod syscall;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use alloc::vec;
|
|||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use crate::system::kernel::render::{RENDERER, ScreenChar};
|
use crate::system::kernel::render::{RENDERER, ScreenChar};
|
||||||
use crate::std::io::Color;
|
use crate::std::io::Color;
|
||||||
|
use num_traits::{Num, ToPrimitive};
|
||||||
|
|
||||||
/// TODO: get a working implementation for CLI apps
|
/// TODO: get a working implementation for CLI apps
|
||||||
/// elements can be created using their from_str() method
|
/// elements can be created using their from_str() method
|
||||||
@@ -61,30 +62,50 @@ impl ColouredChar {
|
|||||||
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct Position {
|
pub struct Position<T: Num> {
|
||||||
pub x: usize,
|
pub x: T,
|
||||||
pub y: usize,
|
pub y: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Position {
|
impl<T: Num + ToPrimitive> Position<T> {
|
||||||
pub fn new(x: usize, y: usize) -> Position {
|
pub fn new(x: T, y: T) -> Position<T> {
|
||||||
Position { x, y }
|
Position { x, y }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn into_usize(self) -> Result<Position<usize>, ()> {
|
||||||
|
Ok(Position {
|
||||||
|
x: self.x.to_usize().ok_or(())?,
|
||||||
|
y: self.y.to_usize().ok_or(())?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
pub fn into_i32(self) -> Result<Position<i32>, ()> {
|
||||||
|
Ok(Position {
|
||||||
|
x: self.x.to_i32().ok_or(())?,
|
||||||
|
y: self.y.to_i32().ok_or(())?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn into_f32(self) -> Result<Position<f32>, ()> {
|
||||||
|
Ok(Position {
|
||||||
|
x: self.x.to_f32().ok_or(())?,
|
||||||
|
y: self.y.to_f32().ok_or(())?,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Dimensions = Position;
|
pub type Dimensions<T> = Position<T>;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Frame {
|
pub struct Frame {
|
||||||
pub position: Position,
|
pub position: Position<usize>,
|
||||||
pub dimensions: Dimensions,
|
pub dimensions: Dimensions<usize>,
|
||||||
pub frame: Vec<Vec<ColouredChar>>,
|
pub frame: Vec<Vec<ColouredChar>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Frame {
|
impl Frame {
|
||||||
pub fn new(position: Position, dimensions: Dimensions) -> Result<Frame, RenderError> {
|
pub fn new(position: Position<usize>, dimensions: Dimensions<usize>) -> Result<Frame, RenderError> {
|
||||||
Ok(Frame {
|
Ok(Frame {
|
||||||
position,
|
position,
|
||||||
dimensions,
|
dimensions,
|
||||||
@@ -126,16 +147,16 @@ impl Frame {
|
|||||||
RENDERER.lock().render_frame(frame);
|
RENDERER.lock().render_frame(frame);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn get_position(&self) -> Position {
|
pub fn get_position(&self) -> Position<usize> {
|
||||||
self.position
|
self.position
|
||||||
}
|
}
|
||||||
pub fn set_position(&mut self, position: Position) {
|
pub fn set_position(&mut self, position: Position<usize>) {
|
||||||
self.position = position
|
self.position = position
|
||||||
}
|
}
|
||||||
pub fn dimensions(&self) -> Dimensions {
|
pub fn dimensions(&self) -> Dimensions<usize> {
|
||||||
self.dimensions
|
self.dimensions
|
||||||
}
|
}
|
||||||
pub fn write(&mut self, position: Position, char: ColouredChar) -> Result<(), RenderError> {
|
pub fn write(&mut self, position: Position<usize>, char: ColouredChar) -> Result<(), RenderError> {
|
||||||
if position.x >= self.dimensions.x || position.y >= self.dimensions.y {
|
if position.x >= self.dimensions.x || position.y >= self.dimensions.y {
|
||||||
return Err(RenderError::OutOfBounds(
|
return Err(RenderError::OutOfBounds(
|
||||||
position.x >= self.dimensions.x,
|
position.x >= self.dimensions.x,
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::std::application::Error;
|
use crate::std::application::Error;
|
||||||
use crate::std::application::Error::ApplicationError;
|
use crate::std::application::Error::ApplicationError;
|
||||||
use crate::std::frame::{ColouredChar, Dimensions, Frame, Position, RenderError};
|
use crate::std::render::{ColouredChar, Dimensions, Frame, Position, RenderError};
|
||||||
use crate::std::io::{Color, ColorCode, Display, KeyStroke, Screen, Stdin};
|
use crate::std::io::{Color, ColorCode, Display, KeyStroke, Screen, Stdin};
|
||||||
use crate::std::random::Random;
|
use crate::std::random::Random;
|
||||||
use crate::system::std::application::Application;
|
use crate::system::std::application::Application;
|
||||||
@@ -17,7 +17,7 @@ use core::any::Any;
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
pub health: i32,
|
pub health: i32,
|
||||||
pub position: Position,
|
pub position: Position<usize>,
|
||||||
}
|
}
|
||||||
impl Player {
|
impl Player {
|
||||||
pub fn new() -> Player {
|
pub fn new() -> Player {
|
||||||
@@ -195,9 +195,9 @@ impl Game {
|
|||||||
|
|
||||||
if let Some(input_key) = Stdin::try_keystroke() {
|
if let Some(input_key) = Stdin::try_keystroke() {
|
||||||
match input_key {
|
match input_key {
|
||||||
KeyStroke::Char('q') => return true,
|
KeyStroke::Char('`') => return true,
|
||||||
KeyStroke::Char('w') => self.player.position.y -= 1,
|
KeyStroke::Char('w') => { if self.player.position.y > 0 { self.player.position.y -= 1 }},
|
||||||
KeyStroke::Char('s') => self.player.position.y += 1,
|
KeyStroke::Char('s') => { if self.player.position.y < 21 { self.player.position.y += 1 }},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -219,7 +219,7 @@ impl Game {
|
|||||||
frame.write_to_screen().unwrap();
|
frame.write_to_screen().unwrap();
|
||||||
|
|
||||||
while let KeyStroke::Char(c) = Stdin::keystroke().await {
|
while let KeyStroke::Char(c) = Stdin::keystroke().await {
|
||||||
if c == 'q' {
|
if c == '`' {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -251,13 +251,13 @@ impl CgComponent for Game {
|
|||||||
.collect::<Vec<(i16, i16)>>()
|
.collect::<Vec<(i16, i16)>>()
|
||||||
{
|
{
|
||||||
frame[i.1 as usize][i.0 as usize] = ColouredChar {
|
frame[i.1 as usize][i.0 as usize] = ColouredChar {
|
||||||
character: '<',
|
character: '«',
|
||||||
colour: ColorCode::new(Color::LightGray, Color::Black),
|
colour: ColorCode::new(Color::LightGray, Color::Black),
|
||||||
};
|
};
|
||||||
(1..5).for_each(|offset| {
|
(1..5).for_each(|offset| {
|
||||||
if i.0 + offset < frame.dimensions.x as i16 {
|
if i.0 + offset < frame.dimensions.x as i16 {
|
||||||
frame[i.1 as usize][(i.0 + offset) as usize] = ColouredChar {
|
frame[i.1 as usize][(i.0 + offset) as usize] = ColouredChar {
|
||||||
character: '=',
|
character: '═',
|
||||||
colour: ColorCode::new(Color::LightGray, Color::Black),
|
colour: ColorCode::new(Color::LightGray, Color::Black),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ use alloc::vec::Vec;
|
|||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use crate::std::application::{Application, Error};
|
use crate::std::application::{Application, Error};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use crate::std::frame::{ColouredChar, Frame, Position, Dimensions, RenderError};
|
use crate::std::render::{ColouredChar, Frame, Position, Dimensions, RenderError};
|
||||||
use crate::std::io::{KeyStroke, Stdin, Color, ColorCode, Display};
|
use crate::std::io::{KeyStroke, Stdin, Color, ColorCode, Display};
|
||||||
use crate::std::time::wait;
|
use crate::std::time::wait;
|
||||||
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
pub mod asteroids;
|
||||||
|
pub mod gameoflife;
|
||||||
|
pub mod crystalrpg;
|
||||||
|
pub mod pong;
|
||||||
|
pub mod snake;
|
||||||
@@ -5,7 +5,7 @@ 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;
|
||||||
use crate::std::frame::{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;
|
||||||
use crate::user::lib::libgui::cg_core::CgComponent;
|
use crate::user::lib::libgui::cg_core::CgComponent;
|
||||||
@@ -59,7 +59,7 @@ impl Application for Game {
|
|||||||
}
|
}
|
||||||
if update_time.is_done() {
|
if update_time.is_done() {
|
||||||
updated = true;
|
updated = true;
|
||||||
self.ball.update(&mut self.player1, &mut self.player2);
|
self.update_ball();
|
||||||
update_time.reset()
|
update_time.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,12 +68,58 @@ impl Application for Game {
|
|||||||
frame.write_to_screen().unwrap();
|
frame.write_to_screen().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// self.ball.update(&self.player1, &self.player2);
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Game {
|
||||||
|
fn update_ball(&mut self) {
|
||||||
|
let pos_next_f32 = Position::new( // invert x direction on collision with player
|
||||||
|
self.ball.pos.x + self.ball.vx,
|
||||||
|
self.ball.pos.y + self.ball.vy,
|
||||||
|
);
|
||||||
|
|
||||||
|
if pos_next_f32.y < 0.0 || pos_next_f32.y >= BUFFER_HEIGHT as f32 { // if the move is outside the screen, then invert the direction
|
||||||
|
self.ball.vy = -self.ball.vy;
|
||||||
|
}
|
||||||
|
|
||||||
|
if pos_next_f32.x < 0.0 {
|
||||||
|
self.player2.score += 1;
|
||||||
|
self.ball.pos = Position::new(40.0, 12.0);
|
||||||
|
self.ball.vx = 1.0;
|
||||||
|
self.ball.vy = 0.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if pos_next_f32.x >= BUFFER_WIDTH as f32 {
|
||||||
|
self.player1.score += 1;
|
||||||
|
self.ball.pos = Position::new(40.0, 12.0);
|
||||||
|
self.ball.vx = -1.0;
|
||||||
|
self.ball.vy = 0.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
let pos_next = Position::new(
|
||||||
|
pos_next_f32.x as usize,
|
||||||
|
pos_next_f32.y as usize,
|
||||||
|
);
|
||||||
|
|
||||||
|
for i in 0..5 {
|
||||||
|
if self.player1.pos.y + i - 2 == pos_next.y && self.player1.pos.x == pos_next.x {
|
||||||
|
self.ball.vx = -self.ball.vx;
|
||||||
|
break;
|
||||||
|
} else if self.player2.pos.y + i - 2 == pos_next.y && self.player2.pos.x == pos_next.x {
|
||||||
|
self.ball.vx = -self.ball.vx;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
self.ball.pos = Position::new(
|
||||||
|
self.ball.pos.x + self.ball.vx,
|
||||||
|
self.ball.pos.y + self.ball.vy
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl CgComponent for Game {
|
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))?;
|
||||||
@@ -82,7 +128,7 @@ impl CgComponent for Game {
|
|||||||
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();
|
||||||
}
|
}
|
||||||
frame.write(self.ball.pos, ColouredChar::coloured('O', ColorCode::new(Color::Green, Color::Black))).unwrap();
|
frame.write(self.ball.pos.into_usize().unwrap(), ColouredChar::coloured('O', ColorCode::new(Color::Green, Color::Black))).unwrap();
|
||||||
|
|
||||||
Ok(frame)
|
Ok(frame)
|
||||||
}
|
}
|
||||||
@@ -93,7 +139,7 @@ impl CgComponent for Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct Player {
|
struct Player {
|
||||||
pos: Position,
|
pos: Position<usize>,
|
||||||
score: i32,
|
score: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,52 +161,13 @@ impl Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct Ball {
|
struct Ball {
|
||||||
pos: Position,
|
pos: Position<f32>,
|
||||||
vx: i32,
|
vx: f32,
|
||||||
vy: i32,
|
vy: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ball {
|
impl Ball {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Ball { pos: Position::new(40, 12), vx: 1, vy: 1 }
|
Ball { pos: Position::new(40.0, 12.0), vx: 1.0, vy: 0.3 }
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, player1: &mut Player, player2: &mut Player) {
|
|
||||||
let pos_next = Position::new( // invert x direction on collision with player
|
|
||||||
(self.pos.x as i32 + self.vx) as usize,
|
|
||||||
(self.pos.y as i32 + self.vy) as usize
|
|
||||||
);
|
|
||||||
for i in 0..5 {
|
|
||||||
if player1.pos.y + i - 2 == pos_next.y && player1.pos.x == pos_next.x {
|
|
||||||
self.vx = -self.vx;
|
|
||||||
break;
|
|
||||||
} else if player2.pos.y + i - 2 == pos_next.y && player2.pos.x == pos_next.x {
|
|
||||||
self.vx = -self.vx;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if pos_next.y < 0 || pos_next.y >= BUFFER_HEIGHT { // if the move is outside the screen, then invert the direction
|
|
||||||
self.vy = -self.vy;
|
|
||||||
}
|
|
||||||
|
|
||||||
if pos_next.x < 0 {
|
|
||||||
player2.score += 1;
|
|
||||||
self.pos = Position::new(40, 12);
|
|
||||||
self.vx = 1;
|
|
||||||
self.vy = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if pos_next.x >= BUFFER_WIDTH {
|
|
||||||
player1.score += 1;
|
|
||||||
self.pos = Position::new(40, 12);
|
|
||||||
self.vx = -1;
|
|
||||||
self.vy = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.pos = Position::new(
|
|
||||||
(self.pos.x as i32 + self.vx) as usize,
|
|
||||||
(self.pos.y as i32 + self.vy) as usize
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,10 @@ use async_trait::async_trait;
|
|||||||
use crate::std::io::{Color, Display, KeyStroke, Stdin};
|
use crate::std::io::{Color, Display, KeyStroke, Stdin};
|
||||||
use crate::std::time;
|
use crate::std::time;
|
||||||
use crate::std::application::{Application, Error};
|
use crate::std::application::{Application, Error};
|
||||||
use crate::std::frame::{ColouredChar, Dimensions, Frame, RenderError, ColorCode};
|
use crate::std::render::{ColouredChar, Dimensions, Frame, RenderError, ColorCode};
|
||||||
use crate::std::random::Random;
|
use crate::std::random::Random;
|
||||||
use crate::system::std::frame;
|
use crate::system::std::render;
|
||||||
use super::super::lib::coords::{Position, Direction};
|
use super::super::super::lib::coords::{Position, Direction};
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
enum Gamemode {
|
enum Gamemode {
|
||||||
@@ -164,7 +164,7 @@ impl Game {
|
|||||||
|
|
||||||
fn render(&mut self) -> Result<(), RenderError> {
|
fn render(&mut self) -> Result<(), RenderError> {
|
||||||
|
|
||||||
let mut frame = Frame::new(frame::Position::new(0, 0), Dimensions::new(80, 25))?;
|
let mut frame = Frame::new(render::Position::new(0, 0), Dimensions::new(80, 25))?;
|
||||||
let mut curr_colour = ColorCode::new(Color::LightBlue, Color::Black);
|
let mut curr_colour = ColorCode::new(Color::LightBlue, Color::Black);
|
||||||
|
|
||||||
for s in self.snakes.clone() {
|
for s in self.snakes.clone() {
|
||||||
@@ -205,7 +205,7 @@ impl Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn render_end_screen(&mut self) -> Result<(), RenderError> {
|
fn render_end_screen(&mut self) -> Result<(), RenderError> {
|
||||||
let mut frame = Frame::new(frame::Position::new(0, 0), Dimensions::new(80, 25))?;
|
let mut frame = Frame::new(render::Position::new(0, 0), Dimensions::new(80, 25))?;
|
||||||
|
|
||||||
frame[10] = Game::centre_text(80, String::from("u lost")).chars().map(|c| ColouredChar::coloured(c, ColorCode::new(Color::Red, Color::Black))).collect();
|
frame[10] = Game::centre_text(80, String::from("u lost")).chars().map(|c| ColouredChar::coloured(c, ColorCode::new(Color::Red, Color::Black))).collect();
|
||||||
frame[12] = Game::centre_text(80, String::from(format!("ur score was {}", self.score))).chars().map(|c| ColouredChar::coloured(c, ColorCode::new(Color::LightGreen, Color::Black))).collect();
|
frame[12] = Game::centre_text(80, String::from(format!("ur score was {}", self.score))).chars().map(|c| ColouredChar::coloured(c, ColorCode::new(Color::LightGreen, Color::Black))).collect();
|
||||||
@@ -5,7 +5,7 @@ use alloc::boxed::Box;
|
|||||||
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::frame::{Frame, Position, Dimensions, ColouredChar, RenderError};
|
use crate::std::render::{Frame, Position, Dimensions, ColouredChar, RenderError};
|
||||||
use crate::std::io::{Display, KeyStroke, Screen, Stdin};
|
use crate::std::io::{Display, KeyStroke, Screen, Stdin};
|
||||||
|
|
||||||
use crate::user::lib::libgui::{
|
use crate::user::lib::libgui::{
|
||||||
|
|||||||
+5
-7
@@ -1,15 +1,13 @@
|
|||||||
|
|
||||||
pub mod calc;
|
pub mod calc;
|
||||||
pub mod crystalfetch;
|
pub mod crystalfetch;
|
||||||
pub mod rickroll;
|
pub mod rickroll;
|
||||||
pub mod shell;
|
pub mod shell;
|
||||||
//pub mod shellrewrite;
|
|
||||||
pub mod tasks;
|
pub mod tasks;
|
||||||
mod gigachad_detector;
|
mod gigachad_detector;
|
||||||
|
|
||||||
//mod shellrewrite;
|
//mod shellrewrite;
|
||||||
mod snake;
|
|
||||||
mod grapher;
|
mod grapher;
|
||||||
mod gameoflife;
|
|
||||||
mod tetris;
|
mod games;
|
||||||
mod asteroids;
|
|
||||||
mod crystalrpg;
|
|
||||||
mod pong;
|
|
||||||
@@ -24,6 +24,7 @@ use crate::user::{
|
|||||||
cg_widgets::CgDialog,
|
cg_widgets::CgDialog,
|
||||||
},
|
},
|
||||||
bin::*,
|
bin::*,
|
||||||
|
bin::games::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
@@ -122,30 +123,30 @@ async fn exec() -> Result<(), Error> {
|
|||||||
let mode = Graphics640x480x16::new();
|
let mode = Graphics640x480x16::new();
|
||||||
mode.set_mode();
|
mode.set_mode();
|
||||||
mode.clear_screen(Color16::Black);
|
mode.clear_screen(Color16::Black);
|
||||||
mode.draw_line((80, 60), (80, 420), Color16::Cyan);
|
mode.draw_line((80, 60), (120, 420), Color16::Cyan);
|
||||||
}
|
}
|
||||||
"graph" => {
|
"graph" => {
|
||||||
grapher::Grapher::new().run(args).await?;
|
grapher::Grapher::new().run(args).await?;
|
||||||
}
|
}
|
||||||
"snake" => {
|
"games/snake" => {
|
||||||
snake::Game::new().run(args).await?;
|
snake::Game::new().run(args).await?;
|
||||||
}
|
}
|
||||||
"asteroids" => {
|
"games/asteroids" => {
|
||||||
let mut asteroid_game = asteroids::Game::new();
|
let mut asteroid_game = asteroids::Game::new();
|
||||||
asteroid_game.run(args).await?;
|
asteroid_game.run(args).await?;
|
||||||
}
|
}
|
||||||
"pong" => {
|
"games/pong" => {
|
||||||
pong::Game::new().run(args).await?;
|
pong::Game::new().run(args).await?;
|
||||||
}
|
}
|
||||||
"serial" => {
|
"serial" => {
|
||||||
let c = Serial::reply_char('e');
|
let c = Serial::reply_char('e');
|
||||||
println!("{}", c);
|
println!("{}", c);
|
||||||
}
|
}
|
||||||
"gameoflife" => {
|
"games/gameoflife" => {
|
||||||
let mut game = gameoflife::GameOfLife::new();
|
let mut game = gameoflife::GameOfLife::new();
|
||||||
game.run(Vec::new()).await?;
|
game.run(Vec::new()).await?;
|
||||||
}
|
}
|
||||||
"tetris" => {
|
"games/tetris" => {
|
||||||
// let mut game = tetris::TetrisEngine::new();
|
// let mut game = tetris::TetrisEngine::new();
|
||||||
// game.run(Vec::new()).await?;
|
// game.run(Vec::new()).await?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
use spin::{Mutex};
|
use spin::{Mutex};
|
||||||
use crate::std::frame::{Frame, RenderError};
|
use crate::std::render::{Frame, RenderError};
|
||||||
|
|
||||||
use alloc::{
|
use alloc::{
|
||||||
boxed::Box,
|
boxed::Box,
|
||||||
|
|||||||
@@ -4,21 +4,21 @@ use alloc::boxed::Box;
|
|||||||
use core::any::Any;
|
use core::any::Any;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use crate::std::application::Exit;
|
use crate::std::application::Exit;
|
||||||
use crate::std::frame::{ColouredChar, Dimensions, Frame, Position, RenderError};
|
use crate::std::render::{ColouredChar, Dimensions, Frame, Position, RenderError};
|
||||||
use crate::std::io::{KeyStroke, Stdin};
|
use crate::std::io::{KeyStroke, Stdin};
|
||||||
use crate::user::lib::libgui::cg_core::{CgComponent, CgTextEdit, CgTextInput, Widget};
|
use crate::user::lib::libgui::cg_core::{CgComponent, CgTextEdit, CgTextInput, Widget};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct CgLineEdit {
|
pub struct CgLineEdit {
|
||||||
pub position: Position,
|
pub position: Position<usize>,
|
||||||
pub dimensions: Dimensions,
|
pub dimensions: Dimensions<usize>,
|
||||||
pub prompt: String,
|
pub prompt: String,
|
||||||
pub text: Vec<char>,
|
pub text: Vec<char>,
|
||||||
pub ptr: usize, // cursor position
|
pub ptr: usize, // cursor position
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CgLineEdit {
|
impl CgLineEdit {
|
||||||
pub fn new(position: Position, width: usize, prompt: String) -> CgLineEdit {
|
pub fn new(position: Position<usize>, width: usize, prompt: String) -> CgLineEdit {
|
||||||
CgLineEdit {
|
CgLineEdit {
|
||||||
position,
|
position,
|
||||||
dimensions: Dimensions::new(width, 1),
|
dimensions: Dimensions::new(width, 1),
|
||||||
@@ -131,15 +131,15 @@ impl CgTextInput for CgLineEdit {
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct CgBoxEdit {
|
pub struct CgBoxEdit {
|
||||||
pub position: Position,
|
pub position: Position<usize>,
|
||||||
pub dimensions: Dimensions,
|
pub dimensions: Dimensions<usize>,
|
||||||
pub prompt: String,
|
pub prompt: String,
|
||||||
pub text: Vec<char>,
|
pub text: Vec<char>,
|
||||||
pub ptr: Position,
|
pub ptr: Position<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CgBoxEdit {
|
impl CgBoxEdit {
|
||||||
pub fn new(position: Position, dimensions: Dimensions, prompt: String) -> CgBoxEdit {
|
pub fn new(position: Position<usize>, dimensions: Dimensions<usize>, prompt: String) -> CgBoxEdit {
|
||||||
CgBoxEdit {
|
CgBoxEdit {
|
||||||
position,
|
position,
|
||||||
dimensions,
|
dimensions,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::std::frame::{ColouredChar, Dimensions, Frame, Position, RenderError};
|
use crate::std::render::{ColouredChar, Dimensions, Frame, Position, RenderError};
|
||||||
|
|
||||||
pub(crate) fn render_outline(frame: &mut Frame, dimensions: Dimensions) -> Result<(), RenderError> {
|
pub(crate) fn render_outline(frame: &mut Frame, dimensions: Dimensions<usize>) -> Result<(), RenderError> {
|
||||||
// draws the sides of the container
|
// draws the sides of the container
|
||||||
for i in 0..frame.dimensions.x {
|
for i in 0..frame.dimensions.x {
|
||||||
frame.write(Position::new(i, 0), ColouredChar::new('─'))?;
|
frame.write(Position::new(i, 0), ColouredChar::new('─'))?;
|
||||||
|
|||||||
@@ -7,19 +7,19 @@ use hashbrown::HashMap;
|
|||||||
use crate::std::application::Exit;
|
use crate::std::application::Exit;
|
||||||
use super::cg_core::{CgComponent, CgKeyboardCapture, Widget};
|
use super::cg_core::{CgComponent, CgKeyboardCapture, Widget};
|
||||||
use super::cg_utils::render_outline;
|
use super::cg_utils::render_outline;
|
||||||
use crate::std::frame::{ColouredChar, Dimensions, Position, Frame, RenderError, ColorCode, BUFFER_WIDTH, BUFFER_HEIGHT};
|
use crate::std::render::{ColouredChar, Dimensions, Position, Frame, RenderError, ColorCode, BUFFER_WIDTH, BUFFER_HEIGHT};
|
||||||
use crate::std::io::{Color, KeyStroke, Stdin};
|
use crate::std::io::{Color, KeyStroke, Stdin};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct CgContainer {
|
pub struct CgContainer {
|
||||||
pub elements: HashMap<&'static str, Widget>,
|
pub elements: HashMap<&'static str, Widget>,
|
||||||
pub position: Position,
|
pub position: Position<usize>,
|
||||||
pub dimensions: Dimensions,
|
pub dimensions: Dimensions<usize>,
|
||||||
pub outlined: bool,
|
pub outlined: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CgContainer {
|
impl CgContainer {
|
||||||
pub fn new(position: Position, dimensions: Dimensions, outlined: bool) -> CgContainer {
|
pub fn new(position: Position<usize>, dimensions: Dimensions<usize>, outlined: bool) -> CgContainer {
|
||||||
CgContainer {
|
CgContainer {
|
||||||
elements: HashMap::new(),
|
elements: HashMap::new(),
|
||||||
position,
|
position,
|
||||||
@@ -60,14 +60,14 @@ impl CgComponent for CgContainer {
|
|||||||
pub struct CgTextBox {
|
pub struct CgTextBox {
|
||||||
title: String,
|
title: String,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
pub position: Position,
|
pub position: Position<usize>,
|
||||||
pub dimensions: Dimensions,
|
pub dimensions: Dimensions<usize>,
|
||||||
outlined: bool,
|
outlined: bool,
|
||||||
wrap_words: bool // if false then will not wrap until the end of a word if possible
|
wrap_words: bool // if false then will not wrap until the end of a word if possible
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CgTextBox {
|
impl CgTextBox {
|
||||||
pub fn new(title: String, content: String, position: Position, dimensions: Dimensions, outlined: bool) -> CgTextBox {
|
pub fn new(title: String, content: String, position: Position<usize>, dimensions: Dimensions<usize>, outlined: bool) -> CgTextBox {
|
||||||
CgTextBox { title, content, position, dimensions, outlined, wrap_words: true }
|
CgTextBox { title, content, position, dimensions, outlined, wrap_words: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,13 +143,13 @@ impl CgComponent for CgTextBox {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct CgLabel {
|
pub struct CgLabel {
|
||||||
content: String,
|
content: String,
|
||||||
position: Position,
|
position: Position<usize>,
|
||||||
dimensions: Dimensions,
|
dimensions: Dimensions<usize>,
|
||||||
centered: bool,
|
centered: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CgLabel {
|
impl CgLabel {
|
||||||
pub fn new(content: String, position: Position, width: usize, centered: bool) -> CgLabel {
|
pub fn new(content: String, position: Position<usize>, width: usize, centered: bool) -> CgLabel {
|
||||||
CgLabel {
|
CgLabel {
|
||||||
content,
|
content,
|
||||||
position: Position::new(position.x, position.y),
|
position: Position::new(position.x, position.y),
|
||||||
@@ -247,12 +247,12 @@ impl CgComponent for CgIndicatorWidget {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct CgIndicatorBar {
|
pub struct CgIndicatorBar {
|
||||||
pub fields: Vec<CgIndicatorWidget>,
|
pub fields: Vec<CgIndicatorWidget>,
|
||||||
position: Position,
|
position: Position<usize>,
|
||||||
dimensions: Dimensions,
|
dimensions: Dimensions<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CgIndicatorBar {
|
impl CgIndicatorBar {
|
||||||
pub fn new(position: Position, width: usize) -> CgIndicatorBar {
|
pub fn new(position: Position<usize>, width: usize) -> CgIndicatorBar {
|
||||||
CgIndicatorBar {
|
CgIndicatorBar {
|
||||||
fields: Vec::new(),
|
fields: Vec::new(),
|
||||||
position: Position::new(position.x, position.y),
|
position: Position::new(position.x, position.y),
|
||||||
@@ -291,8 +291,8 @@ impl CgComponent for CgIndicatorBar {
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct CgStatusBar {
|
pub struct CgStatusBar {
|
||||||
position: Position,
|
position: Position<usize>,
|
||||||
dimensions: Dimensions,
|
dimensions: Dimensions<usize>,
|
||||||
|
|
||||||
window_title: CgIndicatorWidget,
|
window_title: CgIndicatorWidget,
|
||||||
screen_mode: CgIndicatorWidget,
|
screen_mode: CgIndicatorWidget,
|
||||||
@@ -325,7 +325,7 @@ impl CgComponent for CgStatusBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CgStatusBar {
|
impl CgStatusBar {
|
||||||
pub fn new(position: Position, dimensions: Dimensions) -> CgStatusBar {
|
pub fn new(position: Position<usize>, dimensions: Dimensions<usize>) -> CgStatusBar {
|
||||||
let mut widget = CgStatusBar {
|
let mut widget = CgStatusBar {
|
||||||
position,
|
position,
|
||||||
dimensions,
|
dimensions,
|
||||||
|
|||||||
Reference in New Issue
Block a user