Skip to content

Commit

Permalink
simplify loop maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam- committed Jun 25, 2024
1 parent aa8be11 commit 5f7782a
Showing 1 changed file with 14 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ void layout(Layout l)
// bank get added to the layout.

int[] layout = l.getLayout();
int[] layoutScratch = layout.clone();

ItemMatcher[] matchers = {
this::matchExact,
Expand All @@ -141,7 +140,7 @@ void layout(Layout l)
for (ItemMatcher matcher : matchers)
{
// tagged item id
for (int itemId : layoutScratch)
for (int itemId : layout)
{
if (itemId == -1 || layoutToBank.containsKey(itemId))
{
Expand All @@ -167,46 +166,35 @@ void layout(Layout l)
}
}

// Items from the layout and in the bank.
for (int pos = 0; pos < layoutScratch.length; ++pos)
// Items from the layout
for (int pos = 0; pos < layout.length; ++pos)
{
int itemId = layoutScratch[pos]; // tagged item id
int itemId = layout[pos]; // tagged item id
if (itemId == -1)
{
continue;
}

Integer bankItemId = layoutToBank.get(itemId);
if (bankItemId != null)
if (bankItemId == null)
{
layoutScratch[pos] = -1;
Widget c = itemContainer.getChild(pos);
drawItem(l, c, bankItemId, bank.count(bankItemId), pos);
}
}

// Items from the layout but doesn't match an item in the bank.
for (int pos = 0; pos < layoutScratch.length; ++pos)
{
int itemId = layoutScratch[pos]; // tagged item id
if (itemId == -1)
{
continue;
}
// Item is in the layout but doesn't match an item in the bank.
if (log.isDebugEnabled())
{
ItemComposition def = itemManager.getItemComposition(itemId);
log.debug("Layout contains {}{} with no matching item", def.getName(), def.getPlaceholderTemplateId() > -1 && def.getPlaceholderId() > -1 ? " (placeholder)" : "");
}

if (log.isDebugEnabled())
{
ItemComposition def = itemManager.getItemComposition(itemId);
log.debug("Layout contains {}{} with no matching item", def.getName(), def.getPlaceholderTemplateId() > -1 && def.getPlaceholderId() > -1 ? " (placeholder)" : "");
bankItemId = itemId;
}

Widget c = itemContainer.getChild(pos);
drawItem(l, c, itemId, bank.count(itemId), pos);
drawItem(l, c, bankItemId, bank.count(bankItemId), pos);
}

int lastEmptySlot = -1;
boolean modified = false;
// Items in the bank but not in the layout.
// Items from the bank but not in the layout.
for (int itemId : bankItems)
{
while (++lastEmptySlot < layout.length && layout[lastEmptySlot] > -1);
Expand Down

0 comments on commit 5f7782a

Please sign in to comment.