Fixed bug where the previews for mutations with lists in their plots

could get a repeat permutation.
This commit is contained in:
sarah committed 2026-09-07 16:23:45 +02:00
1 parent c723177564
commit ea50b76e26
1 file changed
+75 -38
+75 -38
View File
@@ -4,6 +4,7 @@ let MutationRecipePreviewFrame = 0;
let MutationRecipePreviewTimer = null; let MutationRecipePreviewTimer = null;
const MutationRecipePreviewCells = new Set(); const MutationRecipePreviewCells = new Set();
const MutationRecipePreviewPermutations = new Map();
function GetMutationRecipePreviewListReference( function GetMutationRecipePreviewListReference(
@@ -419,58 +420,94 @@ function CreateMutationRecipePreviewPermutation(
ListNumber, ListNumber,
Frame Frame
) { ) {
const CacheKey =
ListNumber + ":" + ItemCount;
const Cached =
MutationRecipePreviewPermutations.get(
CacheKey
);
if (Cached?.Frame === Frame) {
return Cached.Permutation;
}
const Permutation = const Permutation =
Array.from( Array.from(
{ length: ItemCount }, { length: ItemCount },
(_, Index) => Index (_, Index) => Index
); );
if (ItemCount < 2 || Frame === 0) { 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]
];
}
} }
let State = if (
( ItemCount >= 2 &&
Math.imul( Cached?.Frame === Frame - 1 &&
Frame + 1, Permutation.every(
0x9e3779b1 (Value, Index) =>
) ^ Value ===
Math.imul( Cached.Permutation[Index]
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[0],
Permutation[SwapIndex] Permutation[1]
] = [ ] = [
Permutation[SwapIndex], Permutation[1],
Permutation[Index] Permutation[0]
]; ];
} }
MutationRecipePreviewPermutations.set(
CacheKey,
{
Frame: Frame,
Permutation: Permutation
}
);
return Permutation; return Permutation;
} }