[longomatch] Add Timers and Periods



commit 9d8e94acaba960baab4fa0beb2b29b0802c759b8
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Jun 3 19:07:20 2014 +0200

    Add Timers and Periods

 LongoMatch.Core/LongoMatch.Core.mdp |    2 +
 LongoMatch.Core/Store/Period.cs     |   51 +++++++++++++++++++++++++++
 LongoMatch.Core/Store/Project.cs    |   16 ++++++++
 LongoMatch.Core/Store/Timer.cs      |   66 +++++++++++++++++++++++++++++++++++
 4 files changed, 135 insertions(+), 0 deletions(-)
---
diff --git a/LongoMatch.Core/LongoMatch.Core.mdp b/LongoMatch.Core/LongoMatch.Core.mdp
index 53375ac..7138f53 100644
--- a/LongoMatch.Core/LongoMatch.Core.mdp
+++ b/LongoMatch.Core/LongoMatch.Core.mdp
@@ -137,6 +137,8 @@
     <File subtype="Code" buildaction="Compile" name="Interfaces/Drawing/IDrawable.cs" />
     <File subtype="Code" buildaction="Compile" name="Interfaces/Drawing/ICanvasObject.cs" />
     <File subtype="Code" buildaction="Compile" name="Common/ExtensionMethods.cs" />
+    <File subtype="Code" buildaction="Compile" name="Store/Timer.cs" />
+    <File subtype="Code" buildaction="Compile" name="Store/Period.cs" />
   </Contents>
   <References>
     <ProjectReference type="Package" localcopy="True" refto="System, Version=4.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089" />
diff --git a/LongoMatch.Core/Store/Period.cs b/LongoMatch.Core/Store/Period.cs
new file mode 100644
index 0000000..215f6cf
--- /dev/null
+++ b/LongoMatch.Core/Store/Period.cs
@@ -0,0 +1,51 @@
+//
+//  Copyright (C) 2014 Andoni Morales Alastruey
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using System.Linq;
+using System.Collections.Generic;
+
+namespace LongoMatch.Store
+{
+       public class Period: Timer
+       {
+
+               public Period ()
+               {
+               }
+               
+               public TimeNode PeriodNode {
+                       get {
+                               return new TimeNode {Name=Name,
+                                       Start = new Time (Nodes.Min (tn => tn.Start.MSeconds)),
+                                       Stop = new Time (Nodes.Max (tn => tn.Stop.MSeconds)),
+                               };
+                       }
+                       set {
+                               foreach (TimeNode tn in Nodes) {
+                                       if (tn.Start < value.Start) {
+                                               tn.Start = value.Start;
+                                       }
+                                       if (tn.Stop > value.Stop) {
+                                               tn.Stop = value.Stop;
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
diff --git a/LongoMatch.Core/Store/Project.cs b/LongoMatch.Core/Store/Project.cs
index b1f5e25..dfa72f1 100644
--- a/LongoMatch.Core/Store/Project.cs
+++ b/LongoMatch.Core/Store/Project.cs
@@ -61,6 +61,8 @@ namespace LongoMatch.Store
                        Categories = new Categories();
                        LocalTeamTemplate = new TeamTemplate();
                        VisitorTeamTemplate = new TeamTemplate();
+                       Timers = new List<Timer> ();
+                       Periods = new List<Period> ();
                }
                #endregion
 
@@ -112,6 +114,18 @@ namespace LongoMatch.Store
                        set;
                }
                
+               public List<Period> Periods {
+                       get;
+                       set;
+               }
+               
+               public List<Timer> Timers {
+                       get;
+                       set;
+               }
+               
+               [JsonIgnore]
+               [Obsolete("Game units have been replaced with timers")]
                public GameUnitsList  GameUnits {
                        set {
                                Categories.GameUnits = value;
@@ -138,6 +152,8 @@ namespace LongoMatch.Store
                        Categories.Clear();
                        VisitorTeamTemplate.Clear();
                        LocalTeamTemplate.Clear();
+                       Periods.Clear();
+                       Timers.Clear();
                }
 
 
diff --git a/LongoMatch.Core/Store/Timer.cs b/LongoMatch.Core/Store/Timer.cs
new file mode 100644
index 0000000..0aea162
--- /dev/null
+++ b/LongoMatch.Core/Store/Timer.cs
@@ -0,0 +1,66 @@
+//
+//  Copyright (C) 2014 Andoni Morales Alastruey
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+using System;
+using System.Linq;
+using LongoMatch.Store;
+using System.Collections.Generic;
+using Newtonsoft.Json;
+
+namespace LongoMatch.Store
+{
+       public class Timer
+       {
+               public Timer ()
+               {
+                       Nodes = new List<TimeNode>();
+               }
+               
+               public string Name {
+                       get;
+                       set;
+               }
+               
+               public List<TimeNode> Nodes {
+                       get;
+                       set;
+               }
+               
+               [JsonIgnore]
+               public Time TotalTime {
+                       get {
+                               return new Time (Nodes.Sum (tn => tn.Duration.MSeconds));
+                       }
+               }
+               
+               public void Start (Time start) {
+                       Stop (start);
+                       TimeNode tn = new TimeNode {Name = Name, Start = start};
+                       Nodes.Add (tn);
+               }
+               
+               public void Stop (Time stop) {
+                       if (Nodes.Count > 0) {
+                               TimeNode last = Nodes.Last ();
+                               if (last.Stop == null) {
+                                       last.Stop = stop;
+                               }
+                       }
+               }
+       }
+}
+


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