@quenty/firstpersoncharactertransparency 7.1.0 → 8.0.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,14 @@
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
+ # [8.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/firstpersoncharactertransparency@7.1.0...@quenty/firstpersoncharactertransparency@8.0.0) (2022-10-12)
7
+
8
+ **Note:** Version bump only for package @quenty/firstpersoncharactertransparency
9
+
10
+
11
+
12
+
13
+
6
14
  # [7.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/firstpersoncharactertransparency@7.0.0...@quenty/firstpersoncharactertransparency@7.1.0) (2022-10-11)
7
15
 
8
16
  **Note:** Version bump only for package @quenty/firstpersoncharactertransparency
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/firstpersoncharactertransparency",
3
- "version": "7.1.0",
3
+ "version": "8.0.0",
4
4
  "description": "Allows transparency to manually be controlled for a character in first-person mode",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -27,13 +27,18 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "@quenty/baseobject": "^6.0.0",
30
+ "@quenty/brio": "^8.1.0",
30
31
  "@quenty/humanoidtracker": "^7.1.0",
32
+ "@quenty/instanceutils": "^7.1.0",
31
33
  "@quenty/loader": "^6.0.0",
32
34
  "@quenty/maid": "^2.4.0",
35
+ "@quenty/r15utils": "^7.1.0",
36
+ "@quenty/rx": "^7.1.0",
37
+ "@quenty/statestack": "^8.1.0",
33
38
  "@quenty/transparencyservice": "^7.0.0"
34
39
  },
35
40
  "publishConfig": {
36
41
  "access": "public"
37
42
  },
38
- "gitHead": "69c2153865684748d0a8d6806f1ff999685c2e55"
43
+ "gitHead": "6e40fe4f0e364f7f4e37a31fb8b19d975f4f377d"
39
44
  }
@@ -1,6 +1,6 @@
1
- ---
2
- -- @classmod DisableHatParticles
3
- -- @author Quenty
1
+ --[=[
2
+ @class DisableHatParticles
3
+ ]=]
4
4
 
5
5
  local require = require(script.Parent.loader).load(script)
6
6
 
@@ -0,0 +1,82 @@
1
+ --[=[
2
+ @class HideHead
3
+ ]=]
4
+
5
+ local require = require(script.Parent.loader).load(script)
6
+
7
+ local BaseObject = require("BaseObject")
8
+ local RxBrioUtils = require("RxBrioUtils")
9
+ local RxInstanceUtils = require("RxInstanceUtils")
10
+ local TransparencyService = require("TransparencyService")
11
+ local RxR15Utils = require("RxR15Utils")
12
+
13
+ local HideHead = setmetatable({}, BaseObject)
14
+ HideHead.ClassName = "HideHead"
15
+ HideHead.__index = HideHead
16
+
17
+ function HideHead.new(character, serviceBag)
18
+ local self = setmetatable(BaseObject.new(character), HideHead)
19
+
20
+ self._serviceBag = assert(serviceBag, "No serviceBag")
21
+ self._transparencyService = self._serviceBag:GetService(TransparencyService)
22
+
23
+
24
+ self._maid:GiveTask(self:_observeHeadAndFaceAccessoryPartsBrio():Subscribe(function(brio)
25
+ if brio:IsDead() then
26
+ return
27
+ end
28
+
29
+ local part = brio:GetValue()
30
+ local maid = brio:ToMaid()
31
+
32
+ self._transparencyService:SetTransparency(maid, part, 1)
33
+ maid:GiveTask(function()
34
+ self._transparencyService:ResetTransparency(maid, part)
35
+ end)
36
+ end))
37
+
38
+ self._maid:GiveTask(self:_observeHeadBrio():Subscribe(function(brio)
39
+ if brio:IsDead() then
40
+ return
41
+ end
42
+
43
+ local part = brio:GetValue()
44
+ local maid = brio:ToMaid()
45
+
46
+ self._transparencyService:SetTransparency(maid, part, 1)
47
+ maid:GiveTask(function()
48
+ self._transparencyService:ResetTransparency(maid, part)
49
+ end)
50
+ end))
51
+
52
+ return self
53
+ end
54
+
55
+ function HideHead:_observeHeadBrio()
56
+ return RxR15Utils.observeCharacterPartBrio(self._obj, "Head")
57
+ end
58
+
59
+ function HideHead:_observeHeadAndFaceAccessoryPartsBrio()
60
+ return self:_observeAccessoriesBrio():Pipe({
61
+ RxBrioUtils.flatMapBrio(function(accessory)
62
+ return RxInstanceUtils.observePropertyBrio(accessory, "AccessoryType", function(accessoryType)
63
+ return accessoryType == Enum.AccessoryType.Hat or accessoryType == Enum.AccessoryType.Face
64
+ end):Pipe({
65
+ RxBrioUtils.onlyLastBrioSurvives();
66
+ RxBrioUtils.switchMapBrio(function()
67
+ return RxInstanceUtils.observeDescendantsBrio(accessory, function(child)
68
+ return child:IsA("BasePart")
69
+ end)
70
+ end);
71
+ })
72
+ end)
73
+ })
74
+ end
75
+
76
+ function HideHead:_observeAccessoriesBrio()
77
+ return RxInstanceUtils.observeDescendantsBrio(self._obj, function(inst)
78
+ return inst:IsA("Accessory")
79
+ end)
80
+ end
81
+
82
+ return HideHead
@@ -0,0 +1,85 @@
1
+ --[=[
2
+ @class ShowBody
3
+ ]=]
4
+
5
+ local require = require(script.Parent.loader).load(script)
6
+
7
+ local BaseObject = require("BaseObject")
8
+ local RxBrioUtils = require("RxBrioUtils")
9
+ local RxInstanceUtils = require("RxInstanceUtils")
10
+ local TransparencyService = require("TransparencyService")
11
+
12
+ local ShowBody = setmetatable({}, BaseObject)
13
+ ShowBody.ClassName = "ShowBody"
14
+ ShowBody.__index = ShowBody
15
+
16
+ function ShowBody.new(character, serviceBag)
17
+ local self = setmetatable(BaseObject.new(character), ShowBody)
18
+
19
+ self._serviceBag = assert(serviceBag, "No serviceBag")
20
+ self._transparencyService = self._serviceBag:GetService(TransparencyService)
21
+
22
+ self._maid:GiveTask(self:_observeNonHeadAndFaceAccessoryPartsBrio():Subscribe(function(brio)
23
+ if brio:IsDead() then
24
+ return
25
+ end
26
+
27
+ local part = brio:GetValue()
28
+ local maid = brio:ToMaid()
29
+
30
+ -- Force visibility
31
+ maid:GiveTask(part:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
32
+ part.LocalTransparencyModifier = 0
33
+ end))
34
+ part.LocalTransparencyModifier = 0
35
+ end))
36
+
37
+ self._maid:GiveTask(self:_observeNonHeadParts():Subscribe(function(brio)
38
+ if brio:IsDead() then
39
+ return
40
+ end
41
+
42
+ local part = brio:GetValue()
43
+ local maid = brio:ToMaid()
44
+
45
+ -- Force visibility
46
+ maid:GiveTask(part:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
47
+ part.LocalTransparencyModifier = 0
48
+ end))
49
+ part.LocalTransparencyModifier = 0
50
+ end))
51
+
52
+ return self
53
+ end
54
+
55
+ function ShowBody:_observeNonHeadParts()
56
+ return RxInstanceUtils.observeChildrenBrio(self._obj, function(child)
57
+ return child:IsA("BasePart") and child.Name ~= "Head" -- make some assumptions
58
+ end)
59
+ end
60
+
61
+
62
+ function ShowBody:_observeNonHeadAndFaceAccessoryPartsBrio()
63
+ return self:_observeAccessoriesBrio():Pipe({
64
+ RxBrioUtils.flatMapBrio(function(accessory)
65
+ return RxInstanceUtils.observePropertyBrio(accessory, "AccessoryType", function(accessoryType)
66
+ return accessoryType ~= Enum.AccessoryType.Hat and accessoryType ~= Enum.AccessoryType.Face
67
+ end):Pipe({
68
+ RxBrioUtils.onlyLastBrioSurvives();
69
+ RxBrioUtils.switchMapBrio(function()
70
+ return RxInstanceUtils.observeDescendantsBrio(accessory, function(child)
71
+ return child:IsA("BasePart")
72
+ end)
73
+ end);
74
+ })
75
+ end)
76
+ })
77
+ end
78
+
79
+ function ShowBody:_observeAccessoriesBrio()
80
+ return RxInstanceUtils.observeDescendantsBrio(self._obj, function(inst)
81
+ return inst:IsA("Accessory")
82
+ end)
83
+ end
84
+
85
+ return ShowBody
@@ -1,72 +0,0 @@
1
- ---
2
- -- @classmod CharacterTransparency
3
- -- @author Quenty
4
-
5
- local require = require(script.Parent.loader).load(script)
6
-
7
- local RunService = game:GetService("RunService")
8
-
9
- local BaseObject = require("BaseObject")
10
- local ModelTransparencyEffect = require("ModelTransparencyEffect")
11
- local DisableHatParticles = require("DisableHatParticles")
12
-
13
- local CharacterTransparency = setmetatable({}, BaseObject)
14
- CharacterTransparency.ClassName = "CharacterTransparency"
15
- CharacterTransparency.__index = CharacterTransparency
16
-
17
- function CharacterTransparency.new(serviceBag, character, tweener)
18
- local self = setmetatable(BaseObject.new(character), CharacterTransparency)
19
-
20
- self._character = assert(character, "Bad character")
21
- self._tweener = assert(tweener, "Bad tweener")
22
-
23
- self._modelTransparency = ModelTransparencyEffect.new(serviceBag, self._character)
24
- self._modelTransparency:SetAcceleration(40)
25
- self._maid:GiveTask(self._modelTransparency)
26
-
27
- self._enabled = Instance.new("BoolValue")
28
- self._enabled.Value = false
29
- self._maid:GiveTask(self._enabled)
30
-
31
- self._maid:GiveTask(self._enabled.Changed:Connect(function()
32
- self:_onEnabledChanged()
33
- end))
34
-
35
- self._maid:GiveTask(RunService.RenderStepped:Connect(function()
36
- self:_update()
37
- end))
38
-
39
- self:_update()
40
-
41
- return self
42
- end
43
-
44
- function CharacterTransparency:_update()
45
- self._enabled.Value = self:_getShouldBeVisible()
46
- end
47
-
48
- function CharacterTransparency:_getShouldBeVisible()
49
- if self._tweener:GetPercentVisible() <= 0.5 then
50
- return false
51
- end
52
-
53
- -- hope this isn't slow
54
- local desiredPosition = self._tweener:GetCameraEffect().CameraState.CFrame.p
55
- local position = workspace.CurrentCamera.CFrame.p
56
- return (position - desiredPosition).magnitude <= 2
57
- end
58
-
59
- function CharacterTransparency:_onEnabledChanged()
60
- if self._enabled.Value then
61
- if not self._maid._disableHatParticles then
62
- self._maid._disableHatParticles = DisableHatParticles.new(self._character)
63
- end
64
-
65
- self._modelTransparency:SetTransparency(1)
66
- else
67
- self._modelTransparency:SetTransparency(0)
68
- self._maid._disableHatParticles = nil
69
- end
70
- end
71
-
72
- return CharacterTransparency
@@ -1,182 +0,0 @@
1
- --[=[
2
- Allows transparency to manually be controlled for a character in first-person mode.
3
-
4
- :::tip
5
- Make sure to initialize [TransparencyService] in the [ServiceBag] before using this.
6
- :::
7
-
8
- @class FirstPersonCharacterTransparency
9
- ]=]
10
-
11
- local require = require(script.Parent.loader).load(script)
12
-
13
- local BaseObject = require("BaseObject")
14
- local TransparencyService = require("TransparencyService")
15
- local Maid = require("Maid")
16
-
17
- local FirstPersonCharacterTransparency = setmetatable({}, BaseObject)
18
- FirstPersonCharacterTransparency.ClassName = "FirstPersonCharacterTransparency"
19
- FirstPersonCharacterTransparency.__index = FirstPersonCharacterTransparency
20
-
21
- --[=[
22
- Creates a new FirstPersonCharacterTransparency
23
- @param humanoid Humanoid
24
- @param serviceBag ServiceBag
25
- @return FirstPersonCharacterTransparency
26
- ]=]
27
- function FirstPersonCharacterTransparency.new(humanoid, serviceBag)
28
- local self = setmetatable(BaseObject.new(humanoid), FirstPersonCharacterTransparency)
29
-
30
- self._serviceBag = assert(serviceBag, "No serviceBag")
31
-
32
- self._humanoid = humanoid or error("No humanoid")
33
- self._character = self._humanoid.Parent or error("No character")
34
- self._transparencyService = self._serviceBag:GetService(TransparencyService)
35
-
36
- self._otherParts = {}
37
- self._shownBodyParts = {}
38
- self._transparency = 0
39
-
40
- self._shouldShowArms = Instance.new("BoolValue")
41
- self._shouldShowArms.Value = true
42
- self._maid:GiveTask(self._shouldShowArms)
43
-
44
- -- Listen to parts
45
- for _, part in pairs(self._character:GetDescendants()) do
46
- self:_handlePartAdded(part)
47
- end
48
-
49
- -- Listen to children
50
- self._maid:GiveTask(self._character.DescendantAdded:Connect(function(part)
51
- self:_handlePartAdded(part)
52
- end))
53
- self._maid:GiveTask(self._character.DescendantRemoving:Connect(function(part)
54
- self:_handlePartRemoving(part)
55
- end))
56
-
57
- self._maid:GiveTask(function()
58
- self:_reset()
59
- self._otherParts = nil
60
- self._shownBodyParts = nil
61
- end)
62
-
63
- return self
64
- end
65
-
66
- --[=[
67
- Sets whether body parts should be shown.
68
- @param shouldShowArms boolean
69
- ]=]
70
- function FirstPersonCharacterTransparency:SetShowArms(shouldShowArms)
71
- assert(type(shouldShowArms) == "boolean", "Bad shouldShowArms")
72
-
73
- self._shouldShowArms.Value = shouldShowArms
74
- self:_updateRender()
75
- end
76
-
77
- --[=[
78
- Sets the transparency
79
- @param transparency number
80
- ]=]
81
- function FirstPersonCharacterTransparency:SetTransparency(transparency)
82
- assert(type(transparency) == "number", "Bad transparency")
83
-
84
- if transparency >= 0.999 then
85
- transparency = 1
86
- elseif transparency <= 0.001 then
87
- transparency = 0
88
- end
89
-
90
- if self._transparency == transparency then
91
- return
92
- end
93
-
94
- self._transparency = transparency
95
-
96
- self:_updateRender()
97
- end
98
-
99
- function FirstPersonCharacterTransparency:_getBodyTransparency()
100
- if self._shouldShowArms.Value then
101
- return 0
102
- else
103
- return self._transparency
104
- end
105
- end
106
-
107
- function FirstPersonCharacterTransparency:_reset()
108
- for part, _ in pairs(self._otherParts) do
109
- self:_resetPart(part)
110
- end
111
-
112
- for part, _ in pairs(self._shownBodyParts) do
113
- self:_resetPart(part)
114
- end
115
- end
116
-
117
- function FirstPersonCharacterTransparency:_resetPart(part)
118
- self._transparencyService:ResetTransparency(self, part)
119
- self._transparencyService:ResetLocalTransparencyModifier(self, part)
120
- end
121
-
122
- function FirstPersonCharacterTransparency:_isShowableBodyPart(part)
123
- return not part:FindFirstAncestorWhichIsA("Accessory")
124
- and (part.Name:find("Arm")
125
- or part.Name:find("Hand")
126
- or part.Name == "UpperTorso")
127
- end
128
-
129
- function FirstPersonCharacterTransparency:_handlePartAdded(part)
130
- if not part:IsA("BasePart") then
131
- return
132
- end
133
-
134
- if self:_isShowableBodyPart(part) then
135
- self._shownBodyParts[part] = true
136
- self:_updateBodyPart(part, self:_getBodyTransparency())
137
-
138
- local maid = Maid.new()
139
-
140
- -- Ensure sanity
141
- maid:GiveTask(part:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
142
- self:_updateBodyPart(part, self:_getBodyTransparency())
143
- end))
144
-
145
- self._maid[part] = maid
146
- else
147
- self._otherParts[part] = true
148
-
149
- self:_updatePart(part)
150
- end
151
- end
152
-
153
- function FirstPersonCharacterTransparency:_handlePartRemoving(part)
154
- if part:IsA("BasePart") then
155
- self._otherParts[part] = nil
156
- self._shownBodyParts[part] = nil
157
- self._maid[part] = nil
158
- self:_resetPart(part)
159
- end
160
- end
161
-
162
- function FirstPersonCharacterTransparency:_updatePart(part)
163
- self._transparencyService:SetTransparency(self, part, self._transparency)
164
- end
165
-
166
- function FirstPersonCharacterTransparency:_updateBodyPart(part, bodyTransparency)
167
- self._transparencyService:SetTransparency(self, part, bodyTransparency)
168
- part.LocalTransparencyModifier = 0
169
- end
170
-
171
- function FirstPersonCharacterTransparency:_updateRender()
172
- for part, _ in pairs(self._otherParts) do
173
- self:_updatePart(part)
174
- end
175
-
176
- local bodyTransparency = self:_getBodyTransparency()
177
- for part, _ in pairs(self._shownBodyParts) do
178
- self:_updateBodyPart(part, bodyTransparency)
179
- end
180
- end
181
-
182
- return FirstPersonCharacterTransparency
@@ -1,52 +0,0 @@
1
- --[=[
2
- @class FirstPersonCharacterTransparencyServiceClient
3
- ]=]
4
-
5
- local require = require(script.Parent.loader).load(script)
6
-
7
- local Maid = require("Maid")
8
- local FirstPersonCharacterTransparency = require("FirstPersonCharacterTransparency")
9
-
10
- local FirstPersonCharacterTransparencyServiceClient = {}
11
- FirstPersonCharacterTransparencyServiceClient.ServiceName = "FirstPersonCharacterTransparencyServiceClient"
12
-
13
- function FirstPersonCharacterTransparencyServiceClient:Init(serviceBag)
14
- assert(not self._serviceBag, "Already initialized")
15
- self._serviceBag = assert(serviceBag, "No serviceBag")
16
-
17
- self._serviceBag:GetService(require("TransparencyService"))
18
- self._humanoidTrackerService = self._serviceBag:GetService(require("HumanoidTrackerService"))
19
-
20
- self._maid = Maid.new()
21
-
22
- self._shouldShowArms = Instance.new("BoolValue")
23
- self._shouldShowArms.Value = true
24
- self._maid:GiveTask(self._shouldShowArms)
25
-
26
- self._humanoidTracker = self._humanoidTrackerService:GetHumanoidTracker()
27
- self._maid:GiveTask(self._humanoidTracker.Humanoid:Observe():Subscribe(function(humanoid)
28
- local maid = Maid.new()
29
-
30
- if humanoid then
31
- local firstPersonCharacterTransparency = FirstPersonCharacterTransparency.new(humanoid, serviceBag)
32
- firstPersonCharacterTransparency:SetShowArms(self._shouldShowArms.Value)
33
-
34
- maid:GiveTask(self._shouldShowArms.Changed:Connect(function()
35
- firstPersonCharacterTransparency:SetShowArms(self._shouldShowArms.Value)
36
- end))
37
-
38
- maid:GiveTask(firstPersonCharacterTransparency)
39
- end
40
- self._maid._current = maid
41
- end))
42
- end
43
-
44
- function FirstPersonCharacterTransparencyServiceClient:SetShowArms(shouldShowArms)
45
- self._shouldShowArms.Value = shouldShowArms
46
- end
47
-
48
- function FirstPersonCharacterTransparencyServiceClient:Destroy()
49
- self._maid:DoCleaning()
50
- end
51
-
52
- return FirstPersonCharacterTransparencyServiceClient