From aef93c15f3d8d3cda3f16e57c8982503feefbe93 Mon Sep 17 00:00:00 2001 From: DJSchaffner Date: Mon, 12 Feb 2024 19:52:44 +0100 Subject: [PATCH] first commit --- .github/FUNDING.yml | 13 +++++++++ .vscode/settings.json | 17 +++++++++++ BetterBags_ItemRack.toc | 7 +++++ deploy.bat | 4 +++ main.lua | 65 +++++++++++++++++++++++++++++++++++++++++ readme.md | 6 ++++ 6 files changed, 112 insertions(+) create mode 100644 .github/FUNDING.yml create mode 100644 .vscode/settings.json create mode 100644 BetterBags_ItemRack.toc create mode 100644 deploy.bat create mode 100644 main.lua create mode 100644 readme.md diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..3c2a017 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,13 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry +custom: ['https://www.buymeacoffee.com/djschaffner'] diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..09b4601 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,17 @@ +{ + "Lua.diagnostics.globals": [ + "CreateFrame", + "print", + "UIDropDownMenu_SetWidth", + "UIDropDownMenu_SetText", + "UIDropDownMenu_Initialize", + "SlashCmdList", + "ToggleDropDownMenu", + "UIDropDownMenu_AddButton", + "UIDropDownMenu_CreateInfo", + "UnitBuff", + "DEFAULT_CHAT_FRAME", + "StaticPopupDialogs", + "StaticPopup_Show" + ] +} \ No newline at end of file diff --git a/BetterBags_ItemRack.toc b/BetterBags_ItemRack.toc new file mode 100644 index 0000000..555283f --- /dev/null +++ b/BetterBags_ItemRack.toc @@ -0,0 +1,7 @@ +## Interface: 11501 +## Title: BetterBags - ItemRack +## Notes: Add a category to BetterBags for ItemRack sets +## Author: DJSchaffner +## Version: @1.0 + +main.lua diff --git a/deploy.bat b/deploy.bat new file mode 100644 index 0000000..fad837a --- /dev/null +++ b/deploy.bat @@ -0,0 +1,4 @@ +@echo off +echo Copying files... +cp -r ../BetterBags_ItemRack "C:\Program Files (x86)\World of Warcraft\_classic_era_\Interface\AddOns" +echo Deployed \ No newline at end of file diff --git a/main.lua b/main.lua new file mode 100644 index 0000000..f6f43c1 --- /dev/null +++ b/main.lua @@ -0,0 +1,65 @@ +---@class BetterBags: AceAddon +local addonBetterBags = LibStub('AceAddon-3.0'):GetAddon("BetterBags") +---@class Categories: AceModule +local categories = addonBetterBags:GetModule('Categories') +---@class Localization: AceModule +local L = addonBetterBags:GetModule('Localization') + +local debug = false +local frame = CreateFrame("Frame", nil) +local categoryName = "Sets" +------------------------------------------------------- +local function printChat(message) + if debug == true then + print("[BetterBags ItemRack] "..message) + end +end + +local function split(s, sep) + local fields = {} + + local sep = sep or " " + local pattern = string.format("([^%s]+)", sep) + string.gsub(s, pattern, function(c) fields[#fields + 1] = c end) + + return fields +end + +local function updateCategory() + -- Wipe category since we can't retrieve deleted set from itemRack (Except maybe store duplicate of sets and check last version of it) + categories:WipeCategory(L:G(categoryName)) + + -- Loop all sets + for setName, _ in pairs(ItemRackUser.Sets) do + -- Only update user sets (internals start with '~') + if not string.match(setName, "^~") then + printChat("Updating set: " .. setName) + -- Loop all items of set + for _, item in pairs(ItemRackUser.Sets[setName].equip) do + local id = tonumber(split(item, ":")[1]) + --printChat(id) + --printChat(GetItemInfo(ItemRack.IRStringToItemString(item))) + categories:AddItemToCategory(id, L:G(categoryName)) + printChat("Added item '" .. id .. "' to '" .. categoryName .. "' category") + end + else + printChat("Skipping internal set: " .. setName) + end + end +end + +local function itemRackUpdated(event, _) + printChat(event) + updateCategory() +end +------------------------------------------------------- +frame:RegisterEvent("ADDON_LOADED") +frame:SetScript("OnEvent", function(self, event, addon, ...) + if event == "ADDON_LOADED" and addon == "ItemRack" then + ItemRack:RegisterExternalEventListener("ITEMRACK_SET_SAVED", itemRackUpdated) + ItemRack:RegisterExternalEventListener("ITEMRACK_SET_DELETED", itemRackUpdated) + + printChat("ItemRack Loaded.. Initializing Category") + updateCategory() + end +end) \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..692cc95 --- /dev/null +++ b/readme.md @@ -0,0 +1,6 @@ +## BetterBags - ItemRack +This is a filter for the World of Warcraft addon [BetterBags](https://github.com/Cidan/BetterBags) and requires both [BetterBags](https://github.com/Cidan/BetterBags) and [ItemRack](https://github.com/Rottenbeer/ItemRack) + +Plugin was written for Classic SoD so it might not work for other versions of the game. + +It will collect all items assigned to an ItemRack set and place them in a single category. Might add the option to split them up into seperate categories for each set later but no promises. \ No newline at end of file