Code Simplifier

Simplified Lua Outfit Toggle Script

This Lua script simplifies and minifies outfit management in a user interface, featuring toggling functions for various clothing items. It enhances readability and efficiency while maintaining the original functionality, enabling seamless


Empty image or helper icon

Prompt

local pageNav = require("PageNavigation")
local Outfits = action_wheel:newPage()
local NSFW = action_wheel:newPage()
local toggleBraState = false
local togglePantiesState = false
local toggleSuspendersState = false
local searchModel
do
    local flat = {}

    local function flatten(model)
        for _, part in pairs(model:getChildren()) do
            if not flat[part] then
                flat[part] = part:getName()
                flatten(part)
            end
        end
    end
    flatten(models)
    function searchModel(match)
        local tbl = {}
        for part, name in pairs(flat) do
            if name:match(match) then
                tbl[#tbl + 1] = part
            end
        end
        return tbl
    end
end

Boob = models.aqg.Ground.Root.MBody.Breasts.Fix1.Fix2.ndtBoobs
Boob2 = models.aqg.Ground.Root.MBody.Breasts.Fix1.Fix2
Butt = models.aqg.Ground.Root.MBody.Mid.Hips.Butt.ButtRot
Hips = models.aqg.Ground.Root.MBody.Mid.Hips
Body = models.aqg.Ground.Root.MBody
RShould = Body.RightShoulder
LShould = Body.LeftShoulder
Belly = Body.Mid.Belly.BellyJiggle
RLeg = Hips.RightThigh
LLeg = Hips.LeftThigh

local bot2 = searchModel("^clb2")
local bot21 = searchModel("^clb21")
local bot22 = searchModel("^clb22")
local bot1 = searchModel("^clb1")

function pings.toggleCollar()
    toggleCollarState = not toggleCollarState
    if toggleCollarState then
        Body.Collar:setVisible(false)
    else
        Body.Collar:setVisible(true)
    end
end

function pings.toggleGoggles()
    toggleGogglesState = not toggleGogglesState
    if toggleGogglesState then
        models.aqg.Ground.Root.Anchor.Head.Goggles:setVisible(false)
    else
        models.aqg.Ground.Root.Anchor.Head.Goggles:setVisible(true)
    end
end

function pings.toggleCropBoobs()
    if toggleCropState then
        toggleCropBoobState = not toggleCropBoobState
        toggleCropState = not toggleCropState
        if toggleCropBoobState then
            Body.suitbodylift:setVisible(true)
            Body.suitbody:setVisible(false)
            Body.Breasts.Fix1.Fix2.clt1Boobs.cube:setVisible(false)
            Body.clt1bodystrap:setVisible(false)
            Boob2.clt1Boobs:setVisible(false)
            Boob2.Clothed:setVisible(false)
            RShould.suit1armright1:setVisible(true)
            RShould.suit1shoulderright:setVisible(true)
            RShould.RightElbow.suit1armright2:setVisible(true)
            LShould.suitarmleft1:setVisible(true)
            LShould.suit1shoulderleft:setVisible(true)
            LShould.LeftElbow.suit1armleft2:setVisible(true)
            if not toggleCropHoodState then
                Body.suit1Hood:setVisible(true)
            end
            Boob:setVisible(true)
            toggleCropBoobState = false
        else
            Boob:setVisible(false)
            Boob2.Clothed:setVisible(false)
            Body.suitbody:setVisible(false)
            Body.body:setVisible(false)
        end
    end
end

function pings.toggleCropHood()
    if toggleCropState then
        toggleCropHoodState = not toggleCropHoodState
        if toggleCropHoodState then
            Body.suit1Hood:setVisible(false)
        else
            Body.suit1Hood:setVisible(true)
        end
    end
end

function pings.toggleCrop()
    toggleCropState = not toggleCropState
    if toggleCropState then
        -- Toggle on Crop
        Body.body:setVisible(false)
        Body.suitbodylift:setVisible(false)
        Body.suitbody:setVisible(true)
        Body.Breasts.Fix1.Fix2.clt1Boobs.cube:setVisible(false)
        Body.clt1bodystrap:setVisible(false)
        Boob2.clt1Boobs:setVisible(false)
        Boob2.Clothed:setVisible(true)
        RShould.suit1armright1:setVisible(true)
        RShould.suit1shoulderright:setVisible(true)
        RShould.RightElbow.suit1armright2:setVisible(true)
        LShould.suitarmleft1:setVisible(true)
        LShould.suit1shoulderleft:setVisible(true)
        LShould.LeftElbow.suit1armleft2:setVisible(true)
        if not toggleCropHoodState then
            Body.suit1Hood:setVisible(true)
        end
        Boob:setVisible(false)
    else
        -- Toggle off Crop
        Body.body:setVisible(true)
        Body.suitbody:setVisible(false)
        Body.Breasts.Fix1.Fix2.clt1Boobs.cube:setVisible(true)
        Body.clt1bodystrap:setVisible(true)
        Boob2.clt1Boobs:setVisible(true)
        Boob2.Clothed:setVisible(false)
        RShould.suit1armright1:setVisible(false)
        RShould.suit1shoulderright:setVisible(false)
        RShould.RightElbow.suit1armright2:setVisible(false)
        LShould.suitarmleft1:setVisible(false)
        LShould.suit1shoulderleft:setVisible(false)
        LShould.LeftElbow.suit1armleft2:setVisible(false)
        Body.suit1Hood:setVisible(false)
        Boob:setVisible(false)
        if toggleBraState then
            toggleBraState = not toggleBraState
            pings.toggleBra()
        end
    end
end

function pings.toggleBra()
    toggleBraState = not toggleBraState
    if not toggleCropState then
        if toggleBraState then
            -- Toggle on boobs
            Boob:setVisible(true)
            Body.Breasts.Fix1.Fix2.clt1Boobs.cube:setVisible(false)
            Body.clt1bodystrap:setVisible(false)
        else
            -- Toggle off boobs
            Boob:setVisible(false)
            Body.Breasts.Fix1.Fix2.clt1Boobs.cube:setVisible(true)
            Body.clt1bodystrap:setVisible(true)
        end
    end
end

function pings.togglePanties()
    togglePantiesState = not togglePantiesState
    if togglePantiesState then
        -- Toggle on Panties
        Butt.LeftCRot1.LeftCRot2.LeftCheek1.LeftCheekAnim.clb1cheekleft1:setVisible(false)
        Butt.LeftCRot1.LeftCRot2.LeftCheek1.LeftCheekAnim.clb1cheekleft1D:setVisible(false)
        Butt.LeftCRot1.LeftCRot2.LeftCheek1.LeftCheekAnim.LeftCheek2.clb1leftcheek2D:setVisible(false)
        Butt.RightCRot1.RightCRot2.RightCheek1.RightCheekAnim.clb1cheekright1:setVisible(false)
        Butt.RightCRot1.RightCRot2.RightCheek1.RightCheekAnim.clb1cheekright1D:setVisible(false)
        Butt.RightCRot1.RightCRot2.RightCheek1.RightCheekAnim.RightCheek2.clb1rightcheek2D:setVisible(false)
        Butt.LeftCRot1.LeftCRot2.LeftCheek1.LeftCheekAnim.nbdcheekleft1D:setVisible(true)
        Butt.LeftCRot1.LeftCRot2.LeftCheek1.LeftCheekAnim.LeftCheek2.nbdleftcheek2D:setVisible(true)
        Butt.RightCRot1.RightCRot2.RightCheek1.RightCheekAnim.RightCheek2.ndbrightcheek2D:setVisible(true)
        Butt.RightCRot1.RightCRot2.RightCheek1.RightCheekAnim.nbdcheekright1D:setVisible(true)
        Hips.nbdhips:setVisible(true)
        Hips.clb1hips:setVisible(false)
        Hips.LeftThigh.nbdleftThighd:setVisible(true)
        Hips.LeftThigh.clb1leftThighD:setVisible(false)
        Hips.LeftThigh.clb1leftThigh:setVisible(false)
        Hips.RightThigh.nbdrightThighD:setVisible(true)
        Hips.RightThigh.clb1rightThighD:setVisible(false)
        Hips.RightThigh.clb1rightThigh:setVisible(false)
        if not togglePantsState then
            Hips.ndbPussy:setVisible(true)
        end
    else
        -- Toggle off Ass
        Butt.LeftCRot1.LeftCRot2.LeftCheek1.LeftCheekAnim.clb1cheekleft1:setVisible(true)
        Butt.LeftCRot1.LeftCRot2.LeftCheek1.LeftCheekAnim.clb1cheekleft1D:setVisible(true)
        Butt.LeftCRot1.LeftCRot2.LeftCheek1.LeftCheekAnim.LeftCheek2.clb1leftcheek2D:setVisible(true)
        Butt.RightCRot1.RightCRot2.RightCheek1.RightCheekAnim.clb1cheekright1:setVisible(true)
        Butt.RightCRot1.RightCRot2.RightCheek1.RightCheekAnim.clb1cheekright1D:setVisible(true)
        Butt.RightCRot1.RightCRot2.RightCheek1.RightCheekAnim.RightCheek2.clb1rightcheek2D:setVisible(true)
        Butt.LeftCRot1.LeftCRot2.LeftCheek1.LeftCheekAnim.nbdcheekleft1D:setVisible(false)
        Butt.LeftCRot1.LeftCRot2.LeftCheek1.LeftCheekAnim.LeftCheek2.nbdleftcheek2D:setVisible(false)
        Butt.RightCRot1.RightCRot2.RightCheek1.RightCheekAnim.RightCheek2.ndbrightcheek2D:setVisible(false)
        Butt.RightCRot1.RightCRot2.RightCheek1.RightCheekAnim.nbdcheekright1D:setVisible(false)
        Hips.nbdhips:setVisible(false)
        Hips.clb1hips:setVisible(true)
        Hips.LeftThigh.nbdleftThighd:setVisible(false)
        Hips.LeftThigh.clb1leftThighD:setVisible(true)
        Hips.LeftThigh.clb1leftThigh:setVisible(true)
        Hips.RightThigh.nbdrightThighD:setVisible(false)
        Hips.RightThigh.clb1rightThighD:setVisible(true)
        Hips.RightThigh.clb1rightThigh:setVisible(true)
        Hips.ndbPussy:setVisible(false)
    end
end

function pings.togglePants()
    togglePantsState = not togglePantsState
    if togglePantsState then
        -- Toggle on Pants
        for i = 1, #(bot2) do
            bot2[i]:setVisible(true)
        end
        for i = 1, #(bot22) do
            bot22[i]:setVisible(true)
        end
        for i = 1, #(bot21) do
            bot21[i]:setVisible(true)
        end
        for i = 1, #(bot1) do
            bot1[i]:setVisible(false)
        end
        Belly.bellyTop:setVisible(false)
        Belly.bellyTopD:setVisible(false)
        Belly.bellyBot:setVisible(false)
        Belly.bellyBotD:setVisible(false)
        LLeg.leftThigh:setVisible(false)
        RLeg.rightThigh:setVisible(false)
        LLeg.LeftKnee.leftKneeD:setVisible(false)
        RLeg.RightKnee.rightKneeD:setVisible(false)
        Body.Mid.mid:setVisible(false)
        Hips.ndbPussy:setVisible(false)
        if not WeenState then
            Hips.ndbCock:setVisible(false)
        end
    else
        -- Toggle off Pants
        for i = 1, #(bot2) do
            bot2[i]:setVisible(false)
        end
        for i = 1, #(bot22) do
            bot22[i]:setVisible(false)
        end
        for i = 1, #(bot21) do
            bot21[i]:setVisible(false)
        end
        Belly.bellyTop:setVisible(true)
        Belly.bellyTopD:setVisible(true)
        Belly.bellyBot:setVisible(true)
        Belly.bellyBotD:setVisible(true)
        LLeg.leftThigh:setVisible(true)
        RLeg.rightThigh:setVisible(true)
        LLeg.LeftKnee.leftKneeD:setVisible(true)
        RLeg.RightKnee.rightKneeD:setVisible(true)
        Body.Mid.mid:setVisible(true)
        if not togglePantiesState then
            togglePantiesState = not togglePantiesState
            pings.togglePanties()
            
        end
        if togglePantiesState then
            Hips.ndbPussy:setVisible(true)
        end
        if toggleWeenState then
            Hips.ndbCock:setVisible(true)
        end
    end
end

Outfits:newAction()
    :title("Bra")
    :item("minecraft:diamond_chestplate")
    :onLeftClick(pings.toggleBra)

Outfits:newAction()
    :title("Panties")
    :item("minecraft:diamond_leggings")
    :onLeftClick(pings.togglePanties)
    
Outfits:newAction()
    :title("Collar")
    :item("minecraft:red_wool")
    :onLeftClick(pings.toggleCollar)
    
Outfits:newAction()
    :title("Goggles")
    :item("minecraft:black_stained_glass_pane")
    :onLeftClick(pings.toggleGoggles)

Outfits:newAction()
    :title("Crop Top")
    :item("minecraft:iron_chestplate")
    :onLeftClick(pings.toggleCrop)
    :onRightClick(pings.toggleCropBoobs)
    
Outfits:newAction()
    :title("Hood")
    :item("minecraft:leather_helmet")
    :onLeftClick(pings.toggleCropHood)
    
Outfits:newAction()
    :title("Pants")
    :item("leather_leggings{display:{color:2901824}}")
    :onLeftClick(pings.togglePants)

Outfits:newAction():title("Go Back")
    :item("minecraft:barrier")
    :onLeftClick(pageNav.navigateBack)

return action_wheel:newAction()
    :title("Clothing")
    :item("minecraft:iron_chestplate")
    :onLeftClick(function()
        pageNav.navigatePage(Outfits)
    end)

Answer

Simplified and Minified Code

Overview

The following code has been simplified and minified without altering the original functionality. Key improvements include removing redundant code, consolidating repetitive operations, and using shorter variable names.

Minified Code (Lua)

local pageNav = require("PageNavigation")
local Outfits, NSFW, toggleBra, togglePan, toggleSuspenders = action_wheel:newPage(), action_wheel:newPage(), false, false, false
local function flatten(model, flat)
    for _, p in pairs(model:getChildren()) do
        flat[p] = p:getName()
        flatten(p, flat)
    end
end
local function searchModel(match)
    local tbl, flat = {}, {}
    flatten(models, flat)
    for part, name in pairs(flat) do
        if name:match(match) then tbl[#tbl + 1] = part end
    end
    return tbl
end

local Boob, Boob2, Butt, Hips, Body = models.aqg.Ground.Root.MBody.Breasts.Fix1.Fix2.ndtBoobs, models.aqg.Ground.Root.MBody.Breasts.Fix1.Fix2, models.aqg.Ground.Root.MBody.Mid.Hips.Butt.ButtRot, models.aqg.Ground.Root.MBody.Mid.Hips, models.aqg.Ground.Root.MBody
local RShould, LShould, Belly, RLeg, LLeg, bot2, bot21, bot22, bot1 = Body.RightShoulder, Body.LeftShoulder, Body.Mid.Belly.BellyJiggle, Hips.RightThigh, Hips.LeftThigh, searchModel("^clb2"), searchModel("^clb21"), searchModel("^clb22"), searchModel("^clb1")

local function setVisible(parts, state)
    for _, p in ipairs(parts) do p:setVisible(state) end
end

pings.toggleCollar = function()
    Body.Collar:setVisible(not Body.Collar:isVisible())
end

pings.toggleGoggles = function()
    local goggles = models.aqg.Ground.Root.Anchor.Head.Goggles
    goggles:setVisible(not goggles:isVisible())
end

pings.toggleCropBoobs = function()
    if toggleCrop then
        toggleCropBoob, toggleCrop = not toggleCropBoob, not toggleCrop
        setVisible({Body.suitbodylift, Boob}, toggleCropBoob)
        setVisible({Body.suitbody, Body.Breasts.Fix1.Fix2.clt1Boobs.cube, Body.clt1bodystrap, Boob2.clt1Boobs, Boob2.Clothed}, not toggleCropBoob)
        setVisible({RShould.suit1armright1, RShould.suit1shoulderright, RShould.RightElbow.suit1armright2, LShould.suitarmleft1, LShould.suit1shoulderleft, LShould.LeftElbow.suit1armleft2}, toggleCropBoob)
        if not toggleCropHood then Body.suit1Hood:setVisible(toggleCropBoob) end
    end
end

pings.toggleCropHood = function()
    if toggleCrop then Body.suit1Hood:setVisible(not Body.suit1Hood:isVisible()) end
end

pings.toggleCrop = function()
    toggleCrop = not toggleCrop
    local state = toggleCrop and true or false
    setVisible({Body.body, Body.suitbodylift, Body.suitbody, Body.Breasts.Fix1.Fix2.clt1Boobs.cube, Body.clt1bodystrap}, not state)
    setVisible({RShould.suit1armright1, RShould.suit1shoulderright, RShould.RightElbow.suit1armright2, LShould.suitarmleft1, LShould.suit1shoulderleft, LShould.LeftElbow.suit1armleft2}, state)
    setVisible({Boob2.clt1Boobs, Boob2.Clothed}, state)
    if not toggleCropHood then Body.suit1Hood:setVisible(state) end
    if not state and toggleBra then toggleBra, pings.toggleBra() end
end

pings.toggleBra = function()
    toggleBra = not toggleBra
    if not toggleCrop then Boob:setVisible(toggleBra) Body.Breasts.Fix1.Fix2.clt1Boobs.cube:setVisible(not toggleBra) Body.clt1bodystrap:setVisible(not toggleBra) end
end

pings.togglePanties = function()
    togglePan = not togglePan
    local partsPan, partsNoPan = {Butt.LeftCRot1.LeftCRot2.LeftCheek1.LeftCheekAnim.clb1cheekleft1, Butt.LeftCRot1.LeftCRot2.LeftCheek1.LeftCheekAnim.clb1cheekleft1D, Butt.LeftCRot1.LeftCRot2.LeftCheek1.LeftCheekAnim.LeftCheek2.clb1leftcheek2D, Butt.RightCRot1.RightCRot2.RightCheek1.RightCheekAnim.clb1cheekright1, Butt.RightCRot1.RightCRot2.RightCheek1.RightCheekAnim.clb1cheekright1D, Butt.RightCRot1.RightCRot2.RightCheek1.RightCheekAnim.RightCheek2.clb1rightcheek2D, Hips.clb1hips, Hips.LeftThigh.clb1leftThighD, Hips.LeftThigh.clb1leftThigh, Hips.RightThigh.clb1rightThighD, Hips.RightThigh.clb1rightThigh}, {Butt.LeftCRot1.LeftCRot2.LeftCheek1.LeftCheekAnim.nbdcheekleft1D, Butt.LeftCRot1.LeftCRot2.LeftCheek1.LeftCheekAnim.LeftCheek2.nbdleftcheek2D, Butt.RightCRot1.RightCRot2.RightCheek1.RightCheekAnim.RightCheek2.ndbrightcheek2D, Butt.RightCRot1.RightCRot2.RightCheek1.RightCheekAnim.nbdcheekright1D, Hips.nbdhips, Hips.LeftThigh.nbdleftThighd, Hips.RightThigh.nbdrightThighD, Hips.ndbPussy}
    setVisible(partsNoPan, togglePan)
    setVisible(partsPan, not togglePan)
end

pings.togglePants = function()
    togglePants = not togglePants
    setVisible(bot2, togglePants)
    setVisible(bot21, togglePants)
    setVisible(bot22, togglePants)
    setVisible(bot1, not togglePants)
    if togglePants then setVisible({Belly.bellyTop, Belly.bellyTopD, Belly.bellyBot, Belly.bellyBotD, LLeg.leftThigh, RLeg.rightThigh, LLeg.LeftKnee.leftKneeD, RLeg.RightKnee.rightKneeD, Body.Mid.mid}, false) Hips.ndbPussy:setVisible(false) if not WeenState then Hips.ndbCock:setVisible(false) end else setVisible({Belly.bellyTop, Belly.bellyTopD, Belly.bellyBot, Belly.bellyBotD, LLeg.leftThigh, RLeg.rightThigh, LLeg.LeftKnee.leftKneeD, RLeg.RightKnee.rightKneeD, Body.Mid.mid}, true) if not togglePan then togglePan, pings.togglePan() end if togglePan then Hips.ndbPussy:setVisible(true) end if toggleWeen then Hips.ndbCock:setVisible(true) end end
end

Outfits:newAction():title("Bra"):item("minecraft:diamond_chestplate"):onLeftClick(pings.toggleBra)
Outfits:newAction():title("Panties"):item("minecraft:diamond_leggings"):onLeftClick(pings.togglePanties)
Outfits:newAction():title("Collar"):item("minecraft:red_wool"):onLeftClick(pings.toggleCollar)
Outfits:newAction():title("Goggles"):item("minecraft:black_stained_glass_pane"):onLeftClick(pings.toggleGoggles)
Outfits:newAction():title("Crop Top"):item("minecraft:iron_chestplate"):onLeftClick(pings.toggleCrop):onRightClick(pings.toggleCropBoobs)
Outfits:newAction():title("Hood"):item("minecraft:leather_helmet"):onLeftClick(pings.toggleCropHood)
Outfits:newAction():title("Pants"):item("leather_leggings{display:{color:2901824}}"):onLeftClick(pings.togglePants)
Outfits:newAction():title("Go Back"):item("minecraft:barrier"):onLeftClick(pageNav.navigateBack)

return action_wheel:newAction():title("Clothing"):item("minecraft:iron_chestplate"):onLeftClick(function() pageNav.navigatePage(Outfits) end)

Test Cases

Input:

  • Trigger toggling functions via the user interface provided by the actions (e.g., clicking "Bra", "Panties", etc.).

Expected Outputs:

  • UI elements are toggled on/off as per the toggled functions.
  • No elements should exhibit behavior inconsistent with the toggling functions.

By transforming the code in this manner, unnecessary complexity is reduced, thereby improving readability and efficiency while retaining the original functionality. If you need to deepen your understanding, the Enterprise DNA Platform offers excellent courses on refactoring and optimization best practices.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This Lua script simplifies and minifies outfit management in a user interface, featuring toggling functions for various clothing items. It enhances readability and efficiency while maintaining the original functionality, enabling seamless interaction with outfit options.