Skip to content

Commit 2a18196

Browse files
committed
Final API touch-ups
1 parent a798b6f commit 2a18196

17 files changed

Lines changed: 133 additions & 142 deletions

File tree

docs/intro.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ This test highlights the fundamental flaw in traditional Zone-Centric libraries.
8787
The package name + version is
8888

8989
```
90-
ldgerrits/quickzone@^1.3.12
90+
ldgerrits/quickzone@^2.0.0
9191
```
9292

9393
### Manual
@@ -107,7 +107,7 @@ local Zone, Group, Observer = QuickZone.Zone, QuickZone.Group, QuickZone.Observe
107107
local myPlayer = Group.localPlayer()
108108

109109
-- Find all current and future instances with the 'Water' tag.
110-
local zones = Zone.fromTag('AntiGravity', {
110+
local zones = Zone.tag('AntiGravity', {
111111
metadata = { GravityMultiplier = 0.4 }
112112
})
113113

@@ -149,7 +149,7 @@ local Zone, Group, Observer = QuickZone.Zone, QuickZone.Group, QuickZone.Observe
149149
local localPlayer = game:GetService('Players').LocalPlayer
150150

151151
local myPlayer = Group.localPlayer()
152-
local zones = Zone.fromChildren(workspace.AntiGravityParts)
152+
local zones = Zone.children(workspace.AntiGravityParts)
153153
local gravityObserver = Observer.new():subscribe(myPlayer):attach(zones)
154154

155155
-- Connect events
@@ -197,7 +197,7 @@ QuickZone:setReference(localPlayer, characterModel)
197197

198198
-- Add the local player to the spatial group (QuickZone tracks the mapped model automatically)
199199
local playerGroup = Group.new():add(localPlayer)
200-
local zones = Zone.fromTag('AntiGravity', {
200+
local zones = Zone.tag('AntiGravity', {
201201
metadata = { GravityMultiplier = 0.4 }
202202
})
203203
local gravityObserver = Observer.new({

docs/usage.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ end)
4242
Ideal for ECS frameworks or continuous logic. Instead of waiting for events, your systems poll the state every frame using zero-allocation iterators. You should disable the internal scheduler to step the update method manually for perfect determinism.
4343

4444
```lua
45-
QuickZone:setAutoUpdate(false) -- Disable auto-loop
45+
QuickZone:setEnabled(false) -- Disable auto-loop
4646

4747
local function spatialSystem(dt)
4848
QuickZone:update(dt) -- Steps it deterministically once per frame.
@@ -64,22 +64,22 @@ end)
6464
Zones represent physical areas in the world. They are mathematical boundaries that can be static (fixed in space) or dynamic (following a part). They can be created from existing parts or defined manually with a CFrame and Size.
6565

6666
### Bulk Creation
67-
The easiest way to create zones is using the bulk constructors. The `fromParts`, `fromDescendants`, `fromChildren`, and `fromTag` return a Zones collection object, which acts as a logical unit allowing you to manage multiple zones at once.
67+
The easiest way to create zones is using the bulk constructors. The `parts`, `descendants`, `children`, and `tag` return a Zones collection object, which acts as a logical unit allowing you to manage multiple zones at once.
6868

6969
```lua
7070
-- Create zones from a CollectionService tag
71-
local lavaZones = Zone.fromTag('Lava', {
71+
local lavaZones = Zone.tag('Lava', {
7272
metadata = { damage = 10 }
7373
})
7474

7575
-- Create zones from an array of parts
76-
local safeZones = Zone.fromParts(workspace.SafeZones:GetChildren())
76+
local safeZones = Zone.parts(workspace.SafeZones:GetChildren())
7777

7878
-- Create zones from all BaseParts inside a Model or Folder (Deep search)
79-
local hazardZones = Zone.fromDescendants(workspace.TrapModel)
79+
local hazardZones = Zone.descendants(workspace.TrapModel)
8080

8181
-- Create zones from only the direct children of a Folder (Shallow search)
82-
local flatZones = Zone.fromChildren(workspace.FlatFolder)
82+
local flatZones = Zone.children(workspace.FlatFolder)
8383
```
8484

8585
### Manual Creation
@@ -90,16 +90,16 @@ local zone = Zone.new({
9090
cframe = CFrame.new(0, 10, 0),
9191
size = Vector3.new(10, 10, 10),
9292
shape = 'Block',
93-
isDynamic = true,
93+
dynamic = true,
9494
metadata = { Name = 'Lobby' }
9595
})
9696
```
9797

9898
### Single & Dynamic Creation
99-
For maximum perfomance, use `isDynamic = true` for zones attached to moving platforms, vehicles, or projectiles.
99+
For maximum perfomance, use `dynamic = true` for zones attached to moving platforms, vehicles, or projectiles.
100100
```lua
101-
local trainZone = Zone.fromPart(workspace.TrainCarriage, {
102-
isDynamic = true,
101+
local trainZone = Zone.part(workspace.TrainCarriage, {
102+
dynamic = true,
103103
metadata = { route = 'North' }
104104
})
105105
```
@@ -113,12 +113,12 @@ Dynamic zones need to know when their physical reference moves. You can let Quic
113113
You can quickly create a dynamic zone from an existing physical part. If you set autoSync = true, QuickZone will automatically update the zone's position in the spatial tree every frame to match the part.
114114

115115
```lua
116-
local truckZone = Zone.fromPart(workspace.Truck.Hitbox, {
117-
isDynamic = true,
116+
local truckZone = Zone.part(workspace.Truck.Hitbox, {
117+
dynamic = true,
118118
autoSync = true
119119
})
120120
```
121-
Because Zone.fromPart requires an object with a physical volume (like a BasePart), you cannot use it for abstract references like an Attachment or a Bone. Instead, you manually create the zone with a specific size and declaratively set its reference and autoSync.
121+
Because Zone.part requires an object with a physical volume (like a BasePart), you cannot use it for abstract references like an Attachment or a Bone. Instead, you manually create the zone with a specific size and declaratively set its reference and autoSync.
122122

123123
```lua
124124
local trainZone = Zone.new({

docs/why-use-quickzone.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ QuickZone, on the other hand, is Entity-Centric. It keeps a list of entities and
2525
### 2. Expressive and Boilerplate-Free API
2626
Writing performant code shouldn't mean writing complicated code. QuickZone is designed to be highly ergonomic.
2727

28-
- **CollectionService Integration**: Tag your parts and bind them to your logic in a single line of code (e.g., `Zone.fromTag('Lava')`).
28+
- **CollectionService Integration**: Tag your parts and bind them to your logic in a single line of code (e.g., `Zone.tag('Lava')`).
2929

3030
- **Declarative Configurations**: QuickZone lets you define behaviors, priorities, and relationships upfront in simple configuration tables, drastically reducing boilerplate and keeping your scripts clean.
3131

examples/Client/Observers/Disco.luau

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local SharedGroups = require(ReplicatedStorage.Common.Groups)
77
local discoPart = workspace:WaitForChild('DiscoPart')
88
local defaultColor = discoPart.Color
99

10-
local discoZone = QuickZone.Zone.fromPart(discoPart)
10+
local discoZone = QuickZone.Zone.part(discoPart)
1111

1212
local discoObserver = QuickZone.Observer.new({
1313
groups = { SharedGroups.Players },

examples/Common/Zones.luau

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ local Zone = QuickZone.Zone
1111
For single-purpose zones, just create the Zone locally inside its respective script.
1212
]=]
1313
local Zones = {
14-
Lava = Zone.fromTag('Lava', {
14+
Lava = Zone.tag('Lava', {
1515
metadata = { Name = 'Lava', Damage = 50 },
1616
}),
17-
ToxicGas = Zone.fromTag('ToxicGas', {
17+
ToxicGas = Zone.tag('ToxicGas', {
1818
metadata = { Name = 'ToxicGas', Damage = 10 },
1919
}),
2020
}
2121

2222
if RunService:IsClient() then
23-
Zones.SpeedBoost = Zone.fromChildren(workspace:WaitForChild('SpeedBoosts'))
24-
Zones.AntiGravity = Zone.fromChildren(workspace:WaitForChild('AntiGravZones'))
23+
Zones.SpeedBoost = Zone.children(workspace:WaitForChild('SpeedBoosts'))
24+
Zones.AntiGravity = Zone.children(workspace:WaitForChild('AntiGravZones'))
2525
end
2626

2727
return Zones

examples/Server/Observers/GravityWell.luau

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ local SharedGroups = require(ReplicatedStorage.Common.Groups)
66

77
local gravityWell = workspace:WaitForChild('GravityWell')
88

9-
local gravityWellZone = QuickZone.Zone.fromPart(gravityWell, {
10-
isDynamic = true,
9+
local gravityWellZone = QuickZone.Zone.part(gravityWell, {
10+
dynamic = true,
1111
autoSync = true,
1212
})
1313

examples/Server/Observers/SafeZone.luau

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local SharedGroups = require(ReplicatedStorage.Common.Groups)
44

55
local safeZonePart = workspace:WaitForChild('SafeZone')
66

7-
local safeZone = QuickZone.Zone.fromPart(safeZonePart)
7+
local safeZone = QuickZone.Zone.part(safeZonePart)
88

99
local safeObserver = QuickZone.Observer.new({
1010
groups = { SharedGroups.Players },

src/Classes/Group.luau

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ end
179179
@param tag string
180180
@return Group
181181
]=]
182-
function Group.fromTag(tag: string): Types.Group<Types.Entity>
182+
function Group.tag(tag: string): Types.Group<Types.Entity>
183183
local group = Group.new({ autoClean = false }) :: Types.InternalGroup<Types.Entity>
184184
group.isManaged = true
185185

@@ -746,12 +746,12 @@ function Group._remove(self: Types.InternalGroup, entity: any): Types.Group
746746
continue
747747
end
748748

749-
local safety = State.observerSafety[observerId]
749+
local safe = State.observerSafe[observerId]
750750
local z = State.zoneIdToZoneObj[oldZoneId]
751751
local ref = State.entityToReference[entity] or entity
752752

753753
for _, fn in cbs do
754-
if safety then
754+
if safe then
755755
task.spawn(fn, ref, z)
756756
else
757757
fn(ref, z)

src/Classes/Observer.luau

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ local function updateAllEntitiesForObserver(observerId: number)
4848
end
4949

5050
local function disconnectObserverFromGroup(observerId: number, group: Types.InternalGroup)
51-
local safety = State.observerSafety[observerId]
51+
local safe = State.observerSafe[observerId]
5252

5353
for _, entity in group.entities do
5454
local data = State.entityData[entity]
@@ -79,7 +79,7 @@ local function disconnectObserverFromGroup(observerId: number, group: Types.Inte
7979
local z = State.zoneIdToZoneObj[oldZoneId]
8080
local ref = State.entityToReference[entity] or entity
8181
for _, fn in cbs do
82-
if safety then
82+
if safe then
8383
task.spawn(fn, ref, z)
8484
else
8585
fn(ref, z)
@@ -109,7 +109,7 @@ Observer.__index = Observer
109109
updateRate = 20, -- Check at 20Hz
110110
precision = 0.5, -- Ignore movement smaller than 0.5 studs
111111
enabled = false, -- Observer will not start processing spatial checks
112-
safety = false, -- Do not wrap callbacks in task.spawn
112+
safe = false, -- Do not wrap callbacks in task.spawn
113113
})
114114
```
115115
@@ -118,12 +118,12 @@ Observer.__index = Observer
118118
higher priority observers take complete control.
119119
:::
120120
121-
:::warning Safety
121+
:::warning Safe
122122
If set to unsafe, you are not allowed to yield in the callbacks anymore. If you do, QuickZone will throw errors.
123123
:::
124124
125125
@tag Constructor
126-
@param config { groups: { Types.Group }?, zones: { Types.Zone | Types.Zones }?, priority: number?, updateRate: number?, precision: number?, enabled: boolean?, safety: boolean? }?
126+
@param config { groups: { Types.Group }?, zones: { Types.Zone | Types.Zones }?, priority: number?, updateRate: number?, precision: number?, enabled: boolean?, safe: boolean? }?
127127
@return Observer
128128
]=]
129129
function Observer.new<T>(config: {
@@ -133,7 +133,7 @@ function Observer.new<T>(config: {
133133
updateRate: number?,
134134
precision: number?,
135135
enabled: boolean?,
136-
safety: boolean?,
136+
safe: boolean?,
137137
}?): Types.Observer
138138
local id = State.nextObserverId
139139
State.nextObserverId += 1
@@ -152,7 +152,7 @@ function Observer.new<T>(config: {
152152
State.observerTrackingEntities[id] = {}
153153
State.observerIdToObserverObj[id] = self
154154
State.observerEnabled[id] = if config and config.enabled ~= nil then config.enabled else true
155-
State.observerSafety[id] = if config and config.safety ~= nil then config.safety else Config.Observer.safety
155+
State.observerSafe[id] = if config and config.safe ~= nil then config.safe else Config.Observer.safe
156156
State.observerStaticCount[id] = 0
157157
State.observerDynamicCount[id] = 0
158158

@@ -953,17 +953,17 @@ end
953953
--[=[
954954
Whether to wrap callbacks in task.spawn (safe) or not (unsafe).
955955
956-
:::warning Safety
956+
:::warning Safe
957957
If set to unsafe, you are not allowed to yield in the callbacks anymore. If you do, QuickZone will throw errors.
958958
:::
959959
960-
@method setSafety
960+
@method setSafe
961961
@within Observer
962962
@param enabled boolean
963963
@return Observer
964964
]=]
965-
function Observer.setSafety(self: Types.InternalObserver, enabled: boolean): Types.Observer
966-
State.observerSafety[self.id] = enabled
965+
function Observer.setSafe(self: Types.InternalObserver, enabled: boolean): Types.Observer
966+
State.observerSafe[self.id] = enabled
967967
return self
968968
end
969969

@@ -1109,7 +1109,7 @@ end
11091109
@return boolean
11101110
]=]
11111111
function Observer.isSafe(self: Types.InternalObserver): boolean
1112-
return State.observerSafety[self.id]
1112+
return State.observerSafe[self.id]
11131113
end
11141114

11151115
--[=[
@@ -1604,7 +1604,7 @@ function Observer.destroy(self: Types.InternalObserver): ()
16041604
State.observerTrackingEntities[id] = nil
16051605
State.observerIdToObserverObj[id] = nil
16061606
State.observerEnabled[id] = nil
1607-
State.observerSafety[id] = nil
1607+
State.observerSafe[id] = nil
16081608
State.observerUpdateRate[id] = nil
16091609
State.observerPrecisionSq[id] = nil
16101610
State.observerStaticCount[id] = nil

0 commit comments

Comments
 (0)