Skip to content

Commit 2562e86

Browse files
committed
fix: worldswitch changes so it makes more sense
1 parent 232d0e4 commit 2562e86

File tree

1 file changed

+101
-19
lines changed

1 file changed

+101
-19
lines changed

osrs/interfaces/gametabs/worldswitcher.simba

Lines changed: 101 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ switcher in the {ref}`Logout` gametab.
1010

1111
type
1212
(*
13-
## ERSWorldSwitcherButton
13+
## ERSWorldSwitcherButton enum
1414
```pascal
1515
ERSWorldSwitcherButton = enum(CONFIGURE, CLOSE, LOGOUT);
1616
```
@@ -19,15 +19,15 @@ Enum representing the world switcher buttons.
1919
ERSWorldSwitcherButton = enum(CONFIGURE, CLOSE, LOGOUT);
2020

2121
(*
22-
## TRSWorld
22+
## TRSWorld type
2323
Helper record for {ref}`TRSworldSwitcher`.
2424
*)
2525
TRSWorld = record
2626
Number: Integer;
2727
Bounds: TBox;
2828
end;
2929
(*
30-
## TRSWorldArray
30+
## TRSWorldArray type
3131
Helper type for {ref}`TRSworldSwitcher`.
3232
*)
3333
TRSWorldArray = array of TRSWorld;
@@ -51,7 +51,7 @@ end;
5151

5252
type
5353
(*
54-
## TRSWorldSwitcher
54+
## TRSWorldSwitcher type
5555
Main record that interacts with the {ref}`WorldSwitcher`.
5656
*)
5757
TRSWorldSwitcher = record
@@ -416,17 +416,13 @@ begin
416416
end;
417417

418418
(*
419-
## WorldSwitcher.World
419+
## WorldSwitcher.World property
420420
```pascal
421421
property TRSWorldSwitcher.World: Integer;
422-
property TRSWorldSwitcher.World(world: Integer): Boolean;
423-
property TRSWorldSwitcher.World(worlds: TIntegerArray): Boolean;
422+
property TRSWorldSwitcher.World(next: Integer): Boolean;
424423
```
425424
Returns or sets the current world we are on.
426425

427-
When setting, if there's multiple worlds available we will hop to the next on
428-
the list available.
429-
430426
Setting a new world will only happen if `TRSWorldSwitcher.Cooldown` is finished,
431427
which is a cooldown that starts everytime you change worlds.
432428

@@ -435,8 +431,6 @@ Example:
435431
WriteLn WorldSwitcher.World;
436432
WorldSwitcher.World := 311;
437433
WriteLn WorldSwitcher.World;
438-
WorldSwitcher.World[[311,312,313]];
439-
WriteLn WorldSwitcher.World;
440434
```
441435
*)
442436
property TRSWorldSwitcher.World: Integer;
@@ -456,27 +450,115 @@ begin
456450
Result := Self._Hop(next);
457451
end;
458452

459-
property TRSWorldSwitcher.World(worlds: TIntegerArray): Boolean;
453+
(*
454+
## WorldSwitcher.Next
455+
```pascal
456+
function TRSWorldSwitcher.Next(): Boolean;
457+
```
458+
Hops to the world that follows our current world according to the contents of
459+
`Profiles[ProfileIndex].Worlds`.
460+
461+
Example:
462+
```pascal
463+
WriteLn WorldSwitcher.World;
464+
WorldSwitcher.Next();
465+
WriteLn WorldSwitcher.World;
466+
```
467+
*)
468+
function TRSWorldSwitcher.Next(): Boolean;
460469
var
461470
current, next: Integer;
462471
begin
463472
if not Self.Cooldown.IsFinished or not Self.Open() then
464473
Exit;
465474

466-
if worlds = [] then
467-
raise GetDebugLn('WorldSwitcher', 'worlds parameter is empty.');
475+
if Profiles[ProfileIndex].Worlds = [] then
476+
raise GetDebugLn('WorldSwitcher', 'Current profile has no worlds saved.');
468477

469478
current := Self.World;
470-
if worlds = [current] then
479+
if Profiles[ProfileIndex].Worlds = [current] then
471480
Exit(True);
472481

473-
next := worlds.IndexOf(current);
474-
if Inc(next) > High(worlds) then
482+
next := Profiles[ProfileIndex].Worlds.IndexOf(current);
483+
if Inc(next) > High(Profiles[ProfileIndex].Worlds) then
475484
next := 0;
476485

477-
Result := Self._Hop(worlds[next]);
486+
Result := Self._Hop(Profiles[ProfileIndex].Worlds[next]);
478487
end;
479488

489+
(*
490+
## WorldSwitcher.Previous
491+
```pascal
492+
function TRSWorldSwitcher.Previous(): Boolean;
493+
```
494+
Hops to the world that comes before our current world according to the contents
495+
of `Profiles[ProfileIndex].Worlds`.
496+
497+
Example:
498+
```pascal
499+
WriteLn WorldSwitcher.World;
500+
WorldSwitcher.Previous();
501+
WriteLn WorldSwitcher.World;
502+
```
503+
*)
504+
function TRSWorldSwitcher.Previous(): Boolean;
505+
var
506+
current, prev: Integer;
507+
begin
508+
if not Self.Cooldown.IsFinished or not Self.Open() then
509+
Exit;
510+
511+
if Profiles[ProfileIndex].Worlds = [] then
512+
raise GetDebugLn('WorldSwitcher', 'Current profile has no worlds saved.');
513+
514+
current := Self.World;
515+
if Profiles[ProfileIndex].Worlds = [current] then
516+
Exit(True);
517+
518+
prev := Profiles[ProfileIndex].Worlds.IndexOf(current);
519+
if Dec(prev) < 0 then
520+
prev := High(Profiles[ProfileIndex].Worlds);
521+
522+
Result := Self._Hop(Profiles[ProfileIndex].Worlds[prev]);
523+
end;
524+
525+
(*
526+
## WorldSwitcher.Random
527+
```pascal
528+
function TRSWorldSwitcher.Random(): Boolean;
529+
```
530+
Hops to a random world that's in `Profiles[ProfileIndex].Worlds` and is not our
531+
current world.
532+
533+
Example:
534+
```pascal
535+
WriteLn WorldSwitcher.World;
536+
WorldSwitcher.Random();
537+
WriteLn WorldSwitcher.World;
538+
```
539+
*)
540+
function TRSWorldSwitcher.Random(): Boolean;
541+
var
542+
current, rnd: Integer;
543+
begin
544+
if not Self.Cooldown.IsFinished or not Self.Open() then
545+
Exit;
546+
547+
if Profiles[ProfileIndex].Worlds = [] then
548+
raise GetDebugLn('WorldSwitcher', 'Current profile has no worlds saved.');
549+
550+
current := Self.World;
551+
if Profiles[ProfileIndex].Worlds = [current] then
552+
Exit(True);
553+
554+
repeat
555+
rnd := Profiles[ProfileIndex].Worlds.Random();
556+
until rnd <> current;
557+
558+
Result := Self._Hop(rnd);
559+
end;
560+
561+
480562
(*
481563
## WorldSwitcher.WaitSwitch
482564
```pascal

0 commit comments

Comments
 (0)