Skip to content

Commit

Permalink
Added invisible stat accessor.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielWillett committed Jan 4, 2025
1 parent aa6c44f commit 7c4c274
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
30 changes: 26 additions & 4 deletions UncreatedWarfare/Layouts/Phases/LeaderboardPhase.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using DanielWillett.ReflectionTools.Emit;
using DanielWillett.ReflectionTools.Emit;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using Uncreated.Warfare.Events.Models;
Expand Down Expand Up @@ -137,6 +138,24 @@ public void Dispose()

public virtual LeaderboardSet[] CreateLeaderboardSets()
{
for (int i = 0; i < _players.Length; ++i)
{
List<LeaderboardPlayer> players = _players[i];
foreach (LeaderboardPlayer player in players)
{
for (int j = 0; j < _players.Length; ++j)
{
if (j == i)
continue;

List<LeaderboardPlayer> otherPlayers = _players[j];
int olderPlayer = otherPlayers.FindIndex(x => x.Player.Equals(player) && x.LastJoinedTeam <= player.LastJoinedTeam);
if (olderPlayer >= 0)
otherPlayers.RemoveAt(olderPlayer);
}
}
}

LeaderboardSet[] set = new LeaderboardSet[TeamManager.AllTeams.Count];

for (int i = 0; i < TeamManager.AllTeams.Count; ++i)
Expand Down Expand Up @@ -245,8 +264,11 @@ private void CheckPlayer(WarfarePlayer player)
List<LeaderboardPlayer> players = _players[teamIndex];
foreach (LeaderboardPlayer pl in players)
{
if (pl.Player.Equals(player))
return;
if (!pl.Player.Equals(player))
continue;

pl.LastJoinedTeam = Time.realtimeSinceStartup;
return;
}

players.Add(new LeaderboardPlayer(player, team));
Expand All @@ -264,7 +286,7 @@ public class LeaderboardPhaseStatInfo
public string Name { get; set; } = string.Empty;
public string? FormulaName { get; set; }

public bool Visible { get; set; } = true;
public bool IsLeaderboardColumn { get; set; } = true;

public string? Expression { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using Uncreated.Warfare.Layouts.Teams;
using Uncreated.Warfare.Layouts.Teams;
using Uncreated.Warfare.Players;

namespace Uncreated.Warfare.Layouts.UI.Leaderboards;
public class LeaderboardPlayer
{
public WarfarePlayer Player { get; }
public Team Team { get; }
public float LastJoinedTeam { get; set; }
public LeaderboardPlayer(WarfarePlayer player, Team team)
{
Player = player;
Team = team;
LastJoinedTeam = Time.realtimeSinceStartup;
}
}
12 changes: 9 additions & 3 deletions UncreatedWarfare/Layouts/UI/Leaderboards/LeaderboardSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public LeaderboardSet(CreateRow callback, LeaderboardPhaseStatInfo[] stats, IEnu
int visibleColumns = 0;
for (int i = 0; i < stats.Length; ++i)
{
if (stats[i].Visible)
if (stats[i].IsLeaderboardColumn)
++visibleColumns;
}

Expand All @@ -54,7 +54,7 @@ public LeaderboardSet(CreateRow callback, LeaderboardPhaseStatInfo[] stats, IEnu
for (int i = 0; i < stats.Length; ++i)
{
LeaderboardPhaseStatInfo stat = stats[i];
if (stat.Visible)
if (stat.IsLeaderboardColumn)
visibleStats[++visibleColumns] = stat;
}

Expand All @@ -81,7 +81,7 @@ public LeaderboardSet(CreateRow callback, LeaderboardPhaseStatInfo[] stats, IEnu
_inverseSortMaps = new int[visibleStats.Length * 2][];
}

public double GetStatisticValue(string statName, CSteamID player)
public int GetStatisticIndex(string statName)
{
int statIndex = -1;
for (int i = 0; i < Stats.Length; ++i)
Expand All @@ -93,6 +93,12 @@ public double GetStatisticValue(string statName, CSteamID player)
break;
}

return statIndex;
}

public double GetStatisticValue(string statName, CSteamID player)
{
int statIndex = GetStatisticIndex(statName);
if (statIndex == -1)
return 0;

Expand Down

0 comments on commit 7c4c274

Please sign in to comment.