diff --git a/src/facilities/farmyard/farmyard.js b/src/facilities/farmyard/farmyard.js index e0fc533929cc24caebe804cf5ed2b41ffff64736..872dc00a9adfa43c425877f52d09e613ce87d91d 100644 --- a/src/facilities/farmyard/farmyard.js +++ b/src/facilities/farmyard/farmyard.js @@ -393,118 +393,105 @@ App.Facilities.Farmyard.farmyard = function() { if (App.Entity.facilities.farmyard.employeesIDs().size > 0) { // TODO: redo this with V.farmyardShowgirls if (V.farmyardShows && (V.canines || V.hooved || V.felines)) { - const - desc = document.createElement("div"), - option = document.createElement("span"), - bold = App.UI.DOM.makeElement("span", '', "bold"); - - bold.append(`are`); - desc.append(`Slaves `, bold, ` putting on shows with animals. `); - - option.append(App.UI.DOM.passageLink("End shows", "Farmyard", () => { - V.farmyardShows = 0; - V.farmyardBreeding = 0; - V.farmyardRestraints = 0; - })); + const rule = makeRule( + ['Slaves', 'are putting on shows with animals'], + 'are', + "End shows", + [], + ["farmyardShows", "farmyardBreeding", "farmyardRestraints"] + ); - desc.append(option); - frag.append(desc); + frag.append(rule); if (V.seeBestiality) { if (V.farmyardBreeding) { - const - desc = document.createElement("div"), - option = document.createElement("span"), - bold = App.UI.DOM.makeElement("span", '', "bold"); - - bold.append(`are`); - desc.append(`Slaves `, bold, ` being bred with animals. `); - - option.append(App.UI.DOM.passageLink("End breeding", "Farmyard", () => { - V.farmyardShows = 1; - V.farmyardBreeding = 0; - V.farmyardRestraints = 0; - })); + const rule = makeRule( + ['Slaves', 'are being bred with animals'], + 'are', + "End breeding", + ["farmyardShows"], + [ "farmyardBreeding", "farmyardRestraints"] + ); - desc.append(option); - frag.append(desc); + frag.append(rule); if (V.farmyardRestraints) { - const - desc = document.createElement("div"), - option = document.createElement("span"), - bold = App.UI.DOM.makeElement("span", '', "bold"); - - bold.append(`All of the slaves`); - desc.append(` are being restrained. `); - - desc.prepend(bold); - - option.append(App.UI.DOM.passageLink("Restrain only disobedient slaves", "Farmyard", () => { - V.farmyardShows = 1; - V.farmyardBreeding = 1; - V.farmyardRestraints = 0; - })); + const rule = makeRule( + 'are being restrained', + 'All of the slaves', + "Restrain only disobedient slaves", + ["farmyardShows", "farmyardBreeding"], + ["farmyardRestraints"] + ); - desc.append(option); - frag.append(desc); + frag.append(rule); } else { - const - desc = document.createElement("div"), - option = document.createElement("span"), - bold = App.UI.DOM.makeElement("span", '', "bold"); - - bold.append(`Only disobedient slaves`); - desc.append(` are being restrained. `); - - desc.prepend(bold); - - option.append(App.UI.DOM.passageLink("Restrain all slaves", "Farmyard", () => { - V.farmyardShows = 1; - V.farmyardBreeding = 1; - V.farmyardRestraints = 1; - })); + const rule = makeRule( + 'are being restrained', + 'Only disobedient slaves', + "Restrain all slaves", + ["farmyardShows", "farmyardBreeding", "farmyardRestraints"], + [] + ); - desc.append(option); - frag.append(desc); + frag.append(rule); } } else { - const - desc = document.createElement("div"), - option = document.createElement("span"), - bold = App.UI.DOM.makeElement("span", '', "bold"); - - bold.append(`are not`); - desc.append(`Slaves `, bold, ` being bred with animals. `); - - option.append(App.UI.DOM.passageLink("Begin breeding", "Farmyard", () => { - V.farmyardShows = 1; - V.farmyardBreeding = 1; - V.farmyardRestraints = 0; - })); + const rule = makeRule( + ['Slaves', 'being bred with animals'], + 'are not', + "Begin breeding", + ["farmyardShows", "farmyardBreeding"], + ["farmyardRestraints"] + ); - desc.append(option); - frag.append(desc); + frag.append(rule); } } } else { - const - desc = document.createElement("div"), - option = document.createElement("span"), - bold = App.UI.DOM.makeElement("span", '', "bold"); + const rule = makeRule( + ['Slaves', 'putting on shows with animals'], + 'are not', + "Begin shows", + ["farmyardShows"], + ["farmyardBreeding", "farmyardRestraints"] + ); - bold.append(`are not`); - desc.append(`Slaves `, bold, ` putting on shows with animals. `); + frag.append(rule); + } + } - option.append(App.UI.DOM.passageLink("Begin shows", "Farmyard", () => { - V.farmyardShows = 1; - V.farmyardBreeding = 0; - V.farmyardRestraints = 0; - })); + /** + * Creates a new rule button + * @param {string|[string]} descText The base description for the rule + * @param {string} boldText The part in bold + * @param {string} linkText The link text + * @param {[string]} enabled Variables to be set to 1 + * @param {[string]} disabled Variables to be set to 0 + */ + function makeRule(descText, boldText, linkText, enabled, disabled) { + const + frag = new DocumentFragment(), - desc.append(option); - frag.append(desc); + desc = document.createElement("div"), + bold = App.UI.DOM.makeElement("span", boldText, "bold"), + link = document.createElement("span"); + + if (Array.isArray(descText)) { + desc.append(`${descText[0]} `, bold, ` ${descText[1]}. `); + } else { + desc.append(bold, ` ${descText}. `); } + + link.append(App.UI.DOM.passageLink(linkText, "Farmyard", () => { + enabled.forEach(i => V[i] = 1); + disabled.forEach(i => V[i] = 0); + })); + + desc.append(link); + frag.append(desc); + + return frag; } return frag;