Beispiel #1
0
 /// <summary>
 /// Reads filter definitions from a node and adds them into the manager.
 /// </summary>
 /// <param name="node">Node to get data from.</param>
 /// <param name="isCommonTag">Specifies if node describes CCK native categories.</param>
 void AddFiltersFromConfig(ConfigNode node, bool isCommonTag)
 {
     foreach (var item in node.GetNodes("Item"))
     {
         var filterItem = new PartsFilter(
             item.GetValue("tag"), item.GetValue("name"),
             item.GetValue("normalIcon"), item.GetValue("selectedIcon"),
             isCommonTag);
         AddFilter(filterItem);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Adds filter for a tag if one doesn't exist. In case of there is a filter with the same
        /// tag a better candidate will be chosen.
        /// </summary>
        /// <remarks>
        /// When a filter for an existing tag is being added a decision is made on which filter to
        /// keep:
        /// <list type="bullet">
        /// <item>Native (a.k.a. "common") CCK filter is always favored over a custom filter.</item>
        /// <item>
        /// Custom filters are compared by their title and the one which is lexicographically "less"
        /// (case-sensitive) will be kept, and the other one dropped.
        /// </item>
        /// </list>
        /// </remarks>
        /// <param name="newFilter">Filter description to add.</param>
        void AddFilter(PartsFilter newFilter)
        {
            var existingFilter = filters.FirstOrDefault(x => x.tag == newFilter.tag);

            if (existingFilter != null && newFilter.isCommon)
            {
                // Normally never happens.
                Debug.LogErrorFormat("Duplicated common filter: {0}. Ignoring.", tag);
            }
            else if (existingFilter == null)
            {
                Debug.LogFormat("Create new CCK filter: {0}", newFilter);
                filters.Add(newFilter);
            }
            else if (existingFilter != null)
            {
                // A very simple tie-break approach. Main idea here is being consistent, i.e. always
                // showing the same category on game load.
                var tieBreakValue = string.Compare(
                    newFilter.title, existingFilter.title, StringComparison.Ordinal);
                if (!existingFilter.isCommon && tieBreakValue < 0)
                {
                    Debug.LogWarningFormat(
                        "Replacing existing CCK filter with a new one: existing=[{0}], new=[{1}]",
                        existingFilter, newFilter);
                    filters.Remove(existingFilter);
                    filters.Add(newFilter);
                }
                else
                {
                    Debug.LogWarningFormat("Ignoring new CCK filter in favor of the existing one:"
                                           + " existing=[{0}], new=[{1}]",
                                           existingFilter, newFilter);
                }
            }
        }