local R=(require(((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\083\099\114\105\112\116\115")):WaitForChild("\067\111\110\115\111\108\101"))).sourced("\086\101\099\116\111\114 \077\111\110\105\116\111\114")R.log("\076\111\097\100\105\110\103 \100\101\112\101\110\100\101\110\099\105\101\115\046\046\046")local s=require(script.Parent)local t=require(script.Parent:WaitForChild("\065\120\105\115\077\111\110\105\116\111\114"))local W=require(script.Parent.Parent:WaitForChild("\073\110\112\117\116\084\121\112\101"))local V=require(script.Parent.Parent:WaitForChild("\086\101\099\116\111\114\068\105\114\101\099\116\105\111\110"))R.log("\073\110\105\116\105\097\108\105\122\105\110\103 \099\111\110\115\116\097\110\116\115\046\046\046")local H={[V.Vertical]=Vector2.new(0,1);[V.Horizontal]=Vector2.new(1,0)}R.log("\073\110\105\116\105\097\108\105\122\105\110\103 \118\097\114\105\097\098\108\101\115\046\046\046")local Y=s.new()R.log("\067\111\110\115\116\114\117\099\116\105\110\103 \111\098\106\101\099\116\115\046\046\046")Y.__index=Y function Y.new()local R=setmetatable({},Y)return R end function Y.transformValue(t,R,s)local Y=R.Type local k=R.Offset or Vector2.new(0,0)if Y==W.None or Y==W.Keyboard or Y==W.MouseButton or Y==W.GamepadButton then return(s and Vector2.new(0,1)or Vector2.new(0,0))+k,1 elseif Y==W.MouseMovement or Y==W.GamepadDirection then if R.Code==Enum.KeyCode.ButtonL2 or R.Code==Enum.KeyCode.ButtonR2 then return Vector2.new(0,s.Z)+k,1 else return Vector2.new(s.X,s.Y)+k,1 end elseif Y==W.Scheme then local s=Vector2.new(0,0)for t,W in pairs(V)do local V=R.Code[t]s=s+H[W]*V:Update()end return s+k,1 end return Vector2.new(0,0),1 end function Y.addValue(t,R,s)return R+s end function Y.scaleValue(t,R,s)return R/s end function Y.nullValue(R)return Vector2.new(0,0)end function Y.processEntry(s,R)if R.Type==W.Scheme then local s=R.Code R.Code={}for W,V in pairs(V)do if s.ControlSet[W]~=nil then local V=t.new()V:Bind(s.ControlSet[W])R.Code[W]=V end end end end function Y.clean(R) end R.log("\068\111\110\101\046")return Y.new()
--- A Monitor with an vector value.
-- Provides a two dimensional vector value for the Control being activated.
--
-- @author LastTalon
-- @version 0.1.1, 2020-10-01
-- @since 0.1
--
-- @module VectorMonitor

local Console = require(game:GetService("ReplicatedStorage"):WaitForChild("Scripts"):WaitForChild("Console")).sourced("Vector Monitor")

-- Dependencies --
Console.log("Loading dependencies...")

local Monitor = require(script.Parent)
local AxisMonitor = require(script.Parent:WaitForChild("AxisMonitor"))
local InputType = require(script.Parent.Parent:WaitForChild("InputType"))
local Direction = require(script.Parent.Parent:WaitForChild("VectorDirection"))

-- Constants --
Console.log("Initializing constants...")

-- Direction vectors
local directional_value = {
	[Direction.Vertical] = Vector2.new(0, 1),
	[Direction.Horizontal] = Vector2.new(1, 0)
}

-- Variables --
Console.log("Initializing variables...")

local VectorMonitor = Monitor.new()

-- Local Objects --
Console.log("Constructing objects...")

VectorMonitor.__index = VectorMonitor

--- The default constructor.
--
-- @return the new VectorMonitor
function VectorMonitor.new()
	local self = setmetatable({}, VectorMonitor)
	return self
end

--- Transforms the value to a Vector2.
-- For most binary InputTypes true is transformed to (0, 1) and false
-- transformed to (0, 0). For vector InputTypes the Vector3 is transformed to
-- Vector2 with the axes being dropped depending on the InputType. For scheme
-- InputTypes the scheme's Monitor is updated and the value retrieved. An
-- offset is applied to all InputTypes and all InputTypes get an equal scale.
--
-- @param input the input that produced the value being transformed
-- @param value the value being transformed
-- @return the transformed value. A Vector2.
-- @return the scaling factor. Always 1, all scaling is even.
function VectorMonitor:transformValue(input, value)
	local type = input.Type
	local offset = (input.Offset or Vector2.new(0, 0))
	if type == InputType.None or type == InputType.Keyboard or type == InputType.MouseButton or type == InputType.GamepadButton then
		return ((value and Vector2.new(0, 1)) or Vector2.new(0, 0)) + offset, 1
	elseif type == InputType.MouseMovement or type == InputType.GamepadDirection then
		if input.Code == Enum.KeyCode.ButtonL2 or input.Code == Enum.KeyCode.ButtonR2 then
			return Vector2.new(0, value.Z) + offset, 1
		else
			return Vector2.new(value.X, value.Y) + offset, 1
		end
	elseif type == InputType.Scheme then
		local schemeValue = Vector2.new(0, 0)
		for id, enum in pairs(Direction) do
			local monitor = input.Code[id]
			schemeValue = schemeValue + (directional_value[enum] * monitor:Update())
		end
		return schemeValue + offset, 1
	end
	return Vector2.new(0, 0), 1
end

--- Adds two vector values together.
-- Combines the values using vector addition.
--
-- @param lhs the left hand side operand of the add operation
-- @param rhs the right hand side operand of the add operation
-- @return the added value.
function VectorMonitor:addValue(original, new)
	return original + new
end

--- Scales an Input's value by a scaling factor.
-- Scales using scalar division.
--
-- @param value the value to be scaled
-- @param scale the scaling factor
-- @return the scaled value
function VectorMonitor:scaleValue(value, scale)
	return value / scale
end

--- Gets the default value of (0, 0) for a VectorMonitor.
--
-- @return the default value. Always (0, 0).
function VectorMonitor:nullValue()
	return Vector2.new(0, 0)
end

--- Creates a Monitor for any entries with axis schemes.
--
-- @param entry the entry to process
function VectorMonitor:processEntry(entry)
	if entry.Type == InputType.Scheme then
		local scheme = entry.Code
		entry.Code = {}
		for id, _ in pairs(Direction) do
			if scheme.ControlSet[id] ~= nil then
				local monitor = AxisMonitor.new()
				monitor:Bind(scheme.ControlSet[id])
				entry.Code[id] = monitor
			end
		end
	end
end

--- Does no cleaning.
-- VectorMonitor keeps no special state, so no special cleaning is needed.
function VectorMonitor:clean()
end

-- End --
Console.log("Done.")

return VectorMonitor.new()
