Справочник › Справочник функций › Core

Core.point_conditions.pointIdentity

зависимость

Как вызывать

Core.point_conditions.pointIdentity(self, unit, key)

Запишите зависимость Core.point_conditions.pointIdentity и вызывайте её по этому имени. Вызов через пространство имён не передаёт self: используйте вызов через двоеточие или передайте объект сами.

Что делает

Observes whether unit exists and, if so, its class, for the point-resource selectors. For the player it reuses a class stored in self.longtermCache under key when it was recorded against the same UnitClass function, and otherwise stores the freshly read class there.

Аргументы

ИмяТипЧто делает
selfRMAddonRotation Master addon instance.
unitstringUnit token to observe.
keyanyLong-term cache key for the player's class; only used for "player". The addon passes a private table.

Возвращает

1table | nil{exists=false}, or {exists=true, class=token}; nil when unavailable.
2string | nilThe platform observer's reason for nil.

Издания

Встроенные помощники регистрируются во всех изданиях. Различается игровой API, который они читают; если нужного API нет, помощник использует запасной вариант или возвращает nil с причиной.

  • Недоступно в этом издании (причина — во всплывающей подсказке)
  • Только пока включены запасные реализации Blizzard для устаревших функций
Игровой APIClassic EraTBC AnniversaryClassic ProgressionForeverRetail
UnitClassClassic EraTBC AnniversaryClassic ProgressionForeverRetail

Секретные значения (Retail и Forever)

В Retail и Forever игра передаёт аддонам секретные значения. Этот помощник проверяет то, что читает (addon.Platform:CanReadValue), и вместо секретного значения, которое нельзя сравнить, возвращает nil с причиной, например restricted-value. Считайте nil недоступным значением, а не ложью.

Пример

-- needs the dependency Core.point_conditions.pointIdentity
local record, reason = Functions.cache.getCached(cache, Core.point_conditions.pointIdentity, addon, "target")
if not record then return nil, reason end
return record.exists and record.class == "ROGUE"

Исходный код

Core/point_conditions.lua, строка 27. В игре только для чтения; «Дублировать» создаёт редактируемую копию.

Core.point_conditions.pointIdentity(self, unit, key)
    local platform=self.Platform
    local nativeClass=UnitClass
    local longterm=self.longtermCache
    if not platform:CanReadValue(longterm) or type(longterm)~='table' then longterm=nil end
    local class
    if unit=='player' and longterm and platform:CanReadValue(nativeClass) and type(nativeClass)=='function' then
        local entry=rawget(longterm,key)
        if platform:CanReadValue(entry) and type(entry)=='table' then
            local api,candidate=rawget(entry,'api'),rawget(entry,'class')
            if platform:CanReadValue(api) and api==nativeClass and platform:CanReadValue(candidate) and type(candidate)=='string' and candidate~='' then class=candidate end
        end
    end
    local record,reason=platform:GetUnitPointIdentityObservation(unit,class==nil)
    if not record then return nil,reason end
    if not record.exists then return record end
    if class then record.class=class
    elseif unit=='player' and longterm and type(nativeClass)=='function' and nativeClass==UnitClass then
        rawset(longterm,key,{api=nativeClass,class=record.class})
    end
    return record

Назад: Справочник функций