Projektmodule und vollständiges TBC-Kompilat umsetzen und Change archivieren
This commit is contained in:
@@ -678,6 +678,7 @@ pub struct FormObject {
|
||||
pub name: String,
|
||||
pub class: ObjectClass,
|
||||
pub parent_form: Option<String>,
|
||||
pub parent: Option<u16>,
|
||||
pub array: bool,
|
||||
}
|
||||
|
||||
@@ -698,6 +699,13 @@ impl FormCatalog {
|
||||
self.objects.push(FormObject {
|
||||
name: name.into().to_uppercase(),
|
||||
class,
|
||||
parent: parent_form
|
||||
.and_then(|name| {
|
||||
self.objects
|
||||
.iter()
|
||||
.rposition(|o| o.name.eq_ignore_ascii_case(name))
|
||||
})
|
||||
.map(|id| id as u16),
|
||||
parent_form: parent_form.map(str::to_uppercase),
|
||||
array,
|
||||
});
|
||||
@@ -712,16 +720,33 @@ impl FormCatalog {
|
||||
.map(|(i, o)| (i as u16, o))
|
||||
}
|
||||
|
||||
pub fn append(&mut self, other: &Self) {
|
||||
let offset = self.objects.len() as u16;
|
||||
self.objects
|
||||
.extend(other.objects.iter().cloned().map(|mut object| {
|
||||
object.parent = object.parent.map(|id| id + offset);
|
||||
object
|
||||
}));
|
||||
}
|
||||
|
||||
pub fn find_in(&self, name: &str, form: &str) -> Option<(u16, &FormObject)> {
|
||||
self.objects
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, o)| o.name.eq_ignore_ascii_case(name) && self.belongs_to(o, form))
|
||||
.map(|(id, o)| (id as u16, o))
|
||||
}
|
||||
|
||||
pub fn belongs_to(&self, object: &FormObject, form: &str) -> bool {
|
||||
let mut parent = object.parent_form.as_deref();
|
||||
let mut parent = object.parent;
|
||||
for _ in 0..self.objects.len() {
|
||||
let Some(name) = parent else { return false };
|
||||
if name.eq_ignore_ascii_case(form) {
|
||||
let Some(object) = parent.and_then(|id| self.objects.get(id as usize)) else {
|
||||
return false;
|
||||
};
|
||||
if object.name.eq_ignore_ascii_case(form) {
|
||||
return true;
|
||||
}
|
||||
parent = self
|
||||
.find(name)
|
||||
.and_then(|(_, object)| object.parent_form.as_deref());
|
||||
parent = object.parent;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user