|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.example.jmacro.wjdr;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
import com.example.jmacro.wjdr.base.Legend;
|
|
|
|
|
import com.example.jmacro.wjdr.base.ViewColor;
|
|
|
|
@ -25,6 +26,11 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
*/
|
|
|
|
|
public abstract class JMacro {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 默认超时秒数
|
|
|
|
|
*/
|
|
|
|
|
private int defaultTimeOut = 10;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 机器人操作实例
|
|
|
|
|
*/
|
|
|
|
@ -46,6 +52,14 @@ public abstract class JMacro {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getDefaultTimeOut() {
|
|
|
|
|
return defaultTimeOut;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setDefaultTimeOut(int defaultTimeOut) {
|
|
|
|
|
this.defaultTimeOut = defaultTimeOut;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Robot getRobot() {
|
|
|
|
|
return robot;
|
|
|
|
|
}
|
|
|
|
@ -55,7 +69,7 @@ public abstract class JMacro {
|
|
|
|
|
*/
|
|
|
|
|
public void startFocus() {
|
|
|
|
|
TaskUtil.asyncTask(() -> {
|
|
|
|
|
focusRect = TaskUtil.timeTask(this::focus, 10, TimeUnit.SECONDS);
|
|
|
|
|
focusRect = TaskUtil.timeTask(this::focus, defaultTimeOut, TimeUnit.SECONDS);
|
|
|
|
|
if (focusRect != null) {
|
|
|
|
|
Logger.info("聚焦成功");
|
|
|
|
|
} else {
|
|
|
|
@ -503,7 +517,7 @@ public abstract class JMacro {
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndFindPic(File pic, double minSimilar) {
|
|
|
|
|
return waitAndFindPic(getFocusRect(), pic, minSimilar, 10);
|
|
|
|
|
return waitAndFindPic(getFocusRect(), pic, minSimilar, defaultTimeOut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -514,7 +528,7 @@ public abstract class JMacro {
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndFindPic(BufferedImage pic, double minSimilar) {
|
|
|
|
|
return waitAndFindPic(getFocusRect(), pic, minSimilar, 10);
|
|
|
|
|
return waitAndFindPic(getFocusRect(), pic, minSimilar, defaultTimeOut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -550,7 +564,7 @@ public abstract class JMacro {
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndFindPic(ViewRect rect, File pic, double minSimilar) {
|
|
|
|
|
return waitAndFindPic(rect, pic, minSimilar, 10);
|
|
|
|
|
return waitAndFindPic(rect, pic, minSimilar, defaultTimeOut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -575,7 +589,7 @@ public abstract class JMacro {
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndFindPic(ViewRect rect, BufferedImage pic, double minSimilar) {
|
|
|
|
|
return waitAndFindPic(rect, pic, minSimilar, 10);
|
|
|
|
|
return waitAndFindPic(rect, pic, minSimilar, defaultTimeOut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -656,7 +670,7 @@ public abstract class JMacro {
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndMatchPic(BufferedImage pic, ViewPoint location, double minSimilar) {
|
|
|
|
|
return waitAndMatchPic(pic, location, minSimilar, 10);
|
|
|
|
|
return waitAndMatchPic(pic, location, minSimilar, defaultTimeOut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -796,7 +810,7 @@ public abstract class JMacro {
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public ViewRect waitAndMatchLegend(Legend legend, double minSimilar) {
|
|
|
|
|
return waitAndMatchLegend(legend, minSimilar, 5);
|
|
|
|
|
return waitAndMatchLegend(legend, minSimilar, defaultTimeOut);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -838,6 +852,26 @@ public abstract class JMacro {
|
|
|
|
|
return ColorUtil.isSimilar(pointData[0][0], color.getColor());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 等待并匹配图例
|
|
|
|
|
*
|
|
|
|
|
* @param color 色值坐标点
|
|
|
|
|
* @param seconds 最长等待秒数
|
|
|
|
|
* @return 匹配图片区域
|
|
|
|
|
*/
|
|
|
|
|
public boolean waitAndMatchColor(ViewColor color, long seconds) {
|
|
|
|
|
Boolean result = TaskUtil.timeTask(() -> {
|
|
|
|
|
while (JMainService.getInstance().run) {
|
|
|
|
|
if (matchColor(color)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
delayUnstable();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}, seconds, TimeUnit.SECONDS);
|
|
|
|
|
return Convert.toBool(result, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将相对坐标转为绝对坐标
|
|
|
|
|
*
|
|
|
|
|