PDA

View Full Version : MoreCore sort question



Varsuuk
July 11th, 2020, 07:14
I'm sorry, I am sure this has been asked before.
I did a search on "sort" which of course, gets all kinds of things. And /morecore help of course too.

Anyhow, I did a fast attempt at changing sort to desired order sort. I need to get to sleep so I did it pretty sloppy but to see if had an effect.


In MoreCore\common\template_lists.xml, I tossed the following list_text2 (put directly in morecore to just test - wasn't going to leave there).


<root>
<!-- Display Tabs for GM and Players -->
<template name="categories_all">
<categoryselectioncontrol>
<anchored>
<top anchor="bottom" offset="-39" />
<left offset="24" />
<bottom offset="-1" />
</anchored>
</categoryselectioncontrol>
</template>

<template name="list_text2">
<list_text>
<sortby mergerule="replace"><control>name_sort_order</control></sortby>
</list_text>
</template>

</root>


Then in my OSE extension, I tossed in record_char_more.xml I changed list_text to list_text2


<root>
<!-- Display Tabs for GM and Players -->
<template name="categories_all">
<categoryselectioncontrol>
<anchored>
<top anchor="bottom" offset="-39" />
<left offset="24" />
<bottom offset="-1" />
</anchored>
</categoryselectioncontrol>
</template>

<template name="list_text2">
<list_text>
<sortby mergerule="replace"><control>name_sort_order</control></sortby>
</list_text>
</template>

</root>



Finally, in the pregens xml, I added a tag for each attribute:


<locked type="number">1</locked>
<name type="string">Wisdom</name>
<name_sort_order type="string">5</name_sort_order>. <<----- This one.
<number_min type="number">3</number_min>



Sure, yeah, it was a "Hail Mary" pass. I, of course am OK with the default CoreRPG behavior of alpha sort on name - was just something that popped in my mind and figured try.

Just getting back to work on some stuff, so trying to refamiliarize but MoreCore I never worked with directly.

Varsuuk
July 11th, 2020, 07:45
OK - so I didn't go to sleep... It was bugging me.

Would love to get it to work with the simple <sortby> and perhaps tomorrow I will see why I didn't get that working.

But for now, my pigheadedness got me to a working solution for the attributes (most things I do not care the order)
(I left the sortby in there - has nothing to do with the solution - was just quick/dirty)



<template name="list_text2">
<list_text>
<sortby mergerule="replace"><control>name_sort_order</control></sortby>
<script name="xxx">
function onSortCompare(w1, w2)
return DB.getValue(w1.getDatabaseNode(), "name_sort_order", "") > DB.getValue(w2.getDatabaseNode(), "name_sort_order", "")
end
</script>
</list_text>
</template>



Got that working, but it was my normal "throw stuff at the wall and see if it sticks..." way. Now need to read stuff and see why and which way to really do it - obviously as I said, not leaving it in MoreCore - although, if there isn't one such - perhaps adding a list_text_sorted to morecore which by default looks for "<sort_name>" and if present uses that on onSortCompare and otherwise uses name (and of course there would be a resource for the sort key but that's overkill - just as easy specialize again).

Anyhow - ready to pass out ;) night folks (will update with my final modifications).

Varsuuk
July 12th, 2020, 07:08
"SITE SEARCH" is your friend - please all repeat after me :)

So, before posting a new generalized question asking why adding:
"NOT-WORKING" (quotes are cos it IS working, >I< wasn't "working" ;) )


<sortby mergerule="replace"><control>name_sort_order</control></sortby>


Did not help me, even though I got it to work using onSortCompare... I found out there are TWO options (I DID think it was weird it said <control>...)
control & field. So I changed it to field and it worked fine. I don't need to add a script.

WORKS:


<sortby mergerule="replace"><field>name_sort_order</field></sortby>



So, yes, the above works fine - no need to do onSortCompare.


Now that's done - any reason I would consider onSortCompare for a SINGLE field sort? I would imagine it is useful if I want to sort on field X and if even, then sort on field Y as a simplistic example.


EDIT: OOPS ;) Forgot that the control using text_list was defined in MoreCore so I don't want to touch that. Will instead override the CoreRPG text_list to look at alt_sort_order and if not present, use name. I'll perhaps change that as I learn more - but that's where leaving off tonight.