optimize log output

This commit is contained in:
huiyadanli
2023-10-07 10:15:13 +08:00
parent 3e246a19d0
commit 45414606ce
4 changed files with 36 additions and 12 deletions

View File

@@ -93,7 +93,6 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
}
/// <summary>
/// 在“开始钓鱼”按钮上方安排一个我们的“开始自动钓鱼”按钮
/// </summary>
@@ -135,7 +134,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
var maskButton = new MaskButton("开始自动钓鱼", btnPosition, () =>
{
VisionContext.Instance().DrawContent.RemoveRect("StartFishingButton");
_logger.LogInformation("自动钓鱼,启动!");
_logger.LogInformation("→ {Text}", "自动钓鱼,启动!");
// 点击下面的按钮
var rc = info.GameWindowRect;
new InputSimulator()
@@ -229,10 +228,11 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
_isThrowRod = true;
}
}
if (baitRectArea.IsEmpty() && !waitBiteArea.IsEmpty() && _isThrowRod)
{
_switchBaitContinuouslyFrameNum = 0;
_waitBiteContinuouslyFrameNum ++;
_waitBiteContinuouslyFrameNum++;
_noFishActionContinuouslyFrameNum = 0;
_throwRodWaitFrameNum++;
@@ -565,7 +565,7 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
if (!IsExclusive)
{
_isThrowRod = false;
_logger.LogInformation("退出钓鱼界面");
_logger.LogInformation("← {Text}", "退出钓鱼界面");
_fishBoxRect = Rect.Empty;
VisionContext.Instance().DrawContent.RemoveRect("FishBox");
}

View File

@@ -38,7 +38,6 @@ public class AutoPickTrigger : ITaskTrigger
public AutoPickTrigger()
{
_autoPickAssets = new AutoPickAssets();
}
public void Init()
@@ -49,6 +48,7 @@ public class AutoPickTrigger : ITaskTrigger
{
_blackList = JsonSerializer.Deserialize<List<string>>(blackListJson) ?? new List<string>();
}
var whiteListJson = Global.ReadAllTextIfExist("Config\\pick_white_lists.json");
if (!string.IsNullOrEmpty(whiteListJson))
{
@@ -64,9 +64,16 @@ public class AutoPickTrigger : ITaskTrigger
var scale = TaskContext.Instance().SystemInfo.AssetScale;
var config = TaskContext.Instance().Config.AutoPickConfig;
// 计算出文字区域
var textMat = new Mat(content.CaptureRectArea.SrcGreyMat,
new Rect(foundRectArea.X + (int)(config.FLeftOffset * scale), foundRectArea.Y,
(int)((config.FRightOffset - config.FLeftOffset) * scale), foundRectArea.Height));
var textRect = new Rect(foundRectArea.X + (int)(config.FLeftOffset * scale), foundRectArea.Y,
(int)((config.FRightOffset - config.FLeftOffset) * scale), foundRectArea.Height);
if (textRect.X + textRect.Width > content.CaptureRectArea.SrcGreyMat.Width
|| textRect.Y + textRect.Height > content.CaptureRectArea.SrcGreyMat.Height)
{
Debug.WriteLine("AutoPickTrigger: 文字区域 out of range");
return;
}
var textMat = new Mat(content.CaptureRectArea.SrcGreyMat, textRect);
var paddedMat = PreProcessForInference(textMat);
var text = _pickTextInference.Inference(paddedMat);
@@ -74,15 +81,17 @@ public class AutoPickTrigger : ITaskTrigger
{
if (_whiteList.Contains(text))
{
_logger.LogInformation($"交互或拾取:{text}");
_logger.LogInformation("交互或拾取:{Text}", text);
new InputSimulator().Keyboard.KeyPress(VirtualKeyCode.VK_F);
return;
}
if (_blackList.Contains(text))
{
return;
}
_logger.LogInformation($"交互或拾取:{text}");
_logger.LogInformation("交互或拾取:{Text}", text);
new InputSimulator().Keyboard.KeyPress(VirtualKeyCode.VK_F);
}
});

View File

@@ -3,6 +3,8 @@ using BetterGenshinImpact.GameTask.AutoSkip.Assets;
using Microsoft.Extensions.Logging;
using System;
using System.Diagnostics;
using OpenCvSharp;
using Vanara.PInvoke;
using WindowsInput;
namespace BetterGenshinImpact.GameTask.AutoSkip;
@@ -31,6 +33,12 @@ public class AutoSkipTrigger : ITaskTrigger
IsEnabled = TaskContext.Instance().Config.AutoSkipConfig.Enabled;
}
/// <summary>
/// 用于日志只输出一次
/// frame最好取模,应对极端场景
/// </summary>
private int _prevClickFrameIndex = -1;
public void OnCapture(CaptureContent content)
{
if (content.IsReachInterval(TimeSpan.FromMilliseconds(200)))
@@ -52,7 +60,12 @@ public class AutoSkipTrigger : ITaskTrigger
if (menuRectArea.IsEmpty())
{
optionButtonRectArea.ClickCenter();
_logger.LogInformation("点击选项按钮");
if (_prevClickFrameIndex <= content.FrameIndex - 1 && _prevClickFrameIndex >= content.FrameIndex - 5)
{
_logger.LogInformation("自动剧情:{Text}", "点击选项");
}
_prevClickFrameIndex = content.FrameIndex;
}
});

View File

@@ -24,18 +24,20 @@ namespace BetterGenshinImpact.ViewModel
{
public partial class MainWindowViewModel : ObservableObject
{
private readonly ILogger<MainWindowViewModel> _logger;
private readonly IConfigService _configService;
public MainWindowViewModel(INavigationService navigationService, IConfigService configService)
{
_configService = configService;
_logger = App.GetLogger<MainWindowViewModel>();
}
[RelayCommand]
private void OnLoaded()
{
_logger.LogInformation("更好的原神({Text}) Alpha {Ver}","内测版", 2.2);
}
[RelayCommand]