[longomatch/newui: 13/104] Add a new API to list starting/bench players



commit 326bece8ea621044641f5670c324405b2d55050b
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Mon Aug 18 19:16:49 2014 +0200

    Add a new API to list starting/bench players

 LongoMatch.Core/Store/Templates/TeamTemplate.cs |   20 ++++++++++++++++++++
 Tests/Core/TestPlay.cs                          |    5 ++---
 Tests/Core/TestTeamTemplate.cs                  |   20 ++++++++++++++++++++
 3 files changed, 42 insertions(+), 3 deletions(-)
---
diff --git a/LongoMatch.Core/Store/Templates/TeamTemplate.cs b/LongoMatch.Core/Store/Templates/TeamTemplate.cs
index 239024e..2cde095 100644
--- a/LongoMatch.Core/Store/Templates/TeamTemplate.cs
+++ b/LongoMatch.Core/Store/Templates/TeamTemplate.cs
@@ -107,6 +107,26 @@ namespace LongoMatch.Store.Templates
                        }
                }
 
+               [JsonIgnore]
+               public List<Player> StartingPlayersList {
+                       get {
+                               int count = Math.Min (PlayingPlayers, List.Count);
+                               return List.GetRange (0, count);
+                       }
+               }
+
+               [JsonIgnore]
+               public List<Player> BenchPlayersList {
+                       get {
+                               int playing = PlayingPlayers;
+                               if (List.Count > playing) {
+                                       return List.GetRange (playing, List.Count - playing);
+                               } else {
+                                       return new List<Player> ();
+                               }
+                       }
+               }
+
                public void Save(string filePath) {
                        Serializer.Save(this, filePath);
                }
diff --git a/Tests/Core/TestPlay.cs b/Tests/Core/TestPlay.cs
index d40ff35..04eb560 100644
--- a/Tests/Core/TestPlay.cs
+++ b/Tests/Core/TestPlay.cs
@@ -41,7 +41,7 @@ namespace Tests.Core
                        play.HalfFieldPosition.Points.Add (new Point (4,5));
                        play.GoalPosition = new Coordinates ();
                        play.GoalPosition.Points.Add (new Point (6, 7));
-                       play.PlaybackRate = 1.5f;
+                       play.Rate = 1.5f;
                        play.Name = "Play";
                        play.Start = new Time(1000);
                        play.Stop = new Time(2000);
@@ -66,12 +66,11 @@ namespace Tests.Core
                        Assert.AreEqual (p.FieldPosition, newp.FieldPosition);
                        Assert.AreEqual (p.HalfFieldPosition, newp.HalfFieldPosition);
                        Assert.AreEqual (p.GoalPosition, newp.GoalPosition);
-                       Assert.AreEqual (p.PlaybackRate, newp.PlaybackRate);
+                       Assert.AreEqual (p.Rate, newp.Rate);
                        Assert.AreEqual (p.Name, newp.Name);
                        Assert.AreEqual (p.Start, newp.Start);
                        Assert.AreEqual (p.Stop, newp.Stop);
                        Assert.AreEqual (p.Rate, newp.Rate);
-                       Assert.AreEqual (p.PlaybackRate, newp.PlaybackRate);
                }
        }
 }
diff --git a/Tests/Core/TestTeamTemplate.cs b/Tests/Core/TestTeamTemplate.cs
index 4ae3507..6f189ab 100644
--- a/Tests/Core/TestTeamTemplate.cs
+++ b/Tests/Core/TestTeamTemplate.cs
@@ -99,5 +99,25 @@ namespace Tests.Core
                        Assert.AreEqual (t.Formation[2], 3);
                        Assert.AreEqual (t.Formation[3], 4);
                }
+               
+               [Test()]
+               public void TestBenchPlayers ()
+               {
+                       TeamTemplate t = TeamTemplate.DefaultTemplate (15);
+                       t.FormationStr = "1-2-3-4";
+                       Assert.AreEqual (5, t.BenchPlayersList.Count);
+                       Assert.AreEqual (t.List[10], t.BenchPlayersList[0]);
+                       Assert.AreEqual (t.List[14], t.BenchPlayersList[4]);
+               }
+               
+               [Test()]
+               public void TestStartingPlayers ()
+               {
+                       TeamTemplate t = TeamTemplate.DefaultTemplate (15);
+                       t.FormationStr = "1-2-3-4";
+                       Assert.AreEqual (10, t.StartingPlayersList.Count);
+                       Assert.AreEqual (t.List[0], t.StartingPlayersList[0]);
+                       Assert.AreEqual (t.List[9], t.StartingPlayersList[9]);
+               }
        }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]