Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Assets/Scripts/Catalyst.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions Assets/Scripts/Catalyst/Catalyst.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using UnityEngine;
using FractionGame.Utility;

namespace FractionGame.Ingredients
{
public class Catalyst : Draggable, IIngredient
{
[SerializeField] private int multiplierNumerator = 1;
[SerializeField] private int multiplierDenominator = 1;
[SerializeField] private string catalystName = "Catalyst";

public Fraction Multiplier => new Fraction(multiplierNumerator, multiplierDenominator);

public Fraction Value
{
get
{
return new Fraction(0, 1);
}
}

public IngredientType Type => IngredientType.CATALYST;

public string Name => catalystName;

void Start()
{
if (multiplierDenominator == 0)
{
Debug.LogError("Catalyst denominator cannot be zero.");
multiplierDenominator = 1;
}
}
}
}
2 changes: 2 additions & 0 deletions Assets/Scripts/Catalyst/Catalyst.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 32 additions & 7 deletions Assets/Scripts/Cauldron/Cauldron.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,43 @@ public class Cauldron : MonoBehaviour
public Fraction Value => value;
public IReadOnlyList<IIngredient> Ingredients => ingredients.AsReadOnly();

public void AddIngredient(IIngredient ingredient)
{
if (ingredient == null)
public void AddIngredient(IIngredient ingredient)
{
if (ingredient == null)
{
Debug.LogWarning("Tried to add a null ingredient to the cauldron.");
return;
}

switch (ingredient.Type)
{
case IngredientType.CATALYST:
// Must cast to access multiplier
if (ingredient is Catalyst catalyst)
{
Debug.LogWarning("Tried to add a null ingredient to the cauldron.");
return;
value = value * catalyst.Multiplier;
Debug.Log($"Catalyst '{catalyst.Name}' applied. Multiplier: {catalyst.Multiplier}. New total: {value}");
}
else
{
Debug.LogError("Ingredient is marked as CATALYST but not a Catalyst instance.");
}
break;

case IngredientType.PETAL:
ingredients.Add(ingredient);
value += ingredient.Value;

Debug.Log($"Added {ingredient.Type} '{ingredient.Name}' with value {ingredient.Value}. Total: {value}");
}
break;

default:
Debug.LogWarning($"Unhandled ingredient type: {ingredient.Type}");
break;
}

// Optional: destroy used object
Destroy((ingredient as MonoBehaviour)?.gameObject);
}
public void Subtraction()
{
if (ingredients.Count < 2)
Expand All @@ -43,6 +66,8 @@ public void Subtraction()

value = result;
Debug.Log($"Performed subtraction. Resulting value: {value}");


}

public void ResetCauldron()
Expand Down
12 changes: 8 additions & 4 deletions Assets/Scripts/Utility/Fraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override string ToString()
{
return $"{numerator}/{denominator}";
}

public static Fraction operator +(Fraction a, Fraction b)
{
int numerator = a.numerator * b.denominator + b.numerator * a.denominator;
Expand All @@ -61,9 +61,13 @@ public override string ToString()

public static Fraction operator -(Fraction a, Fraction b)
{
int numerator = a.numerator * b.denominator - b.numerator * a.denominator;
int denominator = a.denominator * b.denominator;
return new Fraction(numerator, denominator);
int numerator = a.numerator * b.denominator - b.numerator * a.denominator;
int denominator = a.denominator * b.denominator;
return new Fraction(numerator, denominator);
}
public static Fraction operator *(Fraction a, Fraction b)
{
return new Fraction(a.Numerator * b.Numerator, a.Denominator * b.Denominator);
}

}
Expand Down
Loading