dis_rs/common/fire/
builder.rs

1use crate::fire::model::Fire;
2use crate::model::{
3    DescriptorRecord, EntityId, EntityType, EventId, Location, MunitionDescriptor, VectorF32,
4};
5
6pub struct FireBuilder(Fire);
7
8impl Default for FireBuilder {
9    fn default() -> Self {
10        Self::new()
11    }
12}
13
14impl FireBuilder {
15    #[must_use]
16    pub fn new() -> Self {
17        FireBuilder(Fire::default())
18    }
19
20    #[must_use]
21    pub fn new_from_body(body: Fire) -> Self {
22        FireBuilder(body)
23    }
24
25    #[must_use]
26    pub fn build(self) -> Fire {
27        self.0
28    }
29
30    #[must_use]
31    pub fn with_firing_entity_id(mut self, firing_entity_id: EntityId) -> Self {
32        self.0.firing_entity_id = firing_entity_id;
33        self
34    }
35
36    #[must_use]
37    pub fn with_target_entity_id(mut self, target_entity_id: EntityId) -> Self {
38        self.0.target_entity_id = target_entity_id;
39        self
40    }
41
42    #[must_use]
43    pub fn with_entity_id(mut self, entity_id: EntityId) -> Self {
44        self.0.entity_id = entity_id;
45        self
46    }
47
48    #[must_use]
49    pub fn with_event_id(mut self, event_id: EventId) -> Self {
50        self.0.event_id = event_id;
51        self
52    }
53
54    #[must_use]
55    pub fn with_fire_mission_index(mut self, fire_mission_index: u32) -> Self {
56        self.0.fire_mission_index = fire_mission_index;
57        self
58    }
59
60    #[must_use]
61    pub fn with_location_in_world(mut self, location_in_world: Location) -> Self {
62        self.0.location_in_world = location_in_world;
63        self
64    }
65
66    #[must_use]
67    pub fn with_descriptor(mut self, descriptor: DescriptorRecord) -> Self {
68        self.0.descriptor = descriptor;
69        self
70    }
71
72    #[must_use]
73    pub fn with_munition_descriptor(
74        mut self,
75        entity_type: EntityType,
76        munition: MunitionDescriptor,
77    ) -> Self {
78        self.0.descriptor = DescriptorRecord::new_munition(entity_type, munition);
79        self
80    }
81
82    #[must_use]
83    pub fn with_expendable_descriptor(mut self, entity_type: EntityType) -> Self {
84        self.0.descriptor = DescriptorRecord::Expendable { entity_type };
85        self
86    }
87
88    #[must_use]
89    pub fn with_velocity(mut self, velocity: VectorF32) -> Self {
90        self.0.velocity = velocity;
91        self
92    }
93
94    #[must_use]
95    pub fn with_range(mut self, range: f32) -> Self {
96        self.0.range = range;
97        self
98    }
99}