From c72317756479ea5c99809199f514be250866e7ac Mon Sep 17 00:00:00 2001 From: Sarahtonin Date: Mon, 7 Sep 2026 16:04:25 +0200 Subject: [PATCH] Changed the preview to be random for lists that are Type Once, since that's more correct. --- Scripts/Garden/MutationRecipePreview.js | 95 +++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 4 deletions(-) diff --git a/Scripts/Garden/MutationRecipePreview.js b/Scripts/Garden/MutationRecipePreview.js index dacaf6d..25429c1 100644 --- a/Scripts/Garden/MutationRecipePreview.js +++ b/Scripts/Garden/MutationRecipePreview.js @@ -373,10 +373,11 @@ function RenderMutationRecipePreviewListCell( } const ItemIndex = - ( - Frame + - Entry.Offset - ) % Items.length; + GetMutationRecipePreviewItemIndex( + Entry, + Frame, + Items.length + ); ApplyMutationRecipePreviewCellDisplay( Entry, @@ -388,6 +389,92 @@ function RenderMutationRecipePreviewListCell( } +function GetMutationRecipePreviewItemIndex( + Entry, + Frame, + ItemCount +) { + if (Entry.List?.Mode !== "Once") { + return ( + Frame + + Entry.Offset + ) % ItemCount; + } + + const Permutation = + CreateMutationRecipePreviewPermutation( + ItemCount, + Entry.ListNumber, + Frame + ); + + return Permutation[ + Entry.Offset % ItemCount + ]; +} + + +function CreateMutationRecipePreviewPermutation( + ItemCount, + ListNumber, + Frame +) { + const Permutation = + Array.from( + { length: ItemCount }, + (_, Index) => Index + ); + + if (ItemCount < 2 || Frame === 0) { + return Permutation; + } + + let State = + ( + Math.imul( + Frame + 1, + 0x9e3779b1 + ) ^ + Math.imul( + ListNumber + 1, + 0x85ebca6b + ) ^ + Math.imul( + ItemCount, + 0xc2b2ae35 + ) + ) >>> 0; + + if (State === 0) { + State = 0x6d2b79f5; + } + + for ( + let Index = ItemCount - 1; + Index > 0; + Index-- + ) { + State ^= State << 13; + State ^= State >>> 17; + State ^= State << 5; + State >>>= 0; + + const SwapIndex = + State % (Index + 1); + + [ + Permutation[Index], + Permutation[SwapIndex] + ] = [ + Permutation[SwapIndex], + Permutation[Index] + ]; + } + + return Permutation; +} + + function GetMutationRecipePreviewItemDisplay( Item, PlantCatalogue