Skip to content

Commit

Permalink
Saved Variables and console commands
Browse files Browse the repository at this point in the history
  • Loading branch information
d87 committed Sep 23, 2022
1 parent 44c0cbc commit 9903133
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 7 deletions.
1 change: 1 addition & 0 deletions NugTotemIcon-Classic.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Title: NugTotemIcon
## Author: d87
## Version: @project-version@
## SavedVariables: NugTotemIconDB

## X-Curse-Project-ID: 439883

Expand Down
1 change: 1 addition & 0 deletions NugTotemIcon-Mainline.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Title: NugTotemIcon
## Author: d87
## Version: @project-version@
## SavedVariables: NugTotemIconDB

## X-Curse-Project-ID: 439883

Expand Down
1 change: 1 addition & 0 deletions NugTotemIcon-TBC.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Title: NugTotemIcon
## Author: d87
## Version: @project-version@
## SavedVariables: NugTotemIconDB

## X-Curse-Project-ID: 439883

Expand Down
1 change: 1 addition & 0 deletions NugTotemIcon-Wrath.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Title: NugTotemIcon
## Author: d87
## Version: @project-version@
## SavedVariables: NugTotemIconDB

## X-Curse-Project-ID: 439883

Expand Down
1 change: 1 addition & 0 deletions NugTotemIcon.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Title: NugTotemIcon
## Author: d87
## Version: @project-version@
## SavedVariables: NugTotemIconDB

## X-Curse-Project-ID: 439883

Expand Down
120 changes: 113 additions & 7 deletions core.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
local addonName, ns = ...

local f = CreateFrame("Frame", nil, UIParent)
f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
f:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
f:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
f:RegisterEvent("PLAYER_LOGIN")

f:SetScript("OnEvent", function(self, event, ...)
return self[event](self, event, ...)
end)

local showDuration = true
local showCooldownCount = false
local showFriendlyTotems = true

local activeTotems = {}
local totemStartTimes = setmetatable({ __mode = "v" }, {})

local defaults = {
showDuration = true,
showCooldownCount = false,
showFriendlyTotems = true,
size = 63,
}

local db

-- /script SetCVar("nameplateShowFriendlyTotems", 1)

-- nameplateShowEnemyGuardians = "0",
Expand All @@ -23,6 +32,19 @@ local totemStartTimes = setmetatable({ __mode = "v" }, {})
-- nameplateShowEnemyPets = "1",
local APILevel = math.floor(select(4,GetBuildInfo())/10000)

function f.PLAYER_LOGIN(self)
_G.NugTotemIconDB = _G.NugTotemIconDB or {}
-- self:DoMigrations(NugTotemIconDB)
-- self.db = LibStub("AceDB-3.0"):New("NugTotemIconDB", defaults, "Default")
db = _G.NugTotemIconDB
ns.SetupDefaults(_G.NugTotemIconDB, defaults)

SLASH_NUGTOTEMICON1= "/nugtotemicon"
SLASH_NUGTOTEMICON2= "/nti"
SlashCmdList["NUGTOTEMICON"] = self.SlashCmd
end


local function GetNPCIDByGUID(guid)
local _, _, _, _, _, npcID = strsplit("-", guid);
return tonumber(npcID)
Expand Down Expand Up @@ -134,7 +156,7 @@ end

local function CreateIcon(nameplate)
local frame = CreateFrame("Frame", nil, nameplate)
frame:SetSize(63, 63)
frame:SetSize(db.size, db.size)
frame:SetPoint("BOTTOM", nameplate, "TOP", 0, 5)

local icon = frame:CreateTexture(nil, "ARTWORK")
Expand All @@ -148,7 +170,7 @@ local function CreateIcon(nameplate)
bg:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 2, -2)

local cd = CreateFrame("Cooldown", nil, frame, "CooldownFrameTemplate")
if not showCooldownCount then
if not db.showCooldownCount then
cd.noCooldownCount = true -- disable OmniCC for this cooldown
cd:SetHideCountdownNumbers(true)
end
Expand All @@ -169,7 +191,7 @@ function f.NAME_PLATE_UNIT_ADDED(self, event, unit)
local npcID = GetNPCIDByGUID(guid)

if npcID and totemNpcIDs[npcID] then
if not showFriendlyTotems then
if not db.showFriendlyTotems then
-- local isAttackable = UnitCanAttack("player", unit)
local isFriendly = UnitReaction(unit, "player") >= 4
if isFriendly then return end
Expand All @@ -181,6 +203,7 @@ function f.NAME_PLATE_UNIT_ADDED(self, event, unit)

local iconFrame = np.NugTotemIcon
iconFrame:Show()
iconFrame:SetSize(db.size, db.size)

local totemData = totemNpcIDs[npcID]
local spellID, duration = unpack(totemData)
Expand All @@ -189,7 +212,7 @@ function f.NAME_PLATE_UNIT_ADDED(self, event, unit)

iconFrame.icon:SetTexture(tex)
local startTime = totemStartTimes[guid]
if startTime and showDuration then
if startTime and db.showDuration then
iconFrame.cooldown:SetCooldown(startTime, duration)
iconFrame.cooldown:Show()
end
Expand Down Expand Up @@ -220,3 +243,86 @@ function f:COMBAT_LOG_EVENT_UNFILTERED(event, unit)
end
end
end


local ParseOpts = function(str)
local t = {}
local capture = function(k,v)
t[k:lower()] = tonumber(v) or v
return ""
end
str:gsub("(%w+)%s*=%s*%[%[(.-)%]%]", capture):gsub("(%w+)%s*=%s*(%S+)", capture)
return t
end

f.Commands = {
["duration"] = function(v)
db.showDuration = not db.showDuration
end,
["cooldowncount"] = function(v)
db.showCooldownCount = not db.showCooldownCount
end,
["friendly"] = function(v)
db.showFriendlyTotems = not db.showFriendlyTotems
end,
["size"] = function(v)
local newSize = tonumber(v)
if newSize then
db.size = newSize
end
end,
}

function f.SlashCmd(msg)
local helpMessage = {
"|cff00ffbb/nti duration|r",
"|cff00ffbb/nti cooldowncount|r",
"|cff00ffbb/nti friendly|r",
"|cff00ffbb/nti size 63|r",
}

local k,v = string.match(msg, "([%w%+%-%=]+) ?(.*)")
if not k or k == "help" then
print("Usage:")
for k,v in ipairs(helpMessage) do
print(" - ",v)
end
end
if f.Commands[k] then
f.Commands[k](v)
end
end



function ns.SetupDefaults(t, defaults)
if not defaults then return end
for k,v in pairs(defaults) do
if type(v) == "table" then
if t[k] == nil then
t[k] = CopyTable(v)
elseif t[k] == false then
t[k] = false --pass
else
ns.SetupDefaults(t[k], v)
end
else
if t[k] == nil then t[k] = v end
end
end
end

function ns.RemoveDefaults(t, defaults)
if not defaults then return end
for k, v in pairs(defaults) do
if type(t[k]) == 'table' and type(v) == 'table' then
ns.RemoveDefaults(t[k], v)
if next(t[k]) == nil then
t[k] = nil
end
elseif t[k] == v then
t[k] = nil
end
end
return t
end

0 comments on commit 9903133

Please sign in to comment.