Skip to content

Commit

Permalink
Restructure some imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Mar 7, 2024
1 parent e58cd67 commit 72a00aa
Show file tree
Hide file tree
Showing 11 changed files with 587 additions and 232 deletions.
110 changes: 110 additions & 0 deletions Source/forms/simba.functionlistform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ TFunctionListState = record
function AddPluginDecl(ParentNode: TTreeNode; Decl: TDeclaration): TTreeNode;

procedure AddSimbaNodes;

procedure ArrangeBaseNodes;

function CompareNodes(A, B: TTreeNode): Integer;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
Expand Down Expand Up @@ -663,13 +667,119 @@ procedure TSimbaFunctionListForm.AddSimbaNodes;
AddSimbaDecl(ParentNode, Decl);
end;

ParentNode := FSimbaNode.FindNode('Base');
if Assigned(ParentNode) then
ParentNode.CustomSort(@CompareNodes);

ArrangeBaseNodes();

FSimbaNode.AlphaSort();
FSimbaNode.Expanded := True; // This needs to be on main thread it seems?

FTreeView.Loading := False;
FTreeView.EndUpdate();
end;

procedure TSimbaFunctionListForm.ArrangeBaseNodes;
var
BaseNode: TTreeNode;
Cur: Integer = 0;

procedure MoveToTop(const NodeText: String);
var
Node: TTreeNode;
begin
Node := BaseNode.FindNode(NodeText);
if not Assigned(Node) then
begin
DebugLn('ArrangeBaseNodes: Not found: ' + NodeText);
Exit;
end;

Node.Index := Cur;
Inc(Cur);
end;

begin
BaseNode := FSimbaNode.FindNode('Base');
if (BaseNode = nil) then
Exit;

MoveToTop('Integer');
MoveToTop('Byte');
MoveToTop('Char');
MoveToTop('Boolean');

MoveToTop('Int8');
MoveToTop('Int16');
MoveToTop('Int32');
MoveToTop('Int64');
MoveToTop('UInt8');
MoveToTop('UInt16');
MoveToTop('UInt32');
MoveToTop('UInt64');

MoveToTop('NativeInt');
MoveToTop('NativeUInt');
MoveToTop('SizeInt');
MoveToTop('SizeUInt');
MoveToTop('PtrInt');
MoveToTop('PtrUInt');

MoveToTop('Single');
MoveToTop('Double');
MoveToTop('Currency');

MoveToTop('ByteBool');
MoveToTop('WordBool');
MoveToTop('LongBool');
MoveToTop('EvalBool');

MoveToTop('AnsiChar');
MoveToTop('WideChar');

MoveToTop('string');
MoveToTop('ShortString');
MoveToTop('AnsiString');
MoveToTop('WideString');
MoveToTop('UnicodeString');

MoveToTop('Pointer');
MoveToTop('ConstPointer');

MoveToTop('TByteArray');
MoveToTop('TBooleanArray');
MoveToTop('TSingleArray');
MoveToTop('TDoubleArray');
MoveToTop('TIntegerArray');
MoveToTop('TInt64Array');
MoveToTop('TStringArray');

MoveToTop('T2DIntegerArray');
MoveToTop('T2DStringArray');
end;

function TSimbaFunctionListForm.CompareNodes(A, B: TTreeNode): Integer;
begin
Result := CompareText(A.Text, B.Text);

case A.ImageIndex of
IMG_TYPE: Dec(Result, 2000);
IMG_CONST: Dec(Result, 1500);
IMG_VAR: Dec(Result, 1000);
IMG_PROC: Dec(Result, 500);
IMG_FUNC: Dec(Result, 500);
end;

case B.ImageIndex of
IMG_TYPE: Inc(Result, 2000);
IMG_CONST: Inc(Result, 1500);
IMG_VAR: Inc(Result, 1000);
IMG_PROC: Inc(Result, 500);
IMG_FUNC: Inc(Result, 500);
end;
end;

procedure TSimbaFunctionListForm.DoIdleBegin(Sender: TObject);
begin
FIsIdle := True;
Expand Down
4 changes: 2 additions & 2 deletions Source/image/simba.image_stringconv.pas
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface
Name: String[128];
end;

procedure SimbaImage_FromString(Image: TSimbaImage; const Str: String);
procedure SimbaImage_FromString(Image: TSimbaImage; Str: String);
function SimbaImage_ToString(Image: TSimbaImage): String;

implementation
Expand All @@ -37,7 +37,7 @@ implementation
FPReadPNG, FPWritePNG,
simba.encoding, simba.image_lazbridge;

procedure SimbaImage_FromString(Image: TSimbaImage; const Str: String);
procedure SimbaImage_FromString(Image: TSimbaImage; Str: String);
var
Stream: TStringStream;
Header: TImageStringHeader;
Expand Down
40 changes: 38 additions & 2 deletions Source/script/imports/simba.import_misc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,39 @@ implementation

uses
clipbrd, lptypes,
simba.nativeinterface,
simba.settings, simba.compress, simba.encoding;
simba.nativeinterface, simba.settings, simba.compress, simba.encoding, simba.env;

(*
Misc
====
Miscellaneous methods that dont go in any other sections.
*)

(*
SimbaEnv
--------
```
type
SimbaEnv = record
const SimbaPath = 'PathToSimbaDir';
const IncludesPath = 'PathToSimbaDir/Includes';
const PluginsPath = 'PathToSimbaDir/Plugins';
const ScriptsPath = 'PathToSimbaDir/Scripts';
const ScreenshotsPath = 'PathToSimbaDir/Screenshots';
const DataPath = 'PathToSimbaDir/Data';
const TempPath = 'PathToSimbaDir/Data/Temp';
end;
```
Record which contains constants to Simba environment paths.
*Example:*
```
WriteLn(SimbaEnv.ScriptsPath);
```
*)

(*
ClearSimbaOutput
----------------
Expand Down Expand Up @@ -151,6 +175,18 @@ procedure ImportMisc(Compiler: TSimbaScript_Compiler);
begin
ImportingSection := 'Misc';

addGlobalType([
'record',
' const SimbaPath = "' + SimbaEnv.SimbaPath + '";',
' const IncludesPath = "' + SimbaEnv.IncludesPath + '";',
' const PluginsPath = "' + SimbaEnv.PluginsPath + '";',
' const ScriptsPath = "' + SimbaEnv.ScriptsPath + '";',
' const ScreenshotsPath = "' + SimbaEnv.ScreenshotsPath + '";',
' const DataPath = "' + SimbaEnv.DataPath + '";',
' const TempPath = "' + SimbaEnv.TempPath + '";',
'end;'
], 'SimbaEnv');

addGlobalFunc(
'procedure SetSimbaTitle(S: String);', [
'begin',
Expand Down
30 changes: 30 additions & 0 deletions Source/script/imports/simba.import_process.pas
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,33 @@ procedure _LapeTerminateProcess(const Params: PParamArray; const Result: Pointer
SimbaProcess.TerminateProcess(PProcessID(Params^[0])^);
end;

procedure _LapeGetEnvVar(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PString(Result)^ := GetEnvironmentVariable(PString(Params^[0])^);
end;

procedure _LapeGetEnvVars(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV

function _GetEnvVars: TStringArray;
var
Count, I: Integer;
begin
Count := 0;

SetLength(Result, GetEnvironmentVariableCount() + 1);
for I := 1 to GetEnvironmentVariableCount() do
if (GetEnvironmentString(I) <> '') then
begin
Result[Count] := GetEnvironmentString(I);
Inc(Count);
end;
SetLength(Result, Count);
end;

begin
PStringArray(Result)^ := _GetEnvVars();
end;

procedure ImportProcess(Compiler: TSimbaScript_Compiler);
begin
with Compiler do
Expand All @@ -163,6 +190,9 @@ procedure ImportProcess(Compiler: TSimbaScript_Compiler);
addGlobalFunc('function RunCommand(Executable: String; Commands: TStringArray): TProcessID; overload', @_LapeRunCommand);
addGlobalFunc('function RunCommandTimeout(Executable: String; Commands: TStringArray; out Output: String; Timeout: Integer): Boolean', @_LapeRunCommandTimeout);

addGlobalFunc('function GetEnvVar(Name: String): String', @_LapeGetEnvVar);
addGlobalFunc('function GetEnvVars: TStringArray', @_LapeGetEnvVars);

ImportingSection := '';
end;
end;
Expand Down
21 changes: 20 additions & 1 deletion Source/script/imports/simba.import_random.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,28 @@ implementation
Methods relating to generating random numbers.
*)

(*
Random
------
> function Random: Double;'
*)

(*
Random
------
> function Random(l: Int64): Int64;
*)

(*
Random
------
> function Random(min, max: Int64): Int64;
> function Random(min, max: Double): Double;
*)

(*
RandSeed
----------
--------
> var RandSeed: UInt32;
The random seed used for all random number generation.
Expand Down
11 changes: 11 additions & 0 deletions Source/script/imports/simba.import_script.pas
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ procedure ImportScript(Compiler: TSimbaScript_Compiler);
begin
ImportingSection := 'Script';

// Assigned later in `TSimbaScript.Run`
addGlobalVar('String', '', 'SCRIPT_FILE').isConstant := True;
addGlobalVar('UInt64', '0', 'SCRIPT_START_TIME').isConstant := True;

addDelayedCode([
'function GetTimeRunning: UInt64;',
'begin',
' Result := GetTickCount() - SCRIPT_START_TIME;',
'end;'
]);

addGlobalFunc('function RunScript(Script: String; Parameters: TStringArray; out Output: String): TProcessExitStatus; overload', @_LapeRunScript);
addGlobalFunc('function RunScript(Script: String; Parameters: TStringArray): TProcessID; overload', @_LapeRunScriptEx);
addGlobalFunc('function RunScriptOutputToFile(Script: String; Parameters: TStringArray; OutputFileName: String): TProcessID', @_LapeRunScriptOutputToFile);
Expand Down
Loading

0 comments on commit 72a00aa

Please sign in to comment.