sea-battle-vr/Assets/Scripts/Common/PluralizeUtil.cs
2026-05-14 14:13:52 +03:00

67 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
/// <summary>
/// Для склонений валюты
/// </summary>
public class PluralizeUtil
{
/// <summary>
/// Склонение для рублей
/// </summary>
public static string Rubles(int n)
{
int lastDigit = n % 10;
int lastTwoDigits = n % 100;
// Исключения для 11–14 (рублей)
if (lastTwoDigits >= 11 && lastTwoDigits <= 14)
return "рублей";
return lastDigit switch
{
1 => "рубль",
2 or 3 or 4 => "рубля",
_ => "рублей"
};
}
/// <summary>
/// Склонение для жетонов
/// </summary>
public static string Tokens(int n)
{
int lastDigit = n % 10;
int lastTwoDigits = n % 100;
// Исключения для 11–14 (жетонов)
if (lastTwoDigits >= 11 && lastTwoDigits <= 14)
return "жетонов";
return lastDigit switch
{
1 => "жетон",
2 or 3 or 4 => "жетона",
_ => "жетонов"
};
}
public static int PlaytimeToMinutes(string playtime)
{
if (playtime == "Тест 0 мин") return 1;
if (playtime == "Неограниченно") return 0;
try
{
string textNumber = playtime.Split(' ')[0];
int minutes = int.Parse(textNumber);
return minutes;
}
catch
{
Debug.Log($"Ошибка парсинга значения {playtime}");
return 0;
}
}
}