2014-06-30 14:37:42 +00:00
|
|
|
unit Game.Base;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
System.Classes;
|
|
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
TCustomGame = class(TInterfacedPersistent)
|
|
|
|
private
|
|
|
|
FLocation: string;
|
2014-06-30 16:07:40 +00:00
|
|
|
FLoaded: Boolean;
|
2014-07-02 14:54:01 +00:00
|
|
|
FModified: Boolean;
|
2014-06-30 14:37:42 +00:00
|
|
|
protected
|
2014-07-02 14:54:01 +00:00
|
|
|
procedure PropertyChanged(const APropertyName: string); virtual;
|
2014-06-30 16:07:40 +00:00
|
|
|
|
|
|
|
procedure DoLoad; virtual; abstract;
|
|
|
|
procedure DoSave; virtual; abstract;
|
2014-06-30 14:37:42 +00:00
|
|
|
public
|
2014-06-30 16:07:40 +00:00
|
|
|
class function GameName: string; virtual; abstract;
|
|
|
|
class function AutoDetect: TCustomGame; virtual;
|
2014-06-30 14:37:42 +00:00
|
|
|
|
|
|
|
constructor Create(const ALocation: string); virtual;
|
|
|
|
|
2014-06-30 16:07:40 +00:00
|
|
|
procedure Load; virtual;
|
|
|
|
procedure Save; virtual;
|
2014-06-30 14:37:42 +00:00
|
|
|
|
2014-07-02 15:22:41 +00:00
|
|
|
function GetExecutable: string; virtual; abstract;
|
|
|
|
function GetParameters: string; virtual;
|
|
|
|
function GetCommandLine: string; virtual;
|
|
|
|
|
2014-06-30 16:07:40 +00:00
|
|
|
property Loaded: Boolean read FLoaded;
|
2014-06-30 14:37:42 +00:00
|
|
|
property Location: string read FLocation;
|
2014-07-02 14:54:01 +00:00
|
|
|
property Modified: Boolean read FModified;
|
2014-06-30 14:37:42 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
TCustomGameClass = class of TCustomGame;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
uses
|
|
|
|
System.Bindings.Helper,
|
|
|
|
System.SysUtils;
|
|
|
|
|
|
|
|
|
|
|
|
{ TCustomGame }
|
|
|
|
constructor TCustomGame.Create(const ALocation: string);
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
|
|
|
FLocation := IncludeTrailingPathDelimiter(ALocation);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-06-30 16:07:40 +00:00
|
|
|
class function TCustomGame.AutoDetect: TCustomGame;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TCustomGame.Load;
|
2014-07-02 14:54:01 +00:00
|
|
|
var
|
|
|
|
wasModified: Boolean;
|
|
|
|
|
2014-06-30 16:07:40 +00:00
|
|
|
begin
|
2014-07-02 14:54:01 +00:00
|
|
|
wasModified := FModified;
|
|
|
|
|
2014-06-30 16:07:40 +00:00
|
|
|
DoLoad;
|
|
|
|
FLoaded := True;
|
2014-07-02 14:54:01 +00:00
|
|
|
|
|
|
|
FModified := False;
|
|
|
|
if wasModified then
|
|
|
|
TBindings.Notify(Self, 'Modified');
|
2014-06-30 16:07:40 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TCustomGame.Save;
|
2014-07-02 14:54:01 +00:00
|
|
|
var
|
|
|
|
wasModified: Boolean;
|
|
|
|
|
2014-06-30 16:07:40 +00:00
|
|
|
begin
|
2014-07-02 14:54:01 +00:00
|
|
|
wasModified := FModified;
|
|
|
|
|
2014-06-30 16:07:40 +00:00
|
|
|
DoSave;
|
2014-07-02 14:54:01 +00:00
|
|
|
|
|
|
|
FModified := False;
|
|
|
|
if wasModified then
|
|
|
|
TBindings.Notify(Self, 'Modified');
|
2014-06-30 16:07:40 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-07-02 15:22:41 +00:00
|
|
|
function TCustomGame.GetParameters: string;
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TCustomGame.GetCommandLine: string;
|
|
|
|
var
|
|
|
|
parameters: string;
|
|
|
|
|
|
|
|
begin
|
2014-07-02 17:38:43 +00:00
|
|
|
Result := '"' + GetExecutable + '"';
|
2014-07-02 15:22:41 +00:00
|
|
|
|
|
|
|
parameters := GetParameters;
|
|
|
|
if Length(parameters) > 0 then
|
|
|
|
Result := Result + ' ' + parameters;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-07-02 14:54:01 +00:00
|
|
|
procedure TCustomGame.PropertyChanged(const APropertyName: string);
|
2014-06-30 14:37:42 +00:00
|
|
|
begin
|
2014-07-02 14:54:01 +00:00
|
|
|
if not FModified then
|
|
|
|
begin
|
|
|
|
FModified := True;
|
|
|
|
TBindings.Notify(Self, 'Modified');
|
|
|
|
end;
|
|
|
|
|
2014-06-30 14:37:42 +00:00
|
|
|
TBindings.Notify(Self, APropertyName);
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|