introduce controlled asset randomness: implement shuffled asset bag logic for balanced and repeatable asset spawning
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 1m56s
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 1m56s
This commit is contained in:
@@ -27,6 +27,7 @@ let presiAssets = [];
|
||||
let presiPlayers = new Map();
|
||||
let presiQuoteInterval = null;
|
||||
let presiAssetInterval = null;
|
||||
let presiAssetBag = []; // Shuffled bag for controlled randomness
|
||||
|
||||
// Central UI State Manager
|
||||
function setUIState(newState) {
|
||||
@@ -982,10 +983,21 @@ async function spawnPresiAsset() {
|
||||
const track = document.querySelector('.presi-assets-track');
|
||||
if (!track) return;
|
||||
|
||||
// Refill the bag if empty
|
||||
if (presiAssetBag.length === 0) {
|
||||
const assetKeys = Object.keys(assetsManifest).filter(k =>
|
||||
['player', 'coin', 'eraser', 'pc-trash', 'godmode', 'jumpboost', 'magnet', 'baskeball', 'desk'].includes(k)
|
||||
);
|
||||
const key = assetKeys[Math.floor(Math.random() * assetKeys.length)];
|
||||
// Add each asset twice for a longer cycle
|
||||
presiAssetBag = [...assetKeys, ...assetKeys];
|
||||
// Shuffle
|
||||
for (let i = presiAssetBag.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[presiAssetBag[i], presiAssetBag[j]] = [presiAssetBag[j], presiAssetBag[i]];
|
||||
}
|
||||
}
|
||||
|
||||
const key = presiAssetBag.pop();
|
||||
const def = assetsManifest[key];
|
||||
|
||||
const el = document.createElement('div');
|
||||
|
||||
Reference in New Issue
Block a user