|
| 1 | +--!strict |
| 2 | +--[=[ |
| 3 | + @class DynamicHideClient |
| 4 | +]=] |
| 5 | + |
| 6 | +local require = require(script.Parent.loader).load(script) |
| 7 | + |
| 8 | +local Binder = require("Binder") |
| 9 | +local DynamicHideBase = require("DynamicHideBase") |
| 10 | +local HideUtils = require("HideUtils") |
| 11 | +local Maid = require("Maid") |
| 12 | +local ServiceBag = require("ServiceBag") |
| 13 | +local TransparencyService = require("TransparencyService") |
| 14 | + |
| 15 | +local DynamicHideClient = setmetatable({}, DynamicHideBase) |
| 16 | +DynamicHideClient.ClassName = "DynamicHideClient" |
| 17 | +DynamicHideClient.__index = DynamicHideClient |
| 18 | + |
| 19 | +export type DynamicHideClient = |
| 20 | + typeof(setmetatable( |
| 21 | + {} :: { |
| 22 | + _obj: Instance, |
| 23 | + _serviceBag: ServiceBag.ServiceBag, |
| 24 | + _transparencyService: any, |
| 25 | + _hideBinder: any, |
| 26 | + }, |
| 27 | + {} :: typeof({ __index = DynamicHideClient }) |
| 28 | + )) |
| 29 | + & DynamicHideBase.DynamicHideBase |
| 30 | + |
| 31 | +function DynamicHideClient.new(instance: Instance, serviceBag: ServiceBag.ServiceBag): DynamicHideClient |
| 32 | + local self: DynamicHideClient = setmetatable(DynamicHideBase.new(instance) :: any, DynamicHideClient) |
| 33 | + |
| 34 | + self._serviceBag = assert(serviceBag, "No serviceBag") |
| 35 | + self._transparencyService = self._serviceBag:GetService(TransparencyService) |
| 36 | + self._hideBinder = self._serviceBag:GetService(require("HideClient")) |
| 37 | + |
| 38 | + self._maid:GiveTask(self:_observeHideChildrenBrio(self._hideBinder):Subscribe(function(childBrio) |
| 39 | + if childBrio:IsDead() then |
| 40 | + return |
| 41 | + end |
| 42 | + |
| 43 | + local childMaid, childInstance = childBrio:ToMaidAndValue() |
| 44 | + self:_hideChild(childMaid, childInstance) |
| 45 | + end)) |
| 46 | + |
| 47 | + return self |
| 48 | +end |
| 49 | + |
| 50 | +function DynamicHideClient._hideChild(self: DynamicHideClient, maid: Maid.Maid, instance: Instance) |
| 51 | + if HideUtils.hasLocalTransparencyModifier(instance) then |
| 52 | + self._transparencyService:SetLocalTransparencyModifier(self, instance, 1) |
| 53 | + |
| 54 | + maid:GiveTask(function() |
| 55 | + self._transparencyService:ResetLocalTransparencyModifier(self, instance) |
| 56 | + end) |
| 57 | + elseif HideUtils.hasTransparency(instance) then |
| 58 | + self._transparencyService:SetTransparency(self, instance, 1) |
| 59 | + |
| 60 | + maid:GiveTask(function() |
| 61 | + self._transparencyService:ResetTransparency(self, instance) |
| 62 | + end) |
| 63 | + else |
| 64 | + error("[DynamicHideClient] - Bad instance for hiding") |
| 65 | + end |
| 66 | +end |
| 67 | + |
| 68 | +return Binder.new("DynamicHide", DynamicHideClient :: any) :: Binder.Binder<DynamicHideClient> |
0 commit comments