World Info: Allow disabling recursion on entries

Recursive scanning is a very great tool used to create a tree hierarchy
of entries. However, some entries should not be included in recursion
due to possible conflicts and resulting leakage in chats.

Add an individual opt-out toggle to exclude the entry from recursive
scanning if the main option is enabled.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri
2023-06-14 12:26:02 -04:00
parent 346d5cfb3a
commit 8b8bf645eb
2 changed files with 23 additions and 1 deletions

View File

@ -2920,6 +2920,10 @@
<input type="checkbox" name="disable" />
<span data-i18n="Disable">Disable</span>
</label>
<label class="checkbox flex-container alignitemscenter">
<input type="checkbox" name="exclude_recursion" />
<span data-i18n="Exclude from recursion">Exclude from recursion</span>
</label>
</div>
<input class="menu_button delete_entry_button" type="submit" value="Delete Entry" />
</div>

View File

@ -332,6 +332,19 @@ function appendWorldEntry(entry) {
$(this).siblings("input").click();
});
const excludeRecursionInput = template.find('input[name="exclude_recursion"]');
excludeRecursionInput.data("uid", entry.uid);
excludeRecursionInput.on("input", function () {
const uid = $(this).data("uid");
const value = $(this).prop("checked");
world_info_data.entries[uid].excludeRecursion = value;
saveWorldInfo();
});
excludeRecursionInput.prop("checked", entry.excludeRecursion).trigger("input");
excludeRecursionInput.siblings(".checkbox_fancy").click(function () {
$(this).siblings("input").click();
});
// delete button
const deleteButton = template.find("input.delete_entry_button");
deleteButton.data("uid", entry.uid);
@ -366,6 +379,7 @@ function createWorldInfoEntry() {
order: 100,
position: 0,
disable: false,
excludeRecursion: false
};
const newUid = getFreeWorldEntryUid();
@ -505,6 +519,7 @@ function checkWorldInfo(chat) {
let worldInfoBefore = "";
let worldInfoAfter = "";
let needsToScan = true;
let count = 0;
let allActivatedEntries = new Set();
const sortedEntries = Object.keys(world_info_data.entries)
@ -512,10 +527,13 @@ function checkWorldInfo(chat) {
.sort((a, b) => b.order - a.order);
while (needsToScan) {
// Track how many times the loop has run
count++;
let activatedNow = new Set();
for (let entry of sortedEntries) {
if (allActivatedEntries.has(entry.uid) || entry.disable == true) {
if (allActivatedEntries.has(entry.uid) || entry.disable == true || (count > 1 && world_info_recursive && entry.excludeRecursion)) {
continue;
}