ChivalryServerLauncher/source/model/Game.List.pas

66 lines
976 B
ObjectPascal

unit Game.List;
interface
uses
System.Generics.Collections,
Game.Base;
type
TGameList = class(TObjectList<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(True);
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.