mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-29 12:32:14 -05:00
Added script property SP_OnTerminate.. This way you can add functions to a OnTerminate event list, these functions will be called at the end of the script.
This commit is contained in:
parent
e8c0e53f68
commit
6183f771c9
@ -21,12 +21,12 @@
|
|||||||
Other.inc for the Mufasa Macro Library
|
Other.inc for the Mufasa Macro Library
|
||||||
}
|
}
|
||||||
|
|
||||||
function ps_SetScriptProp(prop : TSP_Property; Value: String): boolean; extdecl;
|
function ps_SetScriptProp(prop : TSP_Property; Value: TVariantArray): boolean; extdecl;
|
||||||
begin
|
begin
|
||||||
Exit(CurrThread.Prop.SetProp(prop, Value));
|
Exit(CurrThread.Prop.SetProp(prop, Value));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ps_GetScriptProp(prop : TSP_Property; var Value : string) : boolean; extdecl;
|
function ps_GetScriptProp(prop : TSP_Property; var Value : TVariantArray) : boolean; extdecl;
|
||||||
begin;
|
begin;
|
||||||
exit(CurrThread.Prop.GetProp(prop,value));
|
exit(CurrThread.Prop.GetProp(prop,value));
|
||||||
end;
|
end;
|
||||||
|
@ -56,7 +56,7 @@ Sender.Comp.AddTypeS('TStringArray','Array of string;');
|
|||||||
Sender.Comp.AddTypeS('TMousePress', '(mouse_Down, mouse_Up);');
|
Sender.Comp.AddTypeS('TMousePress', '(mouse_Down, mouse_Up);');
|
||||||
Sender.Comp.AddTypeS('Pointer', 'Integer');
|
Sender.Comp.AddTypeS('Pointer', 'Integer');
|
||||||
|
|
||||||
Sender.Comp.AddTypeS('TSP_Property','(SP_WriteTimeStamp)');
|
Sender.Comp.AddTypeS('TSP_Property','(SP_WriteTimeStamp,SP_OnTerminate)');
|
||||||
|
|
||||||
|
|
||||||
Sender.Comp.AddConstantN('mouse_Right','integer').SetInt(ps_mouse_right); //0
|
Sender.Comp.AddConstantN('mouse_Right','integer').SetInt(ps_mouse_right); //0
|
||||||
|
@ -129,8 +129,8 @@ AddFunction(@ps_Random,'function Random(Int: integer): integer;');
|
|||||||
AddFunction(@ps_ClearDebug,'procedure ClearDebug;');
|
AddFunction(@ps_ClearDebug,'procedure ClearDebug;');
|
||||||
AddFunction(@ps_PlaySound,'procedure PlaySound( Sound : string);');
|
AddFunction(@ps_PlaySound,'procedure PlaySound( Sound : string);');
|
||||||
AddFunction(@ps_StopSound,'procedure StopSound;');
|
AddFunction(@ps_StopSound,'procedure StopSound;');
|
||||||
AddFunction(@ps_SetScriptProp, 'function SetScriptProp(Prop : TSP_Property; Value: String): boolean;');
|
AddFunction(@ps_SetScriptProp, 'function SetScriptProp(Prop : TSP_Property; Value: TVariantArray): boolean;');
|
||||||
AddFunction(@ps_GetScriptProp, 'function GetScriptProp(Prop : TSP_Property;var Value: String): boolean;');
|
AddFunction(@ps_GetScriptProp, 'function GetScriptProp(Prop : TSP_Property;var Value: TVariantArray): boolean;');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,6 +131,8 @@ type
|
|||||||
property OpenFileEvent : TOpenFileEvent read FOpenFileEvent write SetOpenFileEvent;
|
property OpenFileEvent : TOpenFileEvent read FOpenFileEvent write SetOpenFileEvent;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TPSThread }
|
||||||
|
|
||||||
TPSThread = class(TMThread)
|
TPSThread = class(TMThread)
|
||||||
public
|
public
|
||||||
procedure OnProcessDirective(Sender: TPSPreProcessor;
|
procedure OnProcessDirective(Sender: TPSPreProcessor;
|
||||||
@ -150,6 +152,7 @@ type
|
|||||||
procedure OnCompImport(Sender: TObject; x: TPSPascalCompiler);
|
procedure OnCompImport(Sender: TObject; x: TPSPascalCompiler);
|
||||||
procedure OnExecImport(Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter);
|
procedure OnExecImport(Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter);
|
||||||
procedure OutputMessages;
|
procedure OutputMessages;
|
||||||
|
procedure HandleScriptTerminates;
|
||||||
public
|
public
|
||||||
PSScript : TPSScript;
|
PSScript : TPSScript;
|
||||||
constructor Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
constructor Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
||||||
@ -801,6 +804,22 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TPSThread.HandleScriptTerminates;
|
||||||
|
var
|
||||||
|
I : integer;
|
||||||
|
begin
|
||||||
|
if (PSScript.Exec.ExceptionCode =ErNoError) and (SP_OnTerminate in Prop.Properties) then
|
||||||
|
begin;
|
||||||
|
for i := 0 to Prop.OnTerminateProcs.Count - 1 do
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
PSScript.ExecuteFunction([],Prop.OnTerminateProcs[i]);
|
||||||
|
finally
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TPSThread.Execute;
|
procedure TPSThread.Execute;
|
||||||
begin
|
begin
|
||||||
CurrThread := Self;
|
CurrThread := Self;
|
||||||
@ -818,7 +837,10 @@ begin
|
|||||||
HandleError(PSScript.ExecErrorRow,PSScript.ExecErrorCol,PSScript.ExecErrorPosition,PSScript.ExecErrorToString,
|
HandleError(PSScript.ExecErrorRow,PSScript.ExecErrorCol,PSScript.ExecErrorPosition,PSScript.ExecErrorToString,
|
||||||
errRuntime, PSScript.ExecErrorFileName)
|
errRuntime, PSScript.ExecErrorFileName)
|
||||||
else
|
else
|
||||||
|
begin
|
||||||
|
HandleScriptTerminates;
|
||||||
psWriteln('Successfully executed.');
|
psWriteln('Successfully executed.');
|
||||||
|
end;
|
||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
OutputMessages;
|
OutputMessages;
|
||||||
|
@ -5,13 +5,14 @@ unit scriptproperties;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils;
|
Classes, SysUtils,MufasaTypes,mufasabase;
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TScriptProperties }
|
{ TScriptProperties }
|
||||||
|
|
||||||
TSP_Property = (
|
TSP_Property = (
|
||||||
SP_WriteTimeStamp //Writes the time infront of a writeln
|
SP_WriteTimeStamp, //Writes the time infront of a writeln
|
||||||
|
SP_OnTerminate
|
||||||
);
|
);
|
||||||
TSP_Properties = set of TSP_Property;
|
TSP_Properties = set of TSP_Property;
|
||||||
|
|
||||||
@ -19,40 +20,50 @@ type
|
|||||||
TScriptProperties = class(TObject)
|
TScriptProperties = class(TObject)
|
||||||
private
|
private
|
||||||
FProperties : TSP_Properties;
|
FProperties : TSP_Properties;
|
||||||
FWriteTimeStamp : boolean;
|
FOnTerminateProcs : TStringList;
|
||||||
|
function HasTimeStamp: boolean;
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function GetProperty(name: ansistring; var Prop : TSP_Property): boolean;
|
function GetProperty(name: ansistring; var Prop : TSP_Property): boolean;
|
||||||
function GetProp(name: ansistring; var Value : ansistring) : Boolean;overload;
|
function GetProp(name: ansistring; var Value : TVariantArray) : Boolean;overload;
|
||||||
function GetProp(Prop : TSP_Property; var Value : ansistring) : Boolean;overload;
|
function GetProp(Prop : TSP_Property; var Value : TVariantArray) : Boolean;overload;
|
||||||
function SetProp(Name: ansistring; Value: ansistring): Boolean;overload;
|
function SetProp(Name: ansistring; Value: TVariantArray): Boolean;overload;
|
||||||
function SetProp(Prop : TSP_Property; Value: ansistring): Boolean;overload;
|
function SetProp(Prop : TSP_Property; Value: TVariantArray): Boolean;overload;
|
||||||
public
|
public
|
||||||
property WriteTimeStamp : boolean read FWriteTimeStamp;
|
property Properties : TSP_Properties read FProperties;
|
||||||
|
property WriteTimeStamp : boolean read HasTimeStamp;
|
||||||
|
property OnTerminateProcs : TStringList read FOnTerminateProcs;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
function TScriptProperties.HasTimeStamp: boolean;
|
||||||
|
begin
|
||||||
|
result := (SP_WriteTimeStamp in FProperties);
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TScriptProperties.Create;
|
constructor TScriptProperties.Create;
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
|
|
||||||
FWriteTimeStamp := False;
|
|
||||||
FProperties := [];
|
FProperties := [];
|
||||||
|
FOnTerminateProcs := TStringList.Create;
|
||||||
|
FOnTerminateProcs.CaseSensitive:= false;
|
||||||
|
FOnTerminateProcs.Duplicates:= dupIgnore;
|
||||||
{ set default values }
|
{ set default values }
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TScriptProperties.Destroy;
|
destructor TScriptProperties.Destroy;
|
||||||
begin
|
begin
|
||||||
|
FOnTerminateProcs.Free;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TScriptProperties.GetProperty(name: ansistring; var Prop : TSP_Property): boolean;
|
function TScriptProperties.GetProperty(name: ansistring; var Prop : TSP_Property): boolean;
|
||||||
const
|
const
|
||||||
Names : array[TSP_Property] of ansistring = ('writetimestamp');
|
Names : array[TSP_Property] of ansistring = ('writetimestamp','onterminate');
|
||||||
var
|
var
|
||||||
i : integer;
|
i : integer;
|
||||||
begin
|
begin
|
||||||
@ -65,7 +76,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TScriptProperties.GetProp(name: ansistring; var Value: ansistring): Boolean;
|
function TScriptProperties.GetProp(name: ansistring; var Value: TVariantArray): Boolean;
|
||||||
var
|
var
|
||||||
Prop : TSP_Property;
|
Prop : TSP_Property;
|
||||||
begin
|
begin
|
||||||
@ -74,16 +85,28 @@ begin
|
|||||||
Result := (GetProp(Prop,value));
|
Result := (GetProp(Prop,value));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TScriptProperties.GetProp(Prop: TSP_Property; var Value: ansistring
|
function TScriptProperties.GetProp(Prop: TSP_Property; var Value: TVariantArray
|
||||||
): Boolean;
|
): Boolean;
|
||||||
|
var
|
||||||
|
i : integer;
|
||||||
begin
|
begin
|
||||||
Result := true;
|
Result := true;
|
||||||
|
Setlength(value,0);
|
||||||
case Prop of
|
case Prop of
|
||||||
SP_WriteTimeStamp : Value := BoolToStr(Prop in FProperties,true);
|
SP_WriteTimeStamp : begin SetLength(Value,1); Value[0] := BoolToStr(Prop in FProperties,true); end;
|
||||||
|
SP_OnTerminate :
|
||||||
|
begin
|
||||||
|
if not (Prop in FProperties) then
|
||||||
|
exit;
|
||||||
|
setlength(value,FOnTerminateProcs.Count);
|
||||||
|
for i := 0 to high(Value) do
|
||||||
|
value[i] := FOnTerminateProcs[i];
|
||||||
|
result := true;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TScriptProperties.SetProp(Name: ansistring; Value: ansistring): Boolean;
|
function TScriptProperties.SetProp(Name: ansistring; Value: TVariantArray): Boolean;
|
||||||
var
|
var
|
||||||
Prop : TSP_Property;
|
Prop : TSP_Property;
|
||||||
begin
|
begin
|
||||||
@ -92,17 +115,38 @@ begin
|
|||||||
Result := (SetProp(Prop,value));
|
Result := (SetProp(Prop,value));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TScriptProperties.SetProp(Prop: TSP_Property; Value: ansistring): Boolean;
|
function TScriptProperties.SetProp(Prop: TSP_Property; Value: TVariantArray): Boolean;
|
||||||
|
var
|
||||||
|
i : integer;
|
||||||
begin
|
begin
|
||||||
|
result := false;
|
||||||
|
if Length(value) < 1 then
|
||||||
|
begin;
|
||||||
|
mDebugLn('SetProp passed a TVarArray with a length of 0' );
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
case Prop of
|
case Prop of
|
||||||
SP_WriteTimeStamp : if lowercase(value) = 'true' then
|
SP_WriteTimeStamp : begin
|
||||||
|
if length(Value) <> 1 then
|
||||||
begin
|
begin
|
||||||
FWriteTimeStamp:= True;
|
mDebugLn('SP_WriteTimeStamp only needs 1 value in the array');
|
||||||
FProperties := FProperties + [Prop];
|
exit;
|
||||||
end else
|
end;
|
||||||
begin
|
try
|
||||||
FWriteTimeStamp := False;
|
if Value[0] = True then
|
||||||
|
FProperties := FProperties + [Prop]
|
||||||
|
else
|
||||||
FProperties := FProperties - [Prop];
|
FProperties := FProperties - [Prop];
|
||||||
|
except
|
||||||
|
mDebugLn('Could not convert your value passed to SetProp');
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
SP_OnTerminate :
|
||||||
|
begin
|
||||||
|
for i := 0 to high(value) do
|
||||||
|
FOnTerminateProcs.Add(Value[i]);
|
||||||
|
FProperties := FProperties + [prop];
|
||||||
|
Result := True;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user