-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving object/checkers utils to separate modules.
- Loading branch information
Showing
14 changed files
with
134 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "@/engine/core/utils/object/object_general"; | ||
export * from "@/engine/core/utils/object/object_location"; | ||
export * from "@/engine/core/utils/object/object_find"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { describe, expect, it } from "@jest/globals"; | ||
import { alife, game_graph } from "xray16"; | ||
|
||
import { isObjectInZone, isObjectOnLevel } from "@/engine/core/utils/object/object_location"; | ||
import { ClientObject, ServerObject } from "@/engine/lib/types"; | ||
import { mockClientGameObject, mockServerAlifeObject } from "@/fixtures/xray"; | ||
|
||
describe("object location utils", () => { | ||
it("'isObjectInZone' check object inside", () => { | ||
const object: ClientObject = mockClientGameObject(); | ||
const zone: ClientObject = mockClientGameObject(); | ||
|
||
expect(isObjectInZone(object, zone)).toBe(false); | ||
expect(zone.inside).toHaveBeenCalledWith(object.position()); | ||
expect(isObjectInZone(null, null)).toBe(false); | ||
expect(isObjectInZone(object, null)).toBe(false); | ||
expect(isObjectInZone(null, zone)).toBe(false); | ||
}); | ||
|
||
it("'isObjectOnLevel' check object inside", () => { | ||
const object: ServerObject = mockServerAlifeObject(); | ||
|
||
expect(isObjectOnLevel(null, "zaton")).toBe(false); | ||
expect(isObjectOnLevel(object, "pripyat")).toBe(true); | ||
|
||
expect(game_graph().vertex(object.m_game_vertex_id).level_id()).toBe(1); | ||
expect(alife().level_name).toHaveBeenCalledWith(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { alife, game_graph } from "xray16"; | ||
|
||
import { registry } from "@/engine/core/database"; | ||
import { ClientObject, Optional, ServerObject, TDistance, TName } from "@/engine/lib/types"; | ||
|
||
/** | ||
* Check whether object is inside another zone object. | ||
* | ||
* @param object - target client object to check | ||
* @param zone - target zone to check | ||
* @returns whether object is inside zone object. | ||
*/ | ||
export function isObjectInZone(object: Optional<ClientObject>, zone: Optional<ClientObject>): boolean { | ||
return object !== null && zone !== null && zone.inside(object.position()); | ||
} | ||
|
||
/** | ||
* Check whether object is on matching level. | ||
* | ||
* @param object - target object to check | ||
* @param levelName - target level name | ||
* @returns whether provided object is on a level | ||
*/ | ||
export function isObjectOnLevel(object: Optional<ServerObject>, levelName: TName): boolean { | ||
return object !== null && alife().level_name(game_graph().vertex(object.m_game_vertex_id).level_id()) === levelName; | ||
} | ||
|
||
/** | ||
* @returns whether distance between objects greater or equal. | ||
*/ | ||
export function isDistanceBetweenObjectsGreaterOrEqual( | ||
first: ClientObject, | ||
second: ClientObject, | ||
distance: TDistance | ||
): boolean { | ||
return first.position().distance_to_sqr(second.position()) >= distance * distance; | ||
} | ||
|
||
/** | ||
* @returns whether distance between objects less or equal. | ||
*/ | ||
export function isDistanceBetweenObjectsLessOrEqual( | ||
first: ClientObject, | ||
second: ClientObject, | ||
distance: TDistance | ||
): boolean { | ||
return first.position().distance_to_sqr(second.position()) <= distance * distance; | ||
} | ||
|
||
/** | ||
* @returns whether distance to actor greater or equal. | ||
*/ | ||
export function isDistanceToActorGreaterOrEqual(object: ClientObject, distance: TDistance): boolean { | ||
return object.position().distance_to_sqr(registry.actor.position()) >= distance * distance; | ||
} | ||
|
||
/** | ||
* @returns whether distance to actor less or equal. | ||
*/ | ||
export function isDistanceToActorLessOrEqual(object: ClientObject, distance: TDistance): boolean { | ||
return object.position().distance_to_sqr(registry.actor.position()) <= distance * distance; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.