-
Notifications
You must be signed in to change notification settings - Fork 48
/
BaseConflict.GlobalManager.pas
96 lines (76 loc) · 1.81 KB
/
BaseConflict.GlobalManager.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
unit BaseConflict.GlobalManager;
interface
uses
BaseConflict.Entity,
Generics.Collections;
type
TCommanderManager = class
protected
FCommander : TList<TEntity>;
FActiveCommander : TEntity;
FActiveIndex : integer;
public
property ActiveCommander : TEntity read FActiveCommander;
property ActiveIndex : integer read FActiveIndex;
function HasActiveCommander : boolean;
function CommanderCount : integer;
procedure Clear;
procedure AddCommander(Commander : TEntity);
procedure ChooseCommander(Index : integer);
constructor Create;
destructor Destroy; override;
end;
var
CommanderManager : TCommanderManager;
implementation
{ TCommanderManager }
procedure TCommanderManager.AddCommander(Commander : TEntity);
begin
FCommander.Add(Commander);
if not assigned(FActiveCommander) then
begin
FActiveCommander := Commander;
FActiveIndex := 0;
end;
end;
procedure TCommanderManager.ChooseCommander(Index : integer);
begin
if index = -1 then
begin
FActiveCommander := nil;
FActiveIndex := -1;
end;
if (index < FCommander.Count) and (index >= 0) then
begin
FActiveCommander := FCommander[index];
FActiveIndex := index;
end;
end;
procedure TCommanderManager.Clear;
begin
FCommander.Clear;
ChooseCommander(-1)
end;
function TCommanderManager.CommanderCount : integer;
begin
Result := FCommander.Count;
end;
constructor TCommanderManager.Create;
begin
FActiveIndex := -1;
FCommander := TList<TEntity>.Create;
end;
destructor TCommanderManager.Destroy;
begin
FCommander.Free;
inherited;
end;
function TCommanderManager.HasActiveCommander : boolean;
begin
Result := ActiveCommander <> nil;
end;
initialization
CommanderManager := TCommanderManager.Create;
finalization
CommanderManager.Free;
end.