diff --git a/public/index.html b/public/index.html index 4ac0433ff..8041b69a1 100644 --- a/public/index.html +++ b/public/index.html @@ -730,17 +730,17 @@ let needsToScan = true; let allActivatedEntries = new Set(); + const sortedEntries = Object.keys(world_info_data.entries).map(x => world_info_data.entries[x]).sort((a, b) => (b.constant - a.constant) || (b.order - a.order)); while (needsToScan) { - let activatedNow = []; + let activatedNow = new Set(); - for (let entryUid in world_info_data.entries) { - const entry = world_info_data.entries[entryUid]; + for (let entry of sortedEntries) { if (allActivatedEntries.has(entry.uid)) { continue; } if (entry.constant) { - activatedNow.push(entry.uid); + activatedNow.add(entry.uid); } if (Array.isArray(entry.key) && entry.key.length) { @@ -749,12 +749,12 @@ if (entry.selective && Array.isArray(entry.keysecondary) && entry.keysecondary.length) { secondary: for (let keysecondary of entry.keysecondary) { if (keysecondary && textToScan.includes(keysecondary.trim().toLowerCase())) { - activatedNow.push(entry.uid); + activatedNow.add(entry.uid); break secondary; } } } else { - activatedNow.push(entry.uid); + activatedNow.add(entry.uid); break primary; } } @@ -762,8 +762,11 @@ } } - needsToScan = activatedNow.length > 0; - const newContents = activatedNow.map(x => world_info_data.entries[x]).map(x => x.content); + needsToScan = activatedNow.size > 0; + const newContents = [...activatedNow] + .map(x => world_info_data.entries[x]) + .sort((a, b) => sortedEntries.indexOf(a) - sortedEntries.indexOf(b)) + .map(x => x.content); for (const content of newContents) { worldInfo = `${worldInfo}${content}\n`; @@ -3336,7 +3339,7 @@ contentInput.val(entry.content).trigger('input'); // selective - const selectiveInput = template.find('input[name="selective"]') + const selectiveInput = template.find('input[name="selective"]'); selectiveInput.data('uid', entry.uid); selectiveInput.on('input', function() { const uid = $(this).data('uid'); @@ -3354,7 +3357,7 @@ // constant - const constantInput = template.find('input[name="constant"]') + const constantInput = template.find('input[name="constant"]'); constantInput.data('uid', entry.uid); constantInput.on('input', function() { const uid = $(this).data('uid'); @@ -3367,6 +3370,17 @@ $(this).siblings('input').click(); }); + // order + const orderInput = template.find('input[name="order"]'); + orderInput.data('uid', entry.uid); + orderInput.on('input', function() { + const uid = $(this).data('uid'); + const value = Number($(this).val()); + world_info_data.entries[uid].order = !isNaN(value) ? value : 0; + saveWorldInfo(); + }); + orderInput.val(entry.order).trigger('input'); + // display uid template.find('.world_entry_form_uid_value').html(entry.uid); @@ -3400,6 +3414,7 @@ content: '', constant: false, selective: false, + order: 0, }; const newUid = getFreeWorldEntryUid(); @@ -3654,26 +3669,37 @@