Quantcast

some tag stuff from sortokk

Darth Predator [04-09-17 - 07:22]
some tag stuff from sortokk
Filename
ElvUI_SLE/libs/LibKitUITags-1.0/LibTitTags-1.0.lua
ElvUI_SLE/libs/LibKituiConditions-1.0/LibKituiConditions-1.0.lua
ElvUI_SLE/libs/load_libs.xml
diff --git a/ElvUI_SLE/libs/LibKitUITags-1.0/LibTitTags-1.0.lua b/ElvUI_SLE/libs/LibKitUITags-1.0/LibTitTags-1.0.lua
new file mode 100644
index 0000000..9679a30
--- /dev/null
+++ b/ElvUI_SLE/libs/LibKitUITags-1.0/LibTitTags-1.0.lua
@@ -0,0 +1,78 @@
+local MAJOR_VERSION = "LibKitUITags-1.0"
+local MINOR_VERSION = 1
+
+if not LibStub then error(MAJOR_VERSION .. " requires LibStub") end
+
+local KitLib, oldLib = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
+if not KitLib then return end
+
+local pairs, ipairs = pairs, ipairs
+
+KitLib.registeredTags = {};
+KitLib.registeredEvents = {};
+KitLib.registeredTagStrings = {};
+
+function KitLib:RegisterTag(tag, updateFunc, ...)
+	local events = { ... };
+	KitLib.registeredTags[tag] = { updateFunc = updateFunc, events = events };
+	for i, event in ipairs(events) do
+		if (not KitLib.registeredEvents[event]) then
+			KitLib.driverFrame:RegisterEvent(event);
+			KitLib.registeredEvents[event] = 0;
+		end
+		KitLib.registeredEvents[event] = KitLib.registeredEvents[event] + 1;
+	end
+end
+
+function KitLib:UnregisterTag(tag)
+	if (not KitLib.registeredTags[tag]) then return end
+	local events = KitLib.registeredTags[tag].events;
+	for i, event in ipairs(events) do
+		KitLib.registeredEvents[event] = KitLib.registeredEvents[event] - 1;
+		if (KitLib.registeredEvents[event] == 0) then
+			KitLib.driverFrame:UnregisterEvent(event);
+			KitLib.registeredEvents[event] = nil;
+		end
+	end
+	KitLib.registeredTags[tag] = nil;
+end
+
+function KitLib:RegisterFontString(key, fs)
+	if (not KitLib.registeredTagStrings[key]) then
+		KitLib.registeredTagStrings[key] = {};
+	end
+	KitLib.registeredTagStrings[key].fs = fs;
+end
+
+function KitLib:UnregisterFontString(key)
+	KitLib.registeredTagStrings[key] = nil;
+end
+
+function KitLib:Tag(key, tagStr)
+	if (not KitLib.registeredTagStrings[key]) then return end
+	KitLib.registeredTagStrings[key].backingText = tagStr;
+	KitLib:UpdateTagStrings();
+end
+
+KitLib.driverFrame = CreateFrame("Frame");
+KitLib.driverFrame:SetScript("OnEvent", function(self, event, ...)
+	KitLib:UpdateTagStrings();
+end)
+
+local CurrentFS;
+KitLib.tagDirector = {};
+setmetatable(KitLib.tagDirector, {
+	__index = function(table, key)
+		if (KitLib.registeredTags[key]) then
+			return KitLib.registeredTags[key].updateFunc(CurrentFS);
+		end
+		return nil;
+	end,
+});
+
+function KitLib:UpdateTagStrings(event)
+	for k, v in pairs(KitLib.registeredTagStrings) do
+		CurrentFS = v.fs;
+		v.fs:SetText(v.backingText:gsub('%[([^%]]+)%]', KitLib.tagDirector));
+	end
+end
\ No newline at end of file
diff --git a/ElvUI_SLE/libs/LibKituiConditions-1.0/LibKituiConditions-1.0.lua b/ElvUI_SLE/libs/LibKituiConditions-1.0/LibKituiConditions-1.0.lua
new file mode 100644
index 0000000..21f1892
--- /dev/null
+++ b/ElvUI_SLE/libs/LibKituiConditions-1.0/LibKituiConditions-1.0.lua
@@ -0,0 +1,87 @@
+local MAJOR_VERSION = "LibKitUIConditions-1.0"
+local MINOR_VERSION = 1
+
+if not LibStub then error(MAJOR_VERSION .. " requires LibStub") end
+
+local KitLib, oldLib = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
+if not KitLib then return end
+
+local unpack, tinsert, pairs = unpack, tinsert, pairs
+local strsub, strlen = strsub, strlen
+
+KitLib.registeredConditions = {};
+
+function KitLib:RegisterCondition(tag, numArguments, validationFunc)
+	if (self.registeredConditions[tag]) then return end
+	self.registeredConditions[tag] = { numArguments = numArguments, validationFunc = validationFunc };
+	self.registeredConditions[tag].matchStr = self:BuildConditionMatch(tag);
+	self.registeredConditions[tag].negateMatchStr = strsub(self.registeredConditions[tag].matchStr,1,2) .. "no" .. strsub(self.registeredConditions[tag].matchStr,3,strlen(self.registeredConditions[tag].matchStr) - 2);
+end
+
+function KitLib:UnregisterCondition(tag)
+	self.registeredConditions[tag] = nil;
+end
+
+function KitLib:BuildConditionMatch(tag)
+	local info = self.registeredConditions[tag];
+	if (not info) then return end
+
+	local matchStr = "%["..tag;
+	if (info.numArguments > 0) then
+		for i = 1, info.numArguments do
+			local sep = ":";
+			if (i > 1) then
+				sep = "/";
+			end
+			matchStr = matchStr .. sep .. "([^/%]]+)";
+		end
+	end
+	matchStr = matchStr .. "%]";
+	return matchStr;
+end
+
+function KitLib:EvaluateConditionString(conditionString)
+	for k, v in pairs(self.registeredConditions) do
+		if (conditionString:match(v.matchStr)) then
+			local args = { conditionString:match(v.matchStr) };
+			if (not v.validationFunc(unpack(args))) then
+				return false;
+			end
+		elseif (conditionString:match(v.negateMatchStr)) then
+			local args = { conditionString:match(v.negateMatchStr) };
+			if (v.validationFunc(unpack(args))) then
+				return false;
+			end
+		end
+	end
+
+	return true;
+end
+
+function KitLib:GetTagsFromConditionString(conditionString)
+	local tagsFound = {};
+	for k, v in pairs(self.registeredConditions) do
+		if (conditionString:match(v.matchStr)) then
+			tinsert(tagsFound, k);
+		end
+	end
+	return tagsFound;
+end
+
+-- function KTValidate(arg)
+	-- if (tonumber(arg) == 77) then
+		-- return true;
+	-- else
+		-- return false;
+	-- end
+-- end
+
+-- function KitTest()
+	-- KitLib:RegisterCondition("test", 1, KTValidate);
+	-- assert(KitLib:EvaluateConditionString("[test:77]"));
+	-- assert(not KitLib:EvaluateConditionString("[notest:77]"));
+	-- assert(not KitLib:EvaluateConditionString("[test:82]"));
+	-- assert(KitLib:EvaluateConditionString("[notest:82]"));
+	-- print("All tests passed");
+	-- KitLib:UnregisterCondition("test");
+-- end
\ No newline at end of file
diff --git a/ElvUI_SLE/libs/load_libs.xml b/ElvUI_SLE/libs/load_libs.xml
index 5fcda03..b5a6472 100644
--- a/ElvUI_SLE/libs/load_libs.xml
+++ b/ElvUI_SLE/libs/load_libs.xml
@@ -1 +1 @@
-<Ui xmlns="http://www.blizzard.com/wow/ui/">
	<Script file="AceAddon-3.0\AceAddon-3.0.lua"/>
	<Script file="AceConsole-3.0\AceConsole-3.0.lua"/>
	<Include file="LibTourist-3.0\lib.xml" />
	<Script file="AceDB-3.0\AceDB-3.0.lua"/>
	<Include file="LibElv-UIButtons-1.0\load_uibuttons.xml"/>
	<Include file="LibElv-GameMenu-1.0\LibElv-GameMenu-1.0.lua"/>
	<Script file="LibAnim\LibAnim.lua"/>
	<Script file="LibQTip-1.0\LibQTip-1.0.lua"/>
	<Script file="LibRangeCheck-2.0\LibRangeCheck-2.0.lua"/>
	<Include file="LibBabble-SubZone-3.0\lib.xml"/>
	<Include file="LibFishing-1.0\lib.xml" />
	<Script file="oUF_OfflineSLE\oUF_OfflineSLE.lua"/>
	<Script file="Lib_SLETags-1.0\Lib_SLETags-1.0.lua"/>
	<Include file="LibProcessable\LibProcessable.lua"/>
</Ui>
\ No newline at end of file
+<Ui xmlns="http://www.blizzard.com/wow/ui/">
	<Script file="AceAddon-3.0\AceAddon-3.0.lua"/>
	<Script file="AceConsole-3.0\AceConsole-3.0.lua"/>
	<Include file="LibTourist-3.0\lib.xml" />
	<Script file="AceDB-3.0\AceDB-3.0.lua"/>
	<Include file="LibElv-UIButtons-1.0\load_uibuttons.xml"/>
	<Include file="LibElv-GameMenu-1.0\LibElv-GameMenu-1.0.lua"/>
	<Script file="LibAnim\LibAnim.lua"/>
	<Script file="LibQTip-1.0\LibQTip-1.0.lua"/>
	<Script file="LibRangeCheck-2.0\LibRangeCheck-2.0.lua"/>
	<Include file="LibBabble-SubZone-3.0\lib.xml"/>
	<Include file="LibFishing-1.0\lib.xml" />
	<Script file="oUF_OfflineSLE\oUF_OfflineSLE.lua"/>
	<Script file="LibKitUITags-1.0\LibKitUITags-1.0.lua"/>
	<Script file="LibKituiConditions-1.0\LibKituiConditions-1.0.lua"/>
	<Include file="LibProcessable\LibProcessable.lua"/>
</Ui>
\ No newline at end of file