/* Known structure (collider) names:
         * Runway: Tier 1
         *  runway_lev1
         * Runway: Tier 2
         *  runway1
         *  runway2
         *  runway3
         *  runway4
         *  runway5
         *  runway6
         *  runway7
         *  grass_dirt_transition
         *  groundPlane
         * VAB: Tier 2
         *  VAB_lev2_groundPlane
         * SPH: Tier 1
         *  SPH_1_ground
         */

        public static Color GetStructureDustColour(List <StructureDust> structures, string colliderName)
        {
            StructureDust structure = null;

            if (_previousStructureDust != null &&
                _previousStructureDust.Name.Equals(colliderName, StringComparison.InvariantCultureIgnoreCase))
            {
                structure = _previousStructureDust;
            }
            else
            {
                foreach (StructureDust s in structures)
                {
                    if (s.Name.Equals(colliderName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        structure = s;
                        _previousStructureDust = s;
                        break;
                    }
                }
            }
            if (structure != null)
            {
                return(structure.DustColour);
            }

            // No colour found.
            return(Color.clear);
        }
        public static void LoadDustColours()
        {
            //c.collider.name = "runway_lev1"


            _bodies = new List <BodyDust>();
            ConfigNode config = ConfigNode.Load(CollisionFX.ConfigPath);

            if (config == null)
            {
                Debug.LogError("[CollisionFX] Configuration file not found at " + CollisionFX.ConfigPath);
                return;
            }
            foreach (ConfigNode node in config.nodes)
            {
                if (!node.name.Equals("BodyDust"))
                {
                    continue;
                }

                // Load body
                BodyDust body;
                if (node.HasValue("name"))
                {
                    body = new BodyDust
                    {
                        Name       = node.GetValue("name"),
                        Biomes     = new List <BiomeDust>(),
                        Structures = new List <StructureDust>()
                    };
                }
                else
                {
                    Debug.LogWarning("[CollisionFX] Invalid BodyDust definition: \"name\" field is missing.");
                    continue;
                }

                // Load biomes
                if (node.HasNode("Biomes"))
                {
                    ConfigNode biomeNode = node.GetNode("Biomes");
                    foreach (ConfigNode.Value biomeDefinition in biomeNode.values)
                    {
                        Color c;
                        if (!TryParseDustColour(biomeDefinition, body.Name, out c))
                        {
                            continue;
                        }

                        BiomeDust biome = new BiomeDust
                        {
                            Name       = biomeDefinition.name,
                            DustColour = c
                        };
                        if (biomeDefinition.name.Equals("Default", StringComparison.InvariantCultureIgnoreCase))
                        {
                            body.DefaultBiomeColour = c;
                        }

                        body.Biomes.Add(biome);
                    }
                }

                // Load structures
                if (node.HasNode("Structures"))
                {
                    ConfigNode structureNode = node.GetNode("Structures");
                    foreach (ConfigNode.Value structureDefinition in structureNode.values)
                    {
                        Color c;
                        if (!TryParseDustColour(structureDefinition, body.Name, out c))
                        {
                            continue;
                        }

                        StructureDust structure = new StructureDust
                        {
                            Name       = structureDefinition.name,
                            DustColour = c
                        };
                        body.Structures.Add(structure);
                    }
                }

                _bodies.Add(body);
            }

            if (_bodies.Count == 0)
            {
                Debug.LogWarning("[CollisionFX] Unable to find dust definitions. Ensure " + CollisionFX.ConfigPath + " contains correct BodyDust entries.");
            }
        }