Skip to content

Commit

Permalink
Fixed BuildingSpecification (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
KYPremco authored Jul 9, 2023
1 parent 0336960 commit aab1f68
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 35 deletions.
6 changes: 3 additions & 3 deletions Core/TimberApi/BottomBarSystem/BottomBarPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
using System.Linq;
using TimberApi.BottomBarUISystem;
using TimberApi.Common.Extensions;
using TimberApi.Common.SingletonSystem;
using TimberApi.ToolGroupSystem;
using TimberApi.ToolSystem;
using Timberborn.BottomBarSystem;
using Timberborn.Persistence;
using Timberborn.SingletonSystem;
using Timberborn.ToolSystem;
using Timberborn.UILayoutSystem;
using UnityEngine.UIElements;

namespace TimberApi.BottomBarSystem
{
public class BottomBarPanel : ILoadableSingleton
public class BottomBarPanel : ILateLoadableSingleton
{
private readonly SortedDictionary<int, VisualElement> _bottomBarPanels = new();

Expand Down Expand Up @@ -44,7 +44,7 @@ public BottomBarPanel(IEnumerable<BottomBarModule> bottomBarModules,
_bottomBarService = bottomBarService;
}

public void Load()
public void LateLoad()
{
SetupBottomBar();
InitializeButtons();
Expand Down
5 changes: 3 additions & 2 deletions Core/TimberApi/BottomBarSystem/BottomBarService.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using TimberApi.Common.SingletonSystem;
using TimberApi.ToolGroupSystem;
using TimberApi.ToolSystem;
using Timberborn.SingletonSystem;

namespace TimberApi.BottomBarSystem
{
public class BottomBarService : ILoadableSingleton
public class BottomBarService : ILateLoadableSingleton
{
private static readonly string BottomBarSection = "BottomBar";

Expand All @@ -31,7 +32,7 @@ public BottomBarService(

public IEnumerable<BottomBarButton> ToolItemButtons => _toolItemButtons;

public void Load()
public void LateLoad()
{
_toolGroupSpecifications = _toolGroupSpecificationService
.GetBySection(BottomBarSection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@

namespace TimberApi.SpecificationSystem.CustomSpecifications.Buildings
{
internal class BuildingChanger : ILoadableSingleton
internal class BuildingChangeApplier : ILoadableSingleton
{
private readonly BuildingSpecificationService _buildingSpecificationService;
private readonly ObjectCollectionService _objectCollectionService;

public BuildingChanger(ObjectCollectionService objectCollectionService, BuildingSpecificationService buildingSpecificationService)
public BuildingChangeApplier(ObjectCollectionService objectCollectionService, BuildingSpecificationService buildingSpecificationService)
{
_objectCollectionService = objectCollectionService;
_buildingSpecificationService = buildingSpecificationService;
}

public void Load()
{
foreach (var building in _objectCollectionService.GetAllMonoBehaviours<Building>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace TimberApi.SpecificationSystem.CustomSpecifications.Buildings
/// Represents the various settings that can be changed
/// on Buildings using TimberAPI
/// </summary>
internal class BuildingSpecification
public class BuildingSpecification
{
public string BuildingId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void Configure(IContainerDefinition containerDefinition)
containerDefinition.Bind<BuildingSpecificationObjectDeserializer>().AsSingleton();
containerDefinition.Bind<BuildingCostObjectDeserializer>().AsSingleton();
containerDefinition.MultiBind<IObjectSpecificationGenerator>().To<BuildingSpecificationGenerator>().AsSingleton();
containerDefinition.Bind<BuildingChanger>().AsSingleton();
containerDefinition.Bind<BuildingChangeApplier>().AsSingleton();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void Load()
public BuildingSpecification? GetBuildingSpecificationByBuilding(Building building)
{
var prefab = building.GetComponentFast<Prefab>();
string prefabName = prefab.PrefabName.ToLower();
var prefabName = prefab.PrefabName.ToLower();
return _buildingSpecifications.FirstOrDefault(x => x?.BuildingId.ToLower() == prefabName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public class ObjectSpecificationGenerator : ILoadableSingleton

private readonly ObjectSpecificationCacheService _objectSpecificationCacheService;

public ObjectSpecificationGenerator(ObjectCollectionService objectCollectionService,
public ObjectSpecificationGenerator(
ObjectCollectionService objectCollectionService,
IEnumerable<IObjectSpecificationGenerator> objectSpecificationGenerators,
SpecificationRepository specificationRepository,
SpecificationRepository specificationRepository,
ObjectSpecificationCacheService objectSpecificationCacheService)
{
_objectCollectionService = objectCollectionService;
Expand Down
6 changes: 3 additions & 3 deletions Core/TimberApi/ToolGroupSystem/ToolGroupService.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using TimberApi.Common.SingletonSystem;
using TimberApi.ToolGroupUISystem;
using Timberborn.SingletonSystem;
using Timberborn.ToolSystem;

namespace TimberApi.ToolGroupSystem
{
public class ToolGroupService : ILoadableSingleton
public class ToolGroupService : ILateLoadableSingleton
{
private readonly ToolGroupButtonFactoryService _toolGroupButtonFactoryService;

Expand All @@ -33,7 +33,7 @@ public ToolGroupService(

public IEnumerable<ToolGroupButton> ToolGroupButtons => _toolGroupButtons.Select(pair => pair.Value).ToImmutableArray();

public void Load()
public void LateLoad()
{
var toolGroups = new Dictionary<string, IToolGroup>();

Expand Down
13 changes: 5 additions & 8 deletions Core/TimberApi/ToolGroupSystem/ToolGroupSpecificationService.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using TimberApi.SpecificationSystem;
using TimberApi.Common.SingletonSystem;
using Timberborn.Persistence;
using Timberborn.SingletonSystem;
using UnityEngine;

namespace TimberApi.ToolGroupSystem
{
public class ToolGroupSpecificationService : ILoadableSingleton
public class ToolGroupSpecificationService : ILateLoadableSingleton
{
private readonly ISpecificationService _specificationService;

private readonly ToolGroupSpecificationDeserializer _toolGroupSpecificationDeserializer;

private ImmutableDictionary<string, ToolGroupSpecification> _toolGroupSpecifications = null!;

public ToolGroupSpecificationService(
// ReSharper disable once InconsistentNaming
// Required to prevent dependency loop or accessing before specifications are generated
ObjectSpecificationGenerator DEPENDENCY_ORDER_FIX,
ISpecificationService specificationService,
ToolGroupSpecificationDeserializer toolGroupSpecificationDeserializer)
{
Expand All @@ -28,7 +25,7 @@ public ToolGroupSpecificationService(

public ImmutableArray<ToolGroupSpecification> ToolGroupSpecifications => _toolGroupSpecifications.Select(pair => pair.Value).ToImmutableArray();

public void Load()
public void LateLoad()
{
_toolGroupSpecifications = _specificationService.GetSpecifications(_toolGroupSpecificationDeserializer).ToImmutableDictionary(specification => specification.Id.ToLower());
}
Expand Down
8 changes: 4 additions & 4 deletions Core/TimberApi/ToolSystem/ToolService.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using TimberApi.Common.SingletonSystem;
using TimberApi.ToolGroupSystem;
using TimberApi.ToolUISystem;
using Timberborn.SingletonSystem;
using Timberborn.ToolSystem;

namespace TimberApi.ToolSystem
{
public class ToolService : ILoadableSingleton
public class ToolService : ILateLoadableSingleton
{
private readonly ToolButtonFactoryService _toolButtonFactoryService;

Expand All @@ -34,12 +34,12 @@ public ToolService(ToolSpecificationService toolSpecificationService, ToolFactor

public IEnumerable<ToolButton> ToolButtons => _toolButtons.Select(pair => pair.Value).ToImmutableArray();

public void Load()
public void LateLoad()
{
var tools = new Dictionary<string, Tool>();

var toolButtons = new Dictionary<string, ToolButton>();

foreach (var specification in _toolSpecificationService.ToolSpecifications)
{
var toolFactory = _toolFactoryService.Get(specification.Type);
Expand Down
10 changes: 3 additions & 7 deletions Core/TimberApi/ToolSystem/ToolSpecificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using TimberApi.SpecificationSystem;
using TimberApi.Common.SingletonSystem;
using Timberborn.Persistence;
using Timberborn.SingletonSystem;

namespace TimberApi.ToolSystem
{
public class ToolSpecificationService : ILoadableSingleton
public class ToolSpecificationService : ILateLoadableSingleton
{
private readonly ISpecificationService _specificationService;

Expand All @@ -17,9 +16,6 @@ public class ToolSpecificationService : ILoadableSingleton
private ImmutableDictionary<string, ToolSpecification> _toolSpecifications = null!;

public ToolSpecificationService(
// ReSharper disable once InconsistentNaming
// Required to prevent dependency loop or accessing before specifications are generated
ObjectSpecificationGenerator DEPENDENCY_ORDER_FIX,
ISpecificationService specificationService,
ToolSpecificationDeserializer toolSpecificationDeserializer)
{
Expand All @@ -29,7 +25,7 @@ public ToolSpecificationService(

public ImmutableArray<ToolSpecification> ToolSpecifications => _toolSpecifications.Select(pair => pair.Value).ToImmutableArray();

public void Load()
public void LateLoad()
{
_toolSpecifications = _specificationService.GetSpecifications(_toolSpecificationDeserializer).ToImmutableDictionary(specification => specification.Id.ToLower());
}
Expand Down
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Unreleased

### Changes
- Fixed BuildingSpecifications
- Fixed dependency order in a correct way

## TimberAPI v0.5.5.5

Expand Down

0 comments on commit aab1f68

Please sign in to comment.