1+
2+ local PCKeyDefaultRestoreHotfixer = Class (" PCKeyDefaultRestoreHotfixer" , HotfixBase )
3+
4+ local eutil = CS .Torappu .Lua .Util
5+ local _KEY = " KEYBOARD_DEFAULT_RESTORE_HOTFIX_V1"
6+
7+ local function IsNilOrEmpty (value )
8+ return value == nil or value == " "
9+ end
10+
11+ local function HasDone ()
12+ return CS .UnityEngine .PlayerPrefs .GetInt (" KEYBOARD_DEFAULT_RESTORE_HOTFIX_V1" , 0 ) == 1
13+ end
14+
15+ local function MarkDone ()
16+ CS .UnityEngine .PlayerPrefs .SetInt (" KEYBOARD_DEFAULT_RESTORE_HOTFIX_V1" , 1 )
17+ CS .UnityEngine .PlayerPrefs .Save ()
18+ end
19+
20+ local function TryRestore (self )
21+ if self == nil or HasDone () then
22+ return
23+ end
24+
25+ local displayData = CS .Torappu .DisplayMetaDB .data
26+ local gameData = displayData and displayData .pcKeyData
27+ local keySettingData = gameData and gameData .keySettingData
28+ if keySettingData == nil then
29+ return
30+ end
31+
32+ for groupId , groupData in pairs (keySettingData ) do
33+ local itemList = groupData and groupData .itemList
34+ if not IsNilOrEmpty (groupId ) and itemList ~= nil then
35+ for i = 0 , itemList .Count - 1 do
36+ local itemData = itemList [i ]
37+ if itemData ~= nil and itemData .canBeSet then
38+ local funcId = itemData .funcId
39+ local defaultKeyId = itemData .defaultKeyId
40+ if not IsNilOrEmpty (funcId ) and not IsNilOrEmpty (defaultKeyId ) then
41+ local currKey = self :GetKeyItemByFuncId (groupId , funcId )
42+ if currKey == nil then
43+ local config = CS .Torappu .KeyBoardVirtualButtonConfig (groupId , funcId )
44+ local conflict = self :GetConflictFuncInSetting (config , defaultKeyId )
45+ if conflict == nil then
46+ self :SetFuncKey (groupId , funcId , defaultKeyId )
47+ end
48+ end
49+ end
50+ end
51+ end
52+ end
53+ end
54+
55+ MarkDone ()
56+ end
57+
58+ function PCKeyDefaultRestoreHotfixer :OnInit ()
59+ if CS .Torappu .DeviceInfoUtil :IsPCMode () then
60+ self :Fix_ex (CS .Torappu .KeyEntityGroupBase .TorappuKeyBoardLogic , " LoadData" , function (self )
61+ local okLoad , errLoad = xpcall (function ()
62+ self :LoadData ()
63+ TryRestore (self )
64+ end , debug.traceback )
65+ if not okLoad then
66+ eutil .LogHotfixError (" [PCKeyDefaultRestoreHotfixer][LoadData]" .. tostring (errLoad ))
67+ return
68+ end
69+ end )
70+ end
71+ end
72+
73+ return PCKeyDefaultRestoreHotfixer
0 commit comments