ChivalryServerLauncher/source/model/Game.List.pas

66 lines
964 B
ObjectPascal
Raw Normal View History

unit Game.List;
interface
uses
System.Generics.Collections,
Game.Base;
type
TGameList = class(TList<TCustomGame>)
private
class var SInstance: TGameList;
protected
class procedure Finalize;
public
class function Instance: TGameList;
procedure AutoDetect;
end;
implementation
uses
System.SysUtils,
Game.Registry;
{ TGameList }
class procedure TGameList.Finalize;
begin
FreeAndNil(SInstance);
end;
class function TGameList.Instance: TGameList;
begin
if not Assigned(SInstance) then
SInstance := TGameList.Create;
Result := SInstance;
end;
procedure TGameList.AutoDetect;
var
gameClass: TCustomGameClass;
game: TCustomGame;
begin
for gameClass in TGameRegistry.RegisteredGames do
begin
game := gameClass.AutoDetect;
if Assigned(game) then
Add(game);
end;
end;
initialization
finalization
TGameList.Finalize;
end.