|
|
@ -6,13 +6,13 @@ use rhai::{ |
|
|
|
|
|
|
|
|
use std::fmt::{Debug, Display}; |
|
|
use std::fmt::{Debug, Display}; |
|
|
|
|
|
|
|
|
use crate::games::run::types::Card; |
|
|
use crate::games::{Config, run::types::Card}; |
|
|
|
|
|
|
|
|
use super::{ |
|
|
use super::{ |
|
|
types::{CardId, Data, Player, RhaiResult, RunningPile}, |
|
|
types::{CardId, Data, Player, RhaiResult, RunningPile}, |
|
|
}; |
|
|
}; |
|
|
// TODO Write somekind of documentation on functions available & stuff
|
|
|
// TODO Write somekind of documentation on functions available & stuff
|
|
|
pub fn setup_engine() -> Engine { |
|
|
pub fn setup_engine(conf: &Config) -> Engine { |
|
|
let mut engine = Engine::new(); |
|
|
let mut engine = Engine::new(); |
|
|
engine.set_max_expr_depths(0, 0); |
|
|
engine.set_max_expr_depths(0, 0); |
|
|
engine.register_result_fn("shuffle", shuffle_pile); |
|
|
engine.register_result_fn("shuffle", shuffle_pile); |
|
|
@ -65,6 +65,12 @@ pub fn setup_engine() -> Engine { |
|
|
.register_fn("debug", |p: &mut CardId| p.to_string()) |
|
|
.register_fn("debug", |p: &mut CardId| p.to_string()) |
|
|
.register_fn("+", |s: &str, p: CardId| format!("{}{}", s, p)) |
|
|
.register_fn("+", |s: &str, p: CardId| format!("{}{}", s, p)) |
|
|
.register_fn("+", |p: CardId, s: &str| p.to_string().push_str(s)); |
|
|
.register_fn("+", |p: CardId, s: &str| p.to_string().push_str(s)); |
|
|
|
|
|
|
|
|
|
|
|
let available_cards = conf.available_cards.clone(); |
|
|
|
|
|
engine.register_result_fn("new_card", move |kind: &str| { |
|
|
|
|
|
let card = available_cards.get(kind).unwrap(); |
|
|
|
|
|
to_dynamic(Card { kind: kind.to_string(), uuid: uuid::Uuid::new_v4(), other: card.other.clone() }) |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
engine |
|
|
engine |
|
|
} |
|
|
} |
|
|
|