mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-17 09:26:50 +08:00
Feat/multi lan (#1336)
* 记录一次对hutaofisher的访谈,帮助开发者理解其算法
* 本地化HelloWorld
* .csproj取消windows版本号,此处导致了IDE在新建代码文件和自动生成代码时,默认命名空间丢失的问题。已知VisualStudio和ReSharper存在这个问题。
* 优化扩展方法写法,改为从localizer扩展;Converter优化写法,避免冲突;新增两种语言,待测试ocr效果
* Revert ".csproj取消windows版本号,此处导致了IDE在新建代码文件和自动生成代码时,默认命名空间丢失的问题。已知VisualStudio和ReSharper存在这个问题。"
This reverts commit 8bd7ee74c5.
* localizer改为由构造函数传入以支持单元测试;一个英语上钩的单元测试
* 传送任务支持英语游戏界面;本地化参数挪至OtherConfig类下,但界面位置暂不挪动,待定
* 调整resx位置风格,放在直接使用字符串的类下;一条龙合成树脂及领取每日奖励支持游戏内中英双语
* 删除无用碎片文件
* 删去两个不必要的Sdcb包引用
* Paddle服务类去掉分类模型;检测和识别新增支持繁中和法语,配有单元测试;因小语种识别效果不理想,使用正则匹配替换多处识别文本相等或包含判断;钓鱼、一条龙合成树脂及领取每日奖励支持游戏内繁中和法语;
* 检查今日奖励任务的多语言化;右侧联机的P图标检测区域宽度缩减,避免英语角色名被误识别成P
* AutoDomainTask的游戏多语言化,由于我的游戏账号无法测试,仅配一些测试用例
* 修复有3个Mizuki导致异常的bug,临时用拼音代替新角色英文名,并为该数据初始化方法添加单元测试
* 瓦雷莎删去别名“牛牛”,因荒泷一斗已占用此别名;别名加载和读取优化
* 加个锁避免单元测试中多线程初始化paddle崩溃
This commit is contained in:
@@ -36,6 +36,9 @@ using Vanara.PInvoke;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
using static Vanara.PInvoke.Kernel32;
|
||||
using static Vanara.PInvoke.User32;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.AutoDomain;
|
||||
|
||||
@@ -53,6 +56,10 @@ public class AutoDomainTask : ISoloTask
|
||||
|
||||
private CancellationToken _ct;
|
||||
|
||||
private readonly string challengeCompletedLocalizedString;
|
||||
private readonly string autoLeavingLocalizedString;
|
||||
private readonly string skipLocalizedString;
|
||||
|
||||
public AutoDomainTask(AutoDomainParam taskParam)
|
||||
{
|
||||
AutoFightAssets.DestroyInstance();
|
||||
@@ -65,6 +72,12 @@ public class AutoDomainTask : ISoloTask
|
||||
_config = TaskContext.Instance().Config.AutoDomainConfig;
|
||||
|
||||
_combatScriptBag = CombatScriptParser.ReadAndParse(_taskParam.CombatStrategyPath);
|
||||
|
||||
IStringLocalizer<AutoDomainTask> stringLocalizer = App.GetService<IStringLocalizer<AutoDomainTask>>() ?? throw new NullReferenceException();
|
||||
CultureInfo cultureInfo = new CultureInfo(TaskContext.Instance().Config.OtherConfig.GameCultureInfoName);
|
||||
this.challengeCompletedLocalizedString = stringLocalizer.WithCultureGet(cultureInfo, "挑战达成");
|
||||
this.autoLeavingLocalizedString = stringLocalizer.WithCultureGet(cultureInfo, "自动退出");
|
||||
this.skipLocalizedString = stringLocalizer.WithCultureGet(cultureInfo, "跳过");
|
||||
}
|
||||
|
||||
public async Task Start(CancellationToken ct)
|
||||
@@ -541,7 +554,7 @@ public class AutoDomainTask : ISoloTask
|
||||
|
||||
var endTipsRect = ra.DeriveCrop(AutoFightAssets.Instance.EndTipsUpperRect);
|
||||
var text = OcrFactory.Paddle.Ocr(endTipsRect.SrcGreyMat);
|
||||
if (text.Contains("挑战") || text.Contains("达成"))
|
||||
if (Regex.IsMatch(text, this.challengeCompletedLocalizedString))
|
||||
{
|
||||
Logger.LogInformation("检测到秘境结束提示(挑战达成),结束秘境");
|
||||
return true;
|
||||
@@ -549,7 +562,7 @@ public class AutoDomainTask : ISoloTask
|
||||
|
||||
endTipsRect = ra.DeriveCrop(AutoFightAssets.Instance.EndTipsRect);
|
||||
text = OcrFactory.Paddle.Ocr(endTipsRect.SrcGreyMat);
|
||||
if (text.Contains("自动") || text.Contains("退出"))
|
||||
if (Regex.IsMatch(text, this.autoLeavingLocalizedString))
|
||||
{
|
||||
Logger.LogInformation("检测到秘境结束提示(xxx秒后自动退出),结束秘境");
|
||||
return true;
|
||||
@@ -926,7 +939,7 @@ public class AutoDomainTask : ISoloTask
|
||||
|
||||
// OCR识别是否有跳过
|
||||
var ocrList = ra.FindMulti(RecognitionObject.Ocr(captureArea.Width - 230 * assetScale, 0, 230 * assetScale - 5, 80 * assetScale));
|
||||
var skipTextRa = ocrList.FirstOrDefault(t => t.Text.Contains("跳过"));
|
||||
var skipTextRa = ocrList.FirstOrDefault(t => Regex.IsMatch(t.Text, this.skipLocalizedString));
|
||||
if (skipTextRa != null)
|
||||
{
|
||||
hasSkip = true;
|
||||
|
||||
Reference in New Issue
Block a user