Skip to content

Commit

Permalink
fix static gloss/metal, slug random skins
Browse files Browse the repository at this point in the history
  • Loading branch information
katycat5e committed Feb 4, 2025
1 parent 0bb9d01 commit c3d2e2c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
22 changes: 18 additions & 4 deletions SkinManagerMod/SkinProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,13 @@ public static List<CustomPaintTheme> GetSkinsForType(string carId, bool includeD
}
}

var uniqueThemes = result.Distinct().Select(name => _themeDict[name]).ToList();

if (sort)
{
result.Sort();
uniqueThemes.Sort(CompareThemes);
}
return result.Select(name => _themeDict[name]).ToList();
return uniqueThemes;
}

private static int CompareSkins(Skin a, Skin b)
Expand Down Expand Up @@ -292,11 +294,23 @@ public static string GetNewSkin(TrainCarLivery carType)
// random skin
if (Main.Settings.defaultSkinsMode != DefaultSkinsMode.PreferDefaults)
{
if (skinGroups.TryGetValue(carType.id, out var group) && (group.Skins.Count > 0))
var available = new List<Skin>();
if (skinGroups.TryGetValue(carType.id, out var group))
{
available.AddRange(group.Skins);
}

if ((carType.id == Constants.SLUG_LIVERY_ID) && Main.Settings.allowDE6SkinsForSlug && skinGroups.TryGetValue(Constants.DE6_LIVERY_ID, out group))
{
var distinct = group.Skins.Where(s => !available.Any(a => a.Name == s.Name)).ToList();
available.AddRange(distinct);
}

if (available.Count > 0)
{
bool allowRandomDefault = (Main.Settings.defaultSkinsMode == DefaultSkinsMode.AllowForAllCars);

var allowedRandom = group.Skins.Where(AllowRandomSpawning).ToList();
var allowedRandom = available.Where(AllowRandomSpawning).ToList();
int nChoices = allowRandomDefault ? allowedRandom.Count + 1 : allowedRandom.Count;

int choice = UnityEngine.Random.Range(0, nChoices);
Expand Down
24 changes: 16 additions & 8 deletions SkinManagerMod/TextureUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public static class PropNames
public static readonly string EmissionMap = "_EmissionMap";
public static readonly string OcclusionMap = "_OcclusionMap";

public static readonly string Smoothness = "_Glossiness";
public static readonly string Metallic = "_Metallic";

public static readonly string DetailAlbedo = "_DetailAlbedoMap";
public static readonly string DetailNormal = "_DetailNormalMap";
public static readonly string DetailNormalScale = "_DetailNormalMapScale";
Expand Down Expand Up @@ -301,6 +304,17 @@ public static void ApplyTextures(MeshRenderer renderer, Skin skin, CarMaterialDa

var defaultMaterial = defaultData.GetMaterialForBaseTheme(skin.BaseTheme);

// Set scales etc
float metallic = defaultMaterial.GetFloat(PropNames.Metallic);
renderer.material.SetFloat(PropNames.Metallic, metallic);

float smoothness = defaultMaterial.GetFloat(PropNames.Smoothness);
renderer.material.SetFloat(PropNames.Smoothness, smoothness);

float intensity = defaultMaterial.GetFloat(PropNames.DetailNormalScale);
renderer.material.SetFloat(PropNames.DetailNormalScale, intensity);


foreach (var defaultTexture in defaultData.AllTextures)
{
if (skin.ContainsTexture(defaultTexture.TextureName))
Expand Down Expand Up @@ -332,21 +346,15 @@ public static void ApplyTextures(MeshRenderer renderer, Skin skin, CarMaterialDa
var skinTexture = defaultMaterial.GetTexture(defaultTexture.PropertyName);
renderer.material.SetTexture(defaultTexture.PropertyName, skinTexture);

if (defaultTexture.PropertyName == PropNames.DetailNormal)
{
float intensity = defaultMaterial.GetFloat(PropNames.DetailNormalScale);
renderer.material.SetFloat(PropNames.DetailNormalScale, intensity);
}

if ((defaultTexture.PropertyName == PropNames.Main) && !skinTexture)
if (defaultTexture.PropertyName == PropNames.Main)
{
// demo bogies et al. don't have textures...
renderer.material.color = defaultMaterial.color;
}

if (defaultTexture.PropertyName == PropNames.MetalGlossMap)
{
if (!GetMaterialTexture(renderer.material, PropNames.OcclusionMap))
if (skinTexture && !GetMaterialTexture(renderer.material, PropNames.OcclusionMap))
{
renderer.material.SetTexture(PropNames.OcclusionMap, skinTexture);
}
Expand Down

0 comments on commit c3d2e2c

Please sign in to comment.