From 7fdfa5427294cd4ceddb2dbc84a7a75d88f4d99e Mon Sep 17 00:00:00 2001
From: Arkerthan <arkerthan@gmail.com>
Date: Tue, 28 Jan 2020 23:32:33 +0100
Subject: [PATCH] improve replace in limb amputation

---
 src/npc/descriptions/limbs.js | 39 ++++++++++++++++-------------------
 1 file changed, 18 insertions(+), 21 deletions(-)

diff --git a/src/npc/descriptions/limbs.js b/src/npc/descriptions/limbs.js
index 36cc562fe11..c54e253ae1c 100644
--- a/src/npc/descriptions/limbs.js
+++ b/src/npc/descriptions/limbs.js
@@ -47,37 +47,36 @@ App.Desc.limbChange = function() {
 	 */
 	function amputate(slave, oldLimbs, returnTo) {
 		const {his} = getPronouns(slave);
+
+		/**
+		 * @param {number} id
+		 */
+		function install(id) {
+			slave.PLimb = id;
+			surgeryDamage(slave, 10);
+			App.UI.replace("#amputate", App.Desc.limbChange().prosthetic(slave, oldLimbs, returnTo));
+		}
+
+		function noInstall() {
+			App.UI.replace("#amputate", App.Desc.limbChange().reaction(slave, oldLimbs, returnTo));
+		}
+
 		let implant = false;
 		let r = "";
 
 		if (slave.PLimb < 1 && isProstheticAvailable(slave, "interfaceP1")) {
 			implant = true;
-			r += `<<link "Install basic interface">>` +
-				`<<set $activeSlave.PLimb = 1>>
-				<<run surgeryDamage($activeSlave, 10)>>` +
-				`<<replace "#amputate">><<= App.Desc.limbChange().prosthetic($activeSlave, ${JSON.stringify(oldLimbs)}, "${returnTo}")>><</replace>>` +
-				`<</link>>`;
+			r += `<div>${App.UI.link("Install basic interface", install, [1])}</div>`;
 		}
 		if (slave.PLimb < 2 && isProstheticAvailable(slave, "interfaceP2")) {
-			if (implant) {
-				r += "<br>";
-			}
 			implant = true;
-			r += `<<link "Install advanced interface">>` +
-				`<<set $activeSlave.PLimb = 2>>
-				<<run surgeryDamage($activeSlave, 10)>>` +
-				`<<replace "#amputate">><<= App.Desc.limbChange().prosthetic($activeSlave, ${JSON.stringify(oldLimbs)}, "${returnTo}")>><</replace>>` +
-				`<</link>>`;
+			r += `<div>${App.UI.link("Install advanced interface", install, [2])}</div>`;
 		}
 
 		if (implant) {
 			return "<span id='amputate'>" +
 				`<div>Since you already have a prosthetic interface prepared for this slave, you can install it during the operation. The procedure will put additional strain on ${his} health but less so than if you were to perform the procedures separately.</div>` +
-				`${r}
-				<<link "Do not install">>
-				<<replace "#amputate">><<= App.Desc.limbChange().reaction($activeSlave, ${JSON.stringify(oldLimbs)}, "${returnTo}")>><</replace>>
-				<</link>>
-				</span>`;
+				`${r}<div>${App.UI.link("Do not install", noInstall())}</div></span>`;
 		}
 
 		if (slave.PLimb > 0) {
@@ -180,9 +179,7 @@ App.Desc.limbChange = function() {
 			}
 		}
 
-		r = `<<set _newState = [${state}]>><div class='limb-selector'>${r}</div>${apply()}`;
-
-		return r;
+		return `<<set _newState = [${state}]>><div class='limb-selector'>${r}</div>${apply()}`;
 
 		function apply() {
 			let s;
-- 
GitLab