This commit is contained in:
Dummi26 2023-04-25 15:15:03 +02:00
parent ca1dbf2722
commit d66a0f37f2
3 changed files with 27 additions and 10 deletions

View File

@ -21,7 +21,7 @@ pub fn run(tutor: &mut Tutor) {
// thread: Represents a different thread. The thread's return value can be retrieved by using .await(). Thread values are returned by the builtin thread() function. // thread: Represents a different thread. The thread's return value can be retrieved by using .await(). Thread values are returned by the builtin thread() function.
// reference: A mutable reference to some data. Used by things like push() and remove() to avoid having to clone the entire list just to make a small change. // reference: A mutable reference to some data. Used by things like push() and remove() to avoid having to clone the entire list just to make a small change.
// enums: An enum can wrap any type. Enums are identified by their names and can be created using EnumName: inner_value. The type is written EnumName(InnerType). // enums: An enum can wrap any type. Enums are identified by their names and can be created using EnumName: inner_value. The type is written EnumName(InnerType).
// return a value of type GoBackToMenu([int]) to return to the menu. // return any enum to return to the menu.
")); "));
loop { loop {
match tutor.let_user_make_change().run(vec![]).data { match tutor.let_user_make_change().run(vec![]).data {

View File

@ -2,7 +2,7 @@ use crate::script::val_data::VDataEnum;
use super::Tutor; use super::Tutor;
pub const MAX_POS: usize = 3; pub const MAX_POS: usize = 6;
pub fn run(mut tutor: Tutor) { pub fn run(mut tutor: Tutor) {
loop { loop {
@ -11,26 +11,37 @@ pub fn run(mut tutor: Tutor) {
" "
// Welcome to the mers tutor! // Welcome to the mers tutor!
// This is the main menu. Change the number to navigate to a specific part. // This is the main menu. Change the number to navigate to a specific part.
0 fn go_to() 0
// 1 Comments // 1 Comments
// 2 Values // 2 Functions
// 3 Returns // 3 Values
// 4 Variables
// 5 Returns
// 6 Types
go_to()
", ",
)); ));
loop { loop {
match tutor.let_user_make_change().run(vec![]).data { match tutor.let_user_make_change().run(vec![]).data {
VDataEnum::Int(pos) => { VDataEnum::Int(pos) if pos != 0 => {
tutor.current_pos = (pos.max(0) as usize).min(MAX_POS); tutor.current_pos = (pos.max(0) as usize).min(MAX_POS);
match tutor.current_pos { match tutor.current_pos {
0 => continue, 0 => continue,
1 => super::base_comments::run(&mut tutor), 1 => super::base_comments::run(&mut tutor),
2 => super::base_values::run(&mut tutor), 2 => super::base_functions::run(&mut tutor),
3 => super::base_return::run(&mut tutor), 3 => super::base_values::run(&mut tutor),
4 => super::base_variables::run(&mut tutor),
5 => super::base_return::run(&mut tutor),
6 => super::base_types::run(&mut tutor),
_ => unreachable!(), _ => unreachable!(),
} }
} }
other => { other => {
tutor.set_status(format!(" - Returned {} instead of an integer", other)); tutor.set_status(format!(
" - Returned {} instead of a nonzero integer",
other
));
} }
} }
break; break;

View File

@ -6,8 +6,11 @@ use crate::{
}; };
mod base_comments; mod base_comments;
mod base_functions;
mod base_return; mod base_return;
mod base_types;
mod base_values; mod base_values;
mod base_variables;
mod menu; mod menu;
pub fn start(spawn_new_terminal_for_editor: bool) { pub fn start(spawn_new_terminal_for_editor: bool) {
@ -36,6 +39,7 @@ false
editor_join_handle, editor_join_handle,
file_path, file_path,
receiver, receiver,
i_name: None,
}; };
loop { loop {
if let VDataEnum::Bool(true) = tutor.let_user_make_change().run(vec![]).data { if let VDataEnum::Bool(true) = tutor.let_user_make_change().run(vec![]).data {
@ -54,11 +58,13 @@ pub struct Tutor {
editor_join_handle: JoinHandle<()>, editor_join_handle: JoinHandle<()>,
file_path: PathBuf, file_path: PathBuf,
receiver: std::sync::mpsc::Receiver<Result<RScript, ScriptError>>, receiver: std::sync::mpsc::Receiver<Result<RScript, ScriptError>>,
// i_ are inputs from the user
pub i_name: Option<String>,
} }
impl Tutor { impl Tutor {
/// only returns after a successful compile. before returning, does not call self.update() - you have to do that manually. /// only returns after a successful compile. before returning, does not call self.update() - you have to do that manually.
pub fn let_user_make_change(&mut self) -> RScript { pub fn let_user_make_change(&mut self) -> RScript {
// eprintln!(" - - - - - - - - - - - - - - - - - - - - - - - - -"); eprintln!(" - - - - - - - - - - - - - - - - - - - - - - - - -");
let script = loop { let script = loop {
match self.receiver.recv().unwrap() { match self.receiver.recv().unwrap() {
Err(e) => { Err(e) => {