345 lines
8.3 KiB
C#
345 lines
8.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Superlazy;
|
|
using UnityEngine;
|
|
|
|
public abstract class SLTag
|
|
{
|
|
private static Dictionary<string, SLTag> formats;
|
|
|
|
public static void Init(IEnumerable<SLTag> formats = null)
|
|
{
|
|
if (SLTag.formats != null) return;
|
|
|
|
if (formats == null) formats = Enumerable.Empty<SLTag>();
|
|
|
|
SLTag.formats = new Dictionary<string, SLTag>();
|
|
|
|
foreach (var format in formats)
|
|
{
|
|
if (SLTag.formats.ContainsKey(format.Tag))
|
|
{
|
|
SLLog.Warn($"Options Duplicated{SLTag.formats[format.Tag]}, {format} : {format.Tag}");
|
|
}
|
|
|
|
SLTag.formats[format.Tag] = format;
|
|
}
|
|
}
|
|
|
|
public static string Apply(SLEntity value, string tagType)
|
|
{
|
|
if (formats == null) return value.ToString();
|
|
if (formats.ContainsKey(tagType))
|
|
{
|
|
return formats[tagType].GetValue(value);
|
|
}
|
|
|
|
return value.ToString();
|
|
}
|
|
|
|
public abstract string GetValue(SLEntity value);
|
|
|
|
public abstract string Tag { get; }
|
|
}
|
|
|
|
public class SLTagDefault : SLTag
|
|
{
|
|
public override string Tag => string.Empty;
|
|
|
|
public override string GetValue(SLEntity value)
|
|
{
|
|
return value;
|
|
}
|
|
}
|
|
|
|
public class SLSecond : SLTag
|
|
{
|
|
public override string Tag => "S";
|
|
|
|
public override string GetValue(SLEntity value)
|
|
{
|
|
return (Mathf.FloorToInt(value / 6.0f) * 0.1f).ToString();
|
|
}
|
|
}
|
|
|
|
public class SLRemainTime : SLTag
|
|
{
|
|
public override string Tag => "RT";
|
|
|
|
public override string GetValue(SLEntity value)
|
|
{
|
|
var date = value.ToDateTime();
|
|
|
|
var delta = date - SLSystem.Now;
|
|
|
|
if (delta.TotalDays >= 1)
|
|
{
|
|
return $"{delta.Days}<STR:STR_AfterDay>";
|
|
}
|
|
else if (delta.Hours >= 1)
|
|
{
|
|
return $"{delta.Hours}<STR:STR_AfterHour>";
|
|
}
|
|
else if (delta.Minutes >= 1)
|
|
{
|
|
return $"{delta.Minutes}<STR:STR_AfterMinute>";
|
|
}
|
|
else
|
|
{
|
|
return $"{delta.Seconds}<STR:STR_AfterSecond>";
|
|
}
|
|
}
|
|
}
|
|
|
|
//}
|
|
|
|
//public class SLMinute : SLStringFormat
|
|
//{
|
|
// public override string Tag => "M";
|
|
|
|
// public override string GetValue(SLEntity value)
|
|
// {
|
|
// return SLMath.Ceiling(value / 60.0);
|
|
// }
|
|
//}
|
|
|
|
//public class SLHour : SLStringFormat
|
|
//{
|
|
// public override string Tag => "H";
|
|
|
|
// public override string GetValue(SLEntity value)
|
|
// {
|
|
// return SLMath.Ceiling(value / 60.0 / 60.0);
|
|
// }
|
|
//}
|
|
|
|
//public class SLStringRoughAgoTime : SLStringFormat
|
|
//{
|
|
// public override string Tag => "RAT";
|
|
|
|
// public override string GetValue(SLEntity value)
|
|
// {
|
|
// var entity = SLEntity.Empty;
|
|
|
|
// if (value <= 0)
|
|
// {
|
|
// entity["Value"] = 0;
|
|
// return "";
|
|
// }
|
|
|
|
// var delta = SLSystem.Now - value.ToDateTime();
|
|
|
|
// var result = "";
|
|
|
|
// if (delta.TotalDays >= 1)
|
|
// {
|
|
// entity["Value"] = SLMath.Floor(delta.TotalDays);
|
|
// result = SLSystem.GetString("STR_DayAgo", entity);
|
|
// }
|
|
// else if (delta.Hours >= 1)
|
|
// {
|
|
// entity["Value"] = delta.Hours;
|
|
// result = SLSystem.GetString("STR_HourAgo", entity);
|
|
// }
|
|
// else if (delta.Minutes >= 1)
|
|
// {
|
|
// entity["Value"] = delta.Minutes;
|
|
// result = SLSystem.GetString("STR_MinuteAgo", entity);
|
|
// }
|
|
// else
|
|
// {
|
|
// entity["Value"] = delta.Seconds;
|
|
// result = SLSystem.GetString("STR_LessThanMinuteAgo", entity);
|
|
// }
|
|
|
|
// return result;
|
|
// }
|
|
//}
|
|
|
|
//public class SLStringRoughLeftTime : SLStringFormat
|
|
//{
|
|
// public override string Tag => "RLT";
|
|
|
|
// public override float UpdateTick => 60.0f;
|
|
|
|
// public override string GetValue(SLEntity value)
|
|
// {
|
|
// var entity = SLEntity.Empty;
|
|
|
|
// if (value <= 0)
|
|
// {
|
|
// entity["Value"] = 0;
|
|
// return SLSystem.GetString("STR_MinuteLeft", SLEntity.Empty);
|
|
// }
|
|
|
|
// var delta = value.ToDateTime() - SLSystem.Now;
|
|
|
|
// var result = "";
|
|
|
|
// if (delta.TotalDays >= 1)
|
|
// {
|
|
// entity["Value"] = SLMath.Floor(delta.TotalDays);
|
|
// result = SLSystem.GetString("STR_DayLeft", entity);
|
|
// }
|
|
// else if (delta.Hours >= 1)
|
|
// {
|
|
// entity["Value"] = delta.Hours;
|
|
// result = SLSystem.GetString("STR_HourLeft", entity);
|
|
// }
|
|
// else if (delta.Minutes >= 1)
|
|
// {
|
|
// entity["Value"] = delta.Minutes;
|
|
// result = SLSystem.GetString("STR_MinuteLeft", entity);
|
|
// }
|
|
// else
|
|
// {
|
|
// entity["Value"] = delta.Seconds;
|
|
// result = SLSystem.GetString("STR_LessThanMinuteLeft", entity);
|
|
// }
|
|
|
|
// return result;
|
|
// }
|
|
//}
|
|
|
|
public class SLStringLocalDate : SLTag
|
|
{
|
|
public override string Tag => "DATE";
|
|
|
|
public override string GetValue(SLEntity value)
|
|
{
|
|
return value.ToLocalDateTime().ToString("yyyy.MM.dd");
|
|
}
|
|
}
|
|
|
|
public class SLStringLocalTime : SLTag
|
|
{
|
|
public override string Tag => "TIME";
|
|
|
|
public override string GetValue(SLEntity value)
|
|
{
|
|
return value.ToLocalDateTime().ToString("HH:mm");
|
|
}
|
|
}
|
|
|
|
public class SLStringLocalDateTime : SLTag
|
|
{
|
|
public override string Tag => "LDT";
|
|
|
|
public override string GetValue(SLEntity value)
|
|
{
|
|
return value.ToLocalDateTime().ToString("yyyy.MM.dd HH:mm");
|
|
}
|
|
}
|
|
|
|
public class SLStringAbsoluteNumber : SLTag
|
|
{
|
|
public override string Tag => "ABS";
|
|
|
|
public override string GetValue(SLEntity value)
|
|
{
|
|
return string.Format("{0:N0}", Math.Abs(value));
|
|
}
|
|
}
|
|
|
|
public class SLStringNaturalNumber : SLTag
|
|
{
|
|
public override string Tag => "NN";
|
|
|
|
public override string GetValue(SLEntity value)
|
|
{
|
|
return string.Format("{0:N0}", (double)value);
|
|
}
|
|
}
|
|
|
|
public class SLStringSignNumber : SLTag
|
|
{
|
|
public override string Tag => "SN";
|
|
|
|
public override string GetValue(SLEntity value)
|
|
{
|
|
if (value >= 0)
|
|
{
|
|
return string.Format("+{0:N0}", Math.Abs(value));
|
|
}
|
|
else
|
|
{
|
|
return string.Format("-{0:N0}", Math.Abs(value));
|
|
}
|
|
}
|
|
}
|
|
|
|
public class SLStringSignNumberPercent : SLTag
|
|
{
|
|
public override string Tag => "SNP";
|
|
|
|
public override string GetValue(SLEntity value)
|
|
{
|
|
if (value >= 0)
|
|
{
|
|
return string.Format("+{0:N0}%", Math.Abs(value * 100.0));
|
|
}
|
|
else
|
|
{
|
|
return string.Format("-{0:N0}%", Math.Abs(value * 100.0));
|
|
}
|
|
}
|
|
}
|
|
|
|
public class SLStringToRoman : SLTag
|
|
{
|
|
public override string Tag => "RM";
|
|
|
|
public override string GetValue(SLEntity value)
|
|
{
|
|
return value.RomanNumString();
|
|
}
|
|
}
|
|
|
|
public static class SLRomanNumber
|
|
{
|
|
public static string RomanNumString(this SLEntity val)
|
|
{
|
|
return ((int)val).RomanNumString();
|
|
}
|
|
|
|
public static string RomanNumString(this int value)
|
|
{
|
|
if (value >= 1000) return "M" + RomanNumString(value - 1000);
|
|
if (value >= 900) return "CM" + RomanNumString(value - 900);
|
|
if (value >= 500) return "D" + RomanNumString(value - 500);
|
|
if (value >= 400) return "CD" + RomanNumString(value - 400);
|
|
if (value >= 100) return "C" + RomanNumString(value - 100);
|
|
if (value >= 90) return "XC" + RomanNumString(value - 90);
|
|
if (value >= 50) return "L" + RomanNumString(value - 50);
|
|
if (value >= 40) return "XL" + RomanNumString(value - 40);
|
|
if (value >= 10) return "X" + RomanNumString(value - 10);
|
|
if (value >= 9) return "IX" + RomanNumString(value - 9);
|
|
if (value >= 5) return "V" + RomanNumString(value - 5);
|
|
if (value >= 4) return "IV" + RomanNumString(value - 4);
|
|
if (value >= 1) return "I" + RomanNumString(value - 1);
|
|
return string.Empty;
|
|
}
|
|
}
|
|
|
|
public class SLRound1Value : SLTag
|
|
{
|
|
public override string Tag => "R1";
|
|
|
|
public override string GetValue(SLEntity value)
|
|
{
|
|
return MathF.Round(value, 1).ToString("0.0");
|
|
}
|
|
}
|
|
|
|
// Option
|
|
|
|
public class LanguageName : SLTag
|
|
{
|
|
public override string Tag => "LANGUAGENAME";
|
|
|
|
public override string GetValue(SLEntity value)
|
|
{
|
|
return SLSystem.Data["Languages"][value]["Name"];
|
|
}
|
|
} |