local L=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local p=L:WaitForChild("\099\111\109\109\111\110")local A=require(p:WaitForChild("\065\115\115\101\116\115"))local C=L:WaitForChild("\097\115\115\101\116\109\111\100\101\108\115")local K=C:WaitForChild("\101\102\102\101\099\116")local f={}local function h(L)local p=A.byId[L]assert(p,"\073\110\118\097\108\105\100 \097\115\115\101\116 \105\100\058 "..L)assert(p.metadata,("\065\115\115\101\116 \037\115 \104\097\115 \105\110\118\097\108\105\100 \109\101\116\097\100\097\116\097 \102\111\114 \101\102\102\101\099\116 \116\121\112\101"):format(L))local C={}for p,A in pairs(p.metadata.effectInstances or{})do local f=K:FindFirstChild(A)if f then table.insert(C,f:Clone())else warn(("\099\111\117\108\100 \110\111\116 \102\105\110\100 \101\102\102\101\099\116 \037\115 \102\111\114 \101\102\102\101\099\116 \097\115\115\101\116 \037\115"):format(A,L))end end return C end function f.new(L,p)local C=setmetatable({},{__index=f})C.assetId=L C.rig=p local K=A.byId[L]C.effectInstances=h(L)local z=p:WaitForChild("\084\111\114\115\111")if not z then return C end for L,p in pairs(C.effectInstances)do p.Parent=z if p:IsA("\084\114\097\105\108")then p.Attachment0=z:FindFirstChild("\072\097\116\065\116\116\097\099\104\109\101\110\116")p.Attachment1=z:FindFirstChild("\084\114\097\105\108\066\111\116\116\111\109")p.Color=ColorSequence.new(K.metadata.effectColor3)or ColorSequence.new(Color3.new(1,1,1))end end return C end function f.update(L) end function f.destroy(L)for L,p in pairs(L.effectInstances or{})do p:Destroy()end L.rig=nil end return f
-- object based hat renderer, default renderer for hats.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local common = ReplicatedStorage:WaitForChild("common")

local Assets = require(common:WaitForChild("Assets"))

local assetmodels = ReplicatedStorage:WaitForChild("assetmodels")
local effects = assetmodels:WaitForChild("effect")

local EffectRenderer = {}

local function cloneEffectsForAsset(id)
    local asset = Assets.byId[id]
    assert(asset, "Invalid asset id: "..id)
    assert(asset.metadata, ("Asset %s has invalid metadata for effect type"):format(id))
    local newEffects = {}

    for _,name in pairs(asset.metadata.effectInstances or {}) do
        local origEffect = effects:FindFirstChild(name)
        if origEffect then
            table.insert(newEffects,origEffect:Clone())
        else
            warn(("could not find effect %s for effect asset %s"):format(name,id))
        end
    end

    return newEffects
end

function EffectRenderer.new(assetId,rig)
    -- create hat for this rig
    local self = setmetatable({},{__index = EffectRenderer})

    self.assetId = assetId
    self.rig = rig
    local asset = Assets.byId[assetId]

    self.effectInstances = cloneEffectsForAsset(assetId)

    local torso = rig:WaitForChild("Torso")
    if not torso then return self end

    for _,effectInstance in pairs(self.effectInstances) do
        effectInstance.Parent = torso

        if effectInstance:IsA("Trail") then
            effectInstance.Attachment0 = torso:FindFirstChild("HatAttachment")
            effectInstance.Attachment1 = torso:FindFirstChild("TrailBottom")

            effectInstance.Color = ColorSequence.new(asset.metadata.effectColor3) or ColorSequence.new(Color3.new(1,1,1))
        end
    end

    return self
end

function EffectRenderer:update()
    -- nothing needed here
end

function EffectRenderer:destroy()
    for _,v in pairs(self.effectInstances or {}) do
        v:Destroy()
    end
    self.rig = nil
end

return EffectRenderer