1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-25 02:32:19 -05:00
Simba/Projects/SAMufasaGUI/virtualextension.pas

105 lines
2.6 KiB
ObjectPascal
Raw Normal View History

unit virtualextension;
{$mode objfpc}
interface
uses
Classes, SysUtils;
type
2010-03-22 17:21:08 -04:00
{ TVirtualSimbaExtension }
TVirtualSimbaExtension = class(TObject)
2010-03-22 17:21:08 -04:00
protected
FName: String;
FVersion : string;
FFilename : string;
FEnabled : boolean;
procedure SetEnabled(bool : boolean); virtual;
public
2010-03-22 17:21:08 -04:00
OnChange : TNotifyEvent;
{ Must be implemented }
function HookExists(HookName: String): Boolean; virtual; abstract;
{ No Custom Arguments just yet... }
2010-03-22 17:21:08 -04:00
function ExecuteHook(HookName: String; fArgs: Array of Variant; out OutVariant : variant): Integer; virtual; abstract;
2010-03-22 17:21:08 -04:00
function GetName : string;
function GetVersion : String;
property Filename : string read FFilename write FFilename;
property Enabled : boolean read FEnabled write SetEnabled;
end;
2010-03-18 19:31:39 -04:00
{ Each hook has a HookName which the extension uses to identify the hook.
Additionally, variables are exported. Currently we will use an Array of Variant.
Therefore, we will have to specify what amount Arguments we will pass.
( So it is not type safe... Not like Variants are type safe... )
}
type TEventHook = record
HookName: String;
ArgumentCount: Integer;
end;
2010-03-22 17:21:08 -04:00
const
SExt_ok = 0;
SExt_error = 1;
2010-03-18 19:31:39 -04:00
EventHooks: Array [0..7] of TEventHook =
( (HookName : 'onScriptCompile' ; ArgumentCount : 1),
(HookName : 'onScriptStart' ; ArgumentCount : 1),
(HookName : 'onScriptPause' ; ArgumentCount : 1),
(HookName : 'onScriptStop' ; ArgumentCount : 1),
(HookName : 'onColourPick' ; ArgumentCount : 3),
(HookName : 'onOpenFile' ; ArgumentCount : 1),
(HookName : 'onOpenSocket' ; ArgumentCount : 1),
(HookName : 'onWriteFile' ; ArgumentCount : 1));
implementation
2010-03-22 17:21:08 -04:00
{ TVirtualSimbaExtension }
procedure TVirtualSimbaExtension.SetEnabled(bool: boolean);
begin
if assigned(OnChange) then
OnChange(self);
FEnabled:= bool;
end;
function TVirtualSimbaExtension.GetName: string;
var
OutPut : Variant;
begin
Result := '';
if FName <> '' then
Result := FName
else if self.HookExists('GetName') then
begin;
if ExecuteHook('GetName',[],OutPut) <> SExt_ok then
FName := ''
else
FName := OutPut;
result := FName;
end;
end;
function TVirtualSimbaExtension.GetVersion: String;
var
OutPut : Variant;
begin
Result := '';
if FVersion <> '' then
Result := FVersion
else if self.HookExists('GetVersion') then
begin;
if ExecuteHook('GetVersion',[],OutPut) <> SExt_ok then
FVersion := ''
else
FVersion := Output;
result := FVersion;
end;
end;
end.