From d40981586cfd1e7f907865cc208c39febbf15eaa Mon Sep 17 00:00:00 2001 From: Arkerthan <arkerthan@gmail.com> Date: Sun, 15 Dec 2019 20:06:09 +0100 Subject: [PATCH] named parameters --- src/004-base/organFarmBase.js | 4 +- src/js/organFarm.js | 72 +++++++++++++++++++++-------------- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/004-base/organFarmBase.js b/src/004-base/organFarmBase.js index eee443c3636..852f65358e7 100644 --- a/src/004-base/organFarmBase.js +++ b/src/004-base/organFarmBase.js @@ -28,7 +28,7 @@ App.Medicine.Organ = class { * @param {string[]} dependencies * @param {App.Data.OrganImplantAction[]} actions */ - constructor(id, name, tooltip, cost, time, canGrow, dependencies, actions) { + constructor({id, name, tooltip, cost, time, canGrow = () => true, dependencies = [], actions= []} = {}) { this.id = id; this.name = name; this.tooltip = tooltip; @@ -68,7 +68,7 @@ App.Medicine.OrganImplantAction = class { * @param {function(App.Entity.SlaveState):string} implantError * @param {function(App.Entity.SlaveState)} implant */ - constructor(name, tooltip, healthImpact, surgeryType, autoImplant, canImplant, implantError, implant) { + constructor({name, tooltip = "", healthImpact, surgeryType, autoImplant = true, canImplant, implantError, implant} = {}) { this.name = name; this.tooltip = tooltip; this.healthImpact = healthImpact; diff --git a/src/js/organFarm.js b/src/js/organFarm.js index 6d6e9e5237d..deb96513f81 100644 --- a/src/js/organFarm.js +++ b/src/js/organFarm.js @@ -1,33 +1,40 @@ App.Medicine.initOrganFarm = function initOrganFarm() { - new App.Medicine.Organ("penis", "Penis", "will add a prostate if one is not already present", - 5000, 5, () => (V.seeDicks !== 0 || V.makeDicks === 1), [], - [ - new App.Medicine.OrganImplantAction("Implant", "", 20, "addDick", true, - slave => (slave.dick <= 0), - () => "this slave already has a penis", - slave => { + new App.Medicine.Organ({ + id: "penis", name: "Penis", tooltip: "will add a prostate if one is not already present", cost: 5000, time: 5, + canGrow: () => (V.seeDicks !== 0 || V.makeDicks === 1), + actions: [ + new App.Medicine.OrganImplantAction({ + name: "Implant", healthImpact: 20, surgeryType: "addDick", + canImplant: slave => (slave.dick <= 0), + implantError: () => "this slave already has a penis", + implant: slave => { if (slave.prostate === 0) { slave.prostate = 1; } slave.dick = 2; slave.clit = 0; slave.foreskin = slave.dick; - }) - ]); + } + }) + ] + }); - new App.Medicine.Organ("testicles", "Testicles", "will add a prostate if one is not already present; requires a penis for successful implantation", - 5000, 10, () => (V.seeDicks !== 0 || V.makeDicks === 1), ["penis"], - [ - new App.Medicine.OrganImplantAction("Implant", "", 20, "addBalls", true, - slave => (slave.balls <= 0 && slave.dick > 0), - slave => { + new App.Medicine.Organ({ + id: "testicles", name: "Testicles", + tooltip: "will add a prostate if one is not already present; requires a penis for successful implantation", + cost: 5000, time: 10, canGrow: () => (V.seeDicks !== 0 || V.makeDicks === 1), dependencies: ["penis"], + actions: [ + new App.Medicine.OrganImplantAction({ + name: "Implant", healthImpact: 20, surgeryType: "addBalls", + canImplant: slave => (slave.balls <= 0 && slave.dick > 0), + implantError: slave => { if (slave.dick === 0) { return "This slave lacks the penis necessary to accept testicles."; } else { return "This slave already has testicles."; } }, - slave => { + implant: slave => { if (slave.prostate === 0) { slave.prostate = 1; } @@ -45,11 +52,15 @@ App.Medicine.initOrganFarm = function initOrganFarm() { } } } - }), - new App.Medicine.OrganImplantAction("Implant", "You can forgo standard procedure and implant testicles directly into $his abdomen.", 20, "addTesticles", false, - slave => (slave.dick === 0 && slave.balls <= 0 && slave.ballType !== "human"), - slave => ((slave.balls > 0) ? `This slave already has ${slave.ballType} testicles.` : ""), - slave => { + } + }), + new App.Medicine.OrganImplantAction({ + name: "Implant", + tooltip: "You can forgo standard procedure and implant testicles directly into $his abdomen.", + healthImpact: 20, surgeryType: "addTesticles", autoImplant: false, + canImplant: slave => (slave.dick === 0 && slave.balls <= 0 && slave.ballType !== "human"), + implantError: slave => ((slave.balls > 0) ? `This slave already has ${slave.ballType} testicles.` : ""), + implant: slave => { if (slave.prostate === 0) { slave.prostate = 1; } @@ -66,11 +77,14 @@ App.Medicine.initOrganFarm = function initOrganFarm() { } } } - }), - new App.Medicine.OrganImplantAction("Replace", "You can replace the existing testicles with a new pair.", 20, "addTesticles", false, - slave => (slave.balls > 0 && slave.ballType !== "human"), - slave => (slave.balls > 0 ? "This slave already has human testicles." : ""), - slave => { + } + }), + new App.Medicine.OrganImplantAction({ + name: "Replace", tooltip: "You can replace the existing testicles with a new pair.", healthImpact: 20, + surgeryType: "addTesticles", autoImplant: false, + canImplant: slave => (slave.balls > 0 && slave.ballType !== "human"), + implantError: slave => (slave.balls > 0 ? "This slave already has human testicles." : ""), + implant: slave => { slave.balls = 2; slave.ballType = "human"; if (slave.pubertyAgeXY === 0) { @@ -84,6 +98,8 @@ App.Medicine.initOrganFarm = function initOrganFarm() { } } } - }) - ]); + } + }) + ] + }); }; -- GitLab