Nu verkar spelarfördelningen fungerar och poäng räknas up

This commit is contained in:
2025-09-21 13:58:35 +02:00
parent 0e2a283239
commit d20c0095cc
3 changed files with 61 additions and 8 deletions

View File

@ -10,6 +10,8 @@ namespace GreadyPoang.ViewModelLayer;
public class RoundRunningViewModel : ViewModelBase
{
public event EventHandler RebuildRequested;
public RoundRunningViewModel() : base()
{
}
@ -43,6 +45,12 @@ public class RoundRunningViewModel : ViewModelBase
private ObservableCollection<Participant> _ParticipantList = new();
private Collection<PlayerColumn> _playerColumns;
public void TriggerRebuild()
{
// Trigga eventet
RebuildRequested?.Invoke(this, EventArgs.Empty);
}
public ObservableCollection<RoundBuilderElement> RoundElements
{
get { return _roundElements; }
@ -102,6 +110,7 @@ public class RoundRunningViewModel : ViewModelBase
var localElements = _combined.roundBuilderElementsTotalById(_objectMessage.CurrentGroup.GameRoundId);
FillupResultTable(localElements);
}
return RoundElements;
}
@ -128,15 +137,21 @@ public class RoundRunningViewModel : ViewModelBase
{
RoundElements.Add(item);
}
// Uppdatera spelaren som skall spela nästa
var nxt = nextPlayerElement();
BuilderObject.GameRegPoints = 0;
BuilderObject.ParticipantName = RoundElements[nxt].ParticipantName;
BuilderObject.ParticipantId = RoundElements[nxt].ParticipantId;
BuilderObject.GameRoundId = RoundElements[0].GameRoundId;
var localElements = _combined.roundBuilderElementsTotalById(BuilderObject.GameRoundId);
FillupResultTable(localElements);
foreach (var col in _playerColumns)
{
RoundElements.FirstOrDefault(e => e.ParticipantId == col.PlayerId).GameRegPoints = col.PlayerPoints;
}
TriggerRebuild();
}
private int nextPlayerElement()
@ -166,23 +181,28 @@ public class RoundRunningViewModel : ViewModelBase
if (elements.Any(g => g.GameRegPoints > 0))
{
var oldPart = -1;
PlayerColumn player = new PlayerColumn();
foreach (var element in elements)
{
if (element.ParticipantId != oldPart)
player = _playerColumns.FirstOrDefault(p => p.PlayerId == element.ParticipantId);
if (player == null)
{
player = new PlayerColumn
{
PlayerName = element.ParticipantName
PlayerName = element.ParticipantName,
PlayerId = element.ParticipantId,
PlayerPoints = 0
};
}
if (element.GameRegPoints > 0)
player.Values.Add(element.GameRegPoints.ToString());
oldPart = element.ParticipantId;
if (element.GameRegPoints > 0)
{
player.Values.Add(element.GameRegPoints.ToString());
player.PlayerPoints += element.GameRegPoints;
}
//oldPart = element.ParticipantId;
if (!_playerColumns.Contains(player))
{