2024-05-12 15:06:07 +00:00
|
|
|
|
using System.Collections.Generic;
|
2024-05-24 14:58:52 +00:00
|
|
|
|
using ColdMint.scripts.utils;
|
2024-05-12 15:06:07 +00:00
|
|
|
|
using Godot;
|
|
|
|
|
using FileAccess = Godot.FileAccess;
|
2024-04-28 13:55:19 +00:00
|
|
|
|
|
|
|
|
|
namespace ColdMint.scripts;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>SloganProvider</para>
|
|
|
|
|
/// <para>标语提供器</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class SloganProvider
|
|
|
|
|
{
|
2024-05-12 15:06:07 +00:00
|
|
|
|
private static string _csvPath = "res://locals/slogan.csv";
|
|
|
|
|
|
|
|
|
|
private static string[]? _sloganKeys;
|
|
|
|
|
|
2024-04-28 13:55:19 +00:00
|
|
|
|
/// <summary>
|
2024-05-12 15:06:07 +00:00
|
|
|
|
/// <para>Loading CSV file</para>
|
|
|
|
|
/// <para>加载CSV文件</para>
|
2024-04-28 13:55:19 +00:00
|
|
|
|
/// </summary>
|
2024-05-12 15:06:07 +00:00
|
|
|
|
public static void LoadSloganCsv()
|
|
|
|
|
{
|
|
|
|
|
var exists = FileAccess.FileExists(_csvPath);
|
|
|
|
|
if (!exists)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using var file = FileAccess.Open(_csvPath, FileAccess.ModeFlags.Read);
|
|
|
|
|
var content = file.GetAsText();
|
|
|
|
|
var lineStrings = content.Split('\n');
|
|
|
|
|
var keys = new List<string>();
|
|
|
|
|
foreach (var lineString in lineStrings)
|
|
|
|
|
{
|
|
|
|
|
var index = lineString.IndexOf(',');
|
|
|
|
|
if (index > -1)
|
|
|
|
|
{
|
|
|
|
|
keys.Add(lineString[..index]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (keys.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
keys.RemoveAt(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_sloganKeys = keys.ToArray();
|
|
|
|
|
}
|
2024-04-28 13:55:19 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Swipe the machine to get a slogan</para>
|
|
|
|
|
/// <para>刷机获取一个标语</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2024-05-12 15:06:07 +00:00
|
|
|
|
public static string? GetSlogan()
|
2024-04-28 13:55:19 +00:00
|
|
|
|
{
|
2024-05-12 15:06:07 +00:00
|
|
|
|
if (_sloganKeys == null || _sloganKeys.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-24 14:58:52 +00:00
|
|
|
|
return TranslationServerUtils.Translate(_sloganKeys[GD.Randi() % _sloganKeys.Length]);
|
2024-04-28 13:55:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|