mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
refactor(zones): improve types
This commit is contained in:
@@ -1,19 +1,21 @@
|
|||||||
local glm = require 'glm'
|
local glm = require 'glm'
|
||||||
|
|
||||||
---@class CZone
|
---@class ZoneProperties
|
||||||
---@field id number
|
|
||||||
---@field coords vector3
|
---@field coords vector3
|
||||||
---@field distance number
|
---@field debug? boolean
|
||||||
---@field __type 'poly' | 'sphere' | 'box'
|
---@field debugColour? vector4
|
||||||
---@field debugColour vector4?
|
|
||||||
---@field setDebug fun(self: CZone, enable?: boolean, colour?: vector)
|
|
||||||
---@field remove fun()
|
|
||||||
---@field contains fun(self: CZone, coords?: vector3): boolean
|
|
||||||
---@field onEnter fun(self: CZone)?
|
---@field onEnter fun(self: CZone)?
|
||||||
---@field onExit fun(self: CZone)?
|
---@field onExit fun(self: CZone)?
|
||||||
---@field inside fun(self: CZone)?
|
---@field inside fun(self: CZone)?
|
||||||
---@field [string] any
|
---@field [string] any
|
||||||
|
|
||||||
|
---@class CZone : PolyZone, BoxZone, SphereZone
|
||||||
|
---@field id number
|
||||||
|
---@field __type 'poly' | 'sphere' | 'box'
|
||||||
|
---@field remove fun()
|
||||||
|
---@field setDebug fun(self: CZone, enable?: boolean, colour?: vector)
|
||||||
|
---@field contains fun(self: CZone, coords?: vector3): boolean
|
||||||
|
|
||||||
---@type table<number, CZone>
|
---@type table<number, CZone>
|
||||||
local Zones = {}
|
local Zones = {}
|
||||||
_ENV.Zones = Zones
|
_ENV.Zones = Zones
|
||||||
@@ -291,9 +293,10 @@ local function setDebug(self, bool, colour)
|
|||||||
self.debug = self.__type == 'sphere' and debugSphere or debugPoly or nil
|
self.debug = self.__type == 'sphere' and debugSphere or debugPoly or nil
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param data CZone
|
---@param data ZoneProperties
|
||||||
---@return CZone
|
---@return CZone
|
||||||
local function setZone(data)
|
local function setZone(data)
|
||||||
|
---@cast data CZone
|
||||||
data.remove = removeZone
|
data.remove = removeZone
|
||||||
data.contains = data.contains or contains
|
data.contains = data.contains or contains
|
||||||
|
|
||||||
@@ -316,6 +319,11 @@ end
|
|||||||
|
|
||||||
lib.zones = {}
|
lib.zones = {}
|
||||||
|
|
||||||
|
---@class PolyZone : ZoneProperties
|
||||||
|
---@field points vector3[]
|
||||||
|
|
||||||
|
---@param data PolyZone
|
||||||
|
---@return CZone
|
||||||
function lib.zones.poly(data)
|
function lib.zones.poly(data)
|
||||||
data.id = #Zones + 1
|
data.id = #Zones + 1
|
||||||
data.thickness = data.thickness or 4
|
data.thickness = data.thickness or 4
|
||||||
@@ -374,6 +382,7 @@ function lib.zones.poly(data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for i = 1, pointN do
|
for i = 1, pointN do
|
||||||
|
---@diagnostic disable-next-line: param-type-mismatch
|
||||||
points[i] = vec3(data.points[i].xy, zCoord)
|
points[i] = vec3(data.points[i].xy, zCoord)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -386,6 +395,13 @@ function lib.zones.poly(data)
|
|||||||
return setZone(data)
|
return setZone(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@class BoxZone : ZoneProperties
|
||||||
|
---@field size number | vector3
|
||||||
|
---@field thickness? number
|
||||||
|
---@field rotation? vector4
|
||||||
|
|
||||||
|
---@param data BoxZone
|
||||||
|
---@return CZone
|
||||||
function lib.zones.box(data)
|
function lib.zones.box(data)
|
||||||
data.id = #Zones + 1
|
data.id = #Zones + 1
|
||||||
data.coords = convertToVector(data.coords)
|
data.coords = convertToVector(data.coords)
|
||||||
@@ -403,6 +419,11 @@ function lib.zones.box(data)
|
|||||||
return setZone(data)
|
return setZone(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@class SphereZone : ZoneProperties
|
||||||
|
---@field radius? number
|
||||||
|
|
||||||
|
---@param data SphereZone
|
||||||
|
---@return CZone
|
||||||
function lib.zones.sphere(data)
|
function lib.zones.sphere(data)
|
||||||
data.id = #Zones + 1
|
data.id = #Zones + 1
|
||||||
data.coords = convertToVector(data.coords)
|
data.coords = convertToVector(data.coords)
|
||||||
|
|||||||
Reference in New Issue
Block a user