From 8176c8a28b96a681f1d4b6b89ce57f48e151189d Mon Sep 17 00:00:00 2001 From: lowercasedonkey <lowercasedonkey@gmail.com> Date: Sun, 16 Aug 2020 00:47:59 -0400 Subject: [PATCH] convert removeFacilityWorkers to JS --- src/facilities/nursery/nursery.tw | 2 +- src/facilities/widgets/misc.tw | 17 --------------- src/js/assignJS.js | 31 +++++++++++++++++++++++++++ src/uncategorized/arcade.tw | 2 +- src/uncategorized/brothel.tw | 2 +- src/uncategorized/cellblock.tw | 2 +- src/uncategorized/clinic.tw | 2 +- src/uncategorized/club.tw | 2 +- src/uncategorized/dairy.tw | 2 +- src/uncategorized/masterSuite.tw | 2 +- src/uncategorized/schoolroom.tw | 2 +- src/uncategorized/servantsQuarters.tw | 2 +- src/uncategorized/spa.tw | 2 +- 13 files changed, 42 insertions(+), 28 deletions(-) delete mode 100644 src/facilities/widgets/misc.tw diff --git a/src/facilities/nursery/nursery.tw b/src/facilities/nursery/nursery.tw index ca6251730ab..55a031a0a99 100644 --- a/src/facilities/nursery/nursery.tw +++ b/src/facilities/nursery/nursery.tw @@ -129,7 +129,7 @@ <div class="choices"> <<if _NL > 0>> - <<removeFacilityWorkers "nursery" "rest" "rest">> + <<= removeFacilityWorkers("nursery", "rest", "rest")>> <</if>> </div> diff --git a/src/facilities/widgets/misc.tw b/src/facilities/widgets/misc.tw deleted file mode 100644 index a6bf858541d..00000000000 --- a/src/facilities/widgets/misc.tw +++ /dev/null @@ -1,17 +0,0 @@ -:: FacilityMiscWidgets [nobr widget] - -/* Call as removeFacilityWorkers <facilityName> <managerAssignment> <workerAssignment> */ -<<widget "removeFacilityWorkers">> - <<set _facility = App.Entity.facilities[$args[0]]>> - <<set _count = _facility.totalEmployeesCount>> - <<set _NewPop = _count+$dormitoryPopulation>> - <<if _count > 0>> - <<set _passage = passage()>> - <<link "Remove all slaves" _passage>> - <<run App.Utils.moveFacilityWorkers(_facility, $args[1], $args[2])>> - <</link>> - <<if _NewPop > $dormitory>> - @@.red;Dormitory capacity will be exceeded.@@ - <</if>> - <</if>> -<</widget>> diff --git a/src/js/assignJS.js b/src/js/assignJS.js index 16eeef67567..1feba67f71a 100644 --- a/src/js/assignJS.js +++ b/src/js/assignJS.js @@ -924,3 +924,34 @@ globalThis.assignmentTransition = function(slave, assignTo, passage) { Engine.play(passage); } }; + + +/** + * Creates a link that will remove all slaves from a facility, including manager. + * @param {string} facilityName + * @param {string} managerAssignment + * @param {string} workerAssignment + * @returns {string} + */ +globalThis.removeFacilityWorkers = function(facilityName, managerAssignment, workerAssignment) { + const facility = App.Entity.facilities[facilityName]; + const count = facility.totalEmployeesCount; + const array = []; + if (count > 0) { + array.push( + App.UI.link( + "Remove all slaves", + () => { + App.Utils.moveFacilityWorkers(facility, managerAssignment, workerAssignment); + penthouseCensus(); + }, + [], + passage(), + ) + ); + if ((count + V.dormitoryPopulation) > V.dormitory) { + array.push(`<span class="red">Dormitory capacity will be exceeded.</span>`); + } + } + return array.join(" "); +}; diff --git a/src/uncategorized/arcade.tw b/src/uncategorized/arcade.tw index 7d6d6beb788..79d106b2533 100644 --- a/src/uncategorized/arcade.tw +++ b/src/uncategorized/arcade.tw @@ -104,7 +104,7 @@ </div> <div class="choices"> <<if _AL > 0>> - <<removeFacilityWorkers "arcade" "" "work a glory hole">> + <<=removeFacilityWorkers("arcade", "", "work a glory hole")>> <</if>> </div> diff --git a/src/uncategorized/brothel.tw b/src/uncategorized/brothel.tw index 7d41fd1475a..ecc658f13b4 100644 --- a/src/uncategorized/brothel.tw +++ b/src/uncategorized/brothel.tw @@ -173,7 +173,7 @@ </div> <div class="choices"> <<if _BL > 0>> - <<removeFacilityWorkers "brothel" "rest" "whore">> + <<= removeFacilityWorkers("brothel", "rest", "whore",)>> <</if>> </div> </div> diff --git a/src/uncategorized/cellblock.tw b/src/uncategorized/cellblock.tw index 90b64622ccf..7dc373f2894 100644 --- a/src/uncategorized/cellblock.tw +++ b/src/uncategorized/cellblock.tw @@ -84,7 +84,7 @@ </p> <<if _CL > 0>> - <<removeFacilityWorkers "cellblock" "rest" "stay confined">> + <<= removeFacilityWorkers("cellblock", "rest", "stay confined")>> <</if>> <div> <<set _Tmult0 = Math.trunc($cellblock*1000*$upgradeMultiplierArcology)>> diff --git a/src/uncategorized/clinic.tw b/src/uncategorized/clinic.tw index 7e88681d257..2f179502e40 100644 --- a/src/uncategorized/clinic.tw +++ b/src/uncategorized/clinic.tw @@ -94,7 +94,7 @@ </div> <div class="choices"> <<if _CL > 0>> - <<removeFacilityWorkers "clinic" "rest" "rest">> + <<= removeFacilityWorkers("clinic", "rest", "rest")>> <</if>> </div> </div> diff --git a/src/uncategorized/club.tw b/src/uncategorized/club.tw index e486cb76f31..dad4b25d4ba 100644 --- a/src/uncategorized/club.tw +++ b/src/uncategorized/club.tw @@ -236,7 +236,7 @@ </div> <div class="choices"> <<if _CL > 0>> - <<removeFacilityWorkers "club" "rest" "serve the public">> + <<= removeFacilityWorkers("club", "rest", "serve the public")>> <</if>> </div> </div> diff --git a/src/uncategorized/dairy.tw b/src/uncategorized/dairy.tw index e3747483292..5fd03af2630 100644 --- a/src/uncategorized/dairy.tw +++ b/src/uncategorized/dairy.tw @@ -353,7 +353,7 @@ </div> <div class="choices"> <<if _DL > 0>> - <<removeFacilityWorkers "dairy" "rest" "get milked">> + <<= removeFacilityWorkers("dairy", "rest", "get milked")>> <</if>> </div> </div> diff --git a/src/uncategorized/masterSuite.tw b/src/uncategorized/masterSuite.tw index 42a8792219a..08027e52b97 100644 --- a/src/uncategorized/masterSuite.tw +++ b/src/uncategorized/masterSuite.tw @@ -329,7 +329,7 @@ $masterSuiteNameCaps is furnished </div> <<if _MsL > 0>> - <<removeFacilityWorkers "masterSuite" "rest" "please you">> + <<= removeFacilityWorkers("masterSuite", "rest", "please you")>> <</if>> <<if $seePreg != 0>> diff --git a/src/uncategorized/schoolroom.tw b/src/uncategorized/schoolroom.tw index 4e0ea70ca30..c70cb29d377 100644 --- a/src/uncategorized/schoolroom.tw +++ b/src/uncategorized/schoolroom.tw @@ -94,7 +94,7 @@ </div> <div class="choices"> <<if _DL > 0>> - <<removeFacilityWorkers "schoolroom" "rest" "take classes">> + <<= removeFacilityWorkers("schoolroom", "rest", "take classes")>> <</if>> </div> diff --git a/src/uncategorized/servantsQuarters.tw b/src/uncategorized/servantsQuarters.tw index ffd1cec37fd..bd67b81a594 100644 --- a/src/uncategorized/servantsQuarters.tw +++ b/src/uncategorized/servantsQuarters.tw @@ -96,7 +96,7 @@ <div class="choices"> <<if _DL > 0>> - <<removeFacilityWorkers "servantsQuarters" "rest" "be a servant">> + <<= removeFacilityWorkers("servantsQuarters", "rest", "be a servant")>> <</if>> </div> </div> diff --git a/src/uncategorized/spa.tw b/src/uncategorized/spa.tw index a3ef5999615..5e5554c39e2 100644 --- a/src/uncategorized/spa.tw +++ b/src/uncategorized/spa.tw @@ -103,7 +103,7 @@ </div> <div class="choices"> <<if _DL > 0>> - <<removeFacilityWorkers "spa" "rest" "rest">> + <<= removeFacilityWorkers("spa", "rest", "rest")>> <</if>> </div> </div> -- GitLab