Started adding building unlocks

This commit is contained in:
Pasha Bibko
2026-04-21 15:56:00 +01:00
parent 103ae9c645
commit b88fb5cc50
2 changed files with 55 additions and 11 deletions

View File

@@ -3,6 +3,7 @@ using UnityEngine;
using System.IO;
using System.Linq;
using System;
using System.Runtime.CompilerServices;
#if UNITY_EDITOR
using UnityEditor;
@@ -12,6 +13,7 @@ namespace Fruitomation.Game
{
[Serializable] public enum BasicUpgrade
{
//Apple, - Unlocked by default
Grapes,
Bananas,
Kiwi,
@@ -50,8 +52,25 @@ namespace Fruitomation.Game
SpicedPitayaIceCream,
}
[Serializable] public enum IncrementalUpgrade
[Serializable] public enum BuildingUnlock
{
None,
//Wall, - Unlocked by default
//Slope,
Floor,
//Spring, - Unlocked by default
Fan,
Alternator,
//Slicer, - Unlocked by default
//Presser, - Unlocked by default
HeatExchanger,
Grinder,
Mixer,
Fermenter,
Peeler,
}
public class UnlockedUpgrades
@@ -87,17 +106,20 @@ namespace Fruitomation.Game
}
}
private HashSet<BuildingUnlock> Buildings = new();
private HashSet<BasicUpgrade> Unlocks = new();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Unlock(BuildingUnlock unlock) => Buildings.Add(unlock);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Unlock(BasicUpgrade upgrade) => Unlocks.Add(upgrade);
public void Unlock(BasicUpgrade upgrade)
{
Unlocks.Add(upgrade);
}
public bool IsUnlocked(BasicUpgrade upgrade)
{
return Unlocks.Contains(upgrade);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsUnlocked(BuildingUnlock unlock) => Buildings.Contains(unlock);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsUnlocked(BasicUpgrade upgrade) => Unlocks.Contains(upgrade);
}
public static class UpgradeManager
@@ -131,10 +153,31 @@ namespace Fruitomation.Game
File.WriteAllText(Filepath, json);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Unlock(BuildingUnlock unlock)
{
if (unlock == BuildingUnlock.None)
{
throw new ArgumentOutOfRangeException(nameof(unlock));
}
CurrentUpgrades.Unlock(unlock);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Unlock(BasicUpgrade upgrade) => CurrentUpgrades.Unlock(upgrade);
public static bool Is(BasicUpgrade upgrade) => CurrentUpgrades.IsUnlocked(upgrade);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Is(BuildingUnlock unlock)
{
return unlock == BuildingUnlock.None
? throw new ArgumentOutOfRangeException(nameof(unlock))
: CurrentUpgrades.IsUnlocked(unlock);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Is(BasicUpgrade upgrade) => CurrentUpgrades.IsUnlocked(upgrade);
#if UNITY_EDITOR
[MenuItem("Fruitomation/Reset Upgrades")]
public static void ResetUpgrades() => CurrentUpgrades = new UnlockedUpgrades();