Welcome to the Umamusume Wiki! If you want to contribute, please read the guidelines.
Module:Game/TrainingEvents/Data
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Game/TrainingEvents/Data/doc
--[[
!! THIS PAGE IS MANAGED BY GITLAB !!
ANY EDITS TO PAGE CONTENT WILL BE OVERWRITTEN
TO MAKE CHANGES, PLEASE SUBMIT A MERGE REQUEST AT https://gitlab.com/umamusume-wiki/lua-modules
]]
local Data = {}
local Game = require("Module:Game")
---@class TrainingEventData
---@field eventId string
---@field storyId string
---@field titleJP string
---@field titleEN string|nil
---@field chainNum number
---@field chainMax number
---@field isGroupChain boolean
---Get training event data for the given story IDs, assuming no duplicates
---@param storyIds string[]
---@return TrainingEventData[]
function Data.getTrainingEventsByStoryIds(storyIds)
local storyIdsInsert = table.concat(storyIds, ',')
local single_mode_story_datas = Game.queryMaster {
from = "single_mode_story_data",
where = string.format("story_id in (%s)", storyIdsInsert)
}
local idToStoryIdMap = {}
for _, single_mode_story_data in ipairs(single_mode_story_datas) do
idToStoryIdMap[single_mode_story_data.id] = single_mode_story_data.story_id
end
local mapped = Data._mapStoryData(single_mode_story_datas)
local data = {}
for eventId, event in pairs(mapped) do
data[idToStoryIdMap[eventId]] = event
end
return data
end
---Get training event data for the given event IDs
---@param eventIds string[]
---@return TrainingEventData[]
function Data.getTrainingEvents(eventIds)
local eventIdsInsert = table.concat(eventIds, ',')
local single_mode_story_datas = Game.queryMaster {
from = "single_mode_story_data",
where = string.format("id in (%s)", eventIdsInsert)
}
return Data._mapStoryData(single_mode_story_datas)
end
---@param single_mode_story_datas table[]
---@return TrainingEventData[]
function Data._mapStoryData(single_mode_story_datas)
local storyIds = {}
for _, single_mode_story_data in ipairs(single_mode_story_datas) do
table.insert(storyIds, single_mode_story_data.story_id)
end
local storyTitlesJP = Game.getJPText(181, storyIds)
local storyTitlesEN = Game.getENText(181, storyIds)
local datas = {}
for _, single_mode_story_data in ipairs(single_mode_story_datas) do
local titleJP = storyTitlesJP[single_mode_story_data.story_id] or ''
local titleEN = storyTitlesEN[single_mode_story_data.story_id]
local data = { ---@type TrainingEventData
eventId = single_mode_story_data.id,
storyId = single_mode_story_data.story_id,
titleJP = titleJP,
titleEN = titleEN,
chainNum = tonumber(single_mode_story_data.show_progress_1) or 0,
chainMax = tonumber(single_mode_story_data.show_progress_2) or 0,
isGroupChain = single_mode_story_data.show_progress_3 == '1'
}
datas[data.eventId] = data
end
return datas
end
return Data