private AssetViewModel CreateAssetViewModel(AssetDef assetDef) { return(new AssetViewModel { Definition = AssetDefinitionViewModel.Create(assetDef), Built = assetRepository.HasAsset(currentUserContext.PlayerId, assetDef.Id), Prerequisites = string.Join(", ", gameDef.GetAssetNames(assetDef.Prerequisites)), PrerequisitesMet = assetRepository.PrerequisitesMet(currentUserContext.PlayerId, assetDef), Cost = CostViewModel.Create(assetDef.Cost), CanAfford = resourceRepository.CanAfford(currentUserContext.PlayerId, assetDef.Cost), AlreadyQueued = assetRepository.IsBuildQueued(currentUserContext.PlayerId, assetDef.Id), TicksLeftForBuild = assetRepository.TicksLeft(currentUserContext.PlayerId, assetDef.Id), AvailableUnits = gameDef.GetUnitsForAsset(assetDef.Id) .Select(x => UnitDefinitionViewModel.Create(x, unitRepository.PrerequisitesMet(currentUserContext.PlayerId, x))).ToList() }); }
public static UnitViewModel ToUnitViewModel(this UnitImmutable unit, UnitRepository unitRepository, CurrentUserContext currentUserContext, GameDef gameDef) { var unitDef = gameDef.GetUnitDef(unit.UnitDefId); if (unitDef == null) { throw new InvalidGameDefException($"Unit '{unit.UnitDefId}' not found"); } return(new UnitViewModel { UnitId = unit.UnitId.Id, Definition = UnitDefinitionViewModel.Create(unitDef, unitRepository.PrerequisitesMet(currentUserContext.PlayerId, unitDef)), Count = unit.Count, PositionPlayerId = unit.Position?.Id }); }
public IEnumerable <UnitDefinitionViewModel> Get() { return(gameDefinition.Units.Select(x => UnitDefinitionViewModel.Create(x, true /* TODO */)).ToArray()); }