From cc1a7480732ecc105289304f7100f652293a8c3d Mon Sep 17 00:00:00 2001 From: HPotato <12221-hpotato@users.noreply.gitgud.io> Date: Sat, 9 Jan 2021 13:57:01 +1030 Subject: [PATCH] Remove 'Expr' vars and change ExpressiveNumericTargetEditor to use normal vars Implements changes suggested in https://gitgud.io/pregmodfan/fc-pregmod/-/merge_requests/8659#note_142842 and https://gitgud.io/pregmodfan/fc-pregmod/-/merge_requests/8659#note_142794 --- devTools/types/FC/RA.d.ts | 17 ++++++----------- src/js/DefaultRules.js | 32 ++++++++++++++++---------------- src/js/rulesAssistant.js | 5 ----- src/js/rulesAssistantOptions.js | 26 ++++++++++++++------------ 4 files changed, 36 insertions(+), 44 deletions(-) diff --git a/devTools/types/FC/RA.d.ts b/devTools/types/FC/RA.d.ts index 20fc78e3fe6..81b8fa47300 100644 --- a/devTools/types/FC/RA.d.ts +++ b/devTools/types/FC/RA.d.ts @@ -7,7 +7,7 @@ declare namespace FC { interface ExpressiveNumericTarget { cond: string; - val: string; + val: string | number; } interface NumericRange { @@ -52,16 +52,11 @@ declare namespace FC { } interface RuleGrowthSetters { - boobs: NumericTarget; - butt: NumericTarget; - lips: NumericTarget; - dick: NumericTarget; - balls: NumericTarget; - boobsExpr: ExpressiveNumericTarget; - buttExpr: ExpressiveNumericTarget; - lipsExpr: ExpressiveNumericTarget; - dickExpr: ExpressiveNumericTarget; - ballsExpr: ExpressiveNumericTarget; + boobs: ExpressiveNumericTarget; + butt: ExpressiveNumericTarget; + lips: ExpressiveNumericTarget; + dick: ExpressiveNumericTarget; + balls: ExpressiveNumericTarget; intensity: number; } diff --git a/src/js/DefaultRules.js b/src/js/DefaultRules.js index 152813e6a52..1a73892e9c7 100644 --- a/src/js/DefaultRules.js +++ b/src/js/DefaultRules.js @@ -1173,8 +1173,15 @@ globalThis.DefaultRules = (function() { r += `<br>${slave.slaveName} is on ${slave.drugs} and will not be considered for drug enhancement until that regime is complete.`; ProcessOtherDrugs(slave, rule); return; - } else if (rule.growth.boobs === null && rule.growth.butt === null && rule.growth.lips === null && rule.growth.dick === null && rule.growth.balls === null && - rule.growth.boobsExpr === null && rule.growth.buttExpr === null && rule.growth.lipsExpr === null && rule.growth.dickExpr === null && rule.growth.ballsExpr === null) { + } else if ( + [ + rule.growth.boobs, + rule.growth.butt, + rule.growth.lips, + rule.growth.dick, + rule.growth.balls + ].every(r => r === null) ) // Check if all objects in list equal null + { ProcessOtherDrugs(slave, rule); return; } @@ -1265,7 +1272,7 @@ globalThis.DefaultRules = (function() { /** * @param {App.Entity.SlaveState} slave * @param {DrugTarget} asset - * @param {FC.RA.NumericTarget} target + * @param {FC.RA.NumericTarget | FC.RA.ExpressiveNumericTarget} target * @param {{drug: FC.Drug, weight: number}[]} priorities * @param {number} step */ @@ -1277,6 +1284,7 @@ globalThis.DefaultRules = (function() { if (V.experimental.raGrowthExpr === 1 && typeof target.val === 'string') { const interpreter = new Function("slave", "return (" + target.val + ");"); target.val = runWithReadonlyProxy(() => interpreter(createReadonlyProxy(slave))); + console.log(asset + " expression for \'" + slave.slaveName + "\' resolves to " + target.val.toString()); } const flesh = fleshFunc[asset](slave); @@ -1295,19 +1303,11 @@ globalThis.DefaultRules = (function() { /** @type {{drug: FC.Drug, weight: number}[]} */ let _priorities = []; - if (V.experimental.raGrowthExpr !== 1) { - drugs(slave, "boobs", rule.growth.boobs, _priorities, 200); - drugs(slave, "butt", rule.growth.butt, _priorities, 1); - drugs(slave, "lips", rule.growth.lips, _priorities, 1); - drugs(slave, "dick", rule.growth.dick, _priorities, 1); - drugs(slave, "balls", rule.growth.balls, _priorities, 1); - } else { - drugs(slave, "boobs", rule.growth.boobsExpr, _priorities, 200); - drugs(slave, "butt", rule.growth.buttExpr, _priorities, 1); - drugs(slave, "lips", rule.growth.lipsExpr, _priorities, 1); - drugs(slave, "dick", rule.growth.dickExpr, _priorities, 1); - drugs(slave, "balls", rule.growth.ballsExpr, _priorities, 1); - } + drugs(slave, "boobs", rule.growth.boobs, _priorities, 200); + drugs(slave, "butt", rule.growth.butt, _priorities, 1); + drugs(slave, "lips", rule.growth.lips, _priorities, 1); + drugs(slave, "dick", rule.growth.dick, _priorities, 1); + drugs(slave, "balls", rule.growth.balls, _priorities, 1); if (_priorities.length > 0) { const action = _priorities.reduce((acc, cur) => (acc.weight > cur.weight) ? acc : cur); diff --git a/src/js/rulesAssistant.js b/src/js/rulesAssistant.js index fd4a9aea6bc..52199fd9c05 100644 --- a/src/js/rulesAssistant.js +++ b/src/js/rulesAssistant.js @@ -356,11 +356,6 @@ App.RA.newRule = function() { lips: null, dick: null, balls: null, - boobsExpr: null, - buttExpr: null, - lipsExpr: null, - dickExpr: null, - ballsExpr: null, intensity: 0 }; } diff --git a/src/js/rulesAssistantOptions.js b/src/js/rulesAssistantOptions.js index 755df92b92a..b7ea7a12dfe 100644 --- a/src/js/rulesAssistantOptions.js +++ b/src/js/rulesAssistantOptions.js @@ -887,7 +887,7 @@ App.RA.options = (function() { } } - // Basically just a copy of NumericTargetEditor modified to use strings instead of numbers + // Basically just a copy of NumericTargetEditor modified to handle strings as well class ExpressiveNumericTargetEditor extends EditorWithShortcuts { /** * @param {string} prefix @@ -948,7 +948,9 @@ App.RA.options = (function() { } getTextData() { - return this.numEditor.value === null || this.numEditor.value === "" ? null : { cond: this.opSelector.value, val: this.numEditor.value }; + const n = Number(this.numEditor.value); // Attempt to convert numEditor.value to number, + const v = isNaN(n) ? this.numEditor.value : Math.floor(n); // return value as number if success (should result in realData being of number) + return v === null || v === "" ? null : { cond: this.opSelector.value, val: v }; } } @@ -2298,8 +2300,8 @@ App.RA.options = (function() { ["none", 0] ]; super("Breasts", pairs, true, 0, 48000, true); - this.setValue(current_rule.set.growth.boobsExpr); - this.onchange = (value) => current_rule.set.growth.boobsExpr = value; + this.setValue(current_rule.set.growth.boobs); + this.onchange = (value) => current_rule.set.growth.boobs = value; } } @@ -2313,8 +2315,8 @@ App.RA.options = (function() { ["none", 0] ]; super("Butts", pairs, true, 0, 20, true); - this.setValue(current_rule.set.growth.buttExpr); - this.onchange = (value) => current_rule.set.growth.buttExpr = value; + this.setValue(current_rule.set.growth.butt); + this.onchange = (value) => current_rule.set.growth.butt = value; } } @@ -2327,8 +2329,8 @@ App.RA.options = (function() { ["none", 0] ]; super("Lips", pairs, true, 0, 100, true); - this.setValue(current_rule.set.growth.lipsExpr); - this.onchange = (value) => current_rule.set.growth.lipsExpr = value; + this.setValue(current_rule.set.growth.lips); + this.onchange = (value) => current_rule.set.growth.lips = value; } } @@ -2341,8 +2343,8 @@ App.RA.options = (function() { ["none", 0] ]; super("Dicks, if present", pairs, true, 0, 30, true); - this.setValue(current_rule.set.growth.dickExpr); - this.onchange = (value) => current_rule.set.growth.dickExpr = value; + this.setValue(current_rule.set.growth.dick); + this.onchange = (value) => current_rule.set.growth.dick = value; } } @@ -2355,8 +2357,8 @@ App.RA.options = (function() { ["none", 0] ]; super("Balls, if present", pairs, true, 0, 125, true); - this.setValue(current_rule.set.growth.ballsExpr); - this.onchange = (value) => current_rule.set.growth.ballsExpr = value; + this.setValue(current_rule.set.growth.balls); + this.onchange = (value) => current_rule.set.growth.balls = value; } } -- GitLab