Пример #1
0
        private void Run(
            MapGeneratorOptions options,
            IMapTerrainGenerator mapTerrainGenerator,
            Action <string> generationUpdated,
            Action <IMap> mapCompleted
            )
        {
            generationUpdated("Map generation started.");

            generationUpdated("Initializing map.");
            IMap map = _mapFactory.Create(
                options.Columns,
                options.Rows,
                mapTerrainGenerator.Initialize
                );

            generationUpdated("Map initialized.");

            generationUpdated("Building terrain.");
            mapTerrainGenerator.Build(map);
            generationUpdated("Terrain completed.");

            generationUpdated("Map generation completed.");
            mapCompleted(map);
        }
Пример #2
0
        /// <inheritdoc />
        public void Load()
        {
            string worldScriptPath = GameResourcesConstants.Paths.WorldScriptPath;
            var    worldsPaths     = new Dictionary <string, string>();

            using (var textFile = new TextFile(worldScriptPath))
            {
                foreach (var text in textFile.Texts)
                {
                    worldsPaths.Add(text.Key, text.Value.Replace('"', ' ').Trim());
                }
            }

            foreach (string mapDefineName in _worldConfiguration.Maps)
            {
                if (!worldsPaths.TryGetValue(mapDefineName, out string mapName))
                {
                    _logger.LogWarning(GameResourcesConstants.Errors.UnableLoadMapMessage, mapDefineName, $"map is not declared inside '{worldScriptPath}' file");
                    continue;
                }

                if (!_gameResources.Defines.TryGetValue(mapDefineName, out int mapId))
                {
                    _logger.LogWarning(GameResourcesConstants.Errors.UnableLoadMapMessage, mapDefineName, $"map has no define id inside '{GameResourcesConstants.Paths.DataSub0Path}/defineWorld.h' file");
                    continue;
                }

                if (_maps.ContainsKey(mapId))
                {
                    _logger.LogWarning(GameResourcesConstants.Errors.UnableLoadMapMessage, mapDefineName, $"another map with id '{mapId}' already exist.");
                    continue;
                }

                IMapInstance map = _mapFactory.Create(Path.Combine(GameResourcesConstants.Paths.MapsPath, mapName), mapName, mapId);

                _maps.Add(mapId, map);
            }

            _logger.LogInformation("-> {0} maps loaded.", _maps.Count);
        }