Модуль:Prototypes/Механика/Исследование: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 2: | Строка 2: | ||
local dataCache = nil -- Кэш для данных плат | local dataCache = nil -- Кэш для данных плат | ||
local researchDataCache = nil -- Кэш для данных исследований | local researchDataCache = nil -- Кэш для данных исследований | ||
local machineIDCache = {} -- Кэш для машинных ID | |||
-- Функция для загрузки данных плат из JSON-файла | -- Функция для загрузки данных плат из JSON-файла | ||
local function loadData() | local function loadData() | ||
if not dataCache then | if not dataCache then | ||
-- Кэширование данных при первом вызове | |||
dataCache = mw.text.jsonDecode(mw.title.new("Участник:IanComradeBot/entity_prototypes.json"):getContent()) | dataCache = mw.text.jsonDecode(mw.title.new("Участник:IanComradeBot/entity_prototypes.json"):getContent()) | ||
end | end | ||
| Строка 14: | Строка 16: | ||
local function loadResearchData() | local function loadResearchData() | ||
if not researchDataCache then | if not researchDataCache then | ||
-- Кэширование данных исследований при первом вызове | |||
researchDataCache = mw.text.jsonDecode(mw.title.new("User:IanComradeBot/research_prototypes.json"):getContent()) | researchDataCache = mw.text.jsonDecode(mw.title.new("User:IanComradeBot/research_prototypes.json"):getContent()) | ||
end | end | ||
return researchDataCache | return researchDataCache | ||
end | end | ||
-- Функция для перевода ID плат в ID машин с кэшированием | -- Функция для перевода ID плат в ID машин с кэшированием | ||
local function translateBoardIDToMachineID(boardID) | local function translateBoardIDToMachineID(boardID) | ||
if machineIDCache[boardID] then | if machineIDCache[boardID] then | ||
-- Если ID машины уже есть в кэше, возвращаем его | |||
return machineIDCache[boardID] | return machineIDCache[boardID] | ||
end | end | ||
| Строка 60: | Строка 61: | ||
if not shouldExclude then | if not shouldExclude then | ||
-- Кэширование ID машины | |||
machineIDCache[boardID] = entity.id | machineIDCache[boardID] = entity.id | ||
return entity.id | return entity.id | ||