Skip to content

Commit

Permalink
allow DE6 skins on slug again
Browse files Browse the repository at this point in the history
  • Loading branch information
katycat5e committed Feb 4, 2025
1 parent d1fbc83 commit 5ae82ee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
14 changes: 11 additions & 3 deletions SkinManagerMod/CommsRadioSkinSwitcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using DV.ThingTypes;
using DV.UserManagement;
using HarmonyLib;
using SMShared;
using UnityEngine;
using static DV.Common.GameFeatureFlags;

Expand Down Expand Up @@ -456,10 +457,9 @@ private void ApplySelectedSkin()
SkinManager.ApplySkin(SelectedCar, SelectedSkin, AreaToPaint);
//CurrentThemeName = SelectedSkin.name;

if (CarTypes.IsMUSteamLocomotive(SelectedCar.carType) && SelectedCar.rearCoupler.IsCoupled())
if (SelectedCar.rearCoupler.IsCoupled() && (SelectedCar.rearCoupler.coupledTo?.train is TrainCar attachedCar))
{
TrainCar attachedCar = SelectedCar.rearCoupler.coupledTo?.train;
if ((attachedCar != null) && CarTypes.IsTender(attachedCar.carLivery))
if (CarTypes.IsMUSteamLocomotive(SelectedCar.carType) && CarTypes.IsTender(attachedCar.carLivery))
{
// car attached behind loco is tender
if (SelectedSkin.SupportsVehicle(attachedCar.carLivery))
Expand All @@ -468,6 +468,14 @@ private void ApplySelectedSkin()
SkinManager.ApplySkin(attachedCar, SelectedSkin, AreaToPaint);
}
}
else if ((SelectedCar.carLivery.id == Constants.DE6_LIVERY_ID) && CarTypes.IsSlug(attachedCar.carLivery))
{
// car attached behind DE6 is slug
if (SelectedSkin.SupportsVehicle(attachedCar.carLivery))
{
SkinManager.ApplySkin(attachedCar, SelectedSkin, AreaToPaint);
}
}
}
}

Expand Down
16 changes: 14 additions & 2 deletions SkinManagerMod/CustomPaintTheme.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using DV;
using DV.Customization.Paint;
using DV.ThingTypes;
using SMShared;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
Expand All @@ -16,8 +17,12 @@ public class CustomPaintTheme : PaintTheme
public void RemoveSkin(Skin skin) => _skins.Remove(skin.LiveryId);
public void RemoveSkin(string liveryId) => _skins.Remove(liveryId);

public bool SupportsVehicle(string liveryId) => _skins.ContainsKey(liveryId);
public bool SupportsVehicle(TrainCarLivery livery) => _skins.ContainsKey(livery.id);
public bool SupportsVehicle(string liveryId)
{
if (_skins.ContainsKey(liveryId)) return true;
return Main.Settings.allowDE6SkinsForSlug && (liveryId == Constants.SLUG_LIVERY_ID) && _skins.ContainsKey(Constants.DE6_LIVERY_ID);
}
public bool SupportsVehicle(TrainCarLivery livery) => SupportsVehicle(livery.id);

public IEnumerable<TrainCarLivery> SupportedCarTypes => Globals.G.Types.Liveries.Where(type => _skins.ContainsKey(type.id));

Expand All @@ -29,6 +34,13 @@ public void Apply(GameObject target, TrainCar train)

ApplyToTransform(target, skin, defaultSkin);
}
else if ((train.carLivery.id == Constants.SLUG_LIVERY_ID) &&
Main.Settings.allowDE6SkinsForSlug &&
_skins.TryGetValue(Constants.DE6_LIVERY_ID, out skin))
{
var defaultSkin = CarMaterialData.GetDataForCar(Constants.SLUG_LIVERY_ID);
ApplyToTransform(target, skin, defaultSkin);
}
}

private static void ApplyToTransform(GameObject objectRoot, Skin skin, CarMaterialData defaults)
Expand Down
2 changes: 1 addition & 1 deletion SkinManagerMod/SkinProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public static List<CustomPaintTheme> GetSkinsForType(string carId, bool includeD

if (includeDefault)
{
if (IsThemeable(carId))
if (IsThemeable(carId) || (Main.Settings.allowDE6SkinsForSlug && (carId == Constants.SLUG_LIVERY_ID)))
{
result.AddRange(BuiltInThemeNames);
}
Expand Down

0 comments on commit 5ae82ee

Please sign in to comment.