1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-12-24 00:08:52 -05:00
Simba/Projects/SAMufasaGUI/virtualextension.pas

117 lines
3.3 KiB
ObjectPascal
Raw Normal View History

unit virtualextension;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,settingssandbox,MufasaTypes;
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;
FSettings : TMMLSettingsSandbox;
2010-03-22 17:21:08 -04:00
procedure SetEnabled(bool : boolean); virtual;
public
2010-03-22 17:21:08 -04:00
OnChange : TNotifyEvent;
{ Must be implemented }
function HookExists(const HookName: String): Boolean; virtual; abstract;
{ No Custom Arguments just yet... }
function ExecuteHook(const HookName: String;var Args: TVariantArray; out OutVariant : variant): Integer; virtual; abstract;
2010-03-22 17:21:08 -04:00
function GetName : string;
function GetVersion : String;
property Settings : TMMLSettingsSandbox read FSettings write FSettings;
2010-03-22 17:21:08 -04:00
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;
SExt_OnColourPick = 0;
SExt_onOpenFile = 1;
SExt_onWriteFile = 2;
SExt_onOpenConnection = 3;
SExt_onScriptStart = 4;
EventHooks: Array [0..8] of TEventHook =
( (HookName : 'onColourPick' ; ArgumentCount : 3), //const colour,colourx,coloury : integer;
(HookName : 'onOpenFile' ; ArgumentCount : 2), //var filename : string; var Continue : boolean
(HookName : 'onWriteFile' ; ArgumentCount : 2), //var filename : string; var Continue : boolean
(HookName : 'onOpenConnection'; ArgumentCount : 2), //var url : string; var Continue : boolean
(HookName : 'onScriptStart' ; ArgumentCount : 2), //var Script : string; var Continue : boolean; This is called BEFORE it compiles/executes
(HookName : 'onScriptCompile' ; ArgumentCount : 1),
(HookName : 'onScriptExecute' ; ArgumentCount : 1),
2010-03-18 19:31:39 -04:00
(HookName : 'onScriptPause' ; ArgumentCount : 1),
(HookName : 'onScriptStop' ; ArgumentCount : 1));
2010-03-18 19:31:39 -04:00
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;
Args : TVariantArray;
2010-03-22 17:21:08 -04:00
begin
Result := '';
if FName <> '' then
Result := FName
else if self.HookExists('GetName') then
begin;
if ExecuteHook('GetName',Args,OutPut) <> SExt_ok then
2010-03-22 17:21:08 -04:00
FName := ''
else
FName := OutPut;
result := FName;
end;
end;
function TVirtualSimbaExtension.GetVersion: String;
var
OutPut : Variant;
Args : TVariantArray;
2010-03-22 17:21:08 -04:00
begin
Result := '';
if FVersion <> '' then
Result := FVersion
else if self.HookExists('GetVersion') then
begin;
if ExecuteHook('GetVersion',Args,OutPut) <> SExt_ok then
2010-03-22 17:21:08 -04:00
FVersion := ''
else
FVersion := Output;
result := FVersion;
end;
end;
end.