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