--Rename SRB2 Sprites SLADE script by SMS Alfredo local ROTATION_NONE = 0 local ROTATION_FIVE = 1 local ROTATION_EIGHT = 2 local ROTATION_L = 3 local ROTATION_LR = 4 local ROTATION_R = 5 local ROTATION_RL = 6 local ROTATION_FOUR = 7 local ROTATION_NINE = 8 local ROTATION_NINE_ALT = 9 local ROTATION_SIXTEEN = 10 local ROTATION_SIXTEEN_ALT = 11 local ROTATIONS = { [ROTATION_NONE] = {"0"}, [ROTATION_FIVE] = {"1", "28", "37", "46", "5"}, [ROTATION_EIGHT] = {"1", "2", "3", "4", "5", "6", "7", "8"}, [ROTATION_L] = {"LR"}, [ROTATION_LR] = {"L", "R"}, [ROTATION_R] = {"RL"}, [ROTATION_RL] = {"R", "L"}, [ROTATION_FOUR] = {"0", "37", "46", "5"}, [ROTATION_NINE] = {"1", "9G", "28", "AF", "37", "BE", "46", "CD", "5"}, [ROTATION_NINE_ALT] = {"1", "28", "37", "46", "5", "9G", "AF", "BE", "CD"}, [ROTATION_SIXTEEN] = {"1", "9", "2", "A", "3", "B", "4", "C", "5", "D", "6", "E", "7", "F", "8", "G"}, [ROTATION_SIXTEEN_ALT] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G"}, } local FRAMES = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz!@" local FRAME_CONVERTER = {} for i = 1, #FRAMES do local frame = FRAMES:sub(i,i) FRAME_CONVERTER[frame] = i - 1 FRAME_CONVERTER[i - 1] = frame end local WALK_NONE = 0 local WALK_FULL = 1 local WALK_SYM = 2 local WALK_SONIC = 3 --Check entries local entries = App.CurrentEntrySelection() if #entries == 0 then UI.MessageBox("Invalid sprite selection", "You need to select some sprites first!") return end --Get name local spritename = UI.PromptString("Enter a sprite name", "Please enter a four letter name to use for the sprites.", "XXXX") if #spritename ~= 4 then UI.MessageBox("Invalid length", "The name needs to be four letters long!") return end --Get letter offset local letteroffset = UI.PromptString("Enter letter offset", "Please enter a single letter to use as the starting frame letter.\nValid entries are A-Z, 0-9, a-z, !, and @.", "A") letteroffset = FRAME_CONVERTER[letteroffset] if letteroffset == nil then UI.MessageBox("Invalid letter", "That's not a valid frame letter!") return end --Get rotation type local rotationtype = UI.PromptNumber("Enter rotation type", "Enter rotation type." .."\n0 = None" .."\n1 = 8-Angled Symmetrical (Default)\n2 = 8-Angled Asymmetrical" .."\n3 = LR Symmetrical\n4 = LR Asymmetrical" .."\n5 = RL Symmetrical\n6 = RL Asymmetrical" .."\n7 = No Front Diagonal Symmetrical" .."\n8 = 16-Angled Symmetrical\n9 = 16-Angled Symmetrical (Alt)" .."\n10 = 16-Angled Asymmetrical\n11 = 16-Angled Asymmetrical (Alt)", ROTATION_FIVE, ROTATION_NONE, #ROTATIONS - 1) local rotationnumbers = ROTATIONS[rotationtype] if rotationnumbers == nil then UI.MessageBox("Invalid rotation type", "That's not a valid rotation type!") return end --Get walk mode local walkmode = WALK_NONE if (#rotationnumbers & 1) ~= 0 and #rotationnumbers ~= 1 then walkmode = UI.PromptNumber("Enter walk mode", "Enter walk naming mode.\n0 = None (Default)\n1 = Full\n2 = Front and Back Symmetrical\n3 = Back Symmetrical Only", WALK_NONE, WALK_NONE, WALK_SONIC) end if walkmode < WALK_NONE or walkmode > WALK_SONIC then UI.MessageBox("Invalid walk mode", "That's not a valid walk mode!") return end --Get naming style local rotfirst = true if #rotationnumbers ~= 1 then rotfirst = UI.PromptYesNo("Set naming style", "Would you like to count up the rotation numbers first? (A1 -> A2A8)\nOtherwise the frame letters will count up first. (A1 -> B1)") end --Get number of frames local totalframes = #FRAMES - letteroffset if walkmode ~= WALK_NONE or not rotfirst then local default = math.ceil(#entries / #rotationnumbers) if default < 1 or default > totalframes then default = 1 end totalframes = UI.PromptNumber("Enter total number of frames", "Enter how many lettered frames you're going to name.", default, 1, totalframes) end --Set up loop variables local framenum = 0 local rotnum = 0 --Iterate through entries for i, entry in ipairs(entries) do local newname local loop = true if not entry then break end while loop do loop = false newname = spritename local frame = FRAME_CONVERTER[framenum + letteroffset] local rotation = rotationnumbers[rotnum + 1] if frame == nil then UI.MessageBox("Error", "The frame count broke somehow! Maybe you selected too many sprites?") return elseif rotation == nil then UI.MessageBox("Error", "The rotation count broke somehow! Maybe you selected too many sprites?") return end --Set up the first part of frame name newname = newname..frame..rotation:sub(1,1) --Set up the second part if we can --Walk mode can potentially skip frames here setting loop to true local frontwalk = walkmode == WALK_SYM and rotation == "1" local backwalk = walkmode >= WALK_SYM and rotation == "5" if walkmode ~= WALK_NONE and framenum >= totalframes/2 and (frontwalk or backwalk) then loop = true elseif #rotation > 1 or frontwalk or backwalk then if walkmode ~= WALK_NONE then local newframe = (framenum + totalframes/2) % totalframes frame = FRAME_CONVERTER[newframe + letteroffset] if frame == nil then UI.MessageBox("Error", "Walk mode broke somehow! Maybe you entered the wrong number of frames?") return end end newname = newname..frame..rotation:sub(#rotation,#rotation) end --Increase loop variables if rotfirst then --Increase rotation rotnum = rotnum + 1 --Reset rotation and increase the frame above the rotation max if rotnum >= #rotationnumbers then rotnum = 0 --Reset rotation framenum = framenum + 1 --Increase frame if framenum >= totalframes then framenum = 0 --Reset frame end end else --Increase frame framenum = framenum + 1 --Reset frame and increase the rotation above the frame max if framenum >= totalframes then framenum = 0 --Reset frame rotnum = rotnum + 1 -- Increase rotation if rotnum >= #rotationnumbers then rotnum = 0 --Reset rotation --Increase letteroffset for next frame set! letteroffset = math.min(letteroffset + totalframes, #FRAMES) end end end end --Add entry extension local extension = entry.type and entry.type.extension if extension then newname = newname.."."..extension end --Rename the entry! entry:Rename(newname) end