comparison api/WarFoundryCore.cs @ 0:520818033bb6

Initial commit of WarFoundry code
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 15:57:51 +0000
parents
children 306558904c2a
comparison
equal deleted inserted replaced
-1:000000000000 0:520818033bb6
1 // WarFoundry.cs
2 //
3 // Copyright (C) 2008 IBBoard
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License version 2.1 of the License as published by the Free
8 // Software Foundation.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 //
19 //
20
21 using System;
22 using IBBoard.Logging;
23 using IBBoard.WarFoundry.API.Objects;
24
25 namespace IBBoard.WarFoundry.API
26 {
27 public class WarFoundryCore
28 {
29 public static event GameSystemChangedDelegate GameSystemChanged;
30 public static event ArmyChangedDelegate ArmyChanged;
31
32 private static GameSystem system;
33 private static Army currentArmy;
34
35 public static GameSystem CurrentGameSystem
36 {
37 get { return system; }
38 set
39 {
40 if (system==null || !system.Equals(value))
41 {
42 GameSystem oldSystem = system;
43 system = value;
44
45 if (system==null)
46 {
47 LogNotifier.Debug(typeof(WarFoundryCore), "Game system set to null");
48 }
49 else
50 {
51 LogNotifier.DebugFormat(typeof(WarFoundryCore), "Game system set to {0} with ID {1}", system.Name, system.ID);
52 }
53
54 if (GameSystemChanged!=null)
55 {
56 GameSystemChanged(oldSystem, system);
57 }
58
59 //If we've changed the game system then we can't keep the current army
60 CurrentArmy = null;
61 }
62 }
63 }
64
65 public static Army CurrentArmy
66 {
67 get { return currentArmy; }
68 set
69 {
70 if (currentArmy==null || !currentArmy.Equals(value))
71 {
72 /*if (currentArmy!=null)
73 {
74 currentArmy.UnitAdded-= UnitAddedMethod;
75 currentArmy.UnitRemoved-= UnitRemovedMethod;
76 currentArmy.PointsValueChanged-= PointsValueChangedMethod;
77 currentArmy.FailedRequirement-=FailedUnitRequirementMethod;
78 }*/
79 Army oldArmy = currentArmy;
80 currentArmy = value;
81
82 if (currentArmy!=null)
83 {
84 CurrentGameSystem = currentArmy.GameSystem; //Set the game system in case the new army is from a different system
85 }
86
87 /*if (currentArmy!=null)
88 {
89 currentArmy.UnitAdded+= UnitAddedMethod;
90 currentArmy.UnitRemoved+= UnitRemovedMethod;
91 currentArmy.PointsValueChanged+= PointsValueChangedMethod;
92 currentArmy.FailedRequirement+=FailedUnitRequirementMethod;
93 }*/
94
95 if (ArmyChanged!=null)
96 {
97 ArmyChanged(oldArmy, currentArmy);
98 }
99 }
100 }
101 }
102 }
103 }