Nu verkar spelarfördelningen fungerar och poäng räknas up
This commit is contained in:
@ -9,6 +9,9 @@ public class PlayerColumn : EntityBase
|
|||||||
_playerName = string.Empty;
|
_playerName = string.Empty;
|
||||||
_values = new List<string>();
|
_values = new List<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private int _playerId;
|
||||||
private string _playerName;
|
private string _playerName;
|
||||||
private List<string> _values;
|
private List<string> _values;
|
||||||
public string PlayerName
|
public string PlayerName
|
||||||
@ -29,4 +32,24 @@ public class PlayerColumn : EntityBase
|
|||||||
RaisePropertyChanged(nameof(Values));
|
RaisePropertyChanged(nameof(Values));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int PlayerId
|
||||||
|
{
|
||||||
|
get { return _playerId; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_playerId = value;
|
||||||
|
RaisePropertyChanged(nameof(PlayerId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int _playerPoints;
|
||||||
|
|
||||||
|
public int PlayerPoints
|
||||||
|
{
|
||||||
|
get { return _playerPoints; }
|
||||||
|
set { _playerPoints = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,8 @@ namespace GreadyPoang.ViewModelLayer;
|
|||||||
public class RoundRunningViewModel : ViewModelBase
|
public class RoundRunningViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public event EventHandler RebuildRequested;
|
||||||
|
|
||||||
public RoundRunningViewModel() : base()
|
public RoundRunningViewModel() : base()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -43,6 +45,12 @@ public class RoundRunningViewModel : ViewModelBase
|
|||||||
private ObservableCollection<Participant> _ParticipantList = new();
|
private ObservableCollection<Participant> _ParticipantList = new();
|
||||||
private Collection<PlayerColumn> _playerColumns;
|
private Collection<PlayerColumn> _playerColumns;
|
||||||
|
|
||||||
|
public void TriggerRebuild()
|
||||||
|
{
|
||||||
|
// Trigga eventet
|
||||||
|
RebuildRequested?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
public ObservableCollection<RoundBuilderElement> RoundElements
|
public ObservableCollection<RoundBuilderElement> RoundElements
|
||||||
{
|
{
|
||||||
get { return _roundElements; }
|
get { return _roundElements; }
|
||||||
@ -102,6 +110,7 @@ public class RoundRunningViewModel : ViewModelBase
|
|||||||
|
|
||||||
var localElements = _combined.roundBuilderElementsTotalById(_objectMessage.CurrentGroup.GameRoundId);
|
var localElements = _combined.roundBuilderElementsTotalById(_objectMessage.CurrentGroup.GameRoundId);
|
||||||
FillupResultTable(localElements);
|
FillupResultTable(localElements);
|
||||||
|
|
||||||
}
|
}
|
||||||
return RoundElements;
|
return RoundElements;
|
||||||
}
|
}
|
||||||
@ -128,15 +137,21 @@ public class RoundRunningViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
RoundElements.Add(item);
|
RoundElements.Add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uppdatera spelaren som skall spela nästa
|
// Uppdatera spelaren som skall spela nästa
|
||||||
var nxt = nextPlayerElement();
|
var nxt = nextPlayerElement();
|
||||||
|
BuilderObject.GameRegPoints = 0;
|
||||||
BuilderObject.ParticipantName = RoundElements[nxt].ParticipantName;
|
BuilderObject.ParticipantName = RoundElements[nxt].ParticipantName;
|
||||||
BuilderObject.ParticipantId = RoundElements[nxt].ParticipantId;
|
BuilderObject.ParticipantId = RoundElements[nxt].ParticipantId;
|
||||||
BuilderObject.GameRoundId = RoundElements[0].GameRoundId;
|
BuilderObject.GameRoundId = RoundElements[0].GameRoundId;
|
||||||
|
|
||||||
var localElements = _combined.roundBuilderElementsTotalById(BuilderObject.GameRoundId);
|
var localElements = _combined.roundBuilderElementsTotalById(BuilderObject.GameRoundId);
|
||||||
FillupResultTable(localElements);
|
FillupResultTable(localElements);
|
||||||
|
foreach (var col in _playerColumns)
|
||||||
|
{
|
||||||
|
RoundElements.FirstOrDefault(e => e.ParticipantId == col.PlayerId).GameRegPoints = col.PlayerPoints;
|
||||||
|
}
|
||||||
|
TriggerRebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int nextPlayerElement()
|
private int nextPlayerElement()
|
||||||
@ -166,23 +181,28 @@ public class RoundRunningViewModel : ViewModelBase
|
|||||||
|
|
||||||
if (elements.Any(g => g.GameRegPoints > 0))
|
if (elements.Any(g => g.GameRegPoints > 0))
|
||||||
{
|
{
|
||||||
var oldPart = -1;
|
|
||||||
PlayerColumn player = new PlayerColumn();
|
PlayerColumn player = new PlayerColumn();
|
||||||
|
|
||||||
foreach (var element in elements)
|
foreach (var element in elements)
|
||||||
{
|
{
|
||||||
if (element.ParticipantId != oldPart)
|
player = _playerColumns.FirstOrDefault(p => p.PlayerId == element.ParticipantId);
|
||||||
|
|
||||||
|
if (player == null)
|
||||||
{
|
{
|
||||||
player = new PlayerColumn
|
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))
|
if (!_playerColumns.Contains(player))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -17,8 +17,18 @@ public partial class RoundRunningView : ContentPage
|
|||||||
BindingContext = ViewModel;
|
BindingContext = ViewModel;
|
||||||
ViewModel.Get();
|
ViewModel.Get();
|
||||||
BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten
|
BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten
|
||||||
|
ViewModel.RebuildRequested += ViewModel_RebuildRequested;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ViewModel_RebuildRequested(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
BuildScoreGrid(ViewModel.PlayerColumns); // <-- h<>r bygger du layouten
|
||||||
|
}
|
||||||
|
|
||||||
|
//protected override
|
||||||
|
|
||||||
public RoundRunningViewModelCommands ViewModel { get; set; }
|
public RoundRunningViewModelCommands ViewModel { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user