dis_rs/common/detonation/
builder.rs1use crate::common::detonation::model::Detonation;
2use crate::common::model::{
3 DescriptorRecord, EntityId, EntityType, EventId, Location, MunitionDescriptor,
4 VariableParameter, VectorF32,
5};
6use crate::enumerations::{DetonationResult, ExplosiveMaterialCategories};
7
8pub struct DetonationBuilder(Detonation);
9
10impl Default for DetonationBuilder {
11 fn default() -> Self {
12 Self::new()
13 }
14}
15
16impl DetonationBuilder {
17 #[must_use]
18 pub fn new() -> Self {
19 DetonationBuilder(Detonation::default())
20 }
21
22 #[must_use]
23 pub fn new_from_body(body: Detonation) -> Self {
24 DetonationBuilder(body)
25 }
26
27 #[must_use]
28 pub fn build(self) -> Detonation {
29 self.0
30 }
31
32 #[must_use]
33 pub fn with_source_entity_id(mut self, source_entity_id: EntityId) -> Self {
34 self.0.source_entity_id = source_entity_id;
35 self
36 }
37
38 #[must_use]
39 pub fn with_target_entity_id(mut self, target_entity_id: EntityId) -> Self {
40 self.0.target_entity_id = target_entity_id;
41 self
42 }
43
44 #[must_use]
45 pub fn with_exploding_entity_id(mut self, exploding_entity_id: EntityId) -> Self {
46 self.0.exploding_entity_id = exploding_entity_id;
47 self
48 }
49
50 #[must_use]
51 pub fn with_event_id(mut self, event_id: EventId) -> Self {
52 self.0.event_id = event_id;
53 self
54 }
55
56 #[must_use]
57 pub fn with_velocity(mut self, velocity: VectorF32) -> Self {
58 self.0.velocity = velocity;
59 self
60 }
61
62 #[must_use]
63 pub fn with_world_location(mut self, location: Location) -> Self {
64 self.0.location_in_world_coordinates = location;
65 self
66 }
67
68 #[must_use]
69 pub fn with_descriptor(mut self, descriptor: DescriptorRecord) -> Self {
70 self.0.descriptor = descriptor;
71 self
72 }
73
74 #[must_use]
75 pub fn with_munition_descriptor(
76 mut self,
77 entity_type: EntityType,
78 munition: MunitionDescriptor,
79 ) -> Self {
80 self.0.descriptor = DescriptorRecord::new_munition(entity_type, munition);
81 self
82 }
83
84 #[must_use]
85 pub fn with_expendable_descriptor(mut self, entity_type: EntityType) -> Self {
86 self.0.descriptor = DescriptorRecord::Expendable { entity_type };
87 self
88 }
89
90 #[must_use]
91 pub fn with_explosion_descriptor(
92 mut self,
93 entity_type: EntityType,
94 explosive_material: ExplosiveMaterialCategories,
95 explosive_force: f32,
96 ) -> Self {
97 self.0.descriptor =
98 DescriptorRecord::new_explosion(entity_type, explosive_material, explosive_force);
99 self
100 }
101
102 #[must_use]
103 pub fn with_entity_location(mut self, location: VectorF32) -> Self {
104 self.0.location_in_entity_coordinates = location;
105 self
106 }
107
108 #[must_use]
109 pub fn with_detonation_result(mut self, detonation_result: DetonationResult) -> Self {
110 self.0.detonation_result = detonation_result;
111 self
112 }
113
114 #[must_use]
115 pub fn with_variable_parameter(mut self, parameter: VariableParameter) -> Self {
116 self.0.variable_parameters.push(parameter);
117 self
118 }
119
120 #[must_use]
121 pub fn with_variable_parameters(mut self, parameters: Vec<VariableParameter>) -> Self {
122 self.0.variable_parameters = parameters;
123 self
124 }
125}