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

Merge branch 'pregmod-master' into 'pregmod-master'

Add simple Find Slave passage to help locate slaves that you might have misplaced

See merge request pregmodfan/fc-pregmod!5529
parents 259898e5 8b891bdb
No related branches found
No related tags found
No related merge requests found
App.FindSlave = {};
/**
* Fragment searching: See if every needle can found somewhere in the field of haystacks
* @param {string[]} haystacks
* @param {RegExp[]} needles
* @returns {boolean}
*/
App.FindSlave._fragmentSearch = function(haystacks, needles) {
const hs = haystacks.join(" ");
return needles.every((needle) => { return needle.test(hs); });
};
/**
* Get slave indices which match a predicate
* @param {function} predicate
* @returns {number[]}
*/
App.FindSlave._slaveIndices = function(predicate) {
return V.slaves.reduce((acc, slave, ind) => {
if (predicate(createReadonlyProxy(slave))) {
acc.push(ind);
}
return acc;
}, []);
};
/**
* Generate a slave list as the result of fragment searching all the name-type fields
* @param {string} query
* @returns {DocumentFragment}
*/
App.FindSlave.searchByName = function(query) {
const needles = query.split(" ").map((needle) => { return new RegExp(needle, "i"); });
const indices = this._slaveIndices((slave) => { return this._fragmentSearch([slave.slaveName, slave.slaveSurname, slave.birthName, slave.birthSurname], needles); });
return App.UI.SlaveList.render.listDOM(indices, [], App.UI.SlaveList.SlaveInteract.stdInteract);
};
/**
* Generate a slave list as the result of fragment searching profession and origin
* @param {string} query
* @returns {DocumentFragment}
*/
App.FindSlave.searchByBackground = function(query) {
const needles = query.split(" ").map((needle) => { return new RegExp(needle, "i"); });
const indices = this._slaveIndices((slave) => { return this._fragmentSearch([slave.career, slave.origin], needles); });
return App.UI.SlaveList.render.listDOM(indices, [], App.UI.SlaveList.SlaveInteract.stdInteract);
};
/**
* Generate a slave list as the result of evaluating an expression
* @param {string} query
* @returns {DocumentFragment}
*/
App.FindSlave.searchByExpression = function(query) {
const pred = new Function("slave", "return (" + query + ");");
const indices = runWithReadonlyProxy(() => { return this._slaveIndices(pred); });
return App.UI.SlaveList.render.listDOM(indices, [], App.UI.SlaveList.SlaveInteract.stdInteract);
};
:: Find Slave [nobr]
<<set $nextButton = "Back to Main", $nextLink = "Main", $showEncyclopedia = 0>>
After spending a minute trying to remember some details about one of your slaves, you sit down behind your desk and tell $assistantName that you need to locate a particular slave's records.<br><br>
"Certainly, <<= properMaster()>>. What can you tell me about them?"<br><br>
"They're called something like:
<<textbox "_nameSearch" "" autofocus>>
<<link "Locate">>
<<script>>$('#slaveList').empty().append(App.FindSlave.searchByName(State.temporary.nameSearch));<</script>>
<</link>>
<br>//(Enter a fragment of their nickname, name, surname, birth name, or birth surname)//<br><br>
"In the past, they were:
<<textbox "_backgroundSearch" "">>
<<link "Locate">>
<<script>>$('#slaveList').empty().append(App.FindSlave.searchByBackground(State.temporary.backgroundSearch));<</script>>
<</link>>
<br>//(Enter a fragment of their origin or past job, for example, "shelter" or "lawyer")//<br><br>
"Their data should meet this condition:
<<textbox "_dataSearch" "">>
<<link "Locate">>
<<script>>$('#slaveList').empty().append(App.FindSlave.searchByExpression(State.temporary.dataSearch));<</script>>
<</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>
<span id="slaveList">
/* results list gets populated here by jQuery */
</span>
...@@ -539,6 +539,12 @@ ...@@ -539,6 +539,12 @@
<<if ($corpSpecToken > 0) && ($corpSpecTimer == 0)>>@@.yellow;[!]@@<</if>> <<if ($corpSpecToken > 0) && ($corpSpecTimer == 0)>>@@.yellow;[!]@@<</if>>
<</if>> <</if>>
<<if _Pass != "Find Slave">>
<span id="findSlave"> <br>
<<link [[Locate Slave|Find Slave]]>><</link>>
</span>
<</if>>
<<if $sideBarOptions.compact === 0 && _Pass === "Main" || $sideBarOptions.compact === 1 && _Pass === "Manage Arcology">> <br> <<if $sideBarOptions.compact === 0 && _Pass === "Main" || $sideBarOptions.compact === 1 && _Pass === "Manage Arcology">> <br>
<<if $FSAnnounced>> <<if $FSAnnounced>>
<span id="FSButton"> <br> <span id="FSButton"> <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