Skip to content

Commit

Permalink
Fixed an issue with items being split mid-stack for similar items
Browse files Browse the repository at this point in the history
  • Loading branch information
m committed Oct 9, 2024
1 parent 8383c78 commit a60e90a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 35 deletions.
4 changes: 0 additions & 4 deletions IAGrim/IAGrim.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@
<Reference Include="System.Text.Json, Version=8.0.0.4, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Json.8.0.4\lib\net462\System.Text.Json.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Channels, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Channels.7.0.0\lib\net462\System.Threading.Channels.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
<Private>True</Private>
Expand Down
5 changes: 3 additions & 2 deletions IAGrim/Log4net.config
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@
</logger>
-->
<root>
<level value="DEBUG" />
<level value="INFO" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="RollingFileAppender" />
<appender-ref ref="textbox"/>
<appender-ref ref="textbox"/>
</root>


<logger name="NHibernate.Engine.ForeignKeys" additivity="false">
<level value="ERROR"/>
<appender-ref ref="RollingFileAppender" />
Expand Down
26 changes: 13 additions & 13 deletions IAGrim/Services/ItemPaginationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ class ItemPaginationService {
private int _skip;
private List<PlayerHeldItem> _items = new List<PlayerHeldItem>();

public int NumItems {
public int NumItems => _items.Count;

private int Remaining {
get {
var uniques = _items.Select(item => {
if (item is PlayerItem pi) {
return (pi.BaseRecord ?? string.Empty) + (pi.PrefixRecord ?? string.Empty) + (pi.SuffixRecord ?? string.Empty) + pi.Seed;
}
else if (item is BuddyItem bi) {
return (bi.BaseRecord ?? string.Empty) + (bi.PrefixRecord ?? string.Empty) + (bi.SuffixRecord ?? string.Empty) + bi.Seed;
if (_limit >= NumItems - _skip) {
return Math.Min(_limit, NumItems - _skip);
} else {
int takeUntil = Math.Min(_limit, NumItems - _skip);

// If the next base record is the same, keep taking more items to prevent splitting an item "stack"
while (takeUntil < NumItems - _skip - 1 && _items[takeUntil].BaseRecord == _items[takeUntil+1].BaseRecord) {
takeUntil++;
}

return item.BaseRecord;
}).ToHashSet();

return uniques.Count;
return takeUntil;
}
}
}

private int Remaining => Math.Min(_limit, NumItems - _skip);


public ItemPaginationService(int limit) {
this._limit = limit;
Expand Down
19 changes: 4 additions & 15 deletions IAGrim/UI/Controller/SearchController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using IAGrim.Database;
using IAGrim.Database.Dto;
using IAGrim.Database.Interfaces;
using IAGrim.Database.Synchronizer;
using IAGrim.Services;
using IAGrim.UI.Controller.dto;
using IAGrim.UI.Misc;
using IAGrim.UI.Misc.CEF;
using IAGrim.Utilities;
using log4net;
Expand All @@ -13,7 +11,6 @@
using System.Linq;
using System.Threading;
using EvilsoftCommons.Exceptions;
using IAGrim.Settings;

namespace IAGrim.UI.Controller {
public class SearchController {
Expand Down Expand Up @@ -51,17 +48,6 @@ private void JsBind_OnRequestItems(object sender, EventArgs e) {
OnSearch?.Invoke(this, null);
}

public string Search(ItemSearchRequest query, bool includeBuddyItems, bool orderByLevel) {
// Signal that we are loading items
Browser.ShowLoadingAnimation(true);

var message = Search_(query, includeBuddyItems, orderByLevel);



return message;
}

private void UpdateCollectionItems(ItemSearchRequest query) {
Thread thread = new Thread(() => {
ExceptionReporter.EnableLogUnhandledOnThread();
Expand Down Expand Up @@ -94,10 +80,13 @@ private bool ApplyItems(bool append) {
return true;
}

private string Search_(ItemSearchRequest query, bool includeBuddyItems, bool orderByLevel) {
public string Search(ItemSearchRequest query, bool includeBuddyItems, bool orderByLevel) {
OnSearch?.Invoke(this, null);
string message;

// Signal that we are loading items
Browser.ShowLoadingAnimation(true);


Logger.Info("Searching for items..");

Expand Down
1 change: 0 additions & 1 deletion create.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ copy /y %appdata%\..\local\evilsoft\iagd\tags_ia.template.txt installer\tags_ia.
Inno\iscc Inno\gdia.iss

echo "Checking for unstaged changes before tagging to git.."
git diff --exit-code || exit
set-commit-tags.cmd

pause

0 comments on commit a60e90a

Please sign in to comment.