Fix build issues due to comparison operators
This commit is contained in:
@@ -35,6 +35,14 @@ public class GameManager : MonoBehaviour
|
|||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
_instance = this;
|
_instance = this;
|
||||||
|
if (gameSettings == null)
|
||||||
|
{
|
||||||
|
gameSettings = Resources.Load<GameSettings>("DefaultSettings");
|
||||||
|
if (gameSettings == null)
|
||||||
|
{
|
||||||
|
Debug.LogError("GameSettings asset not found in Resources!");
|
||||||
|
}
|
||||||
|
}
|
||||||
// DontDestroyOnLoad(gameObject);
|
// DontDestroyOnLoad(gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +77,8 @@ public class GameManager : MonoBehaviour
|
|||||||
if (gameSettings == null || gameSettings.combinationRules == null) return null;
|
if (gameSettings == null || gameSettings.combinationRules == null) return null;
|
||||||
foreach (var rule in gameSettings.combinationRules)
|
foreach (var rule in gameSettings.combinationRules)
|
||||||
{
|
{
|
||||||
if ((rule.itemA == item1 && rule.itemB == item2) || (rule.itemA == item2 && rule.itemB == item1))
|
if ((PickupItemData.AreEquivalent(rule.itemA, item1) && PickupItemData.AreEquivalent(rule.itemB, item2)) ||
|
||||||
|
(PickupItemData.AreEquivalent(rule.itemA, item2) && PickupItemData.AreEquivalent(rule.itemB, item1)))
|
||||||
{
|
{
|
||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
@@ -85,7 +94,7 @@ public class GameManager : MonoBehaviour
|
|||||||
if (gameSettings == null || gameSettings.slotItemConfigs == null || slotItem == null) return null;
|
if (gameSettings == null || gameSettings.slotItemConfigs == null || slotItem == null) return null;
|
||||||
foreach (var config in gameSettings.slotItemConfigs)
|
foreach (var config in gameSettings.slotItemConfigs)
|
||||||
{
|
{
|
||||||
if (config.slotItem == slotItem)
|
if (PickupItemData.AreEquivalent(slotItem, config.slotItem))
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace Interactions
|
|||||||
if (heldItemData != null && _currentlySlottedItemObject == null)
|
if (heldItemData != null && _currentlySlottedItemObject == null)
|
||||||
{
|
{
|
||||||
// First check for forbidden items at the very start so we don't continue unnecessarily
|
// First check for forbidden items at the very start so we don't continue unnecessarily
|
||||||
if (forbidden.Contains(heldItemData))
|
if (PickupItemData.ListContainsEquivalent(forbidden, heldItemData))
|
||||||
{
|
{
|
||||||
DebugUIMessage.Show("Can't place that here.", Color.red);
|
DebugUIMessage.Show("Can't place that here.", Color.red);
|
||||||
onForbiddenItemSlotted?.Invoke();
|
onForbiddenItemSlotted?.Invoke();
|
||||||
@@ -127,7 +127,7 @@ namespace Interactions
|
|||||||
// the correct item we're looking for
|
// the correct item we're looking for
|
||||||
var config = GameManager.Instance.GetSlotItemConfig(itemData);
|
var config = GameManager.Instance.GetSlotItemConfig(itemData);
|
||||||
var allowed = config?.allowedItems ?? new List<PickupItemData>();
|
var allowed = config?.allowedItems ?? new List<PickupItemData>();
|
||||||
if (allowed.Contains(itemToSlotData))
|
if (PickupItemData.ListContainsEquivalent(allowed, itemToSlotData))
|
||||||
{
|
{
|
||||||
if (itemToSlot != null)
|
if (itemToSlot != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
[CreateAssetMenu(fileName = "PickupItemData", menuName = "Game/Pickup Item Data")]
|
[CreateAssetMenu(fileName = "PickupItemData", menuName = "Game/Pickup Item Data")]
|
||||||
public class PickupItemData : ScriptableObject
|
public class PickupItemData : ScriptableObject
|
||||||
@@ -7,4 +8,22 @@ public class PickupItemData : ScriptableObject
|
|||||||
[TextArea]
|
[TextArea]
|
||||||
public string description;
|
public string description;
|
||||||
public Sprite mapSprite;
|
public Sprite mapSprite;
|
||||||
|
|
||||||
|
public static bool AreEquivalent(PickupItemData a, PickupItemData b)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(a, b)) return true;
|
||||||
|
if (a is null || b is null) return false;
|
||||||
|
// Compare by itemName as a fallback
|
||||||
|
return a.itemName == b.itemName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool ListContainsEquivalent(List<PickupItemData> list, PickupItemData item)
|
||||||
|
{
|
||||||
|
foreach (var entry in list)
|
||||||
|
{
|
||||||
|
if (AreEquivalent(entry, item))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user