private static JToken[] SelectTokens([NotNull] JToken[] tokens, [NotNull] IConfigurationSelector <JToken, JToken> selector)
        {
            if (tokens == null)
            {
                throw new ArgumentNullException(nameof(tokens));
            }
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            var configs = new JToken[tokens.Length];

            for (var i = 0; i < tokens.Length; i++)
            {
                var config = tokens[i];

                if (config != null)
                {
                    config = selector.Select(config);
                }

                configs[i] = config;
            }

            return(configs);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Primary generation method. Summary:
        ///
        /// 1. Gather feature list (stubbed for now)
        /// 2. Generate starting room
        /// 3. If ending condition is met, goto 10. Else continue.
        /// 4. Select next Feature.
        /// 5. Select next position.
        /// 6. Compute all valid configurations.
        /// 7. Select next configuration.
        /// 8. Add all the Sections of the configured Feature.
        /// 9. Goto 3.
        /// 10. Done.
        /// </summary>
        private void Generate()
        {
            // Temporary: feature list
            Feature basicFeature = new Feature();

            // TODO I don't think this works properly with connections specified.
            basicFeature.Add(new Vector2Int(0, 0), Connection.All, externalConnections: Connection.All);

            Feature[] featureList = { basicFeature };

            // Initialize with a single starting room
            // Later, this can be e.g. a specific starting chamber.
            grid[0, 0] = Section.Default();

            // Pick some ending condition. For now it's just "try 100 times".
            int count = 0;

            while (count++ < 100)
            {
                Feature nextFeature = featureSelector.Select(featureList);
                if (nextFeature == null)
                {
                    Debug.Log("Failed to get valid Feature.");
                    continue;
                }

                Vector2Int nextPosition = positionSelector.Select(new ReadOnlyGrid(grid));

                // Get all valid placements
                List <Feature.Configuration> configurations = nextFeature.CanConnect(new ReadOnlyGrid(grid), nextPosition);

                if (configurations.Count == 0)
                {
                    Debug.Log("Failed to find valid configuration at position: " + nextPosition);
                    continue;
                }

                // Choose one of those placements
                Feature.Configuration configuration = configurationSelector.Select(configurations.ToArray());

                // Add that Feature in
                Dictionary <Vector2Int, Section> toAdd = nextFeature.GetConfiguration(configuration);
                foreach (KeyValuePair <Vector2Int, Section> pair in toAdd)
                {
                    grid[pair.Key] = pair.Value;
                }
            }
        }
Ejemplo n.º 3
0
        private JToken[] SelectTokens(IConfigurationSelector <JToken, JToken> selector)
        {
            if (selector == null)
            {
                return(_tokens);
            }

            var configs = new JToken[_tokens.Length];

            for (var i = 0; i < _tokens.Length; i++)
            {
                var config = _tokens[i];

                if (config != null)
                {
                    config = selector.Select(config);
                }

                configs[i] = config;
            }

            return(configs);
        }
        /// <inheritdoc />
        public TConfiguration GetConfiguration <TConfiguration>(IConfigurationSelector <IConfiguration, IConfiguration> selector = null)
        {
            var configuration = selector == null ? _configuration : selector.Select(_configuration);

            return(_converter.Convert <TConfiguration>(configuration));
        }