From 6b2a93ea747b1a4e0e1603e5f1e705e6f21066ab Mon Sep 17 00:00:00 2001 From: D-Cysteine <54219287+D-Cysteine@users.noreply.github.com> Date: Wed, 4 Jan 2023 05:14:18 -0700 Subject: [PATCH] Fix shaped recipes --- libs/NESQL-Exporter-0.1.0-sql.jar | Bin 34865 -> 34870 bytes .../base/display/recipe/DisplayRecipe.java | 66 ++++++++---------- .../nesql/server/service/SearchService.java | 20 +++--- src/main/resources/static/css/main.css | 4 +- 4 files changed, 41 insertions(+), 49 deletions(-) diff --git a/libs/NESQL-Exporter-0.1.0-sql.jar b/libs/NESQL-Exporter-0.1.0-sql.jar index 8f1ec05281447a126109a64fd53e63a008e074fb..36b2f4e4720b9bf2aaf84689fe053f3a6edd9715 100644 GIT binary patch delta 4238 zcmZ9Pc|25a`^RTSj6DfuOElSuWT|A!zRQ}OA=}txXN<9=h%t5|>mVYNec!2Mi=sq@ zv1Og4glEotf6wpx>N$U$&-vWf`?}8SoVm|E_w^zL(vSk7H`JjxMGFE^Q-jbj41E9v z3I@ZVdC7tkJVSD3AkqN=PNahsTS#*rbHD(B!LU&9b*BFb^N_-Przt@H79|zHqQJ@! z6b#!3)*_|hPeV{plEtUeG*JRx_w*7N@KR^&Ab?Lh%M1pzoaHw;Uc#XU1^ha%4LPn2 zJ55$A{zM2+c2!Ul2uleqQ3GW-u3A$8K3I+i2;;MFB#?2~tu1m{R>gnHo>9{vm$lTj zBF7u`naDb9_=>FQ#){b^-B@A%gAeib=OMVemlSRo0>>w8fGl%)<4yNoz>6D0@>(rhMaXP z)qG~Sr$)Gy+m~3;R%Ie;vm!NM;W4{o*P$4D1)2E2J6G_-~uTL!n2jwZO zY%~-8Y&H|}!Zw@Dk%yyOC#tH+6Qf@P9^@kvFxt7g9RrK&x*gq%q^r`g#%~9a@xwvv zC!+qNlD{rsx1@f7v4p#a(JEI4+|u%mRxckP8mO5?bBynrW=bSSS9WwDE`n`3pLlTHf8Q(2T_u8gjPKzwle0+XA4nDO}rV2$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G$smkadjysLtjx=*k?+uUa7;NKZNL=ZVFJh*eLNhB*?Nv(5ayy8oJ=WMWyB=?B=ZRMe%ffWVpuVuYZlbmO}qxrWVmnE&XxQ+xW&~ z9sgMNC~=}jn%Y@=JmzvUh&xN>Tt_Mr`o<<})eXtC9-SI=;bZEa)be||js#~N8|u&M z<7Pde{!*E18W7wOtT#1;o&VweGzzuE>o;S&`gCo(n@pEE^?E7wwre13GRU=M4_`A9E zw7uR-6iSD=%ww<<1LrSaq{1)oDhWpKy&tOn0#0X%yufojCt#Z%wKim%&8oV=hbqNw zt&9DFaU7Ldq_K2==wd;>I(}RgT-$)3wy+?+GQQFi%Gq_ZK5wW)jJrL*TAeH3xv?dM zp}F+Fukhu+KrcoiXNnsaM61|TgtV!rO*Dq5|GJCa{B^&d%SGEXQaqm3XZczz=EK?F z9-hLILNXzCemgl%rTwteqgV9(!mr8&0eNaT=y=f{tE-Kz^PACx|i#CvANA_q@1 z0_$S9;%389Ctx!p3NQ!dzh^t#Ktu#E)!}p^Wyri8sYGT?q$X)z!hMar4nQ@^2*BMa zI51nyMA-mJKH3FP_oKZ4bsQZ8sK6L+KuyQ^0nkO>1W<(x2Ou1K8^GgOa>AK7S0KSV z4gnZn#yJ7%0?HFmSX2O@_EF??r+6R0*dOl!Kn5KOpadNTfcFkL0e!~>P)m3G0hlNF z1H)Nof(`kR{GZ_rC!A;t1jHpmz}MYz<~|CzOm|kCOAI3rznOR*yx~ch%@qM$1x_6t&k)L_;PAoxh;~4Hjshc7I%fA3B(mGWD diff --git a/src/main/java/com/github/dcysteine/nesql/server/plugin/base/display/recipe/DisplayRecipe.java b/src/main/java/com/github/dcysteine/nesql/server/plugin/base/display/recipe/DisplayRecipe.java index caafbaa..4adb3ad 100644 --- a/src/main/java/com/github/dcysteine/nesql/server/plugin/base/display/recipe/DisplayRecipe.java +++ b/src/main/java/com/github/dcysteine/nesql/server/plugin/base/display/recipe/DisplayRecipe.java @@ -14,8 +14,10 @@ import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableTable; +import com.google.common.collect.Maps; import java.util.Iterator; +import java.util.Map; /** * Packages up a {@link Recipe} for displaying on a page. @@ -28,34 +30,30 @@ public abstract class DisplayRecipe implements Comparable { public static DisplayRecipe create(Recipe recipe, ItemRepository itemRepository) { DisplayRecipeType displayRecipeType = DisplayRecipeType.create(recipe.getRecipeType()); - ImmutableList displayItemInputs = - recipe.getItemInputs().stream() - .map(itemGroup -> DisplayItemGroup.buildIcon(itemGroup, itemRepository)) - .collect(ImmutableList.toImmutableList()); + Map displayItemInputs = + Maps.transformValues( + recipe.getItemInputs(), + itemGroup -> DisplayItemGroup.buildIcon(itemGroup, itemRepository)); ImmutableTable itemInputs = buildIngredientsGrid( displayRecipeType.getItemInputGrid(), displayItemInputs, recipe); - ImmutableList displayFluidInputs = - recipe.getFluidInputs().stream() - .map(DisplayFluidGroup::buildIcon) - .collect(ImmutableList.toImmutableList()); + Map displayFluidInputs = + Maps.transformValues(recipe.getFluidInputs(), DisplayFluidGroup::buildIcon); ImmutableTable fluidInputs = buildIngredientsGrid( displayRecipeType.getFluidInputGrid(), displayFluidInputs, recipe); - ImmutableList displayItemOutputs = - recipe.getItemOutputs().stream() - .map(DisplayItemStackWithProbability::buildIcon) - .collect(ImmutableList.toImmutableList()); + Map displayItemOutputs = + Maps.transformValues( + recipe.getItemOutputs(), DisplayItemStackWithProbability::buildIcon); ImmutableTable itemOutputs = buildIngredientsGrid( displayRecipeType.getItemOutputGrid(), displayItemOutputs, recipe); - ImmutableList displayFluidOutputs = - recipe.getFluidOutputs().stream() - .map(DisplayFluidStackWithProbability::buildIcon) - .collect(ImmutableList.toImmutableList()); + Map displayFluidOutputs = + Maps.transformValues( + recipe.getFluidOutputs(), DisplayFluidStackWithProbability::buildIcon); ImmutableTable fluidOutputs = buildIngredientsGrid( displayRecipeType.getFluidOutputGrid(), displayFluidOutputs, recipe); @@ -113,33 +111,27 @@ public static Icon buildIcon(Recipe recipe) { public abstract ImmutableTable getFluidOutputs(); private static ImmutableTable buildIngredientsGrid( - Dimension gridDimension, Iterable ingredients, Recipe recipe) { + Dimension gridDimension, Map ingredients, Recipe recipe) { ImmutableTable.Builder builder = ImmutableTable.builder(); - Iterator iterator = ingredients.iterator(); - for (int row = 0; row < gridDimension.getHeight(); row++) { - for (int col = 0; col < gridDimension.getHeight(); col++) { - if (!iterator.hasNext()) { - break; - } - - Icon icon = iterator.next(); - if (icon != null) { - builder.put(row, col, icon); - } + int excessEntries = 0; + int maxIndex = 0; + for (Map.Entry entry : ingredients.entrySet()) { + int row = entry.getKey() / gridDimension.getWidth(); + int col = entry.getKey() % gridDimension.getWidth(); + builder.put(row, col, entry.getValue()); + + if (row >= gridDimension.getHeight()) { + excessEntries++; + maxIndex = Math.max(maxIndex, entry.getKey()); } } - if (iterator.hasNext()) { - int excess = 0; - while (iterator.hasNext()) { - excess++; - iterator.next(); - } - + if (excessEntries > 0) { Main.Logger.error( "Tried to build recipe ingredients grid with too many ingredients!\n" - + "Expected {}x{}; got {} excess for recipe {}", - gridDimension.getWidth(), gridDimension.getHeight(), excess, recipe.getId()); + + "Expected {}x{}; got {} excess, {} max index for recipe {}", + gridDimension.getHeight(), gridDimension.getWidth(), + excessEntries, maxIndex, recipe.getId()); } return builder.build(); diff --git a/src/main/java/com/github/dcysteine/nesql/server/service/SearchService.java b/src/main/java/com/github/dcysteine/nesql/server/service/SearchService.java index 3e27e56..c20f421 100644 --- a/src/main/java/com/github/dcysteine/nesql/server/service/SearchService.java +++ b/src/main/java/com/github/dcysteine/nesql/server/service/SearchService.java @@ -27,17 +27,17 @@ public , R, D> String handleGetAll( public , R, D> String handleSearch( int page, Model model, T repository, Specification spec, Function buildDisplay) { - // Pageable uses 0-index page, but we want 1-indexed. - Pageable pageable = Pageable.ofSize(externalConfig.getPageSize()).withPage(page - 1); - Page results = repository.findAll(spec, pageable).map(buildDisplay); + // Pageable uses 0-index page, but we want 1-indexed. + Pageable pageable = Pageable.ofSize(externalConfig.getPageSize()).withPage(page - 1); + Page results = repository.findAll(spec, pageable).map(buildDisplay); - String baseUri = - ServletUriComponentsBuilder.fromCurrentRequest() - .replaceQueryParam("page") - .toUriString(); + String baseUri = + ServletUriComponentsBuilder.fromCurrentRequest() + .replaceQueryParam("page") + .toUriString(); - model.addAttribute("page", results); - model.addAttribute("baseUri", baseUri); - return "search_results"; + model.addAttribute("page", results); + model.addAttribute("baseUri", baseUri); + return "search_results"; } } diff --git a/src/main/resources/static/css/main.css b/src/main/resources/static/css/main.css index dbc6d67..7587e5f 100644 --- a/src/main/resources/static/css/main.css +++ b/src/main/resources/static/css/main.css @@ -30,10 +30,10 @@ span.icon-overlay.bottom-right { } table.recipe-grid-table tr { - height: 70px; + height: 80px; } table.recipe-grid-table td { - width: 70px; + width: 80px; text-align: center; vertical-align: center; border: 1px solid black;