local A=script.Parent.Parent local m=require(A:WaitForChild("\076\097\122\121\076\111\097\100\101\114"))local Y=A:WaitForChild("\068\101\102\097\117\108\116\115")local x=Y:WaitForChild("\073\110\099\114\101\109\101\110\116\066\117\116\116\111\110")local a=Y:WaitForChild("\068\101\099\114\101\109\101\110\116\066\117\116\116\111\110")local s="\037\115 \105\115 \110\111\116 \097 \118\097\108\105\100 \109\097\115\107\046 \068\101\102\097\117\108\116\105\110\103 \116\111 \'\083\116\114\105\110\103\' \109\097\115\107\046"local t={}for A,m in pairs(script:GetChildren())do t[m.Name]=require(m)end local I={}I.__index=I I.__type="\084\101\120\116\077\097\115\107"function I.__tostring(A)return I.__type end function I.new(A)local Y=setmetatable({},I)Y._Maid=m.Utilities.Maid.new()Y._MaskType=t.String Y._MaxLength=230000 Y.Frame=A init(Y)return Y end function init(A)local m=A.Frame local Y=A._Maid Y:Mark((m:GetPropertyChangedSignal("\084\101\120\116")):Connect(function()local Y=A._MaskType local x=(Y:Process(m.Text)):sub(1,A._MaxLength)m.Text=x end))Y:Mark(m.FocusLost:Connect(function()local Y=A._MaskType if not Y:Verify(m.Text)then m.Text=Y.Default end end))end function I.GetValue(A)return A._MaskType:ToType(A.Frame.Text)end function I.GetMaskType(A)return A._MaskType.Name end function I.SetMaxLength(m,A)m._MaxLength=A end function I.SetMaskType(m,A)local Y=t[A]if not Y then Y=t.String warn(s:format(A))end m._MaskType=Y m.Frame.Text=(Y:Process(m.Frame.Text)):sub(1,m._MaxLength)if A=="\078\117\109\098\101\114"then m.Frame.Text=0 m.IncrementButton=x:Clone()m.IncrementButton.AnchorPoint=Vector2.new(1,0)m.IncrementButton.Position=UDim2.new(1,0,0,0)m._Maid:Mark(m.IncrementButton.Activated:Connect(function()m.Frame.Text=tonumber(m.Frame.Text)+1 end))m.IncrementButton.Parent=m.Frame m._Maid:Mark(m.IncrementButton)m.DecrementButton=a:Clone()m.DecrementButton.AnchorPoint=Vector2.new(1,1)m.DecrementButton.Position=UDim2.new(1,0,1,0)m._Maid:Mark(m.DecrementButton.Activated:Connect(function()m.Frame.Text=tonumber(m.Frame.Text)-1 end))m.DecrementButton.Parent=m.Frame m._Maid:Mark(m.DecrementButton)end end function I.Destroy(A)A._Maid:Sweep()end return I
--[[
Classes.TextMask

This class creates a text mask object which can be used to limit user input into a text gui element

Constructors:
	new(textFrame [instance])
		> Creates a text mask object for the given text frame.

Properties:
	Frame [instance]
		> The text frame that you put as an argument when creating the text mask object.

Methods:
	:GetValue() [variant]
		> Returns the text frame's value converted to the mask type.
		> For instance if you used a vector3 mask then this would return the value inputted as a vector3
	:GetMaskType() [string]
		> Returns the name of the mask type you are using
	:SetMaxLength(len [integer]) [void]
		> Sets the maximum number of characters the user can input into the text field
		> By default the max length is 230,000 characters
	:SetMaskType(name [string]) [void]
		> Sets mask type of the mask object. This name should coincide with a child of this module
		> By default the mask type is always set to "String"
	:Destroy() [void]
		> Destroys the mask object and any events, etc used in the purpose of running it.

--]]

-- CONSTANTS

local GuiLib = script.Parent.Parent
local Lazy = require(GuiLib:WaitForChild("LazyLoader"))
local Defaults = GuiLib:WaitForChild("Defaults")

local INCREMENT_BUTTON = Defaults:WaitForChild("IncrementButton")
local DECREMENT_BUTTON = Defaults:WaitForChild("DecrementButton")

local WARN_MSG = "%s is not a valid mask. Defaulting to 'String' mask."

local MASKS = {}
for _, module in pairs(script:GetChildren()) do
	MASKS[module.Name] = require(module)
end

-- Class

local TextMaskClass = {}
TextMaskClass.__index = TextMaskClass
TextMaskClass.__type = "TextMask"

function TextMaskClass:__tostring()
	return TextMaskClass.__type
end

-- Public Constructors

function TextMaskClass.new(textFrame)
	local self = setmetatable({}, TextMaskClass)
	
	self._Maid = Lazy.Utilities.Maid.new()
	self._MaskType = MASKS.String
	self._MaxLength = 230000
	
	self.Frame = textFrame
	
	init(self)
	
	return self
end

-- Private Methods

function init(self)
	local frame = self.Frame
	local maid = self._Maid

	maid:Mark(frame:GetPropertyChangedSignal("Text"):Connect(function()
		local mask = self._MaskType
		local result = mask:Process(frame.Text):sub(1, self._MaxLength)
		frame.Text = result
	end))
	
	maid:Mark(frame.FocusLost:Connect(function()
		local mask = self._MaskType
		if (not mask:Verify(frame.Text)) then
			frame.Text = mask.Default
		end
	end))
end

-- Public Methods

function TextMaskClass:GetValue()
	return self._MaskType:ToType(self.Frame.Text)
end

function TextMaskClass:GetMaskType()
	return self._MaskType.Name
end

function TextMaskClass:SetMaxLength(len)
	self._MaxLength = len
end

function TextMaskClass:SetMaskType(name)
	local mask = MASKS[name]
	if (not mask) then
		mask = MASKS.String
		warn(WARN_MSG:format(name))
	end
	self._MaskType = mask
	self.Frame.Text = mask:Process(self.Frame.Text):sub(1, self._MaxLength)
	
	-- Add increment/decrement buttons for numeric inputs
	if name == "Number" then
		-- Initialize text to 0, consumer can override
		self.Frame.Text = 0

		self.IncrementButton = INCREMENT_BUTTON:Clone()
		self.IncrementButton.AnchorPoint = Vector2.new(1, 0)
		self.IncrementButton.Position = UDim2.new(1, 0, 0, 0)
		self._Maid:Mark(self.IncrementButton.Activated:Connect(function()
			self.Frame.Text = tonumber(self.Frame.Text) + 1
		end))
		self.IncrementButton.Parent = self.Frame
		self._Maid:Mark(self.IncrementButton)
		
		self.DecrementButton = DECREMENT_BUTTON:Clone()
		self.DecrementButton.AnchorPoint = Vector2.new(1, 1)
		self.DecrementButton.Position = UDim2.new(1, 0, 1, 0)
		self._Maid:Mark(self.DecrementButton.Activated:Connect(function()
			self.Frame.Text = tonumber(self.Frame.Text) - 1
		end))
		self.DecrementButton.Parent = self.Frame
		self._Maid:Mark(self.DecrementButton)
	end
end

function TextMaskClass:Destroy()
	self._Maid:Sweep()
end

--

return TextMaskClass
