From 2a15db9095ab0494c0cbaec9fbbf1fe11146306b Mon Sep 17 00:00:00 2001 From: Florrie Date: Fri, 11 Aug 2017 10:31:13 -0300 Subject: Make group-shuffle actually work --- src/pickers.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/pickers.js b/src/pickers.js index 6a30c37..2d8c631 100644 --- a/src/pickers.js +++ b/src/pickers.js @@ -1,6 +1,15 @@ 'use strict' -const { flattenGrouplike } = require('./playlist-utils') +const { flattenGrouplike, isGroup } = require('./playlist-utils') + +function shuffleGroups(grouplike) { + if (isGroup(grouplike) && grouplike.items.every(isGroup)) { + const items = shuffleArray(grouplike.items.map(shuffleGroups)) + return Object.assign({}, grouplike, {items}) + } else { + return grouplike + } +} function makePicker(grouplike, sort, loop) { // Options to take into consideration: @@ -31,7 +40,8 @@ function makePicker(grouplike, sort, loop) { } if (sort === 'shuffle-top-level' || sort === 'shuffle-groups') { - topLevel.items = flattenGrouplike(shuffleArray(grouplike.items)) + console.log(JSON.stringify(shuffleGroups(grouplike), null, 2)) + topLevel.items = flattenGrouplike(shuffleGroups(grouplike)).items } console.log(topLevel.items.map(require('./playlist-utils').getItemPathString).join('\n')) -- cgit 1.3.0-6-gf8a5