@quenty/characterutils 12.4.0 → 12.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [12.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/characterutils@12.4.0...@quenty/characterutils@12.5.0) (2024-09-12)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add RxCharacterUtil helper methods ([7b0b7a9](https://github.com/Quenty/NevermoreEngine/commit/7b0b7a94b4c8c7c76b030b48ecdab1f1c8a7ff53))
12
+
13
+
14
+
15
+
16
+
6
17
  # [12.4.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/characterutils@12.3.0...@quenty/characterutils@12.4.0) (2024-08-09)
7
18
 
8
19
  **Note:** Version bump only for package @quenty/characterutils
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/characterutils",
3
- "version": "12.4.0",
3
+ "version": "12.5.0",
4
4
  "description": "CharacterUtils",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -25,16 +25,16 @@
25
25
  "Quenty"
26
26
  ],
27
27
  "dependencies": {
28
- "@quenty/brio": "^14.4.0",
28
+ "@quenty/brio": "^14.5.0",
29
29
  "@quenty/deferred": "^2.2.0",
30
- "@quenty/instanceutils": "^13.4.0",
31
- "@quenty/loader": "^10.3.0",
32
- "@quenty/maid": "^3.2.0",
33
- "@quenty/promise": "^10.3.0",
34
- "@quenty/rx": "^13.4.0"
30
+ "@quenty/instanceutils": "^13.5.0",
31
+ "@quenty/loader": "^10.4.0",
32
+ "@quenty/maid": "^3.3.0",
33
+ "@quenty/promise": "^10.4.0",
34
+ "@quenty/rx": "^13.5.0"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "ba466bdbc05c42fb607cf5e228c16339201d21d7"
39
+ "gitHead": "fb172906f3ee725269ec1e5f4daf9dca227e729d"
40
40
  }
@@ -5,11 +5,14 @@
5
5
 
6
6
  local require = require(script.Parent.loader).load(script)
7
7
 
8
+ local Players = game:GetService("Players")
9
+
8
10
  local Brio = require("Brio")
9
11
  local Maid = require("Maid")
10
12
  local Observable = require("Observable")
11
13
  local RxBrioUtils = require("RxBrioUtils")
12
14
  local RxInstanceUtils = require("RxInstanceUtils")
15
+ local Rx = require("Rx")
13
16
 
14
17
  local RxCharacterUtils = {}
15
18
 
@@ -37,6 +40,57 @@ function RxCharacterUtils.observeCharacter(player)
37
40
  return RxInstanceUtils.observeProperty(player, "Character")
38
41
  end
39
42
 
43
+ function RxCharacterUtils.observeCharacterBrio(player)
44
+ return RxInstanceUtils.observePropertyBrio(player, "Character", function(character)
45
+ return character ~= nil
46
+ end)
47
+ end
48
+
49
+ function RxCharacterUtils.observeIsOfLocalCharacter(instance)
50
+ assert(typeof(instance) == "Instance", "Bad instance")
51
+
52
+ local localPlayer = Players.LocalPlayer
53
+ if not localPlayer then
54
+ warn("[RxCharacterUtils] - No localPlayer")
55
+ return Rx.EMPTY
56
+ end
57
+
58
+ return Rx.combineLatest({
59
+ character = RxCharacterUtils.observeLocalPlayerCharacter();
60
+ _ancestry = RxInstanceUtils.observeAncestry(instance)
61
+ }):Pipe({
62
+ Rx.map(function(state)
63
+ if state.character then
64
+ return instance == state.character or instance:IsDescendantOf(state.character)
65
+ else
66
+ return false
67
+ end
68
+ end);
69
+ Rx.distinct();
70
+ })
71
+ end
72
+
73
+ function RxCharacterUtils.observeIsOfLocalCharacterBrio(instance)
74
+ return RxCharacterUtils.observeIsOfLocalCharacter(instance):Pipe({
75
+ RxBrioUtils.switchToBrio(function(value)
76
+ return value
77
+ end)
78
+ })
79
+ end
80
+
81
+ function RxCharacterUtils.observeLocalPlayerCharacter()
82
+ return RxInstanceUtils.observeProperty(Players, "LocalPlayer"):Pipe({
83
+ Rx.switchMap(function(player)
84
+ if player then
85
+ return RxCharacterUtils.observeCharacter(player)
86
+ else
87
+ return Rx.of(nil)
88
+ end
89
+ end);
90
+ Rx.distinct();
91
+ })
92
+ end
93
+
40
94
  --[=[
41
95
  Observe a player's last humanoid. Note that it may not be alive!
42
96
  @param player Player