local x=script.Parent.Parent local C=require(x:WaitForChild("\076\097\122\121\076\111\097\100\101\114"))local I="\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 N=C.Classes.Children.TextMask local X={}X.__index=X X.__type="\084\101\120\116\077\097\115\107"function X.__tostring(x)return X.__type end function X.new(x)local I=setmetatable({},X)I._Maid=C.Utilities.Maid.new()I._MaskType=N.String I._MaxLength=230000 I.Frame=x init(I)return I end function init(x)local C=x.Frame local I=x._Maid I:Mark((C:GetPropertyChangedSignal("\084\101\120\116")):Connect(function()local I=x._MaskType local N=(I:Process(C.Text)):sub(1,x._MaxLength)C.Text=N end))I:Mark(C.FocusLost:Connect(function()local I=x._MaskType if not I:Verify(C.Text)then C.Text=I.Default end end))end function X.GetValue(x)return x._MaskType:ToType(x.Frame.Text)end function X.GetMaskType(x)return x._MaskType.Name end function X.SetMaxLength(C,x)C._MaxLength=x end function X.SetMaskType(C,x)local X=N[x]if not X then X=N.String warn(I:format(x))end C._MaskType=X C.Frame.Text=(X:Process(C.Frame.Text)):sub(1,C._MaxLength)end function X.Destroy(x)x._Maid:Sweep()end return X
--[[
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 WARN_MSG = "%s is not a valid mask. Defaulting to 'String' mask."

local MASKS = Lazy.Classes.Children.TextMask

-- 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)
end

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

--

return TextMaskClass
