|
- using System;
- using CIG.Translation;
- using SUISSEngine;
- using UnityEngine;
-
- public static class CIGUtilities
- {
- public static bool HasGold(Currencies currency)
- {
- return currency.ContainsApproximate("Gold");
- }
-
- public static bool HasCash(Currencies currency)
- {
- return currency.ContainsApproximate("Cash");
- }
-
- public static string QuantityKey(float quantity, string baseKey)
- {
- if (CIGUtilities.IsSingular(quantity))
- {
- return baseKey + "$1";
- }
- return baseKey + "$n";
- }
-
- public static bool IsSingular(float value)
- {
- return Mathf.Approximately(value, 0f) || Mathf.Approximately(value, 1f) || (value > 0f && value < 1f);
- }
-
- public static bool IsSingular(int value)
- {
- return CIGUtilities.IsSingular((float)value);
- }
-
- public static bool IsPlural(float value)
- {
- return !CIGUtilities.IsSingular(value);
- }
-
- public static bool IsPlural(int value)
- {
- return !CIGUtilities.IsSingular(value);
- }
-
- public static ILocalizedString LocalizedString(this Currencies rawCurrencies)
- {
- Currencies currencies = rawCurrencies.Round();
- ILocalizedString localizedString = Localization.EmptyLocalizedString;
- bool flag = false;
- if (currencies.ContainsApproximate("Cash"))
- {
- localizedString = Localization.Concat(new ILocalizedString[]
- {
- localizedString,
- Localization.Integer(currencies.GetValue("Cash")),
- Localization.LiteralWhiteSpace,
- Localization.Key("cash")
- });
- flag = true;
- }
- if (currencies.ContainsApproximate("Gold"))
- {
- ILocalizedString localizedString2 = (!flag) ? Localization.EmptyLocalizedString : Localization.Literal(", ");
- localizedString = Localization.Concat(new ILocalizedString[]
- {
- localizedString,
- localizedString2,
- Localization.Integer(currencies.GetValue("Gold")),
- Localization.LiteralWhiteSpace,
- Localization.Key("gold")
- });
- flag = true;
- }
- if (currencies.ContainsApproximate("XP"))
- {
- ILocalizedString localizedString3 = (!flag) ? Localization.EmptyLocalizedString : Localization.Literal(", ");
- localizedString = Localization.Concat(new ILocalizedString[]
- {
- localizedString,
- localizedString3,
- Localization.Integer(currencies.GetValue("XP")),
- Localization.LiteralWhiteSpace,
- Localization.Key("experience")
- });
- flag = true;
- }
- return (!flag) ? Localization.Integer(0) : localizedString;
- }
-
- public static ILocalizedString LocalizedAmountString(this Currencies rawCurrencies)
- {
- Currencies currencies = rawCurrencies.Round();
- if (currencies.ContainsApproximate("Cash"))
- {
- return Localization.Integer(currencies.GetValue("Cash"));
- }
- if (currencies.ContainsApproximate("Gold"))
- {
- return Localization.Integer(currencies.GetValue("Gold"));
- }
- if (currencies.ContainsApproximate("XP"))
- {
- return Localization.Integer(currencies.GetValue("XP"));
- }
- return Localization.EmptyLocalizedString;
- }
-
- public static ILocalizedString SizeToString(long size)
- {
- int num = 0;
- while (num < CIGUtilities.SizeSuffix.Length - 1 && size > 800000L)
- {
- num++;
- size /= 1024L;
- }
- return Localization.Concat(new ILocalizedString[]
- {
- Localization.Float((double)size / 1024.0, 1, false),
- Localization.Literal(CIGUtilities.SizeSuffix[num])
- });
- }
-
- public static Currencies WithoutXPCurrency(this Currencies currencies)
- {
- Currencies c = new Currencies(currencies);
- return c - new Currencies("XP", currencies.GetValue("XP"));
- }
-
- public static Rect ScaleSprite(Rect bounds, Sprite sprite)
- {
- return CIGUtilities.KeepRectInsideBoundsWhileKeepingAspectRatio(bounds, sprite.rect);
- }
-
- public static Rect KeepRectInsideBoundsWhileKeepingAspectRatio(Rect bounds, Rect r)
- {
- float width = r.width;
- float height = r.height;
- float num = bounds.width / width;
- float num2 = bounds.height / height;
- float num3;
- if (num2 < num)
- {
- num3 = num2;
- }
- else
- {
- num3 = num;
- }
- float width2 = width * num3;
- float height2 = height * num3;
- return new Rect(bounds.x, bounds.y, width2, height2);
- }
-
- public static int SortByUnlockASC(CIGBuilding a, CIGBuilding b)
- {
- if (a.unlockLevels[0] > b.unlockLevels[0])
- {
- return 1;
- }
- if (a.unlockLevels[0] < b.unlockLevels[0])
- {
- return -1;
- }
- int num = Mathf.FloorToInt((float)a.PurchasePrice.GetValue("Gold"));
- int num2 = Mathf.FloorToInt((float)b.PurchasePrice.GetValue("Gold"));
- if (num < num2)
- {
- return 1;
- }
- if (num > num2)
- {
- return -1;
- }
- return a.name.CompareTo(b.name);
- }
-
- public static Comparison<T> reverse<T>(Comparison<T> compare)
- {
- return (T a, T b) => -compare(a, b);
- }
-
- private static readonly string[] SizeSuffix = new string[]
- {
- "kb",
- "mb",
- "gb",
- "tb"
- };
- }
|