PDA

View Full Version : Library List Filter



leozelig
August 14th, 2017, 12:26
I want to sort a list of NPCs by hit dice (HD), which is in the format '1d8' or '3d10+3' for example. I created a function in the scripts/library file that allows you to sort the HD filter by the first number only. But the pull-down filter menu still lists the full HD field, so there might be multiple sort fields for a 1 HD creature (1d6, 1d8+1, 1d10). Is there a way to populate the pull-down filter menu with just the first number of the HD so it filters based on just the first number of the HD field (1, 2, 3, etc)?

I can post a screenshot if my description is confusing.

Moon Wizard
August 14th, 2017, 17:38
You will need to write a custom filter getValue function in order to support a campaign index list filter like this.

Try checking out the 5E ruleset in the data_library_5E.lua file for a couple examples (NPC type = custom filter value, Spell source = custom filter value, plus multiple filter values per record).

Regards,
JPG

celestian
August 14th, 2017, 21:05
Leo, try something like



["npc"] = {
bExport = true,
aDataMap = { "npc", "reference.npcdata" },
aDisplayIcon = { "button_people", "button_people_down" },
-- sRecordDisplayClass = "npc",
aGMListButtons = { "button_npc_letter", "button_npc_hd", "button_npc_type" };
aCustomFilters = {
["HitDice"] = { sField = "hitDice", fGetValue = getNPCHitDice },
["Type"] = { sField = "type", sType = "string" },
},



Here is the code I used for mine. This will grab the first number of the value and return it as the HitDice.

You probably want DB.getValue(vNode, "hd", "") instead of DB.getValue(vNode, "hitDice", "") if it's for 5e.



-- get hitDice and get just the first number
function getNPCHitDice(vNode)
local sHitDice = StringManager.trim(DB.getValue(vNode, "hitDice", ""));
local sHD = sHitDice:match("^%d+");
if sHD then
sHitDice = StringManager.trim(sHD);
end
return sHitDice;
end




You will need to write a custom filter getValue function in order to support a campaign index list filter like this.

Try checking out the 5E ruleset in the data_library_5E.lua file for a couple examples (NPC type = custom filter value, Spell source = custom filter value, plus multiple filter values per record).

Regards,
JPG

Everytime I read something you post I find something else to play with, thanks ;)

So, I played with this a little today and was wondering.... I've a field that has multiple entries. like "Arid, Temperate, Mountain, Hills"

I was trying to think of a way so that the search fields listed, instead of having all those on one line ... would have "Arid" then "Hills" then etc... instead and actually work on search.

I can certainly chop it into one field by just splitting on comma but im wondering if it's possible to have a single object have multiple entries so that if they selected "Arid" or "Hills" for search the creatures with both would show in both?

I've a similar situation with spells and Spheres and Schools. Some will have multiple spheres and/or schools and this would also be useful there.

Moon Wizard
August 14th, 2017, 21:33
I believe what you are asking is exactly what the Spell source field does in 5E. Look at the getSpellSourceValue function in data_library_5#.lua.

Cheers,
JPG

celestian
August 14th, 2017, 22:07
I believe what you are asking is exactly what the Spell source field does in 5E. Look at the getSpellSourceValue function in data_library_5#.lua.

Cheers,
JPG

Wow, sure nuff. It handles it just by splitting. That's WAY easier than I expected!

Works perfectly.

leozelig
August 14th, 2017, 23:47
Thanks for the replies.

I had actually swiped your 'NPC Type' filter from 5E, Moon. My function was slightly different than celestian's, but I got the same result with the changes. A screenshot will probably help you understand what I'm asking...

20142

I want the filter list to read 1, 2, 3... excluding everything other than the first number. I was able to sort the list so it doesn't place the 12, 14, 16 before the 1, but my bigger issue is how to get all of the 1dxx + x HD monsters to filter as 1, and so on.

The answer might be that it's not possible, or it's possible but very complicated. If that's the case, I will move on ;)

celestian
August 15th, 2017, 01:22
Thanks for the replies.

I had actually swiped your 'NPC Type' filter from 5E, Moon. My function was slightly different than celestian's, but I got the same result with the changes. A screenshot will probably help you understand what I'm asking...

20142

I want the filter list to read 1, 2, 3... excluding everything other than the first number. I was able to sort the list so it doesn't place the 12, 14, 16 before the 1, but my bigger issue is how to get all of the 1dxx + x HD monsters to filter as 1, and so on.

The answer might be that it's not possible, or it's possible but very complicated. If that's the case, I will move on ;)

I actually noticed the same problem and sorted (pun!) it out. This is what I did. Keep in mind this is for my output which is specifcally a number only. Not 1+1 or 3+5 or the like. I had issues with 100 being before 1 so...

This was the bit in the "npc" section.


["HitDice"] = { sField = "hitDice", fGetValue = getNPCHitDice,fSort = sortNPCHitDice },




-- see if this will sort HD better
function sortNPCHitDice(aFilterValues)
local function fNPCSortValue(a)
local v = tonumber(a) or 0;
return v;
end
table.sort(aFilterValues, function(a,b) return fNPCSortValue(a) < fNPCSortValue(b); end);
return aFilterValues;
end


You just need to come up with a similar sort function that'll deal with your values.

leozelig
August 15th, 2017, 11:59
Thanks, celestian. I will use the sort function, that's good enough for me. I think that's the best I'm gonna do with that.

leozelig
August 16th, 2017, 02:19
Seems to be working now. Thanks celestian and JPG!