From 4fa9e0d1cbf4789f1e5764ce46e177fb917af29e Mon Sep 17 00:00:00 2001
From: Arkerthan <arkerthan@mailbox.org>
Date: Wed, 22 Feb 2023 16:49:59 +0100
Subject: [PATCH] Allow setting a custom slave title

---
 src/002-config/fc-version.js                  |  2 +-
 .../backwardsCompatibility/datatypeCleanup.js |  4 ++++
 src/interaction/siCustom.js                   | 21 +++++++++++++++++++
 src/js/SlaveState.js                          |  2 ++
 src/js/utilsSlave.js                          |  3 +++
 5 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/002-config/fc-version.js b/src/002-config/fc-version.js
index 5e322c743b7..86917d4b348 100644
--- a/src/002-config/fc-version.js
+++ b/src/002-config/fc-version.js
@@ -2,5 +2,5 @@ App.Version = {
 	base: "0.10.7.1", // The vanilla version the mod is based off of, this should never be changed.
 	pmod: "4.0.0-alpha.23",
 	commitHash: null,
-	release: 1186, // When getting close to 2000, please remove the check located within the onLoad() function defined at line five of src/js/eventHandlers.js.
+	release: 1187, // When getting close to 2000, please remove the check located within the onLoad() function defined at line five of src/js/eventHandlers.js.
 };
diff --git a/src/data/backwardsCompatibility/datatypeCleanup.js b/src/data/backwardsCompatibility/datatypeCleanup.js
index eb155928a0f..6c457b108f7 100644
--- a/src/data/backwardsCompatibility/datatypeCleanup.js
+++ b/src/data/backwardsCompatibility/datatypeCleanup.js
@@ -249,6 +249,10 @@ App.Entity.Utils.SlaveDataSchemeCleanup = (function() {
 				hairVector: "customHairVector"
 			});
 		}
+
+		if (!slave.custom.hasOwnProperty("name")) {
+			slave.custom.name = "";
+		}
 	}
 
 	/**
diff --git a/src/interaction/siCustom.js b/src/interaction/siCustom.js
index e8e6312e3a8..71418245b01 100644
--- a/src/interaction/siCustom.js
+++ b/src/interaction/siCustom.js
@@ -33,6 +33,7 @@ App.UI.SlaveInteract.custom = function(slave, refresh) {
 		customTattoo(),
 		customOriginStory(),
 		customDescription(),
+		customSlaveTitle(),
 		customLabel()
 	);
 
@@ -635,6 +636,26 @@ App.UI.SlaveInteract.custom = function(slave, refresh) {
 		return el;
 	}
 
+	function customSlaveTitle() {
+		let el = document.createElement('p');
+		el.append(`Change ${his} custom slave title: `);
+		el.appendChild(
+			App.UI.DOM.makeTextBox(slave.custom.name,
+				v => {
+					slave.custom.name = v;
+					refresh();
+				}
+			)
+		);
+
+		let choices = document.createElement('div');
+		choices.className = "choices";
+		choices.appendChild(App.UI.DOM.makeElement('span', ` For best results, should fit into a sentence like: '${SlaveFullName(slave)} is a "slave title"'`, 'note'));
+		el.appendChild(choices);
+
+		return el;
+	}
+
 	function customLabel() {
 		let el = document.createElement('p');
 		el.append(`Change ${his} custom label: `);
diff --git a/src/js/SlaveState.js b/src/js/SlaveState.js
index 4954d4c97a5..5224aead3fb 100644
--- a/src/js/SlaveState.js
+++ b/src/js/SlaveState.js
@@ -358,6 +358,8 @@ App.Entity.SlaveCustomAddonsState = class SlaveCustomAddonsState {
 		this.desc = "";
 		/** What the slave refers to you as. */
 		this.title = "";
+		/** Replaces SlaveTitle() if set. */
+		this.name = "";
 		/** What the slave refers to you as, with a lisp.*/
 		this.titleLisp = "";
 		/**
diff --git a/src/js/utilsSlave.js b/src/js/utilsSlave.js
index 336c3ec997e..9c0c46f67e8 100644
--- a/src/js/utilsSlave.js
+++ b/src/js/utilsSlave.js
@@ -1592,6 +1592,9 @@ globalThis.PoliteRudeTitle = function(slave) {
  * @returns {string}
  */
 globalThis.SlaveTitle = function(slave, adjective = true, variability = true) {
+	if (slave.custom.name) {
+		return slave.custom.name;
+	}
 	let r;
 	if (V.newDescriptions === 1) {
 		if (slave.dick > 0 && slave.balls > 0 && slave.boobs > 300 && slave.vagina > -1 && slave.ovaries === 1) {
-- 
GitLab