Loads more work on battling, initial stretch to run a turn done.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user