Esempio n. 1
0
        private void DocMaterials(Player self)
        {
            if (Generated)
            {
                return;
            }

            Jotunn.Logger.LogInfo("Documenting prefab materials");

            AddHeader(1, "Prefab material list");
            AddText("All materials, the prefabs they are used in and their respective shaders and keywords currently in the game (ZNetScene and ZoneManager).");
            AddText("This file is automatically generated from Valheim using the JotunnDoc mod found on our GitHub.");
            AddTableHeader("Material", "Prefabs", "Shader", "Keywords");

            List <GameObject> allPrefabs = new List <GameObject>();

            allPrefabs.AddRange(ZNetScene.instance.m_nonNetViewPrefabs);
            allPrefabs.AddRange(ZNetScene.instance.m_prefabs);
            allPrefabs.AddRange(ZoneSystem.instance.m_locations.Where(x => x.m_prefab).Select(x => x.m_prefab));

            Dictionary <string, Material>       mats       = new Dictionary <string, Material>();
            Dictionary <string, List <string> > matPrefabs = new Dictionary <string, List <string> >();

            foreach (GameObject prefab in allPrefabs.Where(x => !CustomPrefab.IsCustomPrefab(x.name)).OrderBy(x => x.name))
            {
                foreach (Material mat in ShaderHelper.GetAllRendererMaterials(prefab))
                {
                    const string instanceToken = " (Instance)";
                    string       matName       = mat.name;

                    // Add distinct materials
                    if (matName.EndsWith(instanceToken))
                    {
                        matName = matName.Substring(0, matName.Length - instanceToken.Length);
                    }

                    if (!mats.ContainsKey(matName))
                    {
                        mats.Add(matName, mat);
                    }

                    // Add prefab per material
                    if (!matPrefabs.ContainsKey(matName))
                    {
                        matPrefabs.Add(matName, new List <string>());
                    }
                    matPrefabs[matName].Add(prefab.name);
                }
            }

            foreach (var entry in mats.OrderBy(x => x.Key))
            {
                Material mat = entry.Value;

                StringBuilder prefabsb = new StringBuilder();
                prefabsb.Append("<ul>");
                foreach (string prefab in matPrefabs[entry.Key].Distinct().OrderBy(x => x))
                {
                    prefabsb.Append("<li>");
                    prefabsb.Append(prefab);
                    prefabsb.Append("</li>");
                }
                prefabsb.Append("</ul>");

                StringBuilder keysb = new StringBuilder();
                keysb.Append("<dl>");
                if (mat.shaderKeywords.Length > 0)
                {
                    foreach (string prop in mat.shaderKeywords)
                    {
                        keysb.Append("<dd>");
                        keysb.Append(prop);
                        keysb.Append("</dd>");
                    }
                }
                keysb.Append("</dl>");

                AddTableRow(entry.Key, prefabsb.ToString(), mat.shader.name, keysb.ToString());
            }

            Save();
        }