main
Elnu 2 years ago
parent 2735a391b8
commit 77bc3b4b09

@ -7,7 +7,7 @@ use std::{
use renrs::State; use renrs::State;
use egui_sfml::{SfEgui, egui}; use egui_sfml::{egui, SfEgui};
use sfml::{ use sfml::{
graphics::{Color, RectangleShape, RenderTarget, RenderWindow, Transformable}, graphics::{Color, RectangleShape, RenderTarget, RenderWindow, Transformable},
system::Vector2f, system::Vector2f,

@ -1,11 +1,12 @@
use std::{collections::HashMap, rc::Rc};
use debug_cell::RefCell; use debug_cell::RefCell;
use std::{collections::HashMap, rc::Rc};
use super::{ use super::{
command::{parse_command, Command}, command::{parse_command, Command},
control::{parse_control, Control}, control::{parse_control, Control},
event::Event,
token::Token, token::Token,
Pair, Rule, event::Event, Pair, Rule,
}; };
pub struct CommandBlock { pub struct CommandBlock {
@ -35,24 +36,21 @@ impl CommandContext {
if let Token::Keyword(_) = value { if let Token::Keyword(_) = value {
todo!("assignment variable interpolation isn't implemented"); todo!("assignment variable interpolation isn't implemented");
} }
let root = self.context let root = self.context.borrow().get_root(&self.context);
.borrow()
.get_root(&self.context);
// Don't want to re-borrow if root is self // Don't want to re-borrow if root is self
let root = if Rc::ptr_eq(&self.context, &root) { let root = if Rc::ptr_eq(&self.context, &root) {
&self.context &self.context
} else { } else {
&root &root
}; };
root root.borrow_mut()
.borrow_mut()
.variables .variables
.as_ref() .as_ref()
.unwrap() .unwrap()
.borrow_mut() .borrow_mut()
.insert(variable.clone(), value.clone()); .insert(variable.clone(), value.clone());
return None; return None;
}, }
Eat { .. } => return None, Eat { .. } => return None,
} }
.process(&self.context), .process(&self.context),

@ -38,7 +38,7 @@ pub fn parse_command(pair: Pair) -> Command {
variable: variable.clone(), variable: variable.clone(),
value: value.clone(), value: value.clone(),
} }
}, }
[Keyword(keyword), Keyword(variable), Keyword(equals), value] [Keyword(keyword), Keyword(variable), Keyword(equals), value]
if keyword.eq("$") && equals.eq("=") => if keyword.eq("$") && equals.eq("=") =>
{ {
@ -46,7 +46,7 @@ pub fn parse_command(pair: Pair) -> Command {
variable: variable.clone(), variable: variable.clone(),
value: value.clone(), value: value.clone(),
} }
}, }
[Keyword(keyword), Str(food), tail @ ..] if keyword.eq("eat") => Eat { [Keyword(keyword), Str(food), tail @ ..] if keyword.eq("eat") => Eat {
food: food.to_owned(), food: food.to_owned(),
politely: match tail { politely: match tail {

@ -1,5 +1,5 @@
use std::{collections::HashMap, rc::Rc};
use debug_cell::RefCell; use debug_cell::RefCell;
use std::{collections::HashMap, rc::Rc};
use regex::Regex; use regex::Regex;
@ -28,7 +28,7 @@ impl Event {
.as_deref() .as_deref()
.map(|name| interpolate_string(&name, &variables)); .map(|name| interpolate_string(&name, &variables));
*text = interpolate_string(&text, &variables); *text = interpolate_string(&text, &variables);
}, }
} }
self self
} }

@ -7,8 +7,8 @@ mod utils;
pub type Pair<'a> = pest::iterators::Pair<'a, Rule>; pub type Pair<'a> = pest::iterators::Pair<'a, Rule>;
use std::{fs, path::PathBuf, rc::Rc};
use debug_cell::RefCell; use debug_cell::RefCell;
use std::{fs, path::PathBuf, rc::Rc};
pub use pest::Parser; pub use pest::Parser;
use pest_derive::Parser; use pest_derive::Parser;

Loading…
Cancel
Save