aoe2_probe/prebuilt/ver1_46/
files.rs1use std::sync::Arc;
2
3use crate::{
4 parse::Token,
5 utils::{map::*, DynString},
6};
7
8use super::AI2;
9
10pub struct Files;
11
12impl Files {
13 pub fn template() -> Token {
14 let mut root = PatchedMap::with_capacity(7);
15 root.push_back("script_file_path", DynString::with_capacity(0_u16, ""));
16 root.push_back("script_file_content", DynString::with_capacity(0_u32, ""));
17 root.push_back("ai_files_present", 0_u32);
18 root.push_back("unknown", vec![0_u8.into(); 4]);
19 root.push_back("number_of_ai_files", vec![0_u32.into()]);
20
21 root.patches.insert(
22 "number_of_ai_files".to_string(),
23 Arc::new(|map: &mut PatchedMap, template: &mut Token| {
24 if map.contains("ai_files_present") {
25 let count = *map["ai_files_present"].try_u32();
26 let unit = template.try_vec()[0].clone();
27 let vec = template.try_mut_vec();
28 vec.clear();
29
30 for _ in 0..count {
31 vec.push(unit.clone());
32 }
33 }
34 }),
35 );
36
37 root.push_back("ai_files", vec![AI2::template(); 1]);
38
39 root.patches.insert(
40 "ai_files".to_string(),
41 Arc::new(|map: &mut PatchedMap, template: &mut Token| {
42 if map.contains("number_of_ai_files") {
43 if map["number_of_ai_files"].try_vec().len() > 0 {
44 let count = *map["number_of_ai_files"].try_vec()[0].try_u32();
45 let unit = template.try_vec()[0].clone();
46 let vec = template.try_mut_vec();
47 vec.clear();
48
49 for _ in 0..count {
50 vec.push(unit.clone());
51 }
52 } else {
53 let vec = template.try_mut_vec();
54 vec.clear();
55 }
56 }
57 }),
58 );
59
60 root.into()
61 }
62}