计分本配置接口接入
This commit is contained in:
89
src/util.js
89
src/util.js
@@ -296,7 +296,7 @@ export const getElementRect = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const calcRing = (x, y, targetWidth, targetHeight) => {
|
||||
const calcNormalBowTarget = (x, y, targetWidth, targetHeight) => {
|
||||
// 计算靶心坐标(靶纸中心)
|
||||
const centerX = targetWidth / 2;
|
||||
const centerY = targetHeight / 2;
|
||||
@@ -318,7 +318,8 @@ export const calcRing = (x, y, targetWidth, targetHeight) => {
|
||||
// 全环靶有10个环,每个环占半径的10%
|
||||
// 从外到内:1环到10环
|
||||
// 距离越近靶心,环数越高
|
||||
if (relativeDistance <= 0.1) return 10; // 靶心区域
|
||||
if (relativeDistance <= 0.05) return "X";
|
||||
if (relativeDistance <= 0.1) return 10;
|
||||
if (relativeDistance <= 0.2) return 9;
|
||||
if (relativeDistance <= 0.3) return 8;
|
||||
if (relativeDistance <= 0.4) return 7;
|
||||
@@ -332,7 +333,7 @@ export const calcRing = (x, y, targetWidth, targetHeight) => {
|
||||
return 0; // 脱靶
|
||||
};
|
||||
|
||||
const calcSmallBowTarget = (x, y, side) => {
|
||||
const calcHalfBowTarget = (x, y, side, noX = false) => {
|
||||
// 计算靶心坐标(靶纸中心)
|
||||
const centerX = side / 2;
|
||||
const centerY = side / 2;
|
||||
@@ -350,8 +351,8 @@ const calcSmallBowTarget = (x, y, side) => {
|
||||
|
||||
// 计算相对距离(0-1之间)
|
||||
const relativeDistance = distance / targetRadius;
|
||||
if (relativeDistance <= 0.1) return "X"; // 靶心区域
|
||||
if (relativeDistance <= 0.2) return 10;
|
||||
if (relativeDistance <= 0.1) return noX ? 10 : "X";
|
||||
if (relativeDistance <= 0.2) return noX ? 9 : 10;
|
||||
if (relativeDistance <= 0.4) return 9;
|
||||
if (relativeDistance <= 0.6) return 8;
|
||||
if (relativeDistance <= 0.8) return 7;
|
||||
@@ -360,44 +361,76 @@ const calcSmallBowTarget = (x, y, side) => {
|
||||
return 0; // 脱靶
|
||||
};
|
||||
|
||||
export const calcRing2 = (x, y, targetWidth, targetHeight) => {
|
||||
export const calcTripleBowTarget = (
|
||||
x,
|
||||
y,
|
||||
targetWidth,
|
||||
targetHeight,
|
||||
noX = false
|
||||
) => {
|
||||
const side = targetWidth * 0.325;
|
||||
if (x / targetWidth >= 0.337 && x / targetWidth <= 0.663) {
|
||||
if (y / targetHeight <= 0.325) {
|
||||
return calcHalfBowTarget(x - targetWidth * 0.337, y, side, noX);
|
||||
} else if (y / targetHeight >= 0.335 && y / targetHeight <= 0.662) {
|
||||
return calcHalfBowTarget(
|
||||
x - targetWidth * 0.337,
|
||||
y - targetHeight * 0.335,
|
||||
side,
|
||||
noX
|
||||
);
|
||||
} else if (y / targetHeight >= 0.674) {
|
||||
return calcHalfBowTarget(
|
||||
x - targetWidth * 0.337,
|
||||
y - targetHeight * 0.674,
|
||||
side,
|
||||
noX
|
||||
);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
export const calcPinBowTarget = (
|
||||
x,
|
||||
y,
|
||||
targetWidth,
|
||||
targetHeight,
|
||||
noX = false
|
||||
) => {
|
||||
const side = targetWidth * 0.48;
|
||||
if (
|
||||
x / targetWidth >= 0.26 &&
|
||||
x / targetWidth <= 0.74 &&
|
||||
y / targetHeight <= 0.48
|
||||
) {
|
||||
return calcSmallBowTarget(x - targetWidth * 0.26, y, side);
|
||||
return calcHalfBowTarget(x - targetWidth * 0.26, y, side, noX);
|
||||
} else if (x / targetHeight <= 0.48 && y / targetHeight >= 0.456) {
|
||||
return calcSmallBowTarget(x, y - targetHeight * 0.456, side);
|
||||
return calcHalfBowTarget(x, y - targetHeight * 0.456, side, noX);
|
||||
} else if (x / targetHeight >= 0.52 && y / targetHeight >= 0.456) {
|
||||
return calcSmallBowTarget(
|
||||
return calcHalfBowTarget(
|
||||
x - targetWidth * 0.52,
|
||||
y - targetHeight * 0.456,
|
||||
side
|
||||
side,
|
||||
noX
|
||||
);
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
export const calcRing3 = (x, y, targetWidth, targetHeight) => {
|
||||
const side = targetWidth * 0.325;
|
||||
if (x / targetWidth >= 0.337 && x / targetWidth <= 0.663) {
|
||||
if (y / targetHeight <= 0.325) {
|
||||
return calcSmallBowTarget(x - targetWidth * 0.337, y, side);
|
||||
} else if (y / targetHeight >= 0.335 && y / targetHeight <= 0.662) {
|
||||
return calcSmallBowTarget(
|
||||
x - targetWidth * 0.337,
|
||||
y - targetHeight * 0.335,
|
||||
side
|
||||
);
|
||||
} else if (y / targetHeight >= 0.674) {
|
||||
return calcSmallBowTarget(
|
||||
x - targetWidth * 0.337,
|
||||
y - targetHeight * 0.674,
|
||||
side
|
||||
);
|
||||
}
|
||||
export const calcRing = (bowtargetId, x, y, targetWidth, targetHeight) => {
|
||||
if (bowtargetId < 4) {
|
||||
return calcNormalBowTarget(x, y, targetWidth, targetHeight);
|
||||
} else if (bowtargetId < 7) {
|
||||
return calcHalfBowTarget(x, y, targetWidth);
|
||||
} else if (bowtargetId === 7) {
|
||||
return calcTripleBowTarget(x, y, targetWidth, targetHeight);
|
||||
} else if (bowtargetId === 8) {
|
||||
return calcPinBowTarget(x, y, targetWidth, targetHeight);
|
||||
} else if (bowtargetId === 9) {
|
||||
return calcTripleBowTarget(x, y, targetWidth, targetHeight, true);
|
||||
} else if (bowtargetId === 10) {
|
||||
return calcPinBowTarget(x, y, targetWidth, targetHeight, true);
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user