local u=LoadLibrary("\082\098\120\085\116\105\108\105\116\121")History={Stack={};Index=0;Changed=u.CreateSignal()}function History.Undo()if History.Index-1<0 then return end local u=History.Stack[History.Index]u:Unapply()History.Index=History.Index-1 History.Changed:fire()end function History.Redo()if History.Index+1>#History.Stack then return end History.Index=History.Index+1 local u=History.Stack[History.Index]u:Apply()History.Changed:fire()end function History.Add(u)History.Index=History.Index+1 History.Stack[History.Index]=u for u=History.Index+1,#History.Stack,1 do History.Stack[u]=nil end History.Changed:fire()end return History

local RbxUtility = LoadLibrary 'RbxUtility';

History = {

	-- Record stack
	Stack = {},

	-- Current position in record stack
	Index = 0,

	-- History change event
	Changed = RbxUtility.CreateSignal()

};

function History.Undo()
	-- Unapplies the previous record in stack

	-- Stay within boundaries
	if History.Index - 1 < 0 then
		return;
	end;

	-- Get the history record, unapply it
	local Record = History.Stack[History.Index];
	Record:Unapply();

	-- Update the index
	History.Index = History.Index - 1;

	-- Fire the Changed event
	History.Changed:fire();

end;

function History.Redo()
	-- Applies the next record in stack

	-- Stay within boundaries
	if History.Index + 1 > #History.Stack then
		return;
	end;

	-- Update the index
	History.Index = History.Index + 1;

	-- Get the history record and apply it
	local Record = History.Stack[History.Index];
	Record:Apply();

	-- Fire the Changed event
	History.Changed:fire();

end;

function History.Add(Record)
	-- Adds new history record to stack

	-- Update the index
	History.Index = History.Index + 1;

	-- Register the new history record
	History.Stack[History.Index] = Record;

	-- Clear history ahead
	for Index = History.Index + 1, #History.Stack do
		History.Stack[Index] = nil;
	end;

	-- Fire the Changed event
	History.Changed:fire();

end;

return History;
