stitch-a-ton/WebApp/Coordinate.cs

43 lines
926 B
C#
Raw Normal View History

2025-07-26 06:56:07 +07:00
namespace WebApp;
internal record Coordinate
{
2025-07-30 21:59:04 +07:00
private static readonly string BasePath = Environment.GetEnvironmentVariable("ASSET_PATH_RO") ?? "";
2025-07-26 06:56:07 +07:00
public string Name { get; }
public int Row { get; }
public int Col { get; }
2025-07-30 21:59:04 +07:00
public string Path => BasePath + Name + ".png";
2025-07-26 06:56:07 +07:00
public Coordinate(string name)
{
Name = name;
int row = 0;
int col = 0;
foreach (var item in name)
{
if (item >= 'A')
{
row = row * 26 + (item - 'A' + 1);
}
2025-07-26 08:50:47 +07:00
else if (item >= '0')
2025-07-26 06:56:07 +07:00
{
2025-07-30 21:24:00 +07:00
col = col * 10 + (item - '0');
2025-07-26 06:56:07 +07:00
}
}
Row = row;
Col = col;
}
public Coordinate(int row, int col)
{
Row = row;
Col = col;
Name = Helper.ToLetters(row) + col;
}
public override string ToString()
{
return Name;
}
}