diff --git a/src/pregmod/FCTV/FCTV.js b/src/pregmod/FCTV/FCTV.js index 2473c9d12d463b4964d74b67371ef2e25fcd536b..244fa09da196399632067e630a1ed514a034c0dd 100644 --- a/src/pregmod/FCTV/FCTV.js +++ b/src/pregmod/FCTV/FCTV.js @@ -18,52 +18,10 @@ globalThis.FCTV = (function() { return { channels: channels, initChannels: initChannels, - showChannel: showChannel, - incrementChannel: incrementChannel, - incrementShow: incrementShow, channelCount: channelCount, FinalTouches: FinalTouches, - checkTags:checkTags, - getEpisode:getEpisode }; - - function getEpisode(sel) { - let epToShow = -1; - const epsArray = []; - /** @type {FctvChannel} */ - const channel = App.Data.FCTV.channels[sel]; - const viewedCount = V.FCTV.channel[num(sel, true)] || 0; - for (let i = 0; i < App.Data.FCTV.channels[sel].episode.length; i++) { - const ep = App.Data.FCTV.channels[sel].episode[i]; - if (ep.tags) { - const x = FCTV.checkTags(ep.tags); - if (x.canSelect !== -1) { - epsArray.push(i); - } - } else { - epsArray.push(i); - } - } - const availableEp = epsArray.length; - if (epsArray.length === 0) { - return -1; - } - - if (availableEp > viewedCount) { // If we watched ep 0 last time, our view count 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 episode 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-1); - } - if (epToShow === -1) { - return epToShow; - } - return epsArray[epToShow]; - } /** Produce an array of numbers representing all available channels in App.Data.FCTV.channels * @returns {Array} */ @@ -82,94 +40,6 @@ globalThis.FCTV = (function() { } } - function showChannel(i = 1, {usedRemote = 0, seeAll = 0} = {}) { - let x = { - canSelect: 1, - text: `A notification is shown: ` - }; - if (App.Data.FCTV.channels.hasOwnProperty(i)) { - if (App.Data.FCTV.channels[i].hasOwnProperty("tags")) { - x = FCTV.checkTags(App.Data.FCTV.channels[i].tags); - } - if (App.Data.FCTV.channels[i].hasOwnProperty("disableSelection")) { - x.canSelect = -1; x.text += `<i>This channel appears at random times</i>`; - } - } - if (i === 11) { - if (V.purchasedSagBGone && V.FCTV.channel[num(i, true)] > 2) { - x.canSelect = -1; x.text += `<i>Product purchase detected, skipping commercials.</i>`; - } - } - - if (seeAll) { x.canSelect = 1; } - return x; - } - - function checkTags(tags){ - let x = { - canSelect: 1, - text: `A notification is shown: ` - }; - for (const tag in tags) { - if (tag) { - switch (tag) { - case "hyperPreg": - if (!V.seeHyperPreg) { - x.canSelect = -1; x.text += `<i>Too much happiness detected, changing program.</i>`; - } - break; - case "preg": - if (!V.seePreg) { - x.canSelect = -1; x.text += `<i>Too much baking detected, changing program.</i>`; - } - break; - case "extreme": - if (!V.seeExtreme) { - x.canSelect = -1; x.text += `<i>Too much hugging detected, changing program.</i>`; - } - break; - case "dicks": - if (!V.seeDicks && !V.makeDicks) { - x.canSelect = -1; x.text += `<i>Too many hot dogs detected, changing program.</i>`; - } - break; - case "incest": - if (!V.seeIncest && tag === "incest") { - x.canSelect = -1; x.text += `<i>Too much familiarity detected, changing program.</i>`; - } - break; - case "loli": - if (V.minimumSlaveAge > 13 && tag === "loli") { - x.canSelect = -1; x.text += `<i>Actor not vintage enough, changing program.</i>`; - } - break; - default: - throw `Tag "${tag}" unknown for ${tags}`; - } - } - } - return x; - } - - function incrementChannel(i = V.FCTV.channel.selected) { - V.FCTV.channel.selected = i; - V.FCTV.channel[num(i, true)]++; - if (i === 2 && V.FCTV.channel[num(i, true)] >= 12) { - V.FCTV.channel[num(i, true)] = 0; - } - if ( - [14, 15].includes(i) && V.FCTV.channel[num(i, true)] === 3 - || [13, 16].includes(i) && V.FCTV.channel[num(i, true)] === 4 - || i === 12 && V.FCTV.channel[num(i, true)] === 9 - ) { - V.FCTV.channel[num(i, true)] = 1; - } - } - - function incrementShow() { - V.show = V.usedRemote ? V.show + 1 : V.show; - } - /** * checks value of selected channel in relation to an arbitrary number. Have we watched it more/less/same than i. * @param {number} i @@ -192,7 +62,11 @@ globalThis.FCTV = (function() { } return false; } - + /** + * Applies some universal changes to FCTV slaves + * @param {App.Entity.SlaveState} slave + * @returns {App.Entity.SlaveState} + */ function FinalTouches(slave) { slave.pubertyXX = 1; slave.career = "a slave"; @@ -292,7 +166,7 @@ globalThis.FctvDisplay = function({usedRemote = 0, seeAll = 0} = {}) { const buttons = []; for (const i of _possibleChannels) { - if (FCTV.showChannel(i, {usedRemote: usedRemote, seeAll: seeAll}).canSelect > 0) { + if (showChannel(i, {usedRemote: usedRemote, seeAll: seeAll}).canSelect > 0) { if (V.FCTV.channel.selected !== i) { buttons.push( App.UI.DOM.link( @@ -320,7 +194,7 @@ globalThis.FctvDisplay = function({usedRemote = 0, seeAll = 0} = {}) { } } else { buttons.push( - App.UI.DOM.disabledLink(i, [FCTV.showChannel(i).text]) + App.UI.DOM.disabledLink(i, [showChannel(i).text]) ); } } @@ -362,6 +236,60 @@ globalThis.FctvDisplay = function({usedRemote = 0, seeAll = 0} = {}) { } return p; } + + function randomShow() { + const frag = new DocumentFragment(); + if (Number.isNaN(V.FCTV.channel.selected)) { + V.FCTV.channel.selected = 1; + } + + if (!usedRemote) { + const channels = FCTV.channels(); + channels.push(3); // Double chance for slave sale + for (let i = 0; ; i++){ + const channel = _.sample(channels); + const x = showChannel(channel); + if (x.canSelect === -1) { + const p = document.createElement("p"); + $(p).append(x.text); + frag.append(p); + } else { + V.FCTV.channel.selected = channel; + break; + } + + // Three strikes, then move on + if (i > 2) { + App.UI.DOM.appendNewElement("p", frag, `It looks like there is simply nothing on FCTV tonight worth watching.`); + return frag; + } + } + } + return frag; + } + + function showChannel(i = 1, {usedRemote = 0, seeAll = 0} = {}) { + let x = { + canSelect: 1, + text: `A notification is shown: ` + }; + if (App.Data.FCTV.channels.hasOwnProperty(i)) { + if (App.Data.FCTV.channels[i].hasOwnProperty("tags")) { + x = checkTags(App.Data.FCTV.channels[i].tags); + } + if (App.Data.FCTV.channels[i].hasOwnProperty("disableSelection")) { + x.canSelect = -1; x.text += `<i>This channel appears at random times</i>`; + } + } + if (i === 11) { + if (V.purchasedSagBGone && V.FCTV.channel[num(i, true)] > 2) { + x.canSelect = -1; x.text += `<i>Product purchase detected, skipping commercials.</i>`; + } + } + + if (seeAll) { x.canSelect = 1; } + return x; + } } @@ -371,12 +299,15 @@ globalThis.FctvDisplay = function({usedRemote = 0, seeAll = 0} = {}) { const sel = V.FCTV.channel.selected; /** @type {FctvChannel} */ const channel = App.Data.FCTV.channels[sel]; - const epToShow = FCTV.getEpisode(sel); + const epToShow = getEpisode(sel); if (epToShow === -1) { frag.append(`no valid episodes`); return frag; } - FCTV.incrementChannel(sel); + + // Increment the viewing record for this channel + V.FCTV.channel[num(sel, true)]++; + let slave; if (channel.episode[epToShow].slaves) { slave = channel.episode[epToShow].slaves[0]; @@ -402,37 +333,88 @@ globalThis.FctvDisplay = function({usedRemote = 0, seeAll = 0} = {}) { } } return frag; - } - function randomShow() { - const frag = new DocumentFragment(); - if (Number.isNaN(V.FCTV.channel.selected)) { - V.FCTV.channel.selected = 1; - } - - // Random - if (!usedRemote) { - const channels = FCTV.channels(); - channels.push(3); // Double chance for slave sale - for (let i = 0; ; i++){ - const channel = _.sample(channels); - const x = FCTV.showChannel(channel); - if (x.canSelect === -1) { - const p = document.createElement("p"); - $(p).append(x.text); - frag.append(p); + function getEpisode(sel) { + let epToShow = -1; + const epsArray = []; + /** @type {FctvChannel} */ + const channel = App.Data.FCTV.channels[sel]; + const viewedCount = V.FCTV.channel[num(sel, true)] || 0; + for (let i = 0; i < App.Data.FCTV.channels[sel].episode.length; i++) { + const ep = App.Data.FCTV.channels[sel].episode[i]; + if (ep.tags) { + const x = checkTags(ep.tags); + if (x.canSelect !== -1) { + epsArray.push(i); + } } else { - V.FCTV.channel.selected = channel; - break; + epsArray.push(i); } + } + const availableEp = epsArray.length; + if (epsArray.length === 0) { + return -1; + } + + if (availableEp > viewedCount) { // If we watched ep 0 last time, our view count 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 episode 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-1); + } + if (epToShow === -1) { + return epToShow; + } + return epsArray[epToShow]; + } + } - // Three strikes, then move on - if (i > 2) { - App.UI.DOM.appendNewElement("p", frag, `It looks like there is simply nothing on FCTV tonight worth watching.`); - return frag; + function checkTags(tags){ + let x = { + canSelect: 1, + text: `A notification is shown: ` + }; + for (const tag in tags) { + if (tag) { + switch (tag) { + case "hyperPreg": + if (!V.seeHyperPreg) { + x.canSelect = -1; x.text += `<i>Too much happiness detected, changing program.</i>`; + } + break; + case "preg": + if (!V.seePreg) { + x.canSelect = -1; x.text += `<i>Too much baking detected, changing program.</i>`; + } + break; + case "extreme": + if (!V.seeExtreme) { + x.canSelect = -1; x.text += `<i>Too much hugging detected, changing program.</i>`; + } + break; + case "dicks": + if (!V.seeDicks && !V.makeDicks) { + x.canSelect = -1; x.text += `<i>Too many hot dogs detected, changing program.</i>`; + } + break; + case "incest": + if (!V.seeIncest && tag === "incest") { + x.canSelect = -1; x.text += `<i>Too much familiarity detected, changing program.</i>`; + } + break; + case "loli": + if (V.minimumSlaveAge > 13 && tag === "loli") { + x.canSelect = -1; x.text += `<i>Actor not vintage enough, changing program.</i>`; + } + break; + default: + throw `Tag "${tag}" unknown for ${tags}`; } } } - return frag; + return x; } };