Skip to content

Commit 016fe2f

Browse files
authored
Add ToolUtils package (#532)
Add ToolUtils package
2 parents 86c00a8 + 5a05b53 commit 016fe2f

File tree

8 files changed

+160
-3
lines changed

8 files changed

+160
-3
lines changed

src/characterutils/src/Shared/RxRootPartUtils.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ end
2929
@return Brio<BasePart>
3030
]=]
3131
function RxRootPartUtils.observeHumanoidRootPartBrioFromHumanoid(humanoid)
32-
return RxInstanceUtils.observePropertyBrio(humanoid, "Parent", function(character)
33-
return character ~= nil
34-
end):Pipe({
32+
return RxInstanceUtils.observeParentBrio(humanoid):Pipe({
3533
RxBrioUtils.switchMapBrio(function(character)
3634
return RxRootPartUtils.observeHumanoidRootPartBrio(character)
3735
end)

src/toolutils/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## ToolUtils
2+
3+
<div align="center">
4+
<a href="http://quenty.github.io/NevermoreEngine/">
5+
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
6+
</a>
7+
<a href="https://discord.gg/mhtGUS8">
8+
<img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
9+
</a>
10+
<a href="https://github.com/Quenty/NevermoreEngine/actions">
11+
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
12+
</a>
13+
</div>
14+
15+
Utility methods for tools
16+
17+
<div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/RxToolUtils">View docs →</a></div>
18+
19+
## Installation
20+
21+
```
22+
npm install @quenty/toolutils --save
23+
```

src/toolutils/default.project.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "toolutils",
3+
"globIgnorePaths": [ "**/.package-lock.json" ],
4+
"tree": {
5+
"$path": "src"
6+
}
7+
}

src/toolutils/package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "@quenty/toolutils",
3+
"version": "1.0.0",
4+
"description": "Utility methods for tools",
5+
"keywords": [
6+
"Roblox",
7+
"Nevermore",
8+
"Lua",
9+
"toolutils"
10+
],
11+
"bugs": {
12+
"url": "https://github.com/Quenty/NevermoreEngine/issues"
13+
},
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/Quenty/NevermoreEngine.git",
17+
"directory": "src/toolutils/"
18+
},
19+
"funding": {
20+
"type": "patreon",
21+
"url": "https://www.patreon.com/quenty"
22+
},
23+
"license": "MIT",
24+
"contributors": [
25+
"Quenty"
26+
],
27+
"dependencies": {
28+
"@quenty/brio": "file:../brio",
29+
"@quenty/instanceutils": "file:../instanceutils",
30+
"@quenty/loader": "file:../loader",
31+
"@quenty/rx": "file:../rx"
32+
},
33+
"publishConfig": {
34+
"access": "public"
35+
}
36+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--[=[
2+
@class RxToolUtils
3+
]=]
4+
5+
local require = require(script.Parent.loader).load(script)
6+
7+
local RxInstanceUtils = require("RxInstanceUtils")
8+
local RxBrioUtils = require("RxBrioUtils")
9+
10+
local RxToolUtils = {}
11+
12+
--[=[
13+
Observes the equipped humanoid of a given tool
14+
15+
@param tool Instance
16+
@return Observable<Brio<Humanoid>>
17+
]=]
18+
function RxToolUtils.observeEquippedHumanoidBrio(tool)
19+
assert(typeof(tool) == "Instance", "Bad tool")
20+
21+
return RxInstanceUtils.observePropertyBrio(tool, "Parent", function(parent)
22+
return parent and parent:IsA("Model")
23+
end):Pipe({
24+
RxBrioUtils.switchMapBrio(function(parent)
25+
return RxInstanceUtils.observeChildrenOfClassBrio(parent, "Humanoid")
26+
end);
27+
})
28+
end
29+
30+
return RxToolUtils
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--[=[
2+
@class ToolUtils
3+
]=]
4+
5+
local require = require(script.Parent.loader).load(script)
6+
7+
local CharacterUtils = require("CharacterUtils")
8+
9+
local ToolUtils = {}
10+
11+
--[=[
12+
Gets the equipped humanoid for a given tool
13+
]=]
14+
function ToolUtils.getEquippedHumanoid(tool: Tool): Humanoid?
15+
assert(typeof(tool) == "Instance", "Bad tool")
16+
17+
local character = tool.Parent
18+
if not (character and character:IsA("Model")) then
19+
return nil
20+
end
21+
22+
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
23+
if not humanoid then
24+
return nil
25+
end
26+
27+
return humanoid
28+
end
29+
30+
--[=[
31+
Gets the equipped player for a given tool
32+
]=]
33+
function ToolUtils.getEquippedPlayer(tool: Tool): Player?
34+
assert(typeof(tool) == "Instance", "Bad tool")
35+
36+
local humanoid = ToolUtils.getEquippedHumanoid(tool)
37+
if not humanoid then
38+
return nil
39+
end
40+
41+
return CharacterUtils.getPlayerFromCharacter(humanoid)
42+
end
43+
44+
return ToolUtils
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "node_modules",
3+
"globIgnorePaths": [ "**/.package-lock.json" ],
4+
"tree": {
5+
"$path": { "optional": "../node_modules" }
6+
}
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "ToolUtilsTest",
3+
"globIgnorePaths": [ "**/.package-lock.json" ],
4+
"tree": {
5+
"$className": "DataModel",
6+
"ServerScriptService": {
7+
"toolutils": {
8+
"$path": ".."
9+
}
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)