public void UpdateDisplay() { List <SpaceshipTemplate> queue = GameController.Instance.GetSelectedLogic().ShipQueue; if (ShipIndex < queue.Count) { SpaceshipTemplate template = GameController.Instance.GetSelectedLogic().ShipQueue[ShipIndex]; ShipName.text = template.DisplayName; } else { ShipName.text = ""; } }
public void CancelConstruction() { CelestialBodyLogic logic = GameController.Instance.GetSelectedLogic(); SpaceshipTemplate template = logic.ShipQueue[ShipIndex]; logic.ShipQueue.RemoveAt(ShipIndex); // Refund foreach (ShipCost cost in template.Costs) { logic.Resources[cost.Resource] += cost.Amount; } Controller.UpdateDisplay(); ConstructionUI.UpdateDisplay(); }
private void ConstructShip(SpaceshipTemplate template) { CelestialBodyResources resources = GetSelectedResources(); if (!CanAfford(resources, template)) { Debug.LogError($"Tried to construct {template.DisplayName} but can't afford!"); return; } foreach (ShipCost cost in template.Costs) { resources[cost.Resource] -= cost.Amount; } GameController.Instance.GetSelectedLogic().ShipQueue.Add(template); UpdateDisplay(); QueueUI.UpdateDisplay(); }
private static bool CanAfford(CelestialBodyResources resources, SpaceshipTemplate template) { return(template.Costs.All(cost => resources[cost.Resource] >= cost.Amount)); }
public Spaceship(SpaceshipTemplate template, CelestialBody orbitingBody) { Template = template; OrbitingBody = orbitingBody; }