Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions lua/wikis/trackmania/Infobox/Person/Player/Custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,34 @@ local Class = Lua.import('Module:Class')

local Achievements = Lua.import('Module:Infobox/Extension/Achievements')
local Injector = Lua.import('Module:Widget/Injector')
local Logic = Lua.import('Module:Logic')
local Player = Lua.import('Module:Infobox/Person')
Comment thread
SobakaPirat marked this conversation as resolved.

local Widgets = Lua.import('Module:Widget/All')
local Cell = Widgets.Cell

---@type table<string, string>
local INPUTS = {
gamepad = 'Gamepad',
joystick = 'Joystick',
kbm = 'Keyboard & Mouse',
keyboard = 'Keyboard',
wheel = 'Wheel',
}

---@type table<string, string>
local CAMERAS = {
['1'] = '1',
['2'] = '2',
['3'] = '3',
['alt1'] = '1 (Alternate)',
['alt2'] = '2 (Alternate)',
['alt3'] = '3 (Alternate)',
['1alt'] = '1 (Alternate)',
['2alt'] = '2 (Alternate)',
['3alt'] = '3 (Alternate)',
Comment thread
SobakaPirat marked this conversation as resolved.
Outdated
}

---@class TrackmaniaInfoboxPlayer: Person
local CustomPlayer = Class.new(Player)
local CustomInjector = Class.new(Injector)
Expand All @@ -35,11 +58,36 @@ end
---@param widgets Widget[]
---@return Widget[]
function CustomInjector:parse(id, widgets)
if id == 'status' then
table.insert(widgets, Cell{name = 'Years Active (Player)', children = {self.caller.args.years_active}})
local caller = self.caller
local args = caller.args
if id == 'custom' then
table.insert(widgets, Cell{name = 'Input Device', children = {caller:formatInput()}})
table.insert(widgets, Cell{name = 'Main Camera', children = {caller:formatCamera()}})
elseif id == 'status' then
table.insert(widgets, Cell{name = 'Years Active (Player)', children = {args.years_active}})
end

return widgets
end

---@param lpdbData table
---@return table
function CustomPlayer:adjustLPDB(lpdbData)
lpdbData.extradata.input = self:formatInput()
lpdbData.extradata.camera = self:formatCamera()
return lpdbData
end

---@return string?
function CustomPlayer:formatInput()
local lowercaseInput = self.args.input and self.args.input:lower() or nil
return Logic.nilOr(INPUTS[lowercaseInput])
end

---@return string?
function CustomPlayer:formatCamera()
local lowercaseCamera = self.args.camera and self.args.camera:lower() or nil
return Logic.nilOr(CAMERAS[lowercaseCamera])
end
Comment thread
SobakaPirat marked this conversation as resolved.

return CustomPlayer
Loading