diff --git a/constants/map.ts b/constants/map.ts index 65fc3d9..3cba743 100644 --- a/constants/map.ts +++ b/constants/map.ts @@ -67,6 +67,7 @@ export interface MapPosition { imageTo: Vector2d; gameFrom: Vector3d; gameTo: Vector3d; + gameReverse: boolean; } export interface MapConfig { @@ -86,11 +87,28 @@ export const MAP_CONFING = { positions: [], }, [MAP.FACTORY]: { - enable: false, + enable: true, image: "/tarkov-live-map/images/maps/factory.webp", - width: 0, - height: 0, - positions: [], + width: 7680, + height: 4320, + positions: [ + { + id: "main", + imageFrom: { x: 2350, y: 800 }, + imageTo: { x: 5390, y: 3988 }, + gameFrom: { x: 68, y: 74, z: -1000 }, + gameTo: { x: -65, y: -65, z: 1000 }, + gameReverse: true, + }, + { + id: "underground", + imageFrom: { x: 4974, y: 800 }, + imageTo: { x: 8014, y: 3988 }, + gameFrom: { x: 68, y: 74, z: -1000 }, + gameTo: { x: -65, y: -65, z: 0.5 }, + gameReverse: true, + }, + ], }, [MAP.GROUND_ZERO]: { enable: true, @@ -104,6 +122,7 @@ export const MAP_CONFING = { imageTo: { x: 4190, y: 5495 }, gameFrom: { x: 235, y: -106, z: -1000 }, gameTo: { x: -63, y: 341, z: 1000 }, + gameReverse: false, }, ], }, @@ -142,6 +161,7 @@ export const MAP_CONFING = { imageTo: { x: 3115, y: 2481 }, gameFrom: { x: 197, y: -265, z: -1000 }, gameTo: { x: -260, y: 206, z: 1000 }, + gameReverse: false, }, */ ], @@ -158,6 +178,7 @@ export const MAP_CONFING = { imageTo: { x: 5350, y: 4423 }, gameFrom: { x: 490, y: -415, z: -1000 }, gameTo: { x: -1040, y: 580, z: 1000 }, + gameReverse: false, }, { id: "admin_1st_floor", @@ -165,6 +186,7 @@ export const MAP_CONFING = { imageTo: { x: 4705, y: 581 }, gameFrom: { x: -229, y: -165, z: -3 }, gameTo: { x: -274, y: -129, z: 1.8 }, + gameReverse: false, }, ], }, @@ -180,6 +202,7 @@ export const MAP_CONFING = { imageTo: { x: 5840, y: 5334 }, gameFrom: { x: 315, y: -283, z: -1000 }, gameTo: { x: -268, y: 528, z: 1000 }, + gameReverse: false, }, ], }, diff --git a/lib/tarkov.ts b/lib/tarkov.ts index f5a562c..8991474 100644 --- a/lib/tarkov.ts +++ b/lib/tarkov.ts @@ -20,8 +20,13 @@ export const screenshotToVector3d = (screenshot: string): Vector3d | null => { /** * Check the Vector3d is in the range of Vector3d */ -export const isVector3dInRange = (from: Vector3d, to: Vector3d, vector: Vector3d): boolean => { +export const isVector3dInRange = (position: MapPosition, vector: Vector3d): boolean => { // Make support both case from > to and to > from. + const { gameFrom: from, gameTo: to, gameReverse } = position; + + const vectorX = gameReverse ? vector.y : vector.x; + const vectorY = gameReverse ? vector.x : vector.y; + const minX = Math.min(from.x, to.x); const maxX = Math.max(from.x, to.x); @@ -32,12 +37,7 @@ export const isVector3dInRange = (from: Vector3d, to: Vector3d, vector: Vector3d const maxZ = Math.max(from.z, to.z); return ( - minX <= vector.x && - vector.x <= maxX && - minY <= vector.y && - vector.y <= maxY && - minZ <= vector.z && - vector.z <= maxZ + minX <= vectorX && vectorX <= maxX && minY <= vectorY && vectorY <= maxY && minZ <= vector.z && vector.z <= maxZ ); }; @@ -45,10 +45,13 @@ export const isVector3dInRange = (from: Vector3d, to: Vector3d, vector: Vector3d * Convert the game Vector3d to the Map Vector2d using the position */ export const vector3dToVector2d = (position: MapPosition, vector: Vector3d): Vector2dWithId => { - const { id, gameFrom, gameTo, imageFrom, imageTo } = position; + const { id, gameFrom, gameTo, gameReverse, imageFrom, imageTo } = position; + + const vectorX = gameReverse ? vector.y : vector.x; + const vectorY = gameReverse ? vector.x : vector.y; - const x = ((vector.x - gameFrom.x) / (gameTo.x - gameFrom.x)) * (imageTo.x - imageFrom.x) + imageFrom.x; - const y = ((vector.y - gameFrom.y) / (gameTo.y - gameFrom.y)) * (imageTo.y - imageFrom.y) + imageFrom.y; + const x = ((vectorX - gameFrom.x) / (gameTo.x - gameFrom.x)) * (imageTo.x - imageFrom.x) + imageFrom.x; + const y = ((vectorY - gameFrom.y) / (gameTo.y - gameFrom.y)) * (imageTo.y - imageFrom.y) + imageFrom.y; return { id, x, y }; }; @@ -62,7 +65,7 @@ export const vector3dToVector2dList = (map: Map, vector: Vector3d): Vector2dWith console.log("mapPositions", mapPositions, vector.x, vector.y, vector.z); // Find the first position that the vector is in. - const matchedPositions = mapPositions.filter(({ gameFrom, gameTo }) => isVector3dInRange(gameFrom, gameTo, vector)); + const matchedPositions = mapPositions.filter(position => isVector3dInRange(position, vector)); console.log("matchedPositions", matchedPositions); diff --git a/public/images/maps/factory.webp b/public/images/maps/factory.webp new file mode 100644 index 0000000..d9ee67a Binary files /dev/null and b/public/images/maps/factory.webp differ