Loads more work on battling, initial stretch to run a turn done.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-06-16 17:59:33 +02:00
parent a33369afcc
commit ff541b0696
50 changed files with 105871 additions and 497 deletions

View File

@@ -23,6 +23,52 @@ macro_rules! script_hook {
};
}
#[macro_export]
macro_rules! script_hook_on_lock {
($hook_name: ident, $source: ident, $($parameters: expr),*) => {
let mut aggregator = $source.read().get_script_iterator();
while let Some(script) = aggregator.get_next() {
let lock = &mut script.get();
let script = lock.as_mut().unwrap();
if script.is_suppressed() {
continue;
}
script.$hook_name($($parameters),*);
}
};
}
#[macro_export]
macro_rules! run_scripts {
($hook_name: ident, $source: ident, $($parameters: expr),*) => {
for script in $source {
match script {
ScriptWrapper::Script(s) => {
if let Some(s) = s.upgrade() {
if let Some(s) = s.write().deref_mut() {
if !s.is_suppressed() {
s.$hook_name($($parameters),*);
}
}
}
}
ScriptWrapper::Set(s) => {
if let Some(s) = s.upgrade() {
for s in s.read().get_underlying() {
let mut s = s.1.get();
if let Some(s) = s.deref_mut() {
if !s.is_suppressed() {
s.$hook_name($($parameters),*);
}
}
}
}
}
}
}
};
}
#[derive(Default, Debug)]
pub struct ScriptSourceData {
is_initialized: bool,
@@ -310,25 +356,11 @@ mod tests {
let scripts = vec![ScriptWrapper::from(&set)];
let mut aggregator = ScriptAggregator::new(&scripts as *const Vec<ScriptWrapper>);
assert_eq!(
aggregator
.get_next()
.unwrap()
.get()
.as_mut()
.unwrap()
.name()
.str(),
aggregator.get_next().unwrap().get().as_mut().unwrap().name().str(),
"test_a"
);
assert_eq!(
aggregator
.get_next()
.unwrap()
.get()
.as_mut()
.unwrap()
.name()
.str(),
aggregator.get_next().unwrap().get().as_mut().unwrap().name().str(),
"test_b"
);
@@ -352,14 +384,7 @@ mod tests {
let scripts = vec![ScriptWrapper::from(&set)];
let mut aggregator = ScriptAggregator::new(&scripts as *const Vec<ScriptWrapper>);
assert_eq!(
aggregator
.get_next()
.unwrap()
.get()
.as_mut()
.unwrap()
.name()
.str(),
aggregator.get_next().unwrap().get().as_mut().unwrap().name().str(),
"test_a"
);
@@ -368,14 +393,7 @@ mod tests {
drop(mut_set);
assert_eq!(
aggregator
.get_next()
.unwrap()
.get()
.as_mut()
.unwrap()
.name()
.str(),
aggregator.get_next().unwrap().get().as_mut().unwrap().name().str(),
"test_c"
);
assert!(aggregator.get_next().is_none());