You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
898 B

  1. use specs::{saveload::MarkedBuilder, Builder, Entity, World, WorldExt};
  2. use crate::{
  3. components::{Fleet, MeetingPointOwned},
  4. misc::{Persistence, WorldPersistence},
  5. };
  6. use super::Error;
  7. #[derive(Default, Clone)]
  8. pub struct FleetBuilder {
  9. owner: Option<Entity>,
  10. }
  11. impl FleetBuilder {
  12. pub fn build(&self, world: &mut World) -> Result<Entity, Error> {
  13. let owner = self.owner.ok_or(Error::MissingValue("owner"))?;
  14. let meeting_point_owned = MeetingPointOwned::new(owner);
  15. let fleet = Fleet::new();
  16. let entity = world
  17. .create_entity()
  18. .marked::<<WorldPersistence as Persistence>::Marker>()
  19. .with(meeting_point_owned)
  20. .with(fleet)
  21. .build();
  22. Ok(entity)
  23. }
  24. pub fn owner(mut self, meeting_point: Entity) -> Self {
  25. self.owner = Some(meeting_point);
  26. self
  27. }
  28. }