diff --git a/src/pregmod/FCTV/FCTV.js b/src/pregmod/FCTV/FCTV.js index b23fd6981bff301de5dbdd8441e329d60067fa59..194cb9de7513b2266e655896b792eaef2cfb304a 100644 --- a/src/pregmod/FCTV/FCTV.js +++ b/src/pregmod/FCTV/FCTV.js @@ -24,8 +24,6 @@ globalThis.FCTV = (function() { channelCount: channelCount, showRange: showRange, FinalTouches: FinalTouches, - watch: watch, - displayShow: displayShow }; /** Produce an array of numbers representing all available channels in App.Data.FCTV.shows @@ -51,7 +49,6 @@ globalThis.FCTV = (function() { canSelect: 1, text: `A notification is shown: ` }; - console.log("i: ", i); if (App.Data.FCTV.shows.hasOwnProperty(i)) { if (App.Data.FCTV.shows[i].hasOwnProperty("tags")) { for (const tag of App.Data.FCTV.shows[i].tags) { @@ -185,6 +182,11 @@ globalThis.FCTV = (function() { slave.health.condition = 75; updateHealth(slave); } +})(); + +globalThis.FCTVdisplay = function({ usedRemote = 0, seeAll = 0 } = {}) { + + return watch({ usedRemote:usedRemote, seeAll:seeAll }); function watch({ usedRemote = 0, seeAll = 0 } = {}) { let p; @@ -210,7 +212,7 @@ globalThis.FCTV = (function() { App.UI.DOM.link( "Use your remote", () => { - FCTV.watch({ usedRemote: 1, seeAll: seeAll }); + watch({ usedRemote: 1, seeAll: seeAll }); } ) ); @@ -263,7 +265,7 @@ globalThis.FCTV = (function() { div.append(`.`); } p.append(div); - App.UI.DOM.appendNewElement("p", p, FCTV.displayShow()); + $(p).append(displayShow()); } p = displayRemote(p); @@ -293,7 +295,7 @@ globalThis.FCTV = (function() { i, () => { V.FCTV.channel.selected = i; - FCTV.watch({ usedRemote: 1, seeAll: seeAll }); + watch({ usedRemote: 1, seeAll: seeAll }); } ) ); @@ -306,7 +308,7 @@ globalThis.FCTV = (function() { i, () => { V.FCTV.channel.selected = i; - FCTV.watch({ usedRemote: 1, seeAll: seeAll }); + watch({ usedRemote: 1, seeAll: seeAll }); } ) ); @@ -343,7 +345,7 @@ globalThis.FCTV = (function() { } else { seeAll = 1; } - FCTV.watch({ usedRemote: usedRemote, seeAll: seeAll }); + watch({ usedRemote: usedRemote, seeAll: seeAll }); } ) ); @@ -354,17 +356,31 @@ globalThis.FCTV = (function() { App.UI.DOM.link( `Randomise channel selection`, () => { - FCTV.watch({ usedRemote: 0, seeAll: seeAll }); + watch({ usedRemote: 0, seeAll: seeAll }); } ) ); return p; } } - function displayShow() { - FCTV.incrementChannel(2); - FCTV.incrementShow(); - return "show!!!!!"; + const sel = V.FCTV.channel.selected || 1; + const channel = App.Data.FCTV.shows[sel]; + const viewedCount = V.FCTV.channel[num(sel, true)]; + const availableEp = channel.episode.length; + let epToShow; + if (availableEp > viewedCount) { // If we watched ep 0 last time, our viewcount will be 1. Now we can use 1 as our new ep, etc. + epToShow = viewedCount; + } else if (channel.loop === true) { + // How many times have we been through this series. Lets say we watched 10 episodes, but there are only 3 uniques [0,1,2]. + const watchedEntireSeason = Math.trunc(viewedCount/availableEp); // we went through 3 times fully + epToShow = viewedCount-(watchedEntireSeason*availableEp); // 10 - 3 seasons (9) is 1. So our last epiode was the first, 0 in the array. And 1 is the next ep! + } else { // We have seen all the episodes, return a random one + epToShow = jsRandom(0, availableEp); + } + FCTV.incrementChannel(sel); + //FCTV.incrementShow(sel); + console.log(channel, epToShow); + return channel.episode[epToShow].text; } -})(); +}; diff --git a/src/pregmod/FCTV/seFCTVwatch.tw b/src/pregmod/FCTV/seFCTVwatch.tw index 4b3210e267d34d9bf039bdcd1f05b5cd8a233bcb..7fdb44b47b13ecf1fc29b3c285cdd3cb633e3b9f 100644 --- a/src/pregmod/FCTV/seFCTVwatch.tw +++ b/src/pregmod/FCTV/seFCTVwatch.tw @@ -4,5 +4,5 @@ <p id="FCTVwatch"></p> <script> - FCTV.watch(); + FCTVdisplay(); </script>