Sorting objects in places and objects pane
Local_Redditor
23 Sept 2021, 18:41I just want to have the exits I put in the "Places and Objects" pane to be place at the top and not below all the objects.
Or maybe, sort them in general perhaps?
mrangel
23 Sept 2021, 23:40The code that prepares this data is in the Quest engine, rather than in the core library, so it's not easy to modify. So you'd need to alter the part you can get to - the javascript function updateList
which is responsible for receiving a list of objects, and using that to display the list in the sidebar.
If you want to sort the list with exits first, you could use the function updateExitLinks
, which receives a list of exits every turn. Store this information in a JS variable, and then use it to order the data for updateList
. So your javascript would look something like (off the top of my head, not tested):
$(function () {
var original_updateList = updateList;
var original_updateExitLinks = updateExitLinks;
var allExits = [];
updateList = function (listname, data) {
var sortorder = {};
$.each(data, function (key, value) {
var item_data = JSON.parse(value);
sortorder[key] = ($.inArray(item_data["ElementId"], allExits) ? "exit" : "object") + item_data("ElementName");
});
var newdata = {};
sortorder.keys().sort (function (a, b) {
return ((sortorder[a] > sortorder[b]) ? -1 : ((sortorder[b] > sortorder[a]) ? 1 : 0));
}).foreach (function (key) {
newdata[key] = data[key];
});
original_updateList (listname, newdata);
};
updateExitLinks = function (data) {
allExits = data;
original_updateExitLinks(data);
};
});
To use that in Quest, you'd compress it and put it in the "UI Initialisation script", on the "Advanced Scripts" tab (after you enabled it on the features tab). The compressed code would look like:
JS.eval("$(function(){var a=updateList,b=updateExitLinks,c=[];updateList=function(b,d){var e={};$.each(d,function(a,b){var d=JSON.parse(b);e[a]=($.inArray(d.ElementId,c)?'e':'o')+d.ElementName});var f={};e.keys().sort(function(c,a){return e[c]>e[a]?-1:e[a]>e[c]?1:0}).foreach(function(a){f[a]=d[a]}),a(b,f)},updateExitLinks=function(a){c=a,b(a)}});")
Is that what you were looking for?