diff --git a/README.txt b/README.txt index 67ced5b..67c9134 100644 --- a/README.txt +++ b/README.txt @@ -6,4 +6,7 @@ aura_env.cloneId does something too maybe taken from asakawa :) aura_env.region:SetDesaturated(true) -easy desaturate \ No newline at end of file +easy desaturate + +Get namepalte for unit, pretty cool +C_NamePlate.GetNamePlateForUnit(unit) \ No newline at end of file diff --git a/scratch.lua b/scratch.lua new file mode 100644 index 0000000..bbae51f --- /dev/null +++ b/scratch.lua @@ -0,0 +1,77 @@ +function(states, event, unit, ...) + if event == "WA_NAMEPLATE_CLOSED" then + for i = 1, 40 do + local unit = "nameplate" .. i + if UnitExists(unit) and UnitCanAttack("player", unit) then + C_Timer.After(0.1, function() WeakAuras.ScanEvents("NAME_PLATE_AURA_NAMES", unit) end) + end + end + end + + if event == "NAME_PLATE_UNIT_ADDED" and unit or event == "NAME_PLATE_AURA_NAMES" and unit then + local GUID = UnitGUID(unit) + if GUID then + aura_env.stored[GUID] = unit + local target = unit .. "-target" + if UnitExists(target) then + local name = ("[%s]"):format(UnitName(target)) + if UnitIsPlayer(target) then name = ("[%s]"):format(target) end + + states[GUID] = { + name = name, + GUID = GUID, + unit = unit, + frame = C_NamePlate.GetNamePlateForUnit(unit), + progressType = "static", + autoHide = true, + changed = true, + show = true, + } + end + end + elseif event == "NAME_PLATE_UNIT_REMOVED" and unit then + local GUID = UnitGUID(unit) + local state = states[GUID] + if state then + state.show = false + state.changed = true + end + if aura_env.stored[GUID] then aura_env.stored[GUID] = nil end + end + if event == "FRAME_UPDATE" then + local theTime = GetTime() + if not aura_env.last or aura_env.last < theTime - aura_env.config.throttle then + for GUID, unit in pairs(aura_env.stored) do + if GUID then + local state = states[GUID] + local target = unit .. "-target" + if UnitExists(target) then + if aura_env.config.self and UnitIsUnit("player", target) then return true end + local name = ("%s"):format(UnitName(target)) + if UnitIsPlayer(target) then name = ("%s"):format(WA_ClassColorName(target)) end + + if state then + state.name = name + state.changed = true + else + states[GUID] = { + name = name, + GUID = GUID, + unit = unit, + frame = C_NamePlate.GetNamePlateForUnit(unit), + progressType = "static", + autoHide = true, + changed = true, + show = true, + } + end + elseif state then + state.show = false + state.changed = true + end + end + end + end + end + return true +end