fix: replace AssetId if-chain with lookup table, improve warnings
This commit is contained in:
+22
-23
@@ -3,31 +3,30 @@ local convert = {}
|
||||
local faceByMesh = require("./faceByMesh")
|
||||
local meshByName = require("./meshByName")
|
||||
|
||||
-- these heads do not expose HeadShape correctly due to Roblox not migrating them fully
|
||||
-- they are mapped by AssetId instead
|
||||
local meshByAssetId: {[number]: string} = {
|
||||
[77954380016578] = "Hex",
|
||||
[123297947692270] = "Diamond",
|
||||
[83797968787123] = "CylinderMadness",
|
||||
[124045894066016] = "Octoblox",
|
||||
[87670789201977] = "iBot",
|
||||
}
|
||||
|
||||
local function headMeshFromHumanoidDescription(humDesc: HumanoidDescription): number
|
||||
for _, bodyPartDescription in humDesc:GetChildren() do
|
||||
if not bodyPartDescription:IsA("BodyPartDescription") then continue end
|
||||
|
||||
local meshName = meshByAssetId[bodyPartDescription.AssetId]
|
||||
if meshName then
|
||||
return meshByName[meshName]
|
||||
end
|
||||
|
||||
local HeadShape = bodyPartDescription.HeadShape
|
||||
|
||||
-- HACK: these heads are not fully supported yet
|
||||
if bodyPartDescription.AssetId == 77954380016578 then
|
||||
return meshByName["Hex"]
|
||||
end
|
||||
if bodyPartDescription.AssetId == 123297947692270 then
|
||||
return meshByName["Diamond"]
|
||||
end
|
||||
if bodyPartDescription.AssetId == 83797968787123 then
|
||||
return meshByName["CylinderMadness"]
|
||||
end
|
||||
if bodyPartDescription.AssetId == 124045894066016 then
|
||||
return meshByName["Octoblox"]
|
||||
end
|
||||
if bodyPartDescription.AssetId == 87670789201977 then
|
||||
return meshByName["iBot"]
|
||||
end
|
||||
|
||||
if HeadShape ~= "" then
|
||||
return meshByName[HeadShape]
|
||||
end
|
||||
|
||||
warn(`rbx-reface: head with ID {bodyPartDescription.AssetId} has no mesh equivalent - defaulting to classic head`)
|
||||
end
|
||||
return meshByName["RobloxClassic"]
|
||||
@@ -36,8 +35,10 @@ 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 currentMesh = humDesc.Head
|
||||
local targetMesh = headMeshFromHumanoidDescription(humDesc)
|
||||
local face = faceByMesh[currentMesh]
|
||||
@@ -47,7 +48,6 @@ function convert.convertCharacter(humanoid: Humanoid): ()
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
humDesc.Head = targetMesh
|
||||
humDesc.Face = face
|
||||
|
||||
@@ -60,16 +60,15 @@ function convert.convertCharacter(humanoid: Humanoid): ()
|
||||
return
|
||||
end
|
||||
|
||||
-- VERY UGLY HACK: iBot head texture workaround
|
||||
-- iBot's texture is not correctly restored
|
||||
if targetMesh == meshByName["iBot"] then
|
||||
local head = humanoid.Parent:FindFirstChild("Head")
|
||||
if head then
|
||||
(head :: MeshPart).TextureID = "rbxassetid://97292285"
|
||||
else
|
||||
warn(`rbx-reface: could not find Head part to apply iBot texture workaround`)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
return convert
|
||||
|
||||
Reference in New Issue
Block a user