diff --git a/devTools/types/FC/facilities.d.ts b/devTools/types/FC/facilities.d.ts index e57b89ab2507819f65e64ebf3eb8d5a995459aee..d506384103756c3cad822b247186462f4e2a3beb 100644 --- a/devTools/types/FC/facilities.d.ts +++ b/devTools/types/FC/facilities.d.ts @@ -59,18 +59,11 @@ declare namespace FC { /** The value to set `property` to when the rule is active. */ value: any; /** Any handler to run upon setting the value. */ - handler?: () => void; + handler?: (value: any) => void; /** Any additional information to display with on the link. */ note?: string; /** Any prerequisites that must be met for the option to be displayed. */ - prereqs?: Array<() => boolean> - /** Any dialog to display upon setting the value. */ - dialog?: { - /** The content displayed in the dialog. */ - content: string|HTMLElement|DocumentFragment; - /** The name of the dialog to display. */ - name?: string; - }; + prereqs?: Array<() => boolean>; }> /** Any additional nodes to attach. */ nodes?: Array<string|HTMLElement|DocumentFragment> diff --git a/src/004-base/facilityFramework.js b/src/004-base/facilityFramework.js index fe284b112f2983ac526ea1ad1fc87256cb9ca461..e8351ab0f33a849c499d0c015a27f2c2bf1d2ec3 100644 --- a/src/004-base/facilityFramework.js +++ b/src/004-base/facilityFramework.js @@ -242,32 +242,9 @@ App.Facilities.Facility = class Facility { rule.options.forEach(o => { if (!o.prereqs || o.prereqs.every(prereq => prereq())) { option.addValue(o.link, o.value); - - const dialogHandler = o.dialog ? function() { - const dialogContent = o.dialog.content; - if (dialogContent) { - if (Dialog.isOpen()) { - Dialog.close(); - } - if (o.dialog.name) { - Dialog.setup(o.dialog.name); - } - $(Dialog.body()).empty().append(dialogContent); - Dialog.open(); - } - } : null; - - if (dialogHandler && o.handler) { - option.addCallback(() => { - o.handler(); - dialogHandler(); - }); - } else if (o.handler) { + if (o.handler) { option.addCallback(o.handler); - } else if (dialogHandler) { - option.addCallback(dialogHandler); } - if (o.note) { option.addComment(o.note); } diff --git a/src/facilities/dairy/dairy.js b/src/facilities/dairy/dairy.js index 2b809810a593fc85569dd9075a814e2b1d3550fb..2af98a5ef7fce71f47d29a205020aa2984b0da72 100644 --- a/src/facilities/dairy/dairy.js +++ b/src/facilities/dairy/dairy.js @@ -378,7 +378,6 @@ App.Facilities.Dairy.dairy = class Dairy extends App.Facilities.Facility { /** @returns {FC.Facilities.Rule[]} */ get rules() { - const effectFunc = (arg) => this._getEffect(arg); // bind to this return [ { property: "dairyFeedersSetting", @@ -390,25 +389,19 @@ App.Facilities.Dairy.dairy = class Dairy extends App.Facilities.Facility { get text() { return `The feeders have been disabled.`; }, link: `Deactivate`, value: 0, - dialog: { - get content() { return effectFunc('feeders'); }, - }, + handler: App.UI.DialogHandler(this._getEffect.bind(this, "feeders")), }, { get text() { return `The feeders are active.`; }, link: `Moderate`, value: 1, - dialog: { - get content() { return effectFunc('feeders'); }, - }, + handler: App.UI.DialogHandler(this._getEffect.bind(this, "feeders")), }, { get text() { return `The feeders are industrial.`; }, link: `Industrial`, value: 2, - dialog: { - get content() { return effectFunc('feeders'); }, - }, + handler: App.UI.DialogHandler(this._getEffect.bind(this, "feeders")), prereqs: [ () => V.dairyRestraintsSetting > 1, ], @@ -425,25 +418,19 @@ App.Facilities.Dairy.dairy = class Dairy extends App.Facilities.Facility { get text() { return `Fertile cows' wombs are not for hire.`; }, link: `Not for hire`, value: 0, - dialog: { - get content() { return effectFunc('preg'); }, - }, + handler: App.UI.DialogHandler(this._getEffect.bind(this, "preg")), }, { get text() { return `Fertile cows' wombs are for hire.`; }, link: `Moderate`, value: 1, - dialog: { - get content() { return effectFunc('preg'); }, - }, + handler: App.UI.DialogHandler(this._getEffect.bind(this, "preg")), }, { get text() { return `Fertile cows' wombs are industrially employed.`; }, link: `Industrial`, value: 2, - dialog: { - get content() { return effectFunc('preg'); }, - }, + handler: App.UI.DialogHandler(this._getEffect.bind(this, "preg")), prereqs: [ () => V.dairyRestraintsSetting > 1, ], @@ -452,9 +439,7 @@ App.Facilities.Dairy.dairy = class Dairy extends App.Facilities.Facility { get text() { return `Fertile cows' wombs are worked to capacity.`; }, link: `Mass production`, value: 3, - dialog: { - get content() { return effectFunc('preg'); }, - }, + handler: App.UI.DialogHandler(this._getEffect.bind(this, "preg")), prereqs: [ () => V.seeExtreme > 0, () => V.seeHyperPreg > 0, @@ -474,25 +459,19 @@ App.Facilities.Dairy.dairy = class Dairy extends App.Facilities.Facility { get text() { return `The sodomizers are inactive.`; }, link: `Deactivate`, value: 0, - dialog: { - get content() { return effectFunc('stimulators'); }, - }, + handler: App.UI.DialogHandler(this._getEffect.bind(this, "stimulators")), }, { get text() { return `The sodomizers are active.`; }, link: `Moderate`, value: 1, - dialog: { - get content() { return effectFunc('stimulators'); }, - }, + handler: App.UI.DialogHandler(this._getEffect.bind(this, "stimulators")), }, { get text() { return `The sodomizers are industrial, employing dildos the size of horse phalli.`; }, link: `Industrial`, value: 2, - dialog: { - get content() { return effectFunc('stimulators'); }, - }, + handler: App.UI.DialogHandler(this._getEffect.bind(this, "stimulators")), prereqs: [ () => !!V.seeExtreme, () => V.dairyRestraintsSetting > 1, @@ -510,25 +489,19 @@ App.Facilities.Dairy.dairy = class Dairy extends App.Facilities.Facility { get text() { return `The cows are restrained only when necessary, allowing obedient cows freedom to range around.`; }, link: `Deactivate`, value: 0, - dialog: { - get content() { return effectFunc('restraints'); }, - }, + handler: App.UI.DialogHandler(this._getEffect.bind(this, "restraints")), }, { get text() { return `The cows are restrained when being milked, giving the machines full play.`; }, link: `Free range`, value: 1, - dialog: { - get content() { return effectFunc('restraints'); }, - }, + handler: App.UI.DialogHandler(this._getEffect.bind(this, "restraints")), }, { get text() { return `The cows are restrained permanently, allowing use of industrial techniques even devoted cows would flinch at.`; }, link: `Permanent machine milking`, value: 2, - dialog: { - get content() { return effectFunc('restraints'); }, - }, + handler: App.UI.DialogHandler(this._getEffect.bind(this, "restraints")), }, ], }, diff --git a/src/gui/options/optionsGroup.js b/src/gui/options/optionsGroup.js index b7403c7b291452cc87043757b2b1925de9405f4b..d51a9902e19397a6605f46e1d3a14c040bc32ce9 100644 --- a/src/gui/options/optionsGroup.js +++ b/src/gui/options/optionsGroup.js @@ -561,3 +561,25 @@ App.UI.OptionsGroup = (function() { } }; })(); + +/** A wrapper for option handlers that shows a dialog with the results of setting the option. + * @template T + * @param {function(T): string|HTMLElement|DocumentFragment} contentGenerator + * @param {string} [caption] + * @returns {function(T): void} + */ +App.UI.DialogHandler = function(contentGenerator, caption) { + return (arg) => { + const dialogContent = contentGenerator(arg); + if (dialogContent) { + if (Dialog.isOpen()) { + Dialog.close(); + } + if (caption) { + Dialog.setup(caption); + } + $(Dialog.body()).empty().append(dialogContent); + Dialog.open(); + } + }; +};