Skip to content

Commit

Permalink
Merge pull request #64 from Thekinghim/63-refactoring
Browse files Browse the repository at this point in the history
63 refactoring
  • Loading branch information
Thekinghim committed May 5, 2024
2 parents 47b5ec3 + 4185644 commit 9219ef2
Show file tree
Hide file tree
Showing 35 changed files with 764 additions and 304 deletions.
4 changes: 2 additions & 2 deletions Keystone-Companion.toc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## Interface: 100206
## Version: 1.0.4
## Version: 2.3.5
## Title: Keystone Companion
## IconTexture: Interface\AddOns\Keystone-Companion\assets\textures\icons\addon
## Author: Kaelon/Jordy141
## Notes: See your party's M+ keystones, dungeon reagents, and dungeon portals.
## SavedVariables: KeystoneCompanionDB
## SavedVariables: KeystoneCompanionDB, KeystoneCompanionDebug
## DefaultState: enabled
## OptionalDeps: MythicDungeonTools
## X-Curse-Project-ID: 984971
Expand Down
19 changes: 19 additions & 0 deletions autoSocket.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
local f = CreateFrame("Frame")
f:RegisterEvent("CHALLENGE_MODE_KEYSTONE_RECEPTABLE_OPEN")
f:SetScript("OnEvent", function()
for bagIndex = 0, NUM_BAG_SLOTS do
for slotIndex = 1, C_Container.GetContainerNumSlots(bagIndex) do
local itemID = C_Container.GetContainerItemID(bagIndex, slotIndex)
if itemID and itemID == 180653 then
local item = ItemLocation:CreateFromBagAndSlot(bagIndex, slotIndex)
if C_ChallengeMode.CanUseKeystoneInCurrentMap(item) then
C_Container.PickupContainerItem(bagIndex, slotIndex)
C_Timer.After(0.1, function()
C_ChallengeMode.SlotKeystone()
end)
break
end
end
end
end
end)
23 changes: 11 additions & 12 deletions communication.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local _, KeystoneCompanion = ...

KeystoneCompanion.communication = { prefix = "keystonecomp", messageTypes = {LOGON = "LOGON", QUERY = "QUERY", UPDATE = "UPDATE"}, handlers = {}}
KeystoneCompanion.communication = { prefix = "keystonecomp", messageTypes = { LOGON = "LOGON", QUERY = "QUERY", UPDATE = "UPDATE" }, handlers = {} }
local LibDeflate = LibStub:GetLibrary("LibDeflate");
local LIB_OPEN_RAID_COMM_PREFIX = 'LRS';
local LIB_OPEN_RAID_KEYSTONE_PREFIX = 'K';
Expand All @@ -10,9 +10,9 @@ local devPrint = KeystoneCompanion.dev.print;
function KeystoneCompanion.communication.SendMessage(...)
local messageType, data = select(1, ...)
local message = messageType .. '::';
if(data ~= nil and strlen(data) > 0) then message = message .. data end
if (data ~= nil and strlen(data) > 0) then message = message .. data end

if(UnitInParty('player') == false and KeystoneCompanion.isDev()) then
if (UnitInParty('player') == false and KeystoneCompanion.isDev()) then
C_ChatInfo.SendAddonMessage(KeystoneCompanion.communication.prefix, message, "WHISPER", UnitName('player'))
else
C_ChatInfo.SendAddonMessage(KeystoneCompanion.communication.prefix, message, "PARTY")
Expand All @@ -25,30 +25,29 @@ function KeystoneCompanion.communication:RegisterMessageHandler(messageType, cal
end

function KeystoneCompanion.communication:RequestKeystoneInfoFromLibOpenRaid()
local payload = LibDeflate:CompressDeflate(LIB_OPEN_RAID_KEYSTONE_REQUEST_PREFIX, {level = 9})
local payload = LibDeflate:CompressDeflate(LIB_OPEN_RAID_KEYSTONE_REQUEST_PREFIX, { level = 9 })
local encodedPayload = LibDeflate:EncodeForWoWAddonChannel(payload);
C_ChatInfo.SendAddonMessage(LIB_OPEN_RAID_COMM_PREFIX, encodedPayload, "PARTY");
end

function KeystoneCompanion.communication:OnLibOpenRaidMessageReceived(text, sender)
if(sender == UnitName("player")) then return end;
if (sender == UnitName("player")) then return end;

local compressedData = LibDeflate:DecodeForWoWAddonChannel(text);
local data = LibDeflate:DecompressDeflate(compressedData);

if(not data or type(data) ~= 'string' or string.len(data) == 0) then return end;
if(data:sub(1, 1) ~= LIB_OPEN_RAID_KEYSTONE_PREFIX) then return end;
if (not data or type(data) ~= 'string' or string.len(data) == 0) then return end;
if (data:sub(1, 1) ~= LIB_OPEN_RAID_KEYSTONE_PREFIX) then return end;

devPrint('received details! keystone info from ' .. sender);
local keystoneInfo = { strsplit(',', data) }
KeystoneCompanion.inventory:LoadFromDetailsInfo(sender, tonumber(keystoneInfo[2]), tonumber(keystoneInfo[3]));

end

function KeystoneCompanion.communication:OnMessageReceived(prefix, text, channel, sender)
sender = Ambiguate(sender, 'short')

if(prefix == LIB_OPEN_RAID_COMM_PREFIX) then
if (prefix == LIB_OPEN_RAID_COMM_PREFIX) then
self:OnLibOpenRaidMessageReceived(text, sender)
return;
end
Expand All @@ -63,7 +62,7 @@ function KeystoneCompanion.communication:OnMessageReceived(prefix, text, channel
if (handlers == nil) then return end

local messageData = '';
if(strlen(text) > prefixSeparatorIndex + 1) then
if (strlen(text) > prefixSeparatorIndex + 1) then
messageData = string.sub(text, prefixSeparatorIndex + 2);
end

Expand All @@ -79,4 +78,4 @@ KeystoneCompanion.communication.EventFrame:SetScript("OnEvent", function(self, e
end)

C_ChatInfo.RegisterAddonMessagePrefix(KeystoneCompanion.communication.prefix);
C_ChatInfo.RegisterAddonMessagePrefix(LIB_OPEN_RAID_COMM_PREFIX);
C_ChatInfo.RegisterAddonMessagePrefix(LIB_OPEN_RAID_COMM_PREFIX);
18 changes: 9 additions & 9 deletions constants/dungeonTeleports.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,46 +34,46 @@ KeystoneCompanion.constants.dungeonTeleports = {

[2451] = {
name = 'Uldaman: Legacy of Tyr',
spell = { id = 393222, name = 'Path of the Watcher\'s Legacy'}
spell = { id = 393222, name = 'Path of the Watcher\'s Legacy' }
},

[2515] = {
name = 'The Azure Vault',
spell = { id = 393279, name = 'Path of Arcane Secrets'}
spell = { id = 393279, name = 'Path of Arcane Secrets' }
},

[2516] = {
name = 'The Nokhud Offensive',
spell = { id = 393262, name = 'Path of the Windswept Plains'}
spell = { id = 393262, name = 'Path of the Windswept Plains' }
},

[2519] = {
name = 'Neltharus',
spell = { id = 393276, name = 'Path of the Obsidian Hoard'}
spell = { id = 393276, name = 'Path of the Obsidian Hoard' }
},

[2520] = {
name = 'Brackenhide Hollow',
spell = { id = 393267, name = 'Path of the Rotting Woods'}
spell = { id = 393267, name = 'Path of the Rotting Woods' }
},

[2521] = {
name = 'Ruby Life Pools',
spell = { id = 393256, name = 'Path of the Clutch Defender'}
spell = { id = 393256, name = 'Path of the Clutch Defender' }
},

[2526] = {
name = 'Algeth\'ar Academy',
spell = { id = 393273, name = 'Path of the Draconic Diploma'}
spell = { id = 393273, name = 'Path of the Draconic Diploma' }
},

[2527] = {
name = 'Halls of Infusion',
spell = { id = 393283, name = 'Path of the Titanic Reservoir'}
spell = { id = 393283, name = 'Path of the Titanic Reservoir' }
},

[2579] = {
name = 'Dawn of the Infinites',
spell = { id = 424197, name = 'Path of Twisted Time' },
}
}
}
2 changes: 1 addition & 1 deletion constants/items.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ for category, entries in pairs(KeystoneCompanion.constants.items) do
for itemId in pairs(entries) do
KeystoneCompanion.constants.itemLookup[itemId] = category
end
end
end
8 changes: 4 additions & 4 deletions constants/roleIcons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local _, KeystoneCompanion = ...

KeystoneCompanion.constants = KeystoneCompanion.constants or {};
KeystoneCompanion.constants.roleIconCoords = {
TANK = { 0, 19 / 64, 22 / 64, 41 / 64 };
HEALER = { 20 / 64, 39 / 64, 1 / 64, 20 / 64 };
DAMAGER = { 20 / 64, 39 / 64, 22 / 64, 41 / 64 };
}
TANK = { 0, 19 / 64, 22 / 64, 41 / 64 },
HEALER = { 20 / 64, 39 / 64, 1 / 64, 20 / 64 },
DAMAGER = { 20 / 64, 39 / 64, 22 / 64, 41 / 64 },
}
18 changes: 9 additions & 9 deletions constants/styles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ local ASSETS_PATH = 'Interface/Addons/' .. addonName .. '/assets/';

local styles = {
COLORS = {
BACKGROUND = CreateColorFromHexString("FF131315");
BORDER = CreateColorFromHexString("FFFF8000");
BACKGROUND = CreateColorFromHexString("FF131315"),
BORDER = CreateColorFromHexString("FFFF8000"),

TEXT_PRIMARY = CreateColorFromHexString("FFFFFFFF");
TEXT_SECONDARY = CreateColorFromHexString("FFA1A1A1");
TEXT_PRIMARY = CreateColorFromHexString("FFFFFFFF"),
TEXT_SECONDARY = CreateColorFromHexString("FFA1A1A1"),
TEXT_HIGHLIGHT = CreateColorFromHexString("FFFF7C0A"),

GREEN_DARK = CreateColorFromHexString("FF009901");
GREEN_LIGHT = CreateColorFromHexString("FF02FF03");

RED_LIGHT = CreateColorFromHexString("FFFF0000");
GREEN_DARK = CreateColorFromHexString("FF009901"),
GREEN_LIGHT = CreateColorFromHexString("FF02FF03"),

RED_LIGHT = CreateColorFromHexString("FFFF0000"),

YELLOW_LIGHT = CreateColorFromHexString("FFF4ED03")
},
Expand Down Expand Up @@ -55,4 +55,4 @@ end

KeystoneCompanion.constants = KeystoneCompanion.constants or {};
KeystoneCompanion.constants.styles = styles;
KeystoneCompanion.constants.ASSETS_PATH = ASSETS_PATH
KeystoneCompanion.constants.ASSETS_PATH = ASSETS_PATH
6 changes: 3 additions & 3 deletions dev.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function KeystoneCompanion.dev.CloneInventory(from, to)
KeystoneCompanion.UI.Rerender();
end

function KeystoneCompanion.dev.print(...)
if(KeystoneCompanion.isDev()) then
function KeystoneCompanion.dev.print(...)
if (KeystoneCompanion.isDev()) then
print('|cffddca2eKeystoneCompanion|r|cffff0000Dev|r: ' .. ...)
end
end
end
5 changes: 1 addition & 4 deletions embeds.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@
<Script file="init.lua"/>
<Include file="constants/embeds.xml" />
<Include file="utils/embeds.xml" />
<Include file="widgets/embeds.xml" />

<Script file="dev.lua"/>
<Script file="inventory.lua"/>
<Script file="communication.lua"/>

<Include file="widgets/embeds.xml" />

<Include file="ui/embeds.xml" />

<Script file="main.lua"/>

<Script file="scoreCalculator.lua"/>
<Script file="itemTooltip.lua"/>
<Script file="autoSocket.lua"/>
</Ui>
10 changes: 7 additions & 3 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
local _, KeystoneCompanion = ...
local addonName, KeystoneCompanion = ...

local rasuGUI = LibStub("RasuGUI")
KeystoneCompanion.RasuGUI = rasuGUI
KeystoneCompanion.widgets = rasuGUI.Widgets

KeystoneCompanionDB = {
settings = {
Expand All @@ -7,10 +11,10 @@ KeystoneCompanionDB = {
}
}

KeystoneCompanion.version = '2.3.4';
KeystoneCompanion.version = C_AddOns.GetAddOnMetadata(addonName, "Version");
KeystoneCompanion.buildType = 'release';
KeystoneCompanion.isDev = function() return KeystoneCompanionDB.settings.DevMode end;
KeystoneCompanion.print = function(msg) print("|cffddca2eKeystoneCompanion|r: " .. msg) end;
KeystoneCompanion.colorise = function(color, msg) return "|cff" .. color .. msg .. "|r" end;

_G.KeystoneCompanion = KeystoneCompanion;
_G.KeystoneCompanion = KeystoneCompanion;
26 changes: 13 additions & 13 deletions inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end
KeystoneCompanion.inventory.self = KeystoneCompanion.inventory:NewEmptyInventory();

function KeystoneCompanion.inventory:GetInventoryString()
if(#self.self.items == 0) then
if (#self.self.items == 0) then
self:ScanInventory();
end

Expand All @@ -23,20 +23,20 @@ function KeystoneCompanion.inventory:GetInventoryString()
return inventoryString;
end

local ToArray = function (itemData)
local ToArray = function(itemData)
local array = {};
for k,v in pairs(itemData) do table.insert(array, { itemID = k, count = v}) end
for k, v in pairs(itemData) do table.insert(array, { itemID = k, count = v }) end
return array;
end

local ScanItem = function (itemCache, bagIndex, bagSlot)
local ScanItem = function(itemCache, bagIndex, bagSlot)
local itemInfo = C_Container.GetContainerItemInfo(bagIndex, bagSlot);
if(itemInfo == nil) then return end
if (itemInfo == nil) then return end

local itemCategory = KeystoneCompanion.constants.itemLookup[itemInfo.itemID];
if(itemCategory == nil) then return end
if (itemCategory == nil) then return end

if(itemCache[itemCategory][itemInfo.itemID] == nil) then
if (itemCache[itemCategory][itemInfo.itemID] == nil) then
itemCache[itemCategory][itemInfo.itemID] = itemInfo.stackCount;
else
itemCache[itemCategory][itemInfo.itemID] = itemCache[itemCategory][itemInfo.itemID] + itemInfo.stackCount
Expand Down Expand Up @@ -68,16 +68,16 @@ function KeystoneCompanion.inventory:ScanInventory()
}

local keystoneMapId = C_MythicPlus.GetOwnedKeystoneMapID();
if(keystoneMapId == nil) then
if (keystoneMapId == nil) then
self.self.keystone = { mapId = nil, level = nil };
else
local keystoneLevel = C_MythicPlus.GetOwnedKeystoneLevel();
self.self.keystone = { mapID = keystoneMapId, level = keystoneLevel };
end

self.self.knownTeleports = {};
for instanceId, dungeonTeleportInfo in pairs(KeystoneCompanion.constants.dungeonTeleports) do
if(IsSpellKnown(dungeonTeleportInfo.spell.id, false)) then
for instanceId, dungeonTeleportInfo in pairs(KeystoneCompanion.constants.dungeonTeleports) do
if (IsSpellKnown(dungeonTeleportInfo.spell.id, false)) then
table.insert(self.self.knownTeleports, instanceId)
end
end
Expand All @@ -103,9 +103,9 @@ function KeystoneCompanion.inventory:LoadString(sender, inventoryString)
end

function KeystoneCompanion.inventory:LoadFromDetailsInfo(sender, level, mapID)
if(self[sender] == nil) then self[sender] = self:NewEmptyInventory() end
if (self[sender] == nil) then self[sender] = self:NewEmptyInventory() end
self[sender].keystone = { mapID = mapID > 0 and mapID or nil, level = level > 0 and level or nil };
if(KeystoneCompanion.UI.Frame:IsShown()) then
if (KeystoneCompanion.UI.Frame:IsShown()) then
KeystoneCompanion.UI.Rerender();
end
end
end

0 comments on commit 9219ef2

Please sign in to comment.