Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5761d96
player & clubshare draft
MischiefCS Mar 19, 2026
dd5da0f
init branch
MischiefCS Mar 19, 2026
c4861c6
updating Prizepoo/base
MischiefCS Mar 20, 2026
3537a31
fixing line too long check
MischiefCS Mar 20, 2026
f6aca54
fixing tab check
MischiefCS Mar 20, 2026
e58b61c
resolving comments
MischiefCS Mar 20, 2026
55896e3
fixing accidental line remove
MischiefCS Mar 20, 2026
8b480b3
fixing spec
MischiefCS Mar 20, 2026
69c0c0d
fixing second storage spec
MischiefCS Mar 20, 2026
312fe20
adding tests
MischiefCS Mar 20, 2026
a1f69c4
resolving comments
MischiefCS Mar 22, 2026
a596874
fixing spec
MischiefCS Mar 22, 2026
652a6b8
fixing defined spec for numbers
MischiefCS Mar 22, 2026
65fb79b
resolving comments
MischiefCS Mar 22, 2026
317736e
add test cases to #7284 (#7293)
hjpalpha Mar 23, 2026
d4f3d71
Merge branch 'main' into clubshare-vrs
MischiefCS Mar 23, 2026
5f94b42
Apply suggestions from code review
MischiefCS Mar 23, 2026
5b914eb
Merge branch 'main' into clubshare-vrs
MischiefCS Mar 23, 2026
7009493
allow setting of club share arg title
MischiefCS Mar 24, 2026
218d90a
removing currency code for shares
MischiefCS Mar 26, 2026
c536845
Merge branch 'main' into clubshare-vrs
ElectricalBoy Mar 27, 2026
8fa7212
chore: update visual snapshots
ElectricalBoy Mar 27, 2026
853e6e0
Merge branch 'main' into clubshare-vrs
hjpalpha May 4, 2026
05615a3
fix the merge conflict resolve
hjpalpha May 4, 2026
9cf2eb5
chore: update visual snapshots
hjpalpha May 4, 2026
d8a442c
resolve comment (#7457)
hjpalpha May 7, 2026
74bc9db
resolving comment for playerShare condition 4248833091
MischiefCS May 8, 2026
0dffae8
Merge branch 'main' into clubshare-vrs
MischiefCS May 8, 2026
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
107 changes: 97 additions & 10 deletions lua/spec/prize_pool_spec.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
--- Triple Comment to Enable our LLS Plugin
local TeamTemplateMock = require('wikis.commons.Mock.TeamTemplate')
describe('prize pool', function()
local PrizePool = require('Module:PrizePool')
local InfoboxLeague = require('Module:Infobox/League/Custom')
Expand All @@ -13,16 +14,18 @@ describe('prize pool', function()
stub(mw.ext.LiquipediaDB, "lpdb_tournament")
LpdbPlacementStub = stub(mw.ext.LiquipediaDB, "lpdb_placement")
InfoboxLeague.run(tournamentData)
TeamTemplateMock.setUp()
end)

after_each(function ()
LpdbPlacementStub:revert()
---@diagnostic disable-next-line: undefined-field
mw.ext.LiquipediaDB.lpdb:revert()
mw.ext.LiquipediaDB.lpdb_tournament:revert()
TeamTemplateMock.tearDown()
end)

local prizePoolArgs = {
local prizePool1Args = {
type = {type = 'solo'},
currencyroundprecision = 3,
lpdb_prefix = 'abc',
Expand All @@ -39,8 +42,19 @@ describe('prize pool', function()
[2] = {qualified1 = true, [1] = {'Salt'}},
}

local prizePool2Args = {
type = {type = 'team'},
currencyroundprecision = 2,
lpdb_prefix = 'abc',
import = false,
playershare = true,
[1] = {usdprize = '400000', playershare = '200000', [1] = {'mouz'}},
[2] = {usdprize = '1,000', [1] = {'t1'}},
}

it('parameters are correctly parsed', function()
local ppt = PrizePool(prizePoolArgs):create()
local ppt = PrizePool(prizePool1Args):create()
local ppt2 = PrizePool(prizePool2Args):create()

assert.are_same(
{
Expand Down Expand Up @@ -73,6 +87,14 @@ describe('prize pool', function()
},
ppt.prizes
)
assert.are_same(
{
{id = 'BASE_CURRENCY1', type = 'BASE_CURRENCY', index = 1, data = {roundPrecision = 2}},
{id = 'PLAYER_SHARE1', type = 'PLAYER_SHARE', index = 1, data = {title = 'Player Share'}},
{id = 'CLUB_SHARE1', type = 'CLUB_SHARE', index = 1, data = {title = 'Club Share', roundPrecision = 2}},
},
ppt2.prizes
)

assert.are_same(
{
Expand All @@ -96,11 +118,12 @@ describe('prize pool', function()

describe('prize pool is correct', function()
it('display', function()
GoldenTest('prize_pool', tostring(PrizePool(prizePoolArgs):create():build()))
GoldenTest('prize_pool', tostring(PrizePool(prizePool1Args):create():build()))
GoldenTest('prize_pool_player_share', tostring(PrizePool(prizePool2Args):create():build()))
end)

it('lpdb storage', function()
PrizePool(prizePoolArgs):create():build()
PrizePool(prizePool1Args):create():build()
assert.stub(LpdbPlacementStub).was.called_with('ranking_abc1_Rathoz', {
date = '2022-10-15',
extradata = '{"prizepoints":"","prizepoints2":""}',
Expand Down Expand Up @@ -157,42 +180,106 @@ describe('prize pool', function()
type = 'Offline',
qualified = 1,
})

PrizePool(prizePool2Args):create():build()
assert.stub(LpdbPlacementStub).was.called_with('ranking_abc_mouz', {
date = '2022-10-15',
extradata = '{"playershare":200000,"prizepoints":"","prizepoints2":""}',
game = 'commons',
icon = 'test.png',
icondark = 'test dark.png',
image = 'MOUZ allmode.png',
imagedark = 'MOUZ allmode.png',
individualprizemoney = 0,
lastvsdata = '[]',
liquipediatier = '1',
liquipediatiertype = 'Qualifier',
opponentname = 'MOUZ',
opponentplayers = '[]',
opponenttype = 'team',
opponenttemplate = 'mouz 2021',
parent = 'FakePage',
participant = 'MOUZ', -- Legacy
participantlink = 'MOUZ', -- Legacy
participanttemplate = 'mouz 2021',
placement = 1,
players = '[]', -- Legacy
prizemoney = 400000,
prizepoolindex = 2,
series = 'Test Series',
shortname = 'Test Tourney',
startdate = '2022-10-13',
tournament = 'Test Tournament',
type = 'Offline',
qualified = 0,
})
assert.stub(LpdbPlacementStub).was.called_with('ranking_abc_t1', {
date = '2022-10-15',
extradata = '{"prizepoints":"","prizepoints2":""}',
game = 'commons',
icon = 'test.png',
icondark = 'test dark.png',
image = 'T1 2019 allmode.png',
imagedark = 'T1 2019 allmode.png',
individualprizemoney = 0,
lastvsdata = '[]',
liquipediatier = '1',
liquipediatiertype = 'Qualifier',
opponentname = 'T1',
opponentplayers = '[]',
opponenttype = 'team',
opponenttemplate = 't1 2019',
parent = 'FakePage',
participant = 'T1', -- Legacy
participantlink = 'T1', -- Legacy
participanttemplate = 't1 2019',
placement = 2,
players = '[]', -- Legacy
prizemoney = 1000,
prizepoolindex = 2,
series = 'Test Series',
shortname = 'Test Tourney',
startdate = '2022-10-13',
tournament = 'Test Tournament',
type = 'Offline',
qualified = 0,
})
end)
end)

describe('enabling/disabling lpdb storage', function()
it('normal behavior', function()
PrizePool(prizePoolArgs):create():build()
PrizePool(prizePool1Args):create():build()
assert.stub(LpdbPlacementStub).called(2)
end)

it('disabled', function()
PrizePool(Table.merge(prizePoolArgs, {storelpdb = false})):create():build()
PrizePool(Table.merge(prizePool1Args, {storelpdb = false})):create():build()
assert.stub(LpdbPlacementStub).called(0)
end)

it('wiki-var enabled', function()
Variables.varDefine('disable_LPDB_storage', 'false')
PrizePool(prizePoolArgs):create():build()
PrizePool(prizePool1Args):create():build()
assert.stub(LpdbPlacementStub).called(2)
end)

it('wiki-var enabled with override', function()
Variables.varDefine('disable_LPDB_storage', 'false')
PrizePool(Table.merge(prizePoolArgs, {storelpdb = false})):create():build()
PrizePool(Table.merge(prizePool1Args, {storelpdb = false})):create():build()
assert.stub(LpdbPlacementStub).called(0)
end)


it('wiki-var disable with override', function()
Variables.varDefine('disable_LPDB_storage', 'true')
PrizePool(Table.merge(prizePoolArgs, {storelpdb = true})):create():build()
PrizePool(Table.merge(prizePool1Args, {storelpdb = true})):create():build()
assert.stub(LpdbPlacementStub).called(2)
end)

it('wiki-var disable without override', function()
Variables.varDefine('disable_LPDB_storage', 'true')
PrizePool(prizePoolArgs):create():build()
PrizePool(prizePool1Args):create():build()
assert.stub(LpdbPlacementStub).called(0)
end)
end)
Expand Down
Binary file added lua/spec/snapshots/prize_pool_player_share.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 73 additions & 3 deletions lua/wikis/commons/PrizePool/Base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ local PRIZE_TYPE_QUALIFIES = 'QUALIFIES'
local PRIZE_TYPE_POINTS = 'POINTS'
local PRIZE_TYPE_PERCENTAGE = 'PERCENT'
local PRIZE_TYPE_FREETEXT = 'FREETEXT'
local PRIZE_TYPE_PLAYER_SHARE = 'PLAYER_SHARE'
local PRIZE_TYPE_CLUB_SHARE = 'CLUB_SHARE'

BasePrizePool.config = {
showBaseCurrency = {
Expand Down Expand Up @@ -357,9 +359,55 @@ BasePrizePool.prizeTypes = {
end
end,
},
[PRIZE_TYPE_FREETEXT] = {
[PRIZE_TYPE_PLAYER_SHARE] = {
sortOrder = 60,

header = 'playershare',
headerParse = function (prizePool, input, context, index)
return {title = 'Player Share'}
end,
headerDisplay = function (data)
return TableCell{children = {data.title}}
end,

row = 'playershare',
rowParse = function (placement, input, context, index)
return BasePrizePool._parseInteger(input)
end,
rowDisplay = function (headerData, data)
if data > 0 then
return TableCell{children = {
Currency.display(BASE_CURRENCY, data,
{formatValue = true, formatPrecision = headerData.roundPrecision, displayCurrencyCode = false})
}}
end
Comment thread
MischiefCS marked this conversation as resolved.
end,
},
[PRIZE_TYPE_CLUB_SHARE] = {
Comment thread
mbergen marked this conversation as resolved.
sortOrder = 70,
header = 'clubshare',
headerParse = function(prizePool, input, context, index)
return {title = String.isNotEmpty(input) and input or 'Club Share'}
end,
headerDisplay = function(data)
return TableCell{children = {data.title}}
end,
row = 'clubshare',
rowParse = function(placement, input, context, index)
return input
end,
rowDisplay = function(headerData, data)
if data and tonumber(data) > 0 then
return TableCell{children = {
Currency.display(BASE_CURRENCY, data,
{formatValue = true, formatPrecision = headerData.roundPrecision, displayCurrencyCode = false})
}}
end
end,
},
[PRIZE_TYPE_FREETEXT] = {
sortOrder = 80,

header = 'freetext',
headerParse = function (prizePool, input, context, index)
return {title = input}
Expand Down Expand Up @@ -423,6 +471,22 @@ function BasePrizePool:create()
self:setConfig('showBaseCurrency', true)
self:addPrize(PRIZE_TYPE_BASE_CURRENCY, 1, {roundPrecision = self.options.currencyRoundPrecision})

local hasPlayerShare = Array.any(self.prizes, function(prize)
return prize.type == PRIZE_TYPE_PLAYER_SHARE
end)
if hasPlayerShare then
Comment thread
MischiefCS marked this conversation as resolved.
local alreadyHasClubShare = Array.any(self.prizes, function(prize)
return prize.type == PRIZE_TYPE_CLUB_SHARE
end)
if not alreadyHasClubShare then
local clubShareTitle = self.args.clubshare
self:addPrize(PRIZE_TYPE_CLUB_SHARE, 1, {
title = String.isNotEmpty(clubShareTitle) and clubShareTitle or 'Club Share',
roundPrecision = self.options.currencyRoundPrecision
})
end
end

if self.options.autoExchange then
local canConvertCurrency = function(prize)
return prize.type == PRIZE_TYPE_LOCAL_CURRENCY
Expand All @@ -434,10 +498,16 @@ function BasePrizePool:create()
return prize.type == PRIZE_TYPE_PERCENTAGE and prize.index == 1
end)

for _, placement in ipairs(self.placements) do
Array.forEach(self.placements, function(placement)
if hasPercentage1 then placement:_calculateFromPercentage(BasePrizePool.prizeTypes, hasLocalCurrency1) end
placement:_setBaseFromRewards(Array.filter(self.prizes, canConvertCurrency), BasePrizePool.prizeTypes)
end
end)
end

if hasPlayerShare then
Array.forEach(self.placements, function(placement)
placement:_setClubShareFromPlayerShare(self.prizes)
end)
end
end

Expand Down
3 changes: 3 additions & 0 deletions lua/wikis/commons/PrizePool/Placement.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ local DASH = '-'
local PRIZE_TYPE_BASE_CURRENCY = 'BASE_CURRENCY'
local PRIZE_TYPE_POINTS = 'POINTS'
local PRIZE_TYPE_QUALIFIES = 'QUALIFIES'
local PRIZE_TYPE_PLAYER_SHARE = 'PLAYER_SHARE'

-- Allowed none-numeric score values.
local SPECIAL_SCORES = {'W', 'FF' , 'L', 'DQ', 'D'}
Expand Down Expand Up @@ -235,6 +236,7 @@ function Placement:_getLpdbData(...)
local pointsReward = self:getPrizeRewardForOpponent(opponent, PRIZE_TYPE_POINTS .. 1)
local pointsReward2 = self:getPrizeRewardForOpponent(opponent, PRIZE_TYPE_POINTS .. 2)
local isQualified = self:getPrizeRewardForOpponent(opponent, PRIZE_TYPE_QUALIFIES .. '1')
local playerShare = tonumber(self:getPrizeRewardForOpponent(opponent, PRIZE_TYPE_PLAYER_SHARE .. 1))

local lpdbData = {
image = image,
Expand Down Expand Up @@ -262,6 +264,7 @@ function Placement:_getLpdbData(...)
participantteam = (opponentType == Opponent.solo and players.p1team)
and Opponent.toName{template = players.p1team, type = 'team', extradata = {}}
or nil,
playershare = playerShare,
},
qualified = isQualified and 1 or 0
-- TODO: We need to create additional LPDB Fields
Expand Down
26 changes: 26 additions & 0 deletions lua/wikis/commons/PrizePool/Placement/Base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ local LOCAL_CURRENCY_VARIABLE_POST_FIX = 'local'
local PRIZE_TYPE_BASE_CURRENCY = 'BASE_CURRENCY'
local PRIZE_TYPE_LOCAL_CURRENCY = 'LOCAL_CURRENCY'
local PRIZE_TYPE_PERCENTAGE = 'PERCENT'
local PRIZE_TYPE_PLAYER_SHARE = 'PLAYER_SHARE'
local PRIZE_TYPE_CLUB_SHARE = 'CLUB_SHARE'

--- A BasePlacement is a set of opponents who all share the same final place/award in the tournament.
--- Its input is generally a table created by `Template:Slot`.
Expand Down Expand Up @@ -210,6 +212,30 @@ function BasePlacement:_setBaseFromRewards(prizesToUse, prizeTypes)
end)
end

-- Calculate club share for the placement
---@param prizes BasePrizePoolPrize[]
function BasePlacement:_setClubShareFromPlayerShare(prizes)
Array.forEach(self.opponents, function(opponent)
local basePrize
local playerShare
Array.forEach(prizes, function(prize)
if prize.type == PRIZE_TYPE_BASE_CURRENCY then
basePrize = opponent.prizeRewards[prize.id] or self.prizeRewards[prize.id]
elseif prize.type == PRIZE_TYPE_PLAYER_SHARE then
playerShare = opponent.prizeRewards[prize.id] or self.prizeRewards[prize.id]
end
end)
basePrize = tonumber(basePrize)
playerShare = tonumber(playerShare)

if not basePrize or not playerShare then
return
end
opponent.prizeRewards = opponent.prizeRewards or {}
opponent.prizeRewards[PRIZE_TYPE_CLUB_SHARE .. '1'] = basePrize - playerShare
end)
end

---@param prizeTypes table
---@param hasLocalCurrency boolean
function BasePlacement:_calculateFromPercentage(prizeTypes, hasLocalCurrency)
Expand Down
6 changes: 4 additions & 2 deletions lua/wikis/commons/TeamParticipants/Repository.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ function TeamParticipantsRepository.save(participant)
lpdbData.players = lpdbData.opponentplayers

-- Calculate individual prize money (prize money per player on team)
if lpdbData.prizemoney then
-- Opt to use playerShare over prizepool if available
local prizevalue = lpdbData.extradata and lpdbData.extradata.playershare or lpdbData.prizemoney
if prizevalue then
local filteredPlayers = Array.filter(activeOpponent.players, function(player)
return player.extradata.type ~= 'staff'
end)
local numberOfPlayersOnTeam = math.max(#(filteredPlayers), 1)
lpdbData.individualprizemoney = lpdbData.prizemoney / numberOfPlayersOnTeam
lpdbData.individualprizemoney = prizevalue / numberOfPlayersOnTeam
end

if lpdbData.mode ~= 'award_individual' then
Expand Down
Loading