Skip to content

Commit

Permalink
implement random spawning prevention
Browse files Browse the repository at this point in the history
  • Loading branch information
katycat5e committed Jan 23, 2025
1 parent 8c12193 commit e0a99bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions SkinConfigurator/ViewModels/ThemeConfigModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public ThemeConfigItem JsonModel()
{
Name = ThemeName,
HideFromStores = HideFromStores,
PreventRandomSpawning = PreventRandomSpawning,
};

if (HasValidImage)
Expand Down
17 changes: 14 additions & 3 deletions SkinManagerMod/SkinProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,18 +307,29 @@ public static string GetNewSkin(TrainCarLivery carType)
(Main.Settings.defaultSkinsMode == DefaultSkinsMode.AllowForAllCars);
// || (CustomCarTypes.ContainsKey(carType) && (Main.Settings.defaultSkinsMode == SkinManagerSettings.DefaultSkinsMode.AllowForCustomCars));

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

int choice = UnityEngine.Random.Range(0, nChoices);
if (choice < group.Skins.Count)
if (choice < allowedRandom.Count)
{
return group.Skins[choice].Name;
return allowedRandom[choice].Name;
}
}

// fall back to default skin
return DefaultThemeName;
}

private static bool AllowRandomSpawning(Skin skin)
{
if (TryGetThemeSettings(skin.Name, out var settings))
{
return !settings.PreventRandomSpawning;
}
return true;
}

#endregion

//====================================================================================================
Expand Down
2 changes: 2 additions & 0 deletions SkinManagerMod/ThemeSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class ThemeSettings
public readonly string ThemeName;
public Version HighestVersion;
public bool HideFromStores;
public bool PreventRandomSpawning;

public SkinTexture CanLabel;
public Color? LabelBaseColor;
Expand Down Expand Up @@ -49,6 +50,7 @@ public static ThemeSettings Create(string basePath, ThemeConfigItem data, Versio
var result = new ThemeSettings(data.Name, version)
{
HideFromStores = data.HideFromStores,
PreventRandomSpawning = data.PreventRandomSpawning,
};

TryParseColor(data.LabelBaseColor, basePath, ref result.LabelBaseColor);
Expand Down

0 comments on commit e0a99bc

Please sign in to comment.