Skip to content

Commit

Permalink
feat(map): Add factory map and update vector
Browse files Browse the repository at this point in the history
  • Loading branch information
LI-NA committed May 5, 2024
1 parent 952f4cf commit 1955d2e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
31 changes: 27 additions & 4 deletions constants/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface MapPosition {
imageTo: Vector2d;
gameFrom: Vector3d;
gameTo: Vector3d;
gameReverse: boolean;
}

export interface MapConfig {
Expand All @@ -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,
Expand All @@ -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,
},
],
},
Expand Down Expand Up @@ -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,
},
*/
],
Expand All @@ -158,13 +178,15 @@ 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",
imageFrom: { x: 4141, y: 113 },
imageTo: { x: 4705, y: 581 },
gameFrom: { x: -229, y: -165, z: -3 },
gameTo: { x: -274, y: -129, z: 1.8 },
gameReverse: false,
},
],
},
Expand All @@ -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,
},
],
},
Expand Down
25 changes: 14 additions & 11 deletions lib/tarkov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -32,23 +37,21 @@ 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
);
};

/**
* 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 };
};
Expand All @@ -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);

Expand Down
Binary file added public/images/maps/factory.webp
Binary file not shown.

0 comments on commit 1955d2e

Please sign in to comment.