Skip to content

Commit

Permalink
1.28.1 fix for decorations hiding
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCSUser committed Nov 9, 2021
1 parent afb6b29 commit 0423946
Show file tree
Hide file tree
Showing 21 changed files with 219 additions and 128 deletions.
34 changes: 34 additions & 0 deletions Features/Decorations/Base/HideDecorations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using com.github.TheCSUser.Shared.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace com.github.TheCSUser.HideItBobby.Features.Decorations
{
internal abstract class HideDecorations : UpdatableFeatureBase
{
protected TerrainProperties TerrainProperties => TerrainManager.exists ? TerrainManager.instance.m_properties : null;

public HideDecorations(IModContext context) : base(context) { }

public override FeatureFlags Update()
{
if (IsDisposed || IsError || !IsAvailable || !IsInitialized) return Result(false);
try
{
var result = OnUpdate();
return Result(result, true);
}
catch (Exception e)
{
IncreaseErrorCount();
Log.Error($"{GetType().Name}.{nameof(OnUpdate)} failed", e);
return Result(false);
}
}

protected override bool OnEnable() => OnUpdate();
protected override bool OnDisable() => OnUpdate();
}
}
26 changes: 12 additions & 14 deletions Features/Decorations/HideCliffDecorations.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
using ColossalFramework;
using com.github.TheCSUser.Shared.Common;
using com.github.TheCSUser.Shared.Common;

namespace com.github.TheCSUser.HideItBobby.Features.Decorations
{
internal sealed class HideCliffDecorations : FeatureBase
internal sealed class HideCliffDecorations : HideDecorations
{
public override FeatureKey Key => FeatureKey.HideCliffDecorations;

public HideCliffDecorations(IModContext context) : base(context) { }

protected override bool OnEnable()
protected override bool OnUpdate()
{
if (!Singleton<TerrainManager>.exists) return false;

Singleton<TerrainManager>.instance.m_properties.m_useCliffDecorations = false;
return true;
}
protected override bool OnDisable()
{
if (!Singleton<TerrainManager>.exists) return false;

Singleton<TerrainManager>.instance.m_properties.m_useCliffDecorations = true;
var properties = TerrainProperties;
if (properties is null)
{
#if DEV
Log.Info($"{GetType().Name}.{nameof(OnUpdate)} {nameof(TerrainProperties)} is null");
#endif
return false;
}
properties.m_useCliffDecorations = !IsEnabled;
return true;
}
}
Expand Down
26 changes: 12 additions & 14 deletions Features/Decorations/HideFertileDecorations.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
using ColossalFramework;
using com.github.TheCSUser.Shared.Common;
using com.github.TheCSUser.Shared.Common;

namespace com.github.TheCSUser.HideItBobby.Features.Decorations
{
internal sealed class HideFertileDecorations : FeatureBase
internal sealed class HideFertileDecorations : HideDecorations
{
public override FeatureKey Key => FeatureKey.HideFertileDecorations;

public HideFertileDecorations(IModContext context) : base(context) { }

protected override bool OnEnable()
protected override bool OnUpdate()
{
if (!Singleton<TerrainManager>.exists) return false;

Singleton<TerrainManager>.instance.m_properties.m_useFertileDecorations = false;
return true;
}
protected override bool OnDisable()
{
if (!Singleton<TerrainManager>.exists) return false;

Singleton<TerrainManager>.instance.m_properties.m_useFertileDecorations = true;
var properties = TerrainProperties;
if (properties is null)
{
#if DEV
Log.Info($"{GetType().Name}.{nameof(OnUpdate)} {nameof(TerrainProperties)} is null");
#endif
return false;
}
properties.m_useFertileDecorations = !IsEnabled;
return true;
}
}
Expand Down
28 changes: 13 additions & 15 deletions Features/Decorations/HideGrassDecorations.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
using ColossalFramework;
using com.github.TheCSUser.Shared.Common;
using com.github.TheCSUser.Shared.Common;

namespace com.github.TheCSUser.HideItBobby.Features.Decorations
{
internal sealed class HideGrassDecorations : FeatureBase
internal sealed class HideGrassDecorations : HideDecorations
{
public override FeatureKey Key => FeatureKey.HideGrassDecorations;

public HideGrassDecorations(IModContext context) : base(context) { }

protected override bool OnEnable()
{
if (!Singleton<TerrainManager>.exists) return false;
public HideGrassDecorations(IModContext context) : base(context) { }

Singleton<TerrainManager>.instance.m_properties.m_useGrassDecorations = false;
return true;
}
protected override bool OnDisable()
protected override bool OnUpdate()
{
if (!Singleton<TerrainManager>.exists) return false;

Singleton<TerrainManager>.instance.m_properties.m_useGrassDecorations = true;
var properties = TerrainProperties;
if (properties is null)
{
#if DEV
Log.Info($"{GetType().Name}.{nameof(OnUpdate)} {nameof(TerrainProperties)} is null");
#endif
return false;
}
properties.m_useGrassDecorations = !IsEnabled;
return true;
}
}
Expand Down
16 changes: 8 additions & 8 deletions Features/FeatureBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public FeatureFlags Initialize()
catch (Exception e)
{
_isInitialized = false;
IsError = true;
IncreaseErrorCount();
Log.Error($"{GetType().Name}.{nameof(OnInitialize)} failed", e);
return Result(false);
}
Expand All @@ -130,7 +130,7 @@ public FeatureFlags Terminate()
}
catch (Exception e)
{
IsError = true;
IncreaseErrorCount();
Log.Error($"{GetType().Name}.{nameof(OnDisable)} failed", e);
return Result(false);
}
Expand All @@ -145,7 +145,7 @@ public FeatureFlags Terminate()
}
catch (Exception e)
{
IsError = true;
IncreaseErrorCount();
Log.Error($"{GetType().Name}.{nameof(OnTerminate)} failed", e);
return Result(false);
}
Expand Down Expand Up @@ -178,7 +178,7 @@ public FeatureFlags Enable(bool force)
catch (Exception e)
{
_isInitialized = false;
IsError = true;
IncreaseErrorCount();
Log.Error($"{GetType().Name}.{nameof(OnInitialize)} failed", e);
return Result(false);
}
Expand All @@ -194,7 +194,7 @@ public FeatureFlags Enable(bool force)
catch (Exception e)
{
_isEnabled = false;
IsError = true;
IncreaseErrorCount();
Log.Error($"{GetType().Name}.{nameof(OnEnable)} failed", e);
return Result(false);
}
Expand All @@ -215,7 +215,7 @@ public FeatureFlags Disable(bool force)
catch (Exception e)
{
_isEnabled = true;
IsError = true;
IncreaseErrorCount();
Log.Error($"{GetType().Name}.{nameof(OnDisable)} failed", e);
return Result(false);
}
Expand All @@ -240,7 +240,7 @@ internal abstract class UpdatableFeatureBase : FeatureBase, IUpdatableFeature
protected UpdatableFeatureBase(IModContext context) : base(context) { }

#region Updatable
public FeatureFlags Update()
public virtual FeatureFlags Update()
{
if (IsDisposed || IsError || !IsAvailable || !IsInitialized) return Result(false);
if (!IsEnabled) return Result(true);
Expand All @@ -251,7 +251,7 @@ public FeatureFlags Update()
}
catch (Exception e)
{
IsError = true;
IncreaseErrorCount();
Log.Error($"{GetType().Name}.{nameof(OnUpdate)} failed", e);
return Result(false);
}
Expand Down
3 changes: 3 additions & 0 deletions HideItBobby.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@
<Compile Include="Compatibility\Base\RequiredDLCCheck.cs" />
<Compile Include="Compatibility\TreeAnarchyModEnabledCheck.cs" />
<Compile Include="Compatibility\UIResolutionModEnabledCheck.cs" />
<Compile Include="Features\Decorations\Base\HideDecorations.cs" />
<Compile Include="Features\Effects\Base\HideFog.cs" />
<Compile Include="Compatibility\TerraformNetworkSubscribedCheck.cs" />
<Compile Include="Features\Problems\HideDisconnectedPowerLinesNotification.cs" />
<Compile Include="Features\Problems\HideTerraformNetworkFloodNotification.cs" />
<Compile Include="Features\UIElements\Shared\UIViewProxy.cs" />
<Compile Include="Mod.Migrations.cs" />
<Compile Include="Scripts\Containers\FeaturesContainer.cs" />
<Compile Include="Scripts\Base\FeaturesScript.cs" />
<Compile Include="Scripts\Containers\IFeaturesContainer.cs" />
Expand Down Expand Up @@ -118,6 +120,7 @@
<Compile Include="UserInterface\Styles.cs" />
<Compile Include="VersionMigrations\Migrate_1_20_to_1_21.cs" />
<Compile Include="VersionMigrations\Migrate_1_18_to_1_21.cs" />
<Compile Include="VersionMigrations\Migrate_1_28_to_1_28_1.cs" />
<Compile Include="VersionMigrations\Migrate_1_24_to_1_25.cs" />
<Compile Include="VersionMigrations\Migrate_1_21_to_1_22.cs" />
<Compile Include="Scripts\Containers\SettingsContainer.cs" />
Expand Down
2 changes: 1 addition & 1 deletion Mod.Dependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace com.github.TheCSUser.HideItBobby
{
public sealed partial class Mod
{
private void InitDependencies()
private void RegisterDependencies()
{
Context
.Register(Use(new NaturalDisastersDLCEnabledCheck(Context)))
Expand Down
54 changes: 54 additions & 0 deletions Mod.Migrations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using com.github.TheCSUser.HideItBobby.Properties;
using com.github.TheCSUser.HideItBobby.Settings.Providers;
using com.github.TheCSUser.HideItBobby.Settings.SettingsFiles;
using com.github.TheCSUser.HideItBobby.VersionMigrations;
using System;
using System.Collections.Generic;

namespace com.github.TheCSUser.HideItBobby
{
public sealed partial class Mod
{
private Provider_Version VersionProvider;
private List<Migration> _migrations;
internal File_Version VersionFile;

private void InitMigrations()
{
VersionProvider = new Provider_Version(Context);

_migrations = new List<Migration>
{
new Migrate_1_18_to_1_21(Context),
new Migrate_1_20_to_1_21(Context),
new Migrate_1_21_to_1_22(Context),
new Migrate_1_24_to_1_25(Context),
new Migrate_1_28_to_1_28_1(Context),
};
}

private void Migrate()
{
try
{
VersionFile = VersionProvider.Load();
if (VersionFile is null || VersionFile.Version < ModProperties.VersionInteger)
{
foreach (var migration in _migrations)
{
if (!(migration is null)) migration.Migrate();
}

VersionProvider.Save(VersionFile = new File_Version()
{
Version = ModProperties.VersionInteger
});
}
}
catch (Exception e)
{
Log.Error($"{nameof(Mod)}.{nameof(Migrate)} failed", e);
}
}
}
}
Loading

0 comments on commit 0423946

Please sign in to comment.