forked from LibraStack/Match3-SDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TerminalGridSlot.cs
44 lines (38 loc) · 1.27 KB
/
TerminalGridSlot.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Runtime.CompilerServices;
using Match3.Core.Interfaces;
using Match3.Core.Structs;
using Terminal.Match3.Interfaces;
namespace Terminal.Match3
{
public sealed class TerminalGridSlot : ITerminalGridSlot
{
public TerminalGridSlot(IGridSlotState state, GridPosition gridPosition)
{
State = state;
GridPosition = gridPosition;
}
public int ItemId => Item.ContentId;
public bool HasItem => Item != null;
public bool IsLocked => State.IsLocked;
public bool CanContainItem => State.CanContainItem;
public bool IsMovable => IsLocked == false && HasItem;
public bool CanSetItem => CanContainItem && HasItem == false;
public ITerminalItem Item { get; private set; }
public IGridSlotState State { get; }
public GridPosition GridPosition { get; }
public void SetItem(ITerminalItem item)
{
EnsureItemIsNotNull(item);
Item = item;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void EnsureItemIsNotNull(ITerminalItem item)
{
if (item == null)
{
throw new NullReferenceException(nameof(item));
}
}
}
}