Skip to content

Commit

Permalink
多版本兼容
Browse files Browse the repository at this point in the history
  • Loading branch information
CvCn committed Aug 19, 2024
1 parent 2be57b9 commit 2730dcb
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 67 deletions.
6 changes: 4 additions & 2 deletions InputInput/API.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ Fun({
},
C_AddOns_GetAddOnEnableState = {
['10.2.0'] = C_AddOns.GetAddOnEnableState,
---@diagnostic disable-next-line: deprecated
['1.0.0'] = GetAddOnEnableState
['1.0.0'] = function(name, character)
---@diagnostic disable-next-line: deprecated
return GetAddOnEnableState(character, name)
end
},
C_AddOns_EnableAddOn = {
['10.2.0'] = C_AddOns.EnableAddOn,
Expand Down
2 changes: 1 addition & 1 deletion InputInput/InIt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local Data = {}
local Locale = {}
local API = {}
local LOG = {}
local Environment = 'PRO'
local Environment = 'DEV'

AddOnesTable[1] = Widget
Widget.N = Name
Expand Down
10 changes: 5 additions & 5 deletions InputInput/Libs/jieba-lua/hmm.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

local MIN_FLOAT = -3.14e100
local start = LibStub("prob_start").prob_start
local emit = LibStub("prob_emit").prob_emit
local trans = LibStub("prob_trans").prob_trans
local ut = LibStub("utils")
local start = LibStub("inputinput-jieba-prob_start").prob_start
local emit = LibStub("inputinput-jieba-prob_emit").prob_emit
local trans = LibStub("inputinput-jieba-prob_trans").prob_trans
local ut = LibStub("inputinput-jieba-utils")

-- 使用 LibStub 创建一个新库
local MAJOR, MINOR = "hmm", 1
local MAJOR, MINOR = "inputinput-jieba-hmm", 1
local M, oldVersion = LibStub:NewLibrary(MAJOR, MINOR)

-- 检查是否成功创建了新版本的库
Expand Down
36 changes: 4 additions & 32 deletions InputInput/Libs/jieba-lua/init.lua
Original file line number Diff line number Diff line change
@@ -1,47 +1,19 @@
local W, M, U, D, G, L, E, API, LOG = unpack((select(2, ...)))

local ut = LibStub("utils")
local utf8 = LibStub("utf8")
local hmm = LibStub("hmm")
local ut = LibStub("inputinput-jieba-utils")
local utf8 = LibStub("inputinput-jieba-utf8")
local hmm = LibStub("inputinput-jieba-hmm")
local p = "[%z\1-\127\194-\244][\128-\191]*"

-- 使用 LibStub 创建一个新库
local MAJOR, MINOR = "jieba", 1
local MAJOR, MINOR = "inputinput-jieba", 1
local init, oldVersion = LibStub:NewLibrary(MAJOR, MINOR)

-- 检查是否成功创建了新版本的库
if not init then
return
end
-- local dict1 = LibStub("dict1").dict
-- local dict2 = LibStub("dict2").dict
-- local dict3 = LibStub("dict3").dict
-- local dict4 = LibStub("dict4").dict
-- local dict5 = LibStub("dict5").dict
-- local dict6 = LibStub("dict6").dict

-- local total = 60101967

-- local logtotal = math.log(total)

-- for i, v in pairs(dict1) do
-- dict1[i] = math.log(v) - logtotal
-- end
-- for i, v in pairs(dict2) do
-- dict2[i] = math.log(v) - logtotal
-- end
-- for i, v in pairs(dict3) do
-- dict3[i] = math.log(v) - logtotal
-- end
-- for i, v in pairs(dict4) do
-- dict4[i] = math.log(v) - logtotal
-- end
-- for i, v in pairs(dict5) do
-- dict5[i] = math.log(v) - logtotal
-- end
-- for i, v in pairs(dict6) do
-- dict6[i] = math.log(v) - logtotal
-- end
local function dictItem(k)
if W.dict1 then
return W.dict1[k] or W.dict2[k] or W.dict3[k] or W.dict4[k] or W.dict5[k] or W.dict6[k]
Expand Down
2 changes: 1 addition & 1 deletion InputInput/Libs/jieba-lua/prob_emit.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- 使用 LibStub 创建一个新库
local MAJOR, MINOR = "prob_emit", 1
local MAJOR, MINOR = "inputinput-jieba-prob_emit", 1
local p, oldVersion = LibStub:NewLibrary(MAJOR, MINOR)

-- 检查是否成功创建了新版本的库
Expand Down
2 changes: 1 addition & 1 deletion InputInput/Libs/jieba-lua/prob_start.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- 使用 LibStub 创建一个新库
local MAJOR, MINOR = "prob_start", 1
local MAJOR, MINOR = "inputinput-jieba-prob_start", 1
local p, oldVersion = LibStub:NewLibrary(MAJOR, MINOR)

-- 检查是否成功创建了新版本的库
Expand Down
2 changes: 1 addition & 1 deletion InputInput/Libs/jieba-lua/prob_trans.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- 使用 LibStub 创建一个新库
local MAJOR, MINOR = "prob_trans", 1
local MAJOR, MINOR = "inputinput-jieba-prob_trans", 1
local p, oldVersion = LibStub:NewLibrary(MAJOR, MINOR)

-- 检查是否成功创建了新版本的库
Expand Down
2 changes: 1 addition & 1 deletion InputInput/Libs/jieba-lua/utf8.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local W, M, U, D, G, L, E, API, LOG = unpack((select(2, ...)))
-- 使用 LibStub 创建一个新库
local MAJOR, MINOR = "utf8", 1
local MAJOR, MINOR = "inputinput-jieba-utf8", 1
local utf8, oldVersion = LibStub:NewLibrary(MAJOR, MINOR)

-- 检查是否成功创建了新版本的库
Expand Down
4 changes: 2 additions & 2 deletions InputInput/Libs/jieba-lua/utils.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local utf8 = LibStub("utf8")
local utf8 = LibStub("inputinput-jieba-utf8")

-- 使用 LibStub 创建一个新库
local MAJOR, MINOR = "utils", 1
local MAJOR, MINOR = "inputinput-jieba-utils", 1
local M, oldVersion = LibStub:NewLibrary(MAJOR, MINOR)

-- 检查是否成功创建了新版本的库
Expand Down
1 change: 1 addition & 0 deletions InputInput/Log4WOW.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ end

function LOG:Error(...)
Uprint("ERROR", ...)
error(...)
end

function LOG:Warn(...)
Expand Down
33 changes: 29 additions & 4 deletions InputInput/Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ local function FindHis(his, patt)
patt = patt:gsub("%|c.-(%[.-%]).-%|r", function(a1)
return a1
end)
local lastChat = getLastUTF8Char(patt)
local pattp = U:CutWord(patt)
if not pattp or #pattp <= 0 then return '' end
for i = #his, 1, -1 do
Expand All @@ -166,11 +167,26 @@ local function FindHis(his, patt)
local hisp = U:CutWord(h)

for h_index, h2 in ipairs(hisp) do
-- 先按分词匹配
local patt2 = pattp[#pattp]
-- LOG:Debug(patt2)
local start, _end = strfind(h2, patt2, 1, true)
if start and start > 0 then
-- LOG:Debug(h2)
-- LOG:Debug(patt2)
if _end ~= # h2 then
return strsub(h2, _end + 1)
else
local pnex = hisp[h_index + 1]
if pnex and #pnex > 0 then
return pnex
end
end
end
-- 再使用最后一个字符匹配
patt2 = lastChat
start, _end = strfind(h2, patt2, 1, true)
if start and start > 0 then
-- LOG:Debug(patt2)
if _end ~= # h2 then
return strsub(h2, _end + 1)
else
Expand All @@ -182,15 +198,19 @@ local function FindHis(his, patt)
end
end
-- 如果分词匹配不到,使用输入的最后一个字符匹配
local lastChat = getLastUTF8Char(patt)
local start, _end = strfind(h, lastChat, 1, true)
if start and start > 0 and _end ~= #h then
return strsub(h, _end + 1)
end
-- LOG:Debug(lastChat)
local playerTip = U:PlayerTip(patt, lastChat)
local playerTip = U:PlayerTip(patt, pattp[#pattp])
if playerTip then
return playerTip
else
playerTip = U:PlayerTip(patt, lastChat)
if playerTip then
return playerTip
end
end
end
end
Expand Down Expand Up @@ -1184,7 +1204,7 @@ frame:HookScript("OnEvent", function(self_f, event, ...)
local isLoad = C_AddOns_GetAddOnEnableState("InputInput_Libraries_zh") == 2
if GetLocale() == 'zhCN' or GetLocale() == 'zhTW' then
if not (C_AddOns_GetAddOnEnableState("InputInput_Libraries_zh") == 2) then
LOG:Warn('|cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffff0000zh|r' ..
LOG:Warn('|cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffF56C6Czh|r' ..
format(L['Not enabled, enter/ii to enable'], "|cff409EFF/ii|r"))
end
end
Expand All @@ -1194,6 +1214,11 @@ frame:HookScript("OnEvent", function(self_f, event, ...)
U:InitGroupMembers()
LoadSize(scale, editBox, backdropFrame2, channel_name, II_TIP, II_LANG)
LoadPostion(editBox)

local jieba = LibStub("inputinput-jieba")
for _, i in ipairs(jieba.lcut('汽车站长说只有按照', false, true)) do
LOG:Debug(i)
end
end
end
end)
4 changes: 2 additions & 2 deletions InputInput/Options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function OPT:loadOPT()
showChannel.Text:SetText(L['Show channel Name'])
showChannel:SetChecked(settings.showChannel)

-- 启用|cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffff0000zh|r
-- 启用|cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffF56C6Czh|r
local enableIL_zh = CreateFrame("CheckButton", W.N .. "enableIL_zh", options,
"InterfaceOptionsCheckButtonTemplate")
enableIL_zh:SetPoint("TOPLEFT", 16, -206)
Expand All @@ -134,7 +134,7 @@ function OPT:loadOPT()
options:SetScript("OnShow", function(self)
UpdateAddOnMemoryUsage()
enableIL_zh.Text:SetText(format(L['Enable InputInput_Libraries_zh'],
'|cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffff0000zh|r') ..
'|cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffF56C6Czh|r') ..
' |cFF909399' .. GetAddonMemory('InputInput_Libraries_zh') .. ' (' .. L['Need To Reload'] .. ')|r')
settings.enableIL_zh = C_AddOns_GetAddOnEnableState("InputInput_Libraries_zh") == 2
enableIL_zh:SetChecked(settings.enableIL_zh)
Expand Down
31 changes: 22 additions & 9 deletions InputInput/Utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ local function isAllWhitespace(str)
return str:match("^%s*$") ~= nil
end

local jieba = LibStub("jieba")
local jieba = LibStub("inputinput-jieba")
local wordCache = {}

function U:InitWordCache(history)
Expand Down Expand Up @@ -349,11 +349,20 @@ function U:InitFriends()
if accountInfo then
local gameAccountInfo = accountInfo.gameAccountInfo
if gameAccountInfo and gameAccountInfo.characterName and gameAccountInfo.isOnline then
-- LOG:Debug(gameAccountInfo.characterName)
local realm = gameAccountInfo.realmName
if not realm or realm == '' then
-- LOG:Debug(gameAccountInfo.richPresence)
local zoneName, realmName = strsplit('-', gameAccountInfo.richPresence)
-- LOG:Debug(realmName)

if realmName and realmName ~= '' then
realm = strtrim(realmName)
end
end
U:AddOrMoveToEnd(friendName,
U:join('-', gameAccountInfo.characterName, gameAccountInfo.realmName))
-- U:AddOrMoveToEnd(friendName, gameAccountInfo.characterName)
-- U:AddOrMoveToEnd(friendName, gameAccountInfo.realmName)
U:join('-', gameAccountInfo.characterName, realm))
U:AddOrMoveToEnd(friendName, gameAccountInfo.characterName)
U:AddOrMoveToEnd(friendName, realm)
end
end
end
Expand All @@ -373,8 +382,8 @@ function U:InitGuilds()
U:AddOrMoveToEnd(guildName, name)
local name, realm = strsplit('-', name)
realm = realm or GetRealmName()
-- U:AddOrMoveToEnd(guildName, name)
-- U:AddOrMoveToEnd(guildName, realm)
U:AddOrMoveToEnd(guildName, name)
U:AddOrMoveToEnd(guildName, realm)
end
end
end
Expand All @@ -388,6 +397,10 @@ function U:InitZones()
end
U:AddOrMoveToEnd(zoneName, GetZoneText())
U:AddOrMoveToEnd(zoneName, GetSubZoneText())
if #zoneName >= 200 then
table.remove(zoneName, 1)
table.remove(zoneName, 1)
end
D:SaveDB('zoneName', zoneName, true)
end

Expand All @@ -410,8 +423,8 @@ function U:InitGroupMembers()

-- 将名字和服务器存储在表中
U:AddOrMoveToEnd(groupMembers, U:join('-', name, realm))
-- U:AddOrMoveToEnd(groupMembers, name)
-- U:AddOrMoveToEnd(groupMembers, realm)
U:AddOrMoveToEnd(groupMembers, name)
U:AddOrMoveToEnd(groupMembers, realm)
end
end

Expand Down
2 changes: 1 addition & 1 deletion InputInput_Libraries_zh/InputInput_Libraries_zh.toc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Interface: 11503
## IconTexture: Interface\AddOns\InputInput\Media\pet_type_dragon

## Title: |cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffff0000zh|r
## Title: |cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffF56C6Czh|r
## Notes: InputInput Libraries ZH
## Notes-zhCN: InputInput插件中文词语处理模块-可以使输入提示更智能
## Notes-zhTW: InputInput插件中文詞語處理模組-可以使輸入提示更智能
Expand Down
2 changes: 1 addition & 1 deletion InputInput_Libraries_zh/InputInput_Libraries_zh_Cata.toc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Interface: 40400

## Title: |cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffff0000zh|r
## Title: |cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffF56C6Czh|r
## Notes: InputInput Libraries ZH
## Notes-zhCN: InputInput插件中文词语处理模块-可以使输入提示更智能
## Notes-zhTW: InputInput插件中文詞語處理模組-可以使輸入提示更智能
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Interface: 11503

## Title: |cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffff0000zh|r
## Title: |cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffF56C6Czh|r
## Notes: InputInput Libraries ZH
## Notes-zhCN: InputInput插件中文词语处理模块-可以使输入提示更智能
## Notes-zhTW: InputInput插件中文詞語處理模組-可以使輸入提示更智能
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Interface: 110002
## IconTexture: Interface\AddOns\InputInput\Media\pet_type_dragon

## Title: |cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffff0000zh|r
## Title: |cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffF56C6Czh|r
## Notes: InputInput Libraries ZH
## Notes-zhCN: InputInput插件中文词语处理模块-可以使输入提示更智能
## Notes-zhTW: InputInput插件中文詞語處理模組-可以使輸入提示更智能
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Interface: 11503

## Title: |cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffff0000zh|r
## Title: |cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffF56C6Czh|r
## Notes: InputInput Libraries ZH
## Notes-zhCN: InputInput插件中文词语处理模块-可以使输入提示更智能
## Notes-zhTW: InputInput插件中文詞語處理模組-可以使輸入提示更智能
Expand Down
2 changes: 1 addition & 1 deletion InputInput_Libraries_zh/InputInput_Libraries_zh_Wrath.toc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Interface: 30403

## Title: |cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffff0000zh|r
## Title: |cff409EFF|cffF56C6Ci|rnput|cffF56C6Ci|rnput|r_Libraries_|cffF56C6Czh|r
## Notes: InputInput Libraries ZH
## Notes-zhCN: InputInput插件中文词语处理模块-可以使输入提示更智能
## Notes-zhTW: InputInput插件中文詞語處理模組-可以使輸入提示更智能
Expand Down

0 comments on commit 2730dcb

Please sign in to comment.