private ValidationResult NoOtherOnTileBoardItemWhenThereIsStronghold(LevelDataScriptable levelData)
        {
            var strongholdDatas = levelData.StrongholdDatas;
            var unitDatas       = levelData.UnitDatas;
            var constructDatas  = levelData.ConstructDatas;
            var passedTest      = true;
            var failedReason    = new List <string>();

            for (var i = 0; i < strongholdDatas.Length; i++)
            {
                if (StrongholdWrapperHasAStronghold(strongholdDatas[i]))
                {
                    if (unitDatas[i] != null)
                    {
                        passedTest = false;
                        failedReason.Add($"There is an unit and a stronghold in index {i}");
                    }
                    if (constructDatas[i] != null)
                    {
                        passedTest = false;
                        failedReason.Add($"There is an construct and a stronghold in index {i}");
                    }
                }
            }

            return(new ValidationResult(failedReason, passedTest));
        }
Ejemplo n.º 2
0
        public void WhenNotAllDataOfCorrectSize_ReturnIsNotValid()
        {
            var emptyLevelData = LevelDataScriptable.Create(LevelData.Empty);

            var returnedValue = _service.Validate(emptyLevelData, _3X3MapConfig);

            Assert.That(returnedValue.IsValid, Is.False);
        }
        public ValidationResult Validate(LevelDataScriptable levelData, MapConfig mapConfiguration)
        {
            var result = SummarizeValidationResult(
                AllDataOfCorrectSize(levelData, mapConfiguration),
                AllTileHasData(levelData.TileDatas, levelData.TileGameObjectFactories),
                UnitAndConstructHasDataWhenHasGameObjectFactoryAndViceVersa(levelData),
                IsStrongHoldSetUpCorrectly(levelData),
                NoOtherOnTileBoardItemWhenThereIsStronghold(levelData)
                );

            return(result);
        }
Ejemplo n.º 4
0
        public static GameEnvironmentScriptable Create(string environmentName,
                                                       MapConfig mapConfiguration,
                                                       WorldConfig worldConfiguration,
                                                       LevelDataScriptable levelDataScriptable)
        {
            var newInstance = CreateInstance <GameEnvironmentScriptable>();

            newInstance.environmentName    = environmentName;
            newInstance.mapConfiguration   = mapConfiguration;
            newInstance.worldConfiguration = worldConfiguration;
            newInstance.levelData          = levelDataScriptable;

            return(newInstance);
        }
        private ValidationResult IsStrongHoldSetUpCorrectly(LevelDataScriptable levelData)
        {
            var dataWrappers = levelData.StrongholdDatas;

            var dataWrapperHasValidData  = StrongholdDataWrapperEitherHasBothUnitAndConstructOrNone(dataWrappers);
            var onlyHasUnitGoWhenHasUnit = DataHasCorrespondingGameObjectProvider(
                dataWrappers.Select(d => d.UnitDataScriptable).ToList(),
                levelData.StrongholdUnitGameObjectFactories,
                nameof(levelData.StrongholdUnitGameObjectFactories)
                );
            var onlyHasConstructGoWhenHasConstruct = DataHasCorrespondingGameObjectProvider(
                dataWrappers.Select(d => d.ConstructDataScriptable).ToList(),
                levelData.StrongholdConstructGameObjectFactories,
                nameof(levelData.StrongholdConstructGameObjectFactories)
                );

            return(SummarizeValidationResult(
                       dataWrapperHasValidData,
                       onlyHasUnitGoWhenHasUnit,
                       onlyHasConstructGoWhenHasConstruct
                       ));
        }
Ejemplo n.º 6
0
        private static void CreateAndSaveAsset(GameEnvironment gameEnvironment,
                                               string fullPath,
                                               string levelDataFilename,
                                               string gameEnvironmentFilename,
                                               string mapConfigFilename,
                                               string worldConfigFilename,
                                               string environmentName)
        {
            //create new instances as they cannot be referencing the old configs
            var levelDataScriptable = LevelDataScriptable.Create(
                gameEnvironment.LevelData
                );
            var mapConfiguration = MapConfig.Create(
                gameEnvironment.MapConfiguration.GetMap2DActualWidth(),
                gameEnvironment.MapConfiguration.GetMap2DActualHeight()
                );
            var worldConfiguration = WorldConfig.Create(
                gameEnvironment.WorldConfiguration.UpAxis,
                gameEnvironment.WorldConfiguration.InnerRadius
                );

            var gameEnvironmentScriptable = GameEnvironmentScriptable.Create(
                environmentName,
                mapConfiguration,
                worldConfiguration,
                levelDataScriptable
                );

            AssetDatabase.CreateAsset(levelDataScriptable, $"{fullPath}/{levelDataFilename}");
            AssetDatabase.CreateAsset(mapConfiguration, $"{fullPath}/{mapConfigFilename}");
            AssetDatabase.CreateAsset(worldConfiguration, $"{fullPath}/{worldConfigFilename}");
            AssetDatabase.CreateAsset(
                gameEnvironmentScriptable,
                $"{fullPath}/{gameEnvironmentFilename}"
                );
        }
 private ValidationResult UnitAndConstructHasDataWhenHasGameObjectFactoryAndViceVersa(LevelDataScriptable levelData) =>
 SummarizeValidationResult(
     DataHasCorrespondingGameObjectProvider(levelData.ConstructDatas, levelData.ConstructGameObjectFactories, nameof(Construct)),
     DataHasCorrespondingGameObjectProvider(levelData.UnitDatas, levelData.UnitGameObjectFactories, nameof(Unit))
     );
        private ValidationResult AllDataOfCorrectSize(LevelDataScriptable levelData, MapConfig mapConfiguration)
        {
            var arraysSize = mapConfiguration.GetTotalMapSize();

            var testTileDatasResult = CheckDataIsOfCorrectSize(
                levelData.TileDatas,
                arraysSize,
                nameof(levelData.TileDatas)
                );

            var testTileGameObjectProvidersResult = CheckDataIsOfCorrectSize(
                levelData.TileGameObjectFactories,
                arraysSize,
                nameof(levelData.TileGameObjectFactories)
                );

            var testConstructDatasResult = CheckDataIsOfCorrectSize(
                levelData.ConstructDatas,
                arraysSize,
                nameof(levelData.ConstructDatas)
                );

            var testConstructGameObjectProvidersResult = CheckDataIsOfCorrectSize(
                levelData.ConstructGameObjectFactories,
                arraysSize,
                nameof(levelData.ConstructGameObjectFactories)
                );

            var testUnitDatasResult = CheckDataIsOfCorrectSize(
                levelData.UnitDatas,
                arraysSize,
                nameof(levelData.UnitDatas)
                );

            var testUnitGameObjectProvidersResult = CheckDataIsOfCorrectSize(
                levelData.UnitGameObjectFactories,
                arraysSize,
                nameof(levelData.UnitGameObjectFactories)
                );

            var testStrongholdDatasResult = CheckDataIsOfCorrectSize(
                levelData.StrongholdDatas,
                arraysSize,
                nameof(levelData.StrongholdDatas)
                );

            var testStrongholdUnitGameObjectProvidersResult = CheckDataIsOfCorrectSize(
                levelData.StrongholdUnitGameObjectFactories,
                arraysSize,
                nameof(levelData.StrongholdUnitGameObjectFactories)
                );

            var testStrongholdConstructGameObjectProvidersResult = CheckDataIsOfCorrectSize(
                levelData.StrongholdConstructGameObjectFactories,
                arraysSize,
                nameof(levelData.StrongholdConstructGameObjectFactories)
                );

            var summaries = SummarizeValidationResult(
                testTileDatasResult,
                testTileGameObjectProvidersResult,
                testConstructDatasResult,
                testConstructGameObjectProvidersResult,
                testUnitDatasResult,
                testUnitGameObjectProvidersResult,
                testStrongholdDatasResult,
                testStrongholdUnitGameObjectProvidersResult,
                testStrongholdConstructGameObjectProvidersResult
                );

            return(summaries);
        }
Ejemplo n.º 9
0
 public static LevelDataScriptable ToScriptable(this LevelData data) => LevelDataScriptable.Create(data);