25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

48 satır
985 B

  1. #![allow(dead_code)]
  2. use space_crush_common::components::{Player, ShipCount};
  3. use specs::{Entity, ReadStorage, World};
  4. pub struct GameState {
  5. player_id: Entity,
  6. player_index: usize,
  7. selection: Option<Selection>,
  8. }
  9. pub struct Selection {
  10. pub fleet: Entity,
  11. pub count: ShipCount,
  12. }
  13. impl GameState {
  14. pub fn new(world: &mut World, player_id: Entity) -> Self {
  15. let player_index = world
  16. .system_data::<ReadStorage<Player>>()
  17. .get(player_id)
  18. .unwrap()
  19. .index();
  20. Self {
  21. player_id,
  22. player_index,
  23. selection: None,
  24. }
  25. }
  26. pub fn player_id(&self) -> Entity {
  27. self.player_id
  28. }
  29. pub fn player_index(&self) -> usize {
  30. self.player_index
  31. }
  32. pub fn selection(&self) -> &Option<Selection> {
  33. &self.selection
  34. }
  35. pub(crate) fn selection_mut(&mut self) -> &mut Option<Selection> {
  36. &mut self.selection
  37. }
  38. }