Skip to content

Commit

Permalink
Move StatLogic 'locale' table definitions to GlobalPatterns
Browse files Browse the repository at this point in the history
  • Loading branch information
raethkcj committed Feb 29, 2024
1 parent f7c684d commit 2cceb0b
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 272 deletions.
4 changes: 2 additions & 2 deletions .pkgmeta
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package-as: RatingBuster
externals:
libs/StatLogic/libs/LibStub:
url: https://repos.wowace.com/wow/libstub/trunk
libs/StatLogic/libs/AceLocale-3.0:
url: https://repos.wowace.com/wow/ace3/trunk/AceLocale-3.0

libs/AceLocale-3.0:
url: https://repos.wowace.com/wow/ace3/trunk/AceLocale-3.0
libs/CallbackHandler-1.0:
url: https://repos.wowace.com/wow/callbackhandler/trunk/CallbackHandler-1.0
libs/AceConsole-3.0:
Expand Down
1 change: 1 addition & 0 deletions embeds.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<!-- Skip externals in local checkout -->
<!--@non-debug@
<Include file="libs\AceLocale-3.0\AceLocale-3.0.xml"/>
<Include file="libs\CallbackHandler-1.0\CallbackHandler-1.0.xml"/>
<Include file="libs\AceConsole-3.0\AceConsole-3.0.xml"/>
<Include file="libs\AceEvent-3.0\AceEvent-3.0.xml"/>
Expand Down
27 changes: 5 additions & 22 deletions libs/StatLogic/StatLogic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@ local addonName, addon = ...
---@class StatLogic
local StatLogic = LibStub(addonName)

---------------
-- Libraries --
---------------
---@type StatLogicLocale
local L = LibStub("AceLocale-3.0"):GetLocale(addonName)

-- Add all lower case strings to ["StatIDLookup"]
if type(L) == "table" and type(L["StatIDLookup"]) == "table" then
local temp = {}
for k, v in pairs(L["StatIDLookup"]) do
temp[k:utf8lower()] = v
end
for k, v in pairs(temp) do
L["StatIDLookup"][k] = v
end
end

function StatLogic:argCheck(argument, number, ...)
local arg = {...}
local validTypeString = table.concat(arg, ", ")
Expand Down Expand Up @@ -93,7 +76,7 @@ local _G = getfenv(0)
local pairs = pairs
local ipairs = ipairs
local type = type
local tonumber = L.tonumber
local tonumber = addon.tonumber
local GetInventoryItemLink = GetInventoryItemLink
local IsUsableSpell = IsUsableSpell
local UnitLevel = UnitLevel
Expand Down Expand Up @@ -1653,7 +1636,7 @@ do
-- Whole Text Lookup --
-----------------------
-- Mainly used for enchants or stuff without numbers:
local idTable = L.WholeTextLookup[text]
local idTable = addon.WholeTextLookup[text]
found = ParseMatch(idTable, text, false, "WholeText")
end

Expand All @@ -1678,7 +1661,7 @@ do
end)
if count > 0 then
statText = statText:trim()
local stats = L.StatIDLookup[statText]
local stats = addon.StatIDLookup[statText]
if stats then
for j, value in ipairs(values) do
found = ParseMatch(stats[j], text, value, "Substitution")
Expand All @@ -1694,7 +1677,7 @@ do
--------------------
-- Exclude strings with prefixes that do not need to be checked,
if not found then
if L.PrefixExclude[text:utf8sub(1, L.PrefixExcludeLength)] or text:sub(1, 1) == '"' then
if addon.PrefixExclude[text:utf8sub(1, addon.PrefixExcludeLength)] or text:sub(1, 1) == '"' then
found = ParseMatch(false, text, nil, "Prefix")
end
end
Expand All @@ -1713,7 +1696,7 @@ do
-- PreScan for special cases, that will fit wrongly into DeepScan
-- PreScan also has exclude patterns
if not found then
for pattern, id in pairs(L.PreScanPatterns) do
for pattern, id in pairs(addon.PreScanPatterns) do
local value
found, _, value = text:find(pattern)
if found then
Expand Down
1 change: 0 additions & 1 deletion libs/StatLogic/StatLogic.toc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#@non-debug@
# libs\LibStub\LibStub.lua
# libs\AceLocale-3.0\AceLocale-3.0.xml
#@end-non-debug@

libs\UTF8\utf8data.lua
Expand Down
1 change: 0 additions & 1 deletion libs/StatLogic/StatLogic_TBC.toc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#@non-debug@
# libs\LibStub\LibStub.lua
# libs\AceLocale-3.0\AceLocale-3.0.xml
#@end-non-debug@

libs\UTF8\utf8data.lua
Expand Down
1 change: 0 additions & 1 deletion libs/StatLogic/StatLogic_Vanilla.toc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#@non-debug@
# libs\LibStub\LibStub.lua
# libs\AceLocale-3.0\AceLocale-3.0.xml
#@end-non-debug@

libs\UTF8\utf8data.lua
Expand Down
1 change: 0 additions & 1 deletion libs/StatLogic/StatLogic_Wrath.toc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#@non-debug@
# libs\LibStub\LibStub.lua
# libs\AceLocale-3.0\AceLocale-3.0.xml
#@end-non-debug@

libs\UTF8\utf8data.lua
Expand Down
2 changes: 1 addition & 1 deletion libs/StatLogic/Vanilla_Logic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ addon.CritPerAgi = {
["HUNTER"] = {
0.2174, 0.2083, 0.2000, 0.1852, 0.1786, 0.1724, 0.1667, 0.1613, 0.1515, 0.1471,
0.1351, 0.1190, 0.1087, 0.1000, 0.0909, 0.0862, 0.0806, 0.0746, nil, 0.0658,
0.0633, nil, 0.0568, nil, 0.0515, 0.0495, 0.0472, 0.0455, 0.0435, 0.0417,
0.0633, 0.0595, 0.0568, nil, 0.0515, 0.0495, 0.0472, 0.0455, 0.0435, 0.0417,
0.0407, 0.0391, 0.0376, 0.0365, 0.0352, 0.0342, 0.0331, 0.0321, 0.0311, 0.0303,
[60] = 0.0189,
},
Expand Down
67 changes: 45 additions & 22 deletions libs/StatLogic/locales/GlobalPatterns.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
local addonName = ...
local addonName, addon = ...
local StatLogic = LibStub(addonName)
local locale = GetLocale()

local L = LibStub("AceLocale-3.0"):GetLocale(addonName)
local StatLogic = LibStub("StatLogic")
local lowerMT = {
__newindex = function(t, k, v)
if k then
rawset(t, k:utf8lower(), v)
end
end
}

addon.WholeTextLookup = setmetatable({}, lowerMT)
local W = addon.WholeTextLookup
addon.StatIDLookup = setmetatable({}, lowerMT)
local L = addon.StatIDLookup

L.WholeTextLookup[EMPTY_SOCKET_RED] = {["EMPTY_SOCKET_RED"] = 1}
L.WholeTextLookup[EMPTY_SOCKET_YELLOW] = {["EMPTY_SOCKET_YELLOW"] = 1}
L.WholeTextLookup[EMPTY_SOCKET_BLUE] = {["EMPTY_SOCKET_BLUE"] = 1}
L.WholeTextLookup[EMPTY_SOCKET_META] = {["EMPTY_SOCKET_META"] = 1}
W[EMPTY_SOCKET_RED] = {["EMPTY_SOCKET_RED"] = 1}
W[EMPTY_SOCKET_YELLOW] = {["EMPTY_SOCKET_YELLOW"] = 1}
W[EMPTY_SOCKET_BLUE] = {["EMPTY_SOCKET_BLUE"] = 1}
W[EMPTY_SOCKET_META] = {["EMPTY_SOCKET_META"] = 1}

local exclusions = {
"",
Expand Down Expand Up @@ -74,13 +86,13 @@ local exclusions = {
}

for _, exclusion in pairs(exclusions) do
L.WholeTextLookup[exclusion] = false
W[exclusion] = false
end

for _, subclass in pairs(Enum.ItemArmorSubclass) do
local subclassName = GetItemSubClassInfo(Enum.ItemClass.Armor, subclass)
if subclassName then
L.WholeTextLookup[subclassName] = false
W[subclassName] = false
end
end

Expand Down Expand Up @@ -133,7 +145,7 @@ local long = {
}

for pattern, stats in pairs(long) do
L.StatIDLookup[unescape(pattern)] = stats
L[unescape(pattern):utf8lower()] = stats
end

local regen = {
Expand All @@ -148,7 +160,7 @@ for pattern, stats in pairs(regen) do
pattern = pattern:gsub("5", "%%s")
local i = stat > five and 1 or 2
table.insert(stats, i, false)
L.StatIDLookup[unescape(pattern)] = stats
L[unescape(pattern):utf8lower()] = stats
end

local short = {
Expand Down Expand Up @@ -199,8 +211,8 @@ local short = {
}

for pattern, stat in pairs(short) do
L.StatIDLookup["%s " .. pattern] = stat
L.StatIDLookup[pattern .. " %s"] = stat
L[("%s " .. pattern):utf8lower()] = stat
L[(pattern .. " %s"):utf8lower()] = stat
end

local resistances = {
Expand All @@ -214,10 +226,10 @@ local resistances = {
if not MAX_SPELL_SCHOOLS then MAX_SPELL_SCHOOLS = 7 end
for i = 2, MAX_SPELL_SCHOOLS do
local school = _G["DAMAGE_SCHOOL" .. i]
L.StatIDLookup[DAMAGE_TEMPLATE_WITH_SCHOOL:format("%s", "%s", school)] = {StatLogic.Stats.MinWeaponDamage, StatLogic.Stats.MaxWeaponDamage}
L.StatIDLookup[PLUS_DAMAGE_TEMPLATE_WITH_SCHOOL:format("%s", "%s", school)] = {StatLogic.Stats.MinWeaponDamage, StatLogic.Stats.MaxWeaponDamage}
L[DAMAGE_TEMPLATE_WITH_SCHOOL:format("%s", "%s", school):utf8lower()] = {StatLogic.Stats.MinWeaponDamage, StatLogic.Stats.MaxWeaponDamage}
L[PLUS_DAMAGE_TEMPLATE_WITH_SCHOOL:format("%s", "%s", school):utf8lower()] = {StatLogic.Stats.MinWeaponDamage, StatLogic.Stats.MaxWeaponDamage}
if resistances[i] then
L.StatIDLookup[unescape(ITEM_RESIST_SINGLE):format("%s", school)] = {resistances[i]}
L[unescape(ITEM_RESIST_SINGLE):format("%s", school):utf8lower()] = {resistances[i]}
end
end

Expand All @@ -238,13 +250,24 @@ local prefixExclusions = {
ITEM_SET_BONUS, -- "Set: %s"
}

------------------
-- Prefix Exclude --
------------------
-- By looking at the first PrefixExcludeLength letters of a line we can exclude a lot of lines
addon.PrefixExclude = {}
local excludeLen = 5
if locale == "koKR" or locale == "zhCN" or locale == "zhTW" then
excludeLen = 3
end
addon.PrefixExcludeLength = excludeLen

for _, exclusion in pairs(prefixExclusions) do
-- Set the string to exactly PrefixExcludeLength characters, right-padded.
-- Set the string to exactly excludeLen characters, right-padded.
local len = string.utf8len(exclusion)
if len > L.PrefixExcludeLength then
exclusion = string.utf8sub(exclusion, 1, L.PrefixExcludeLength)
elseif len < L.PrefixExcludeLength then
exclusion = exclusion .. (" "):rep(L.PrefixExcludeLength - len)
if len > excludeLen then
exclusion = string.utf8sub(exclusion, 1, excludeLen)
elseif len < excludeLen then
exclusion = exclusion .. (" "):rep(excludeLen - len)
end
L.PrefixExclude[exclusion] = true
addon.PrefixExclude[exclusion] = true
end
Loading

0 comments on commit 2cceb0b

Please sign in to comment.