Skip to content
Snippets Groups Projects
Commit 7faff1b2 authored by Pregmodder's avatar Pregmodder
Browse files

Merge branch 'locate-slave-2' into 'pregmod-master'

Improve Locate Slave function.

See merge request pregmodfan/fc-pregmod!6949
parents b98d85bc c0cdc3c5
No related branches found
No related tags found
No related merge requests found
...@@ -183,6 +183,10 @@ App.Data.defaultGameStateVariables = { ...@@ -183,6 +183,10 @@ App.Data.defaultGameStateVariables = {
curativeSideEffects: 1, curativeSideEffects: 1,
disableTiredness: 1, disableTiredness: 1,
disableLongDamage: 1, disableLongDamage: 1,
// Last-used strings in Locate Slave
findName: "",
findBackground: "",
findData: "",
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
pedo_mode: 0, pedo_mode: 0,
......
...@@ -25,15 +25,34 @@ App.FindSlave._slaveIDs = function(predicate) { ...@@ -25,15 +25,34 @@ App.FindSlave._slaveIDs = function(predicate) {
}, []); }, []);
}; };
/**
* Display a list of results, or text indicating that there were none
* @param {number[]} ids
* @param {DocumentFragment} frag
*/
App.FindSlave._appendResultList = function(ids, frag) {
if (ids.length === 0) {
App.UI.DOM.appendNewElement("p", frag, "No matching slaves.");
} else {
frag.appendChild(App.UI.SlaveList.render.listDOM(ids, [], App.UI.SlaveList.SlaveInteract.stdInteract));
}
};
/** /**
* Generate a slave list as the result of fragment searching all the name-type fields * Generate a slave list as the result of fragment searching all the name-type fields
* @param {string} query * @param {string} query
* @returns {DocumentFragment} * @returns {DocumentFragment}
*/ */
App.FindSlave.searchByName = function(query) { App.FindSlave.searchByName = function(query) {
const needles = query.split(" ").map((needle) => { return new RegExp(needle, "i"); }); const frag = document.createDocumentFragment();
const ids = this._slaveIDs((slave) => { return this._fragmentSearch([slave.slaveName, slave.slaveSurname, slave.birthName, slave.birthSurname], needles); }); if (query) {
return App.UI.SlaveList.render.listDOM(ids, [], App.UI.SlaveList.SlaveInteract.stdInteract); const resultTitle = App.UI.DOM.appendNewElement("p", frag, "Query results for name: ");
App.UI.DOM.appendNewElement("code", resultTitle, query);
const needles = query.split(" ").map((needle) => { return new RegExp(needle, "i"); });
const ids = this._slaveIDs((slave) => { return this._fragmentSearch([slave.slaveName, slave.slaveSurname, slave.birthName, slave.birthSurname], needles); });
this._appendResultList(ids, frag);
}
return frag;
}; };
/** /**
...@@ -42,9 +61,15 @@ App.FindSlave.searchByName = function(query) { ...@@ -42,9 +61,15 @@ App.FindSlave.searchByName = function(query) {
* @returns {DocumentFragment} * @returns {DocumentFragment}
*/ */
App.FindSlave.searchByBackground = function(query) { App.FindSlave.searchByBackground = function(query) {
const needles = query.split(" ").map((needle) => { return new RegExp(needle, "i"); }); const frag = document.createDocumentFragment();
const ids = this._slaveIDs((slave) => { return this._fragmentSearch([slave.career, slave.origin], needles); }); if (query) {
return App.UI.SlaveList.render.listDOM(ids, [], App.UI.SlaveList.SlaveInteract.stdInteract); const resultTitle = App.UI.DOM.appendNewElement("p", frag, "Query results for background: ");
App.UI.DOM.appendNewElement("code", resultTitle, query);
const needles = query.split(" ").map((needle) => { return new RegExp(needle, "i"); });
const ids = this._slaveIDs((slave) => { return this._fragmentSearch([slave.career, slave.origin], needles); });
this._appendResultList(ids, frag);
}
return frag;
}; };
/** /**
...@@ -53,7 +78,13 @@ App.FindSlave.searchByBackground = function(query) { ...@@ -53,7 +78,13 @@ App.FindSlave.searchByBackground = function(query) {
* @returns {DocumentFragment} * @returns {DocumentFragment}
*/ */
App.FindSlave.searchByExpression = function(query) { App.FindSlave.searchByExpression = function(query) {
const pred = new Function("slave", "return (" + query + ");"); const frag = document.createDocumentFragment();
const ids = runWithReadonlyProxy(() => { return this._slaveIDs(pred); }); if (query) {
return App.UI.SlaveList.render.listDOM(ids, [], App.UI.SlaveList.SlaveInteract.stdInteract); const resultTitle = App.UI.DOM.appendNewElement("p", frag, "Query results from expression: ");
App.UI.DOM.appendNewElement("code", resultTitle, query);
const pred = new Function("slave", "return (" + query + ");");
const ids = runWithReadonlyProxy(() => { return this._slaveIDs(pred); });
this._appendResultList(ids, frag);
}
return frag;
}; };
...@@ -7,23 +7,23 @@ After spending a minute trying to remember some details about one of your slaves ...@@ -7,23 +7,23 @@ After spending a minute trying to remember some details about one of your slaves
"Certainly, <<= properMaster()>>. What can you tell me about them?"<br><br> "Certainly, <<= properMaster()>>. What can you tell me about them?"<br><br>
"They're called something like: "They're called something like:
<<textbox "_nameSearch" "" autofocus>> <<textbox "$findName" $findName autofocus>>
<<link "Locate">> <<link "Locate">>
<<script>>$('#slaveList').empty().append(App.FindSlave.searchByName(State.temporary.nameSearch));<</script>> <<script>>$('#slaveList').empty().append(App.FindSlave.searchByName(V.findName));<</script>>
<</link>> <</link>>
<br>//(Enter a fragment of their nickname, name, surname, birth name, or birth surname)//<br><br> <br>//(Enter a fragment of their nickname, name, surname, birth name, or birth surname)//<br><br>
"In the past, they were: "In the past, they were:
<<textbox "_backgroundSearch" "">> <<textbox "$findBackground" $findBackground>>
<<link "Locate">> <<link "Locate">>
<<script>>$('#slaveList').empty().append(App.FindSlave.searchByBackground(State.temporary.backgroundSearch));<</script>> <<script>>$('#slaveList').empty().append(App.FindSlave.searchByBackground(V.findBackground));<</script>>
<</link>> <</link>>
<br>//(Enter a fragment of their origin or past job, for example, "shelter" or "lawyer")//<br><br> <br>//(Enter a fragment of their origin or past job, for example, "shelter" or "lawyer")//<br><br>
"Their data should meet this condition: "Their data should meet this condition:
<<textbox "_dataSearch" "">> <<textbox "$findData" $findData>>
<<link "Locate">> <<link "Locate">>
<<script>>$('#slaveList').empty().append(App.FindSlave.searchByExpression(State.temporary.dataSearch));<</script>> <<script>>$('#slaveList').empty().append(App.FindSlave.searchByExpression(V.findData));<</script>>
<</link>> <</link>>
<br>//(Enter a conditional expression which evaluates to true for the slave you want to find, such as "slave.physicalAge >= 18 && slave.physicalAge < 21")//<br><br> <br>//(Enter a conditional expression which evaluates to true for the slave you want to find, such as "slave.physicalAge >= 18 && slave.physicalAge < 21")//<br><br>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment