# HG changeset patch # User Nicholas Jillings # Date 1460458120 -3600 # Node ID cb27ece65a5c0ebcec9d2635f3da8705dc9443d3 # Parent 75ef314b5e64a3a55a25525ef0f6763675bed886 Review for Issue #2. Should be a working implementation. See issue post for usage. diff -r 75ef314b5e64 -r cb27ece65a5c core.js --- a/core.js Tue Apr 12 10:50:52 2016 +0100 +++ b/core.js Tue Apr 12 11:48:40 2016 +0100 @@ -496,6 +496,47 @@ return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1); } +function randomiseOrder(input) +{ + // This takes an array of information and randomises the order + var N = input.length; + + var inputSequence = []; // For safety purposes: keep track of randomisation + for (var counter = 0; counter < N; ++counter) + inputSequence.push(counter) // Fill array + var inputSequenceClone = inputSequence.slice(0); + + var holdArr = []; + var outputSequence = []; + for (var n=0; n array.length) { + num = array.length; + } + var ret = []; + while (num > 0) { + var index = Math.floor(Math.random() * array.length); + ret.push( array.splice(index,1)[0] ); + num--; + } + return ret; +} + function interfacePopup() { // Creates an object to manage the popup this.popup = null; @@ -556,12 +597,14 @@ }; this.hidePopup = function(){ - this.popup.style.zIndex = -1; - this.popup.style.visibility = 'hidden'; - var blank = document.getElementsByClassName('testHalt')[0]; - blank.style.zIndex = -2; - blank.style.visibility = 'hidden'; - this.buttonPrevious.style.visibility = 'inherit'; + if (this.popup) { + this.popup.style.zIndex = -1; + this.popup.style.visibility = 'hidden'; + var blank = document.getElementsByClassName('testHalt')[0]; + blank.style.zIndex = -2; + blank.style.visibility = 'hidden'; + this.buttonPrevious.style.visibility = 'inherit'; + } }; this.postNode = function() { @@ -850,29 +893,68 @@ this.currentStatePosition = null; this.currentStore = null; this.initialise = function(){ - + // Get the data from Specification - var pageHolder = []; + var pagePool = []; + var pageInclude = []; for (var page of specification.pages) { - var repeat = page.repeatCount; - while(repeat >= 0) - { - pageHolder.push(page); - repeat--; + if (page.alwaysInclude) { + pageInclude.push(page); + } else { + pagePool.push(page); } } + + // Find how many are left to get + var numPages = specification.poolSize; + if (numPages > pagePool.length) { + console.log("WARNING - You have specified more pages in than you have created!!"); + numPages = specification.pages.length; + } + if (specification.poolSize == 0) { + numPages = specification.pages.length; + } + numPages -= pageInclude.length; + + if (numPages > 0) { + // Go find the rest of the pages from the pool + var subarr = null; + if (specification.randomiseOrder) { + // Append a random sub-array + subarr = randomSubArray(pagePool,numPages); + } else { + // Append the matching number + subarr = pagePool.slice(0,numPages); + } + pageInclude = pageInclude.concat(subarr); + } + + // We now have our selected pages in pageInclude array if (specification.randomiseOrder) { - pageHolder = randomiseOrder(pageHolder); + pageInclude = randomiseOrder(pageInclude); } - for (var i=0; i - + (1) Very Annoying @@ -28,8 +28,9 @@ (5) Inaudible - + +