local P=Tool:WaitForChild("\076\105\098\114\097\114\105\101\115")local p=require(P:WaitForChild("\083\117\112\112\111\114\116\076\105\098\114\097\114\121"))local W={}W.__index=W function W.new()local P=setmetatable({},W)P.Selection=p.CloneTable(Core.Selection.Items)P.Parts=p.CloneTable(Core.Selection.Parts)P.InitialColor=p.GetMemberMap(P.Parts,"\067\111\108\111\114")P.TargetColor=nil P.InitialUnionColoring={}for p,W in pairs(P.Parts)do if W:IsA("\085\110\105\111\110\079\112\101\114\097\116\105\111\110")then P.InitialUnionColoring[W]=W.UsePartColor end end return P end function W.Unapply(P)local p={}for W,u in ipairs(P.Parts)do table.insert(p,{Part=u,Color=P.InitialColor[u];UnionColoring=P.InitialUnionColoring[u]})end Core.SyncAPI:Invoke("\083\121\110\099\067\111\108\111\114",p)Core.Selection.Replace(P.Selection)end function W.Apply(p,P)local W={}for P,u in ipairs(p.Parts)do table.insert(W,{Part=u;Color=p.TargetColor;UnionColoring=true})end Core.SyncAPI:Invoke("\083\121\110\099\067\111\108\111\114",W)if not P then Core.Selection.Replace(p.Selection)end end return W
-- Libraries
local Libraries = Tool:WaitForChild("Libraries")
local Support = require(Libraries:WaitForChild("SupportLibrary"))

local PaintHistoryRecord = {}
PaintHistoryRecord.__index = PaintHistoryRecord

function PaintHistoryRecord.new()
	local self = setmetatable({}, PaintHistoryRecord)

	-- Include selection
	self.Selection = Support.CloneTable(Core.Selection.Items)
	self.Parts = Support.CloneTable(Core.Selection.Parts)

	-- Initialize color data
	self.InitialColor = Support.GetMemberMap(self.Parts, "Color")
	self.TargetColor = nil

	-- Initialize union data
	self.InitialUnionColoring = {}
	for _, Part in pairs(self.Parts) do
		if Part:IsA("UnionOperation") then
			self.InitialUnionColoring[Part] = Part.UsePartColor
		end
	end

	-- Return new record
	return self
end

function PaintHistoryRecord:Unapply()
	local Changes = {}

	-- Assemble change list
	for _, Part in ipairs(self.Parts) do
		table.insert(Changes, {
			Part = Part,
			Color = self.InitialColor[Part],
			UnionColoring = self.InitialUnionColoring[Part],
		})
	end

	-- Push changes
	Core.SyncAPI:Invoke("SyncColor", Changes)

	-- Restore selection
	Core.Selection.Replace(self.Selection)
end

function PaintHistoryRecord:Apply(KeepSelection)
	local Changes = {}

	-- Assemble change list
	for _, Part in ipairs(self.Parts) do
		table.insert(Changes, {
			Part = Part,
			Color = self.TargetColor,
			UnionColoring = true,
		})
	end

	-- Push changes
	Core.SyncAPI:Invoke("SyncColor", Changes)

	-- Restore selection
	if not KeepSelection then
		Core.Selection.Replace(self.Selection)
	end
end

return PaintHistoryRecord
