Resolve WES-187 "Unit tests justsign and spellingbee"
This commit is contained in:
committed by
Dries Van Schuylenbergh
parent
1e09f09dae
commit
53fc361af4
@@ -276,6 +276,7 @@ public class JustSignController : AbstractMinigameController
|
||||
DestroySymbolAt(0);
|
||||
incorrectSigns++;
|
||||
timingFeedback.text = $"Te laat! \n {offscreenScore}";
|
||||
timingFeedback.color = new Color(0x10 / 255.0f, 0x10 / 255.0f, 0x10 / 255.0f);
|
||||
imageFeedback.sprite = tooLateSprite;
|
||||
}
|
||||
}
|
||||
@@ -360,25 +361,36 @@ public class JustSignController : AbstractMinigameController
|
||||
activeSymbols.Add(newSymbolObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the threshold for a given sign
|
||||
/// </summary>
|
||||
/// <param name="sign"></param>
|
||||
/// <returns></returns>
|
||||
public float GetThreshold(string sign)
|
||||
{
|
||||
Learnable predSign = currentTheme.learnables.Find(l => l.name.ToUpper().Replace(" ", "-") == sign);
|
||||
return predSign.thresholdDistance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The logic to process the signs sent by the signPredictor
|
||||
/// </summary>
|
||||
/// <param name="accuracy">The accuracy of the passed sign</param>
|
||||
/// <param name="predictedSign">The name of the passed sign</param>
|
||||
protected override void ProcessMostProbableSign(float distance, string predictedSign)
|
||||
public override void ProcessMostProbableSign(float distance, string predictedSign)
|
||||
{
|
||||
Learnable predSign = currentTheme.learnables.Find(l => l.name.ToUpper().Replace(" ", "-") == predictedSign);
|
||||
//Learnable predSign = currentTheme.learnables.Find(l => l.name == predictedSign);
|
||||
float threshold = GetThreshold(predictedSign);
|
||||
|
||||
// If there is a feedback-object, we wil change its appearance
|
||||
if (feedbackText != null && feedbackProgressImage != null)
|
||||
{
|
||||
Color col;
|
||||
if (distance < predSign.thresholdDistance)
|
||||
if (distance < threshold)
|
||||
{
|
||||
feedbackText.text = $"Herkent '{predictedSign}'";
|
||||
col = new Color(0x8b / 255.0f, 0xd4 / 255.0f, 0x5e / 255.0f);
|
||||
}
|
||||
else if (distance < 1.5 * predSign.thresholdDistance)
|
||||
else if (distance < 1.5 * threshold)
|
||||
{
|
||||
feedbackText.text = $"Lijkt op '{predictedSign}'";
|
||||
col = new Color(0xf2 / 255.0f, 0x7f / 255.0f, 0x0c / 255.0f);
|
||||
@@ -394,7 +406,7 @@ public class JustSignController : AbstractMinigameController
|
||||
|
||||
float oldValue = feedbackProgress.value;
|
||||
// use an exponential scale
|
||||
float newValue = 1 - Mathf.Clamp(distance - predSign.thresholdDistance, 0.0f, 3.0f) / 3;
|
||||
float newValue = 1 - Mathf.Clamp(distance - threshold, 0.0f, 3.0f) / 3;
|
||||
feedbackProgress.gameObject.Tween("FeedbackUpdate", oldValue, newValue, 0.2f, TweenScaleFunctions.CubicEaseInOut, (t) =>
|
||||
{
|
||||
if (feedbackProgress != null)
|
||||
@@ -405,59 +417,68 @@ public class JustSignController : AbstractMinigameController
|
||||
}
|
||||
|
||||
// The logic for the internal workings of the game
|
||||
if (distance < predSign.thresholdDistance)
|
||||
if (distance < threshold)
|
||||
{
|
||||
int matchedSymbolIndex = activeWords.IndexOf(predictedSign.ToUpper());
|
||||
|
||||
// Destroy the oldest symbol if the current input matches it
|
||||
if (0 <= matchedSymbolIndex)
|
||||
{
|
||||
float x = activeSymbols[matchedSymbolIndex].transform.localPosition.x;
|
||||
|
||||
// parameters to define the Perfect hit zone
|
||||
float perfectRange = hitZonePerfect.sizeDelta.x;
|
||||
float perfectCenter = hitZonePerfect.localPosition.x;
|
||||
// parameters to define the Good hit zone
|
||||
float goodRange = hitZoneGood.sizeDelta.x;
|
||||
float goodCenter = hitZoneGood.localPosition.x;
|
||||
// parameters to define the Meh hit zone
|
||||
float mehRange = hitZoneMeh.sizeDelta.x;
|
||||
float mehCenter = hitZoneMeh.localPosition.x;
|
||||
|
||||
if (perfectCenter - perfectRange / 2 <= x && x <= perfectCenter + perfectRange / 2)
|
||||
{
|
||||
timingFeedback.text = $"Perfect! \n +{perfectScore}";
|
||||
imageFeedback.sprite = perfectSprite;
|
||||
perfectSigns++;
|
||||
timingFeedback.color = new Color(0x8b / 255.0f, 0xd4 / 255.0f, 0x5e / 255.0f);
|
||||
}
|
||||
else if (goodCenter - goodRange / 2 <= x && x <= goodCenter + goodRange / 2)
|
||||
{
|
||||
timingFeedback.text = $"Goed \n +{goodScore}";
|
||||
imageFeedback.sprite = goodSprite;
|
||||
goodSigns++;
|
||||
timingFeedback.color = new Color(0xf7 / 255.0f, 0xad / 255.0f, 0x19 / 255.0f);
|
||||
}
|
||||
else if (mehCenter - mehRange / 2 <= x && x <= mehCenter + mehRange / 2)
|
||||
{
|
||||
timingFeedback.text = $"Bijna... \n +{mehScore}";
|
||||
imageFeedback.sprite = mehSprite;
|
||||
mehSigns++;
|
||||
timingFeedback.color = new Color(0xf2 / 255.0f, 0x7f / 255.0f, 0x0c / 255.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
timingFeedback.text = $"Te vroeg! \n {terribleScore}";
|
||||
imageFeedback.sprite = terribleSprite;
|
||||
terribleSigns++;
|
||||
timingFeedback.color = new Color(0xf5 / 255.0f, 0x49 / 255.0f, 0x3d / 255.0f);
|
||||
}
|
||||
|
||||
DestroySymbolAt(matchedSymbolIndex);
|
||||
MatchedSymbol(matchedSymbolIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The logic to process a correct sign within the zones in the game
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
void MatchedSymbol(int index)
|
||||
{
|
||||
float x = activeSymbols[index].transform.localPosition.x;
|
||||
|
||||
// parameters to define the Perfect hit zone
|
||||
float perfectRange = hitZonePerfect.sizeDelta.x;
|
||||
float perfectCenter = hitZonePerfect.localPosition.x;
|
||||
// parameters to define the Good hit zone
|
||||
float goodRange = hitZoneGood.sizeDelta.x;
|
||||
float goodCenter = hitZoneGood.localPosition.x;
|
||||
// parameters to define the Meh hit zone
|
||||
float mehRange = hitZoneMeh.sizeDelta.x;
|
||||
float mehCenter = hitZoneMeh.localPosition.x;
|
||||
|
||||
if (perfectCenter - perfectRange / 2 <= x && x <= perfectCenter + perfectRange / 2)
|
||||
{
|
||||
timingFeedback.text = $"Perfect! \n +{perfectScore}";
|
||||
imageFeedback.sprite = perfectSprite;
|
||||
perfectSigns++;
|
||||
timingFeedback.color = new Color(0x8b / 255.0f, 0xd4 / 255.0f, 0x5e / 255.0f);
|
||||
}
|
||||
else if (goodCenter - goodRange / 2 <= x && x <= goodCenter + goodRange / 2)
|
||||
{
|
||||
timingFeedback.text = $"Goed \n +{goodScore}";
|
||||
imageFeedback.sprite = goodSprite;
|
||||
goodSigns++;
|
||||
timingFeedback.color = new Color(0xf7 / 255.0f, 0xad / 255.0f, 0x19 / 255.0f);
|
||||
}
|
||||
else if (mehCenter - mehRange / 2 <= x && x <= mehCenter + mehRange / 2)
|
||||
{
|
||||
timingFeedback.text = $"Bijna... \n +{mehScore}";
|
||||
imageFeedback.sprite = mehSprite;
|
||||
mehSigns++;
|
||||
timingFeedback.color = new Color(0xf2 / 255.0f, 0x7f / 255.0f, 0x0c / 255.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
timingFeedback.text = $"Te vroeg! \n {terribleScore}";
|
||||
imageFeedback.sprite = terribleSprite;
|
||||
terribleSigns++;
|
||||
timingFeedback.color = new Color(0xf5 / 255.0f, 0x49 / 255.0f, 0x3d / 255.0f);
|
||||
}
|
||||
|
||||
DestroySymbolAt(index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The logic to set the scoreboard of justsign
|
||||
/// </summary>
|
||||
@@ -517,4 +538,18 @@ public class JustSignController : AbstractMinigameController
|
||||
DestroySymbolAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get sign for the first active symbol
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetFirstSign()
|
||||
{
|
||||
if (activeSymbols.Count > 0)
|
||||
{
|
||||
TMP_Text text = activeSymbols[0].GetComponentInChildren<TMP_Text>();
|
||||
return text.text;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user