Skip to content

Commit

Permalink
fix OpenCvSharp.Rect can't deserialize
Browse files Browse the repository at this point in the history
  • Loading branch information
huiyadanli committed Nov 21, 2023
1 parent 70c1339 commit 34725b5
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 23 deletions.
5 changes: 2 additions & 3 deletions BetterGenshinImpact/Core/Config/MaskWindowConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public partial class MaskWindowConfig : ObservableObject
/// <summary>
/// 日志窗口位置与大小
/// </summary>
[ObservableProperty] private Rect _logBoxLocation = Rect.Empty;
[ObservableProperty] private RectConfig _logBoxLocation = new();

/// <summary>
/// 控件是否锁定(拖拽移动等)
Expand All @@ -50,7 +50,6 @@ public partial class MaskWindowConfig : ObservableObject
/// <summary>
/// 1080p下UID遮盖的位置与大小
/// </summary>
[JsonIgnore]
public Rect UidCoverRect = new(1695, 1052, 168, 22);
public RectConfig UidCoverRect { get; set; } = new(1695, 1052, 168, 22);
}
}
28 changes: 28 additions & 0 deletions BetterGenshinImpact/Core/Config/RectConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using OpenCvSharp;

namespace BetterGenshinImpact.Core.Config;

public class RectConfig
{
public int X { get; set; }
public int Y { get; set; }
public int Width { get; set; }
public int Height { get; set; }

public RectConfig()
{
}

public RectConfig(int x, int y, int width, int height)
{
X = x;
Y = y;
Width = width;
Height = height;
}

public Rect ToRect()
{
return new Rect(X, Y, Width, Height);
}
}
10 changes: 5 additions & 5 deletions BetterGenshinImpact/GameTask/AutoFishing/AutoFishingConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public partial class AutoFishingConfig : ObservableObject
/// </summary>
[ObservableProperty] private bool _enabled = false;

/// <summary>
/// 鱼儿上钩文字识别区域
/// 暂时无用
/// </summary>
[ObservableProperty] private Rect _fishHookedRecognitionArea = Rect.Empty;
///// <summary>
///// 鱼儿上钩文字识别区域
///// 暂时无用
///// </summary>
//[ObservableProperty] private Rect _fishHookedRecognitionArea = Rect.Empty;

/// <summary>
/// 自动抛竿是否启用
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using System.Threading.Tasks;
using OpenCvSharp;
using BetterGenshinImpact.Core.Config;

namespace BetterGenshinImpact.GameTask.AutoGeniusInvokation;

Expand All @@ -18,7 +19,7 @@ public partial class AutoGeniusInvokationConfig : ObservableObject

[ObservableProperty] private int _sleepDelay = 0;

public List<Rect> DefaultCharacterCardRects { get;} = new List<Rect>()
public List<RectConfig> DefaultCharacterCardRects { get; set; } = new()
{
new(667, 632, 165, 282),
new(877, 632, 165, 282),
Expand All @@ -29,25 +30,25 @@ public partial class AutoGeniusInvokationConfig : ObservableObject
/// <summary>
/// 骰子数量文字识别区域
/// </summary>
public Rect MyDiceCountRect { get; } = new(58, 632, 45, 47); // 42,47
public RectConfig MyDiceCountRect { get; set; } = new(58, 632, 45, 47); // 42,47

/// <summary>
/// 角色卡牌区域向左扩展距离,包含HP区域
/// </summary>
public int CharacterCardLeftExtend { get; } = 20;
///// <summary>
///// 角色卡牌区域向左扩展距离,包含HP区域
///// </summary>
//public int CharacterCardLeftExtend { get; } = 20;

/// <summary>
/// 角色卡牌区域向右扩展距离,包含充能区域
/// </summary>
public int CharacterCardRightExtend { get; } = 14;
///// <summary>
///// 角色卡牌区域向右扩展距离,包含充能区域
///// </summary>
//public int CharacterCardRightExtend { get; } = 14;

/// <summary>
/// 出战角色卡牌区域向上或者向下的距离差
/// </summary>
public int ActiveCharacterCardSpace { get; } = 41;
public int ActiveCharacterCardSpace { get; set; } = 41;

/// <summary>
/// HP区域 在 角色卡牌区域 的相对位置
/// </summary>
public Rect CharacterCardExtendHpRect { get; } = new(-20, 0, 60, 55);
public RectConfig CharacterCardExtendHpRect { get; } = new(-20, 0, 60, 55);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ private static void OutputImage(Duel duel, List<Rect> rects, Mat bottomMat, int
public int GetDiceCountByOcr()
{
var srcMat = CaptureGameGreyMat();
var diceCountMap = new Mat(srcMat, _config.MyDiceCountRect);
var diceCountMap = new Mat(srcMat, _config.MyDiceCountRect.ToRect());
var text = OcrFactory.Paddle.Ocr(diceCountMap);
text = text.Replace(" ", "");
_logger.LogInformation("通过OCR识别当前骰子数量: {Text}", text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void Run(GeniusInvokationTaskParam taskParam)
var assetScale = TaskContext.Instance().SystemInfo.AssetScale;
for (var i = 0; i < defaultCharacterCardRects.Count; i++)
{
CharacterCardRects.Add(defaultCharacterCardRects[i].Multiply(assetScale));
CharacterCardRects.Add(defaultCharacterCardRects[i].ToRect().Multiply(assetScale));
}

_logger.LogInformation("获取角色区域失败,使用默认区域");
Expand Down
3 changes: 2 additions & 1 deletion BetterGenshinImpact/Service/ConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class ConfigService : IConfigService
NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals,
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true
WriteIndented = true,
AllowTrailingCommas = true
};

/// <summary>
Expand Down

0 comments on commit 34725b5

Please sign in to comment.