Initial commit: Tiny Tackle Heroes Unity project
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using BumpCombat.Combat;
|
||||
using BumpCombat.Constants;
|
||||
using BumpCombat.Player;
|
||||
using BumpCombat.Progression;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace BumpCombat.PlayModeTests
|
||||
{
|
||||
public sealed class GameplayConstantsConsumptionPlayModeTests
|
||||
{
|
||||
private static readonly BindingFlags NonPublicInstance =
|
||||
BindingFlags.Instance | BindingFlags.NonPublic;
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator ExperienceOrb_UsesChangedPickupRadius()
|
||||
{
|
||||
ItemConstants constants = GameplayConstants.Current.Items;
|
||||
float originalPickupRadius = constants.ExperienceOrbPickupRadius;
|
||||
float originalMagnetSpeed = constants.ExperienceOrbMagnetSpeed;
|
||||
GameObject playerObject = new("Constants Orb Player");
|
||||
GameObject orbObject = new("Constants Orb");
|
||||
try
|
||||
{
|
||||
playerObject.AddComponent<PlayerStats>();
|
||||
playerObject.AddComponent<ExperienceSystem>();
|
||||
Rigidbody2D orbBody = orbObject.AddComponent<Rigidbody2D>();
|
||||
orbObject.AddComponent<CircleCollider2D>();
|
||||
ExperienceOrb orb = orbObject.AddComponent<ExperienceOrb>();
|
||||
orb.Initialize(1);
|
||||
playerObject.transform.position = Vector3.zero;
|
||||
orbBody.position = new Vector2(0.3f, 0f);
|
||||
orbBody.gravityScale = 0f;
|
||||
constants.ExperienceOrbPickupRadius = 0.2f;
|
||||
constants.ExperienceOrbMagnetSpeed = 0f;
|
||||
|
||||
yield return null;
|
||||
// ExperienceOrb resolves its target through the scene-wide
|
||||
// lookup in Start. Bind this fixture back to its own player
|
||||
// after Start so another scene player cannot make the radius
|
||||
// assertion depend on test order.
|
||||
SetPrivate(orb, "experienceSystem",
|
||||
playerObject.GetComponent<ExperienceSystem>());
|
||||
SetPrivate(orb, "player", playerObject.transform);
|
||||
yield return new WaitForFixedUpdate();
|
||||
Assert.That(orb, Is.Not.Null);
|
||||
Assert.That(GetPrivate<bool>(orb, "pickedUp"), Is.False);
|
||||
|
||||
constants.ExperienceOrbPickupRadius = 0.4f;
|
||||
yield return new WaitForFixedUpdate();
|
||||
Assert.That(GetPrivate<bool>(orb, "pickedUp"), Is.True);
|
||||
}
|
||||
finally
|
||||
{
|
||||
constants.ExperienceOrbPickupRadius = originalPickupRadius;
|
||||
constants.ExperienceOrbMagnetSpeed = originalMagnetSpeed;
|
||||
if (playerObject != null)
|
||||
{
|
||||
Object.Destroy(playerObject);
|
||||
}
|
||||
if (orbObject != null)
|
||||
{
|
||||
Object.Destroy(orbObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator CombatFeedback_UsesChangedHeavyEffectLimit()
|
||||
{
|
||||
CombatFeedbackSettings constants = GameplayConstants.Current.CombatFeedback;
|
||||
int originalLimit = constants.MaxConcurrentHeavyEffects;
|
||||
GameObject feedbackObject = new("Constants Feedback Host");
|
||||
GameObject targetObject = new("Constants Feedback Target");
|
||||
try
|
||||
{
|
||||
constants.MaxConcurrentHeavyEffects = 2;
|
||||
feedbackObject.AddComponent<SpriteRenderer>();
|
||||
CombatFeedback feedback = feedbackObject.AddComponent<CombatFeedback>();
|
||||
yield return null;
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
CombatEvents.RaiseEnemyStagger(targetObject, 1, 1, true);
|
||||
CombatEvents.RaiseLaunchResisted(targetObject);
|
||||
}
|
||||
|
||||
Assert.That(CombatFeedback.MaxConcurrentHeavyEffects, Is.EqualTo(2));
|
||||
Assert.That(feedback.ActiveHeavyEffectCount, Is.GreaterThan(0));
|
||||
Assert.That(feedback.ActiveHeavyEffectCount, Is.LessThanOrEqualTo(2));
|
||||
}
|
||||
finally
|
||||
{
|
||||
constants.MaxConcurrentHeavyEffects = originalLimit;
|
||||
if (targetObject != null)
|
||||
{
|
||||
Object.Destroy(targetObject);
|
||||
}
|
||||
if (feedbackObject != null)
|
||||
{
|
||||
Object.Destroy(feedbackObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static T GetPrivate<T>(object target, string fieldName)
|
||||
{
|
||||
FieldInfo field = target.GetType().GetField(fieldName, NonPublicInstance);
|
||||
Assert.That(field, Is.Not.Null, fieldName);
|
||||
return (T)field.GetValue(target);
|
||||
}
|
||||
|
||||
private static void SetPrivate(object target, string fieldName, object value)
|
||||
{
|
||||
FieldInfo field = target.GetType().GetField(fieldName, NonPublicInstance);
|
||||
Assert.That(field, Is.Not.Null, fieldName);
|
||||
field.SetValue(target, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user