Skip to content

Commit d411898

Browse files
authored
Merge pull request #147 from jacz24/Documentation
Multiple commits for documentation mainly inside utils
2 parents 7e2ddf6 + 332fea5 commit d411898

File tree

10 files changed

+320
-32
lines changed

10 files changed

+320
-32
lines changed

osrs/interfaces/mainscreen/shop.simba

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,19 @@ You have 2 ways of getting the shop item slots, a static one:
5050
```pascal
5151
ShowOnTarget(Shop.SlotBoxes);
5252
```
53-
53+
```{figure} ../../images/shop_static_slots.png
54+
The shop static slots.
55+
```
5456

5557
And a dynamic one:
5658
```pascal
5759
ShowOnTarget(Shop.FindItemBoundaries());
5860
```
61+
```{figure} ../../images/shop_item_boundaries.png
62+
The shop "dynamic" slots.
63+
```
5964

6065
There are use cases for both, internally, `Shop.FindItemBoundaries` is usually used.
61-
6266
*)
6367
function TRSShop.FindItemBoundaries(): TBoxArray;
6468
var

utils/assets.simba

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Responsible for managing assets that WaspLib requires to run.
66
{$INCLUDE_ONCE WaspLib/utils.simba}
77

88
type
9+
(*
10+
## TWLAssets
11+
Record for managing WaspLib asset downloads and updates.
12+
*)
913
TWLAssets = record
1014
JSON: TJSONObject;
1115
Queue: TStringArray;

utils/config.simba

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ begin
6262
TJSONParser(Self.Data).Save(Self.Path, [EJSONFormatOption.USE_TABS, EJSONFormatOption.SINGLE_LINE_ARR], 1);
6363
end;
6464

65+
(*
66+
## TConfigINI
67+
Type responsible for dealing with INI configuration files.
68+
*)
6569
type
6670
TConfigINI = record
6771
Path: String;

utils/imagecompare.simba

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
(*
2+
# Image Compare
3+
Utilities for comparing images using template matching.
4+
*)
15
{$DEFINE WL_IMAGECOMPARE_INCLUDED}
26

37
type
8+
(*
9+
## TImageMatch
10+
Record storing image match result with position and similarity score.
11+
*)
412
TImageMatch = record
513
Index: Integer;
614
Box: TBox;
@@ -11,12 +19,23 @@ type
1119

1220
TImageCompareFilter = procedure(constref image, template: TImage) of object;
1321

22+
(*
23+
## TImageCompareUtils
24+
Utilities for comparing and matching images with optional cleaning and alignment.
25+
*)
1426
TImageCompareUtils = record
1527
Clean: procedure (image, template: TImage) of object;
1628
Align: function (image, template: TImage): Boolean of object;
1729
Filter: TImageCompareFilter;
1830
end;
1931

32+
(*
33+
## TImageCompareUtils.Compare
34+
```pascal
35+
function TImageCompareUtils.Compare(image, template: TImage; var similarity: Single): Boolean;
36+
```
37+
Compares two images and returns True if similarity threshold is met.
38+
*)
2039
function TImageCompareUtils.Compare(image, template: TImage; var similarity: Single): Boolean;
2140
var
2241
match: Single;
@@ -57,7 +76,13 @@ begin
5776
Result := Self.Compare(image, template, similarity);
5877
end;
5978

60-
79+
(*
80+
## TImageCompareUtils.FindMatch
81+
```pascal
82+
function TImageCompareUtils.FindMatch(image: TImage; bounds: TBox; out match: TImageMatch): Boolean;
83+
```
84+
Finds the best match for an image within specified bounds using template matching.
85+
*)
6186
function TImageCompareUtils.FindMatch(image: TImage; bounds: TBox; out match: TImageMatch): Boolean;
6287
var
6388
container: TImage;

utils/logger.simba

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
1+
(*
2+
# Logger
3+
Logging utilities for WaspLib scripts.
4+
*)
5+
16
{$DEFINE WL_LOGGER_INCLUDED}
27
{$INCLUDE_ONCE WaspLib/utils.simba}
38

49
type
10+
(*
11+
## ELogLevel
12+
```pascal
13+
ELogLevel = enum(SUCCESS, WARN, ERROR);
14+
```
15+
Enum representing log message severity levels.
16+
*)
517
ELogLevel = enum(SUCCESS, WARN, ERROR);
618

19+
(*
20+
## TLogger
21+
Record for managing script logging to files and console output.
22+
*)
723
TLogger = record
824
Name, Path, PreviousMessage: String;
925
TimeRunning: TStopwatch;
1026
IsSetup, RepeatedMessages: Boolean;
1127
end;
1228

29+
(*
30+
## Logger.Init
31+
```pascal
32+
procedure TLogger.Init();
33+
```
34+
Initializes the logger, creating the log directory and file.
35+
Called automatically at script start.
36+
*)
1337
procedure TLogger.Init();
1438
var
1539
files: TStringArray;
@@ -46,6 +70,18 @@ begin
4670
Self.TimeRunning.Start();
4771
end;
4872

73+
(*
74+
## Logger.Setup
75+
```pascal
76+
procedure TLogger.Setup(name: String = '');
77+
```
78+
Configures the logger with a script name. Creates a dedicated log directory.
79+
80+
Example:
81+
```pascal
82+
Logger.Setup('MyScript');
83+
```
84+
*)
4985
procedure TLogger.Setup(name: String = '');
5086
var
5187
old: String;
@@ -77,10 +113,24 @@ begin
77113
FileAppend(Self.Path, line + LINE_SEP);
78114
end;
79115

80-
81116
var
117+
(*
118+
## Logger variable
119+
Global {ref}`TLogger` variable.
120+
*)
82121
Logger: TLogger;
83122

123+
(*
124+
## GetDebugLn
125+
```pascal
126+
function GetDebugLn(text: String; log: Boolean = True): String;
127+
function GetDebugLn(name, text: String; log: Boolean = True): String; overload;
128+
function GetDebugLn(text: String; level: ELogLevel; log: Boolean = True): String; overload;
129+
function GetDebugLn(name, text: String; level: ELogLevel; log: Boolean = True): String; overload;
130+
```
131+
Returns a formatted debug string with timestamp.
132+
Optionally logs to file and applies color formatting based on `level`.
133+
*)
84134
function GetDebugLn(text: String; log: Boolean = True): String;
85135
begin
86136
Result := GetTimeStamp() + ': ' + text;
@@ -112,6 +162,14 @@ begin
112162
end;
113163

114164

165+
(*
166+
## Logger.Info
167+
```pascal
168+
procedure TLogger.Info(text: String; vars: TVariantArray = []);
169+
```
170+
Logs an info message. Duplicate consecutive messages are suppressed unless
171+
`Logger.RepeatedMessages` is True.
172+
*)
115173
procedure TLogger.Info(text: String; vars: TVariantArray = []);
116174
var
117175
formatted: String;
@@ -124,6 +182,13 @@ begin
124182
Self.PreviousMessage := formatted;
125183
end;
126184

185+
(*
186+
## Logger.Success
187+
```pascal
188+
procedure TLogger.Success(text: String; vars: TVariantArray = []);
189+
```
190+
Logs a success message (green colored output).
191+
*)
127192
procedure TLogger.Success(text: String; vars: TVariantArray = []);
128193
var
129194
formatted: String;
@@ -133,6 +198,13 @@ begin
133198
WriteLn(GetDebugLn(Self.Name, formatted, ELogLevel.SUCCESS, False));
134199
end;
135200

201+
(*
202+
## Logger.Warn
203+
```pascal
204+
procedure TLogger.Warn(text: String; vars: TVariantArray = []);
205+
```
206+
Logs a warning message (yellow colored output).
207+
*)
136208
procedure TLogger.Warn(text: String; vars: TVariantArray = []);
137209
var
138210
formatted: String;
@@ -142,6 +214,13 @@ begin
142214
WriteLn(GetDebugLn(Self.Name, formatted, ELogLevel.WARN, False));
143215
end;
144216

217+
(*
218+
## Logger.Error
219+
```pascal
220+
procedure TLogger.Error(text: String; vars: TVariantArray = []);
221+
```
222+
Logs an error message (red colored output).
223+
*)
145224
procedure TLogger.Error(text: String; vars: TVariantArray = []);
146225
var
147226
formatted: String;
@@ -151,6 +230,13 @@ begin
151230
WriteLn(GetDebugLn(Self.Name, formatted, ELogLevel.ERROR, False));
152231
end;
153232

233+
(*
234+
## Logger.Exception
235+
```pascal
236+
procedure TLogger.Exception(text: String; vars: TVariantArray = []);
237+
```
238+
Logs an error message and raises an exception to halt script execution.
239+
*)
154240
procedure TLogger.Exception(text: String; vars: TVariantArray = []);
155241
var
156242
formatted: String;

0 commit comments

Comments
 (0)