riversong code showcase
This commit is contained in:
66
Source/Riversong/Game/UI/Helpers/TextFormatHelper.cs
Normal file
66
Source/Riversong/Game/UI/Helpers/TextFormatHelper.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
public class TextFormatHelper
|
||||
{
|
||||
public string Pluralize(int value, string singular, string plural)
|
||||
{
|
||||
return value == 1 ? singular : plural;
|
||||
}
|
||||
|
||||
public string FormatImportantText(string text)
|
||||
{
|
||||
return $"<b>{text}</b>";
|
||||
}
|
||||
|
||||
public void FormatImportantText(StringBuilder sb, string text)
|
||||
{
|
||||
sb.Append("<b>");
|
||||
sb.Append(text);
|
||||
sb.Append("</b>");
|
||||
}
|
||||
|
||||
public void FormatUnlockConditions(UnlockDefinition unlock, StringBuilder sb)
|
||||
{
|
||||
if (unlock.Type != UnlockType.UnlockBuilding || unlock.Conditions.Count <= 0) return;
|
||||
|
||||
sb.Append("To unlock the ");
|
||||
FormatImportantText(sb, unlock.Building.BuildingName);
|
||||
sb.AppendLine(", your village needs a little more:");
|
||||
|
||||
foreach (var condition in unlock.Conditions)
|
||||
{
|
||||
sb.AppendLine();
|
||||
FormatUnlockCondition(sb, condition);
|
||||
}
|
||||
}
|
||||
|
||||
private void FormatUnlockCondition(StringBuilder sb, UnlockCondition condition)
|
||||
{
|
||||
sb.Append("\u2022 ");
|
||||
|
||||
switch (condition.Type)
|
||||
{
|
||||
case UnlockConditionType.BuildingPlaced:
|
||||
sb.Append("Add a ");
|
||||
FormatImportantText(sb, condition.Building.BuildingName);
|
||||
sb.Append(" to your village");
|
||||
return;
|
||||
|
||||
case UnlockConditionType.HouseCountAtTierOrAbove:
|
||||
sb.Append("Grow ");
|
||||
sb.Append(condition.HouseCount);
|
||||
sb.Append(' ');
|
||||
sb.Append(Pluralize(condition.HouseCount, "house", "houses"));
|
||||
sb.Append(" to tier ");
|
||||
sb.Append(condition.MinHouseTierIndex + 1);
|
||||
return;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user