Merge pull request #2 from F2KENAME/patch-1
refactor: split "convertCharacter" function for external uses
This commit is contained in:
+25
-16
@@ -32,13 +32,7 @@ local function headMeshFromHumanoidDescription(humDesc: HumanoidDescription): nu
|
||||
return meshByName["RobloxClassic"]
|
||||
end
|
||||
|
||||
function convert.convertCharacter(humanoid: Humanoid): ()
|
||||
local humDesc = humanoid:GetAppliedDescription()
|
||||
if humDesc == nil then
|
||||
warn(`rbx-reface: could not get applied description for {humanoid.Parent.Name}`)
|
||||
return
|
||||
end
|
||||
|
||||
function convert.applyHeadDescription(humDesc: HumanoidDescription): number
|
||||
local currentMesh = humDesc.Head
|
||||
local targetMesh = headMeshFromHumanoidDescription(humDesc)
|
||||
local face = faceByMesh[currentMesh]
|
||||
@@ -50,16 +44,10 @@ function convert.convertCharacter(humanoid: Humanoid): ()
|
||||
|
||||
humDesc.Head = targetMesh
|
||||
humDesc.Face = face
|
||||
return targetMesh
|
||||
end
|
||||
|
||||
local ok, err = pcall(function()
|
||||
humanoid:ApplyDescriptionResetAsync(humDesc)
|
||||
end)
|
||||
|
||||
if not ok then
|
||||
warn(`rbx-reface: failed to apply description: {err}`)
|
||||
return
|
||||
end
|
||||
|
||||
function convert.fixiBotTexture(humanoid: Humanoid, targetMesh: number): ()
|
||||
-- iBot's texture is not correctly restored
|
||||
if targetMesh == meshByName["iBot"] then
|
||||
local head = humanoid.Parent:FindFirstChild("Head")
|
||||
@@ -71,4 +59,25 @@ function convert.convertCharacter(humanoid: Humanoid): ()
|
||||
end
|
||||
end
|
||||
|
||||
function convert.convertCharacter(humanoid: Humanoid): ()
|
||||
local humDesc = humanoid:GetAppliedDescription()
|
||||
if humDesc == nil then
|
||||
warn(`rbx-reface: could not get applied description for {humanoid.Parent.Name}`)
|
||||
return
|
||||
end
|
||||
|
||||
local targetMesh = convert.applyHeadDescription(humDesc)
|
||||
|
||||
local ok, err = pcall(function()
|
||||
humanoid:ApplyDescriptionResetAsync(humDesc)
|
||||
end)
|
||||
|
||||
if not ok then
|
||||
warn(`rbx-reface: failed to apply description: {err}`)
|
||||
return
|
||||
end
|
||||
|
||||
convert.fixHeadTexture(humanoid, targetMesh)
|
||||
end
|
||||
|
||||
return convert
|
||||
|
||||
Reference in New Issue
Block a user