Skip to content

Commit

Permalink
fix(gearhandler): better logic so loading from client is slightly faster
Browse files Browse the repository at this point in the history
  • Loading branch information
Torwent committed Sep 23, 2024
1 parent 9f27333 commit 1ac83fc
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 8 deletions.
15 changes: 7 additions & 8 deletions optional/handlers/gearhandler.simba
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type
Config: TConfigJSON;

CurrentEquipment: array [ERSEquipmentSlot] of TRSItem;
_ValidGear: array [ERSEquipmentSlot] of TRSItemArray;

_FormGearIndex: Int32;
_FormFiltered: Boolean;
Expand All @@ -37,8 +38,7 @@ var
obj: TJSONObject;
slot: ERSEquipmentSlot;
begin
if Self.IsSetup then
Exit;
if Self.IsSetup then Exit;

Self.Config.Setup('gearhandler');
keys := Self.Config.JSON.Keys();
Expand All @@ -54,6 +54,9 @@ begin
Sets[i].Items[slot] := obj.getString(ToStr(slot).Lower());
end;

for slot := Low(ERSEquipmentSlot) to High(ERSEquipmentSlot) do
Self._ValidGear[slot] := GearData.GetItems(slot);

Self.IsSetup := True;
end;

Expand Down Expand Up @@ -473,7 +476,7 @@ procedure TScriptForm._OnLoadGear(sender: TObject);
var
combobox: TComboBox;
parent: TPanel;
items, validItems: TRSItemArray;
items: TRSItemArray;
item: TRSItem;
slot: ERSEquipmentSlot;
name: String;
Expand All @@ -498,13 +501,9 @@ begin
combobox.getItems().Add('None');

items := Equipment.Discover(slot);
validItems := GearData.GetItems(name);
WriteLn validItems.Intersection(items);

for item in validItems.Intersection(items) do
begin
for item in GearHandler._ValidGear[slot].Intersection(items) do
combobox.getItems().Add(ToStr(item).Capitalize());
end;

if combobox.getItems().getCount() = 1 then
combobox.setItemIndex(0)
Expand Down
90 changes: 90 additions & 0 deletions templates/gearhandler_example.simba
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{$DEFINE SCRIPT_GUI}
{$I SRL-T/osr.simba}
{$I WaspLib/optional.simba}

var
gear1, gear2, gear3, gear4, gear5: TRSGear;

type
TMyScriptForm = record(TScriptForm)
GearSelector1, GearSelector2, GearSelector3, GearSelector4, GearSelector5: TLabeledComboBox;
end;

procedure TMyScriptForm.StartScript(sender: TObject); override;
begin
inherited;

//Read your script options.
gear1 := GearHandler.Get(Self.GearSelector1.GetItemIndex());
gear2 := GearHandler.Get(Self.GearSelector2.GetItemIndex());
gear3 := GearHandler.Get(Self.GearSelector3.GetItemIndex());
gear4 := GearHandler.Get(Self.GearSelector4.GetItemIndex());
gear5 := GearHandler.Get(Self.GearSelector5.GetItemIndex());
end;

procedure TMyScriptForm.Run(); override;
var
tab: TTabSheet;
begin
Self.Setup('HELLO WORLD SCRIPT');
Self.Start.setOnClick(@Self.StartScript);

Self.AddTab('Script Settings');
tab := Self.Tabs[High(Self.Tabs)];

Self.GearSelector1.Create(tab);
Self.GearSelector1.SetStyle(TComboBoxStyle.csDropDownList);
Self.GearSelector1.SetCaption('Melee gear:');
Self.GearSelector1.SetLeft(TControl.AdjustToDPI(20));
Self.GearSelector1.SetTop(TControl.AdjustToDPI(170));
GearHandler.AddTo(Self.GearSelector1.ComboBox);

Self.GearSelector2.Create(tab);
Self.GearSelector2.SetStyle(TComboBoxStyle.csDropDownList);
Self.GearSelector2.SetCaption('Ranged gear:');
Self.GearSelector2.SetLeft(TControl.AdjustToDPI(20));
Self.GearSelector2.SetTop(TControl.AdjustToDPI(210));
GearHandler.AddTo(Self.GearSelector2.ComboBox);

Self.GearSelector3.Create(tab);
Self.GearSelector3.SetStyle(TComboBoxStyle.csDropDownList);
Self.GearSelector3.SetCaption('Magic gear:');
Self.GearSelector3.SetLeft(TControl.AdjustToDPI(20));
Self.GearSelector3.SetTop(TControl.AdjustToDPI(250));
GearHandler.AddTo(Self.GearSelector3.ComboBox);

Self.GearSelector4.Create(tab);
Self.GearSelector4.SetStyle(TComboBoxStyle.csDropDownList);
Self.GearSelector4.SetCaption('Dragons gear:');
Self.GearSelector4.SetLeft(TControl.AdjustToDPI(20));
Self.GearSelector4.SetTop(TControl.AdjustToDPI(290));
GearHandler.AddTo(Self.GearSelector4.ComboBox);

Self.GearSelector5.Create(tab);
Self.GearSelector5.SetStyle(TComboBoxStyle.csDropDownList);
Self.GearSelector5.SetCaption('Demons gear:');
Self.GearSelector5.SetLeft(TControl.AdjustToDPI(20));
Self.GearSelector5.SetTop(TControl.AdjustToDPI(330));
GearHandler.AddTo(Self.GearSelector5.ComboBox);

Self.CreateAccountManager(tab);
Self.CreateEquipmentManager();
Self.CreateAntibanManager();
Self.CreateWaspLibSettings();
Self.CreateAPISettings();

inherited;
end;

var
MyScriptForm: TMyScriptForm;

begin
MyScriptForm.Run();

WriteLn(gear1.Items);
WriteLn(gear2.Items);
WriteLn(gear3.Items);
WriteLn(gear4.Items);
WriteLn(gear5.Items);
end.
7 changes: 7 additions & 0 deletions utils/data/data.simba
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ end;
## GearData.GetItems
```pascal
function TGearData.GetItems(key: String): TRSItemArray;
function TGearData.GetItems(slot: ERSEquipmentSlot): TRSItemArray; overload;
```
Method to fetch items under a key in gear.json.
*)
Expand All @@ -1021,5 +1022,11 @@ begin
Result += Self.Data.getJSONArray(key).getString(i);
end;

function TGearData.GetItems(slot: ERSEquipmentSlot): TRSItemArray; overload;
begin
Result := Self.GetItems(LowerCase(ToStr(slot)));
end;


var
{$H-}GearData: TGearData;{$H+}

0 comments on commit 1ac83fc

Please sign in to comment.