Skip to content

Commit

Permalink
fix: ♻️ Apply review changes in MapHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
blinkuz committed Oct 30, 2024
1 parent 275a17d commit 1d7f69a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
23 changes: 13 additions & 10 deletions Intersect.Server.Core/Plugins/Helpers/MapHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Intersect.Server.Framework.Items;
using System.Diagnostics.CodeAnalysis;
using Intersect.Server.Framework.Items;
using Intersect.Server.Framework.Maps;
using Intersect.Server.Maps;

Expand All @@ -7,19 +8,21 @@ namespace Intersect.Server.Plugins.Helpers;
public partial class MapHelper : IMapHelper
{
private static readonly Lazy<MapHelper> _instance = new Lazy<MapHelper>(() => new MapHelper());

public static MapHelper Instance => _instance.Value;

private MapHelper() { }

public event Action<IItemSource, IItem> ItemAdded;

public IMapInstance GetMapInstanceByDescriptorId(Guid mapId, Guid mapInstanceId)
public event ItemAddedHandler ItemAdded;

public bool TryGetMapInstance(Guid mapId, Guid instanceId, [NotNullWhen(true)] out IMapInstance? instance)
{
MapController.TryGetInstanceFromMap(mapId, mapInstanceId, out var instance);
return instance;
instance = null;
if (MapController.TryGetInstanceFromMap(mapId, instanceId, out var mapInstance))
{
instance = mapInstance;
return mapInstance != null;
}
return false;
}

public void InvokeItemAdded(IItemSource source, IItem item)
{
ItemAdded?.Invoke(source, item);
Expand Down
12 changes: 7 additions & 5 deletions Intersect.Server.Framework/Plugins/Helpers/IMapHelper.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Intersect.Server.Framework.Items;
using System.Diagnostics.CodeAnalysis;
using Intersect.Server.Framework.Items;
using Intersect.Server.Framework.Maps;

namespace Intersect.Server.Plugins.Helpers;

public interface IMapHelper
{
event Action<IItemSource, IItem> ItemAdded;
IMapInstance GetMapInstanceByDescriptorId(Guid mapId, Guid mapInstanceId);
void InvokeItemAdded(IItemSource source, IItem item);
}
event ItemAddedHandler ItemAdded;
bool TryGetMapInstance(Guid mapId, Guid instanceId, [NotNullWhen(true)] out IMapInstance? instance);
}

public delegate void ItemAddedHandler(IItemSource? source, IItem item);

0 comments on commit 1d7f69a

Please sign in to comment.