Skip to content

Commit

Permalink
fix(squads): special team input (#4199)
Browse files Browse the repository at this point in the history
* fix(squads): special team input

* fix typo

* unused import
  • Loading branch information
Rathoz authored Apr 22, 2024
1 parent 04d7a40 commit d8a7d1b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
24 changes: 7 additions & 17 deletions components/squad/commons/squad_row.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

local Class = require('Module:Class')
local Icon = require('Module:Icon')
local Info = require('Module:Info')
local Lua = require('Module:Lua')
local OpponentLib = require('Module:OpponentLibraries')
local Opponent = OpponentLib.Opponent
Expand All @@ -34,13 +33,6 @@ local SquadRow = Class.new(
end
)

SquadRow.specialTeamsTemplateMapping = {
retired = 'Team/retired',
inactive = 'Team/inactive',
['passed away'] = 'Team/passed away',
military = 'Team/military',
}

---@return self
function SquadRow:id()
local content = {}
Expand Down Expand Up @@ -159,26 +151,24 @@ end
function SquadRow:newteam()
local function createContent()
local content = {}
local newTeam, newTeamRole = self.model.newteam, self.model.newteamrole
local newTeam, newTeamRole, newTeamSpecial = self.model.newteam, self.model.newteamrole, self.model.newteamspecial
local hasNewTeam, hasNewTeamRole = String.isNotEmpty(newTeam), String.isNotEmpty(newTeamRole)
local hasNewTeamSpecial = String.isNotEmpty(newTeamSpecial)

if not hasNewTeam and not hasNewTeamRole then
if not hasNewTeam and not hasNewTeamRole and not hasNewTeamSpecial then
return content
end

table.insert(content, mw.html.create('div'):addClass('MobileStuff')
:tag('i'):addClass('fa fa-long-arrow-right'):attr('aria-hidden', 'true'):done():wikitext(' '))

if not Info.config.squads.hasSpecialTeam and not hasNewTeam then
table.insert(content, mw.html.create('div'):addClass('NewTeamRole'):wikitext(newTeamRole))
if hasNewTeamSpecial then
table.insert(content, Template.safeExpand(mw.getCurrentFrame(), newTeamSpecial))
return content
end

if not mw.ext.TeamTemplate.teamexists(newTeam) then
local newTeamTemplate = SquadRow.specialTeamsTemplateMapping[newTeam]
if Info.config.squads.hasSpecialTeam and newTeamTemplate then
table.insert(content, Template.safeExpand(mw.getCurrentFrame(), newTeamTemplate))
end
if not hasNewTeam then
table.insert(content, mw.html.create('div'):addClass('NewTeamRole'):wikitext(newTeamRole))
return content
end

Expand Down
11 changes: 11 additions & 0 deletions components/squad/commons/squad_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ SquadUtils.SquadTypeToStorageValue = {
[SquadUtils.SquadType.FORMER_INACTIVE] = 'former',
}

SquadUtils.specialTeamsTemplateMapping = {
retired = 'Team/retired',
inactive = 'Team/inactive',
['passed away'] = 'Team/passed away',
military = 'Team/military',
}

-- TODO: Decided on all valid types
SquadUtils.validPersonTypes = {'player', 'staff'}
SquadUtils.defaultPersonType = 'player'
Expand Down Expand Up @@ -144,6 +151,10 @@ function SquadUtils.readSquadPersonArgs(args)
},
}

if Info.config.squads.hasSpecialTeam and not person.newteam and args.newteam then
person.newteamspecial = SquadUtils.specialTeamsTemplateMapping[args.newteam]
end

if person.joindate ~= args.joindate then
person.extradata.joindatedisplay = args.joindate
end
Expand Down
2 changes: 1 addition & 1 deletion components/squad/wikis/starcraft2/squad_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function CustomSquad._playerRow(person, squadType)
local isMain = Logic.readBool(squadArgs.main) or Logic.isEmpty(squadArgs.squad)
squadPerson.extradata = Table.merge({ismain = tostring(isMain)}, squadPerson.extradata)
end
squadPerson.newteam = Logic.emptyOr(squadPerson.newteam,
squadPerson.newteamspecial = Logic.emptyOr(squadPerson.newteamspecial,
Logic.readBool(person.retired) and 'retired' or nil,
Logic.readBool(person.military) and 'military' or nil)

Expand Down
4 changes: 2 additions & 2 deletions components/squad/wikis/stormgate/squad_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ function CustomSquad._playerRow(person, squadType)
local squadPerson = SquadUtils.readSquadPersonArgs(Table.merge(person, {type = squadType}))
if Logic.isEmpty(squadPerson.newteam) then
if Logic.readBool(person.retired) then
squadPerson.newteam = 'retired'
squadPerson.newteamspecial = 'retired'
elseif Logic.readBool(person.military) then
squadPerson.newteam = 'military'
squadPerson.newteamspecial = 'military'
end
end
SquadUtils.storeSquadPerson(squadPerson)
Expand Down

0 comments on commit d8a7d1b

Please sign in to comment.