Skip to content

Commit

Permalink
fix(alchhandler): now saves it's config as json instead of a weird si…
Browse files Browse the repository at this point in the history
…mba file

old alch handler configs will be reset
  • Loading branch information
Torwent committed May 24, 2024
1 parent e0dcb9a commit 1a2bd63
Showing 1 changed file with 50 additions and 31 deletions.
81 changes: 50 additions & 31 deletions optional/handlers/alchhandler.simba
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,43 @@ type
Timer: TCountDown;
SlotUnder, LowProfit, HighProfit, TotalProfit: Int32;
Disabled: Boolean;
Config: TConfigJSON;
end;

procedure TRSAlchHandler.Setup();
procedure TRSAlchHandler.SaveConfig();
var
settings: TStringArray;
str: String;
i: Int32;
arr: TJSONArray;
begin
if Self.ItemArray <> []then
Exit;
if Self.Config.Has('items') then
begin
Self.Config.JSON.getJSONArray('items').Free();
Self.Config.Remove('items');
end;

arr.Init();

for i := 0 to High(Self.ItemArray) do
arr.Put(ToStr(Self.ItemArray[i]));
Self.Config.Put('items', arr);
end;

procedure TRSAlchHandler.AddItem(item: TRSItem);
begin
Self.ItemArray += item;
Self.SaveConfig();
end;

procedure TRSAlchHandler.AddDefault();
begin
Self.ItemArray := [
'abyssal bracelet(5)', 'adamant platebody', 'air battlestaff',
'amulet of glory', 'amulet of glory(4)', 'black d''hide body',
'black d''hide chaps', 'black d''hide shield', 'black d''hide vambraces',
'blue d''hide body', 'blue d''hide chaps', 'blue d''hide shield',
'blue d''hide vambraces', 'combat bracelet', 'combat bracelet(4)',
'diamond bracelet', 'dragon axe', 'dragon battleaxe', 'dragon cane',
'dragon chainbody', 'dragon dagger', 'dragon dagger(p+)', 'dragon halberd',
'dragon chainbody', 'dragon dagger', 'dragon halberd',
'dragon hasta', 'dragon longsword', 'dragon mace', 'dragon med helm',
'dragon platelegs', 'dragon plateskirt', 'dragon scimitar', 'dragon spear',
'dragon sq shield', 'dragon sword', 'dragonstone ring', 'earth battlestaff',
Expand Down Expand Up @@ -99,19 +117,33 @@ begin
'runite limbs', 'skills necklace', 'skills necklace(4)', 'steel platebody',
'water battlestaff', 'yew longbow'
];
end;

settings += 'RSAlchHandler.ItemArray := [';
for i := 0 to High(Self.ItemArray) do
procedure TRSAlchHandler.LoadItems();
var
i: Int32;
begin
for i := 0 to Self.Config.GetArray('items').High() do
Self.ItemArray += Self.Config.GetArray('items').getString(i);
end;

procedure TRSAlchHandler.Setup();
begin
if Self.ItemArray <> []then
Exit;

Self.Config.Setup('alchhandler');
if not Self.Config.Has('items', False) then
begin
str := " '" + ToString(Self.ItemArray[i]).Replace("'", "''") + "'";
if i < High(Self.ItemArray) then
str += ',';
settings += str;
Self.AddDefault();
Self.SaveConfig();
Exit;
end;
settings += '];';
WriteConfigFile('alch_handler', settings);

Self.LoadItems();
end;


function TRSAlchHandler.GetAlchItem(): TRSItem;
var
match: TRSItemFinderMatch;
Expand Down Expand Up @@ -315,11 +347,10 @@ end;
var
RSAlchHandler: TRSAlchHandler;

{$IFHASFILE Data/WaspLib/configs/alch_handler.simba}
{$I Data/WaspLib/configs/alch_handler.simba}
{$ENDIF}

procedure TSRL.Setup(); override;
begin
inherited;

RSAlchHandler.Setup();
end;

Expand Down Expand Up @@ -379,7 +410,6 @@ begin
end;
end;


function TScriptForm.CreateAlchemyPanel(): TTabSheet;
type TListBox = TListBox;
procedure TListBox._AddSorted(str: String);
Expand Down Expand Up @@ -421,23 +451,12 @@ function TScriptForm.CreateAlchemyPanel(): TTabSheet;
procedure TListBox._ReWriteAlchConfig();
var
i, count: Int32;
str: String;
settings: TStringArray;
begin
RSAlchHandler.ItemArray := [];
settings += 'RSAlchHandler.ItemArray := [';
count := Self.GetCount() - 1;
for i := 0 to count do
begin
RSAlchHandler.ItemArray += Self.getItems().GetStrings(i);
str := ToStr(RSAlchHandler.ItemArray[i]);
str := " '" + str.Replace("'", "''") + "'";
if i < count then
str += ',';
settings += str;
end;
settings += '];';
WriteConfigFile('alch_handler', settings);
RSAlchHandler.SaveConfig();
end;

type TScriptForm = TScriptForm;
Expand Down

0 comments on commit 1a2bd63

Please sign in to comment.