PDA

View Full Version : Trying to find where values are actually set for ref group lists.



celestian
December 3rd, 2018, 07:27
Okay, I've a need to do some tweaking to how values are applied. Here is an example of what works right now.



function onButtonPress()
local w = Interface.openWindow("reference_groupedlist", "reference.weapon");
local rList = {};
rList.sRecordType = "item";
rList.sTitle = Interface.getString("item_button_weapons");
rList.aColumns = {};
table.insert(rList.aColumns, { sName = "name", sType = "string", sHeading = "Name", nWidth=200, nSortOrder=1 });
table.insert(rList.aColumns, { sName = "cost", sType = "string", sHeading = "Cost", bCentered=true });
table.insert(rList.aColumns, { sName = "damage", sType = "string", sHeading = "Damage", nWidth=150, bCentered=true });
table.insert(rList.aColumns, { sName = "weight", sType = "number", sHeading = "Weight", bCentered=true });
table.insert(rList.aColumns, { sName = "properties", sType = "string", sHeading = "Prop.", nWidth=200, bCentered=true });
rList.aFilters = {};
table.insert(rList.aFilters, { sDBField = "type", vFilterValue = "Weapon" });
rList.aGroups = {};
table.insert(rList.aGroups, { sDBField = "subtype" });
rList.aGroupValueOrder = { "Simple Melee Weapons", "Simple Ranged Weapons", "Martial Weapons", "Martial Melee Weapons", "Martial Ranged Weapons" };
w.init(rList);
end


That'll create a menu popup that lists all items with the type "Weapon" with name/cost/damage/weight/properties values displayed. Works great for 5e.

The thing is I've changed how weapons are in my ruleset and I'd like to have it display properly. I have a damagelist instead of a single string.

What I'd like to do is have something like we have to the search filters. The search filters have an option to use a value returned by a function instead. With that I could then define the function and have it return a string with the all the damage nodes damage strings in one formatted string.


If you are familiar with scripts/data_library_5E.lua


["spell"] = {
bExport = true,
aDataMap = { "spell", "reference.spelldata" },
aDisplayIcon = { "button_spells", "button_spells_down" },
sRecordDisplayClass = "power",
aGMEditButtons = { "button_power_import" };
aGMListButtons = { "button_spells_arcane_player", "button_spells_school_player","button_spells_divine_player","button_spells_sphere_player" };
aPlayerListButtons = { "button_spells_school_player", "button_spells_sphere_player" };
aCustomFilters = {
["Sphere"] = { sField = "sphere", fGetValue = getSpellSphereValue },
["School"] = { sField = "school", fGetValue = getSpellSchoolValue },
["Type"] = { sField = "type", sType = "string" },
["Level"] = { sField = "level", sType = "number" };
},


The bolded bit is what I am referring to. The getSpellSphereValue() function takes the spell's "sphere" value and does some fiddling about and returns a more "sane" response.

So, what I'm hoping to add is something like this:



table.insert(rList.aColumns, { sName = "damage", sType = "string", fGet="getFullDamageString" sHeading = "Damage", nWidth=150, bCentered=true });


To that end I've been digging into the ref_* stuff trying to figure out just WHERE this value is set in the window for display. In the above examples I'm looking for something like local someValue = DB.getValue(node,sName,sType); Obviously it'll not look like that, more likely rList.something. The best I can trace it to is to possibly around here in CoreRPG ref/scripts/ref_groupedlist.lua in the function addListRecord() around



local wItem = rList.aGroupings[sGroup].list.createWindow(node);


I suspect it's being set with "list" which I am assuming is a value from and xml entry and uses some other functions in another .lua or inline script to actually grab the values and list them.

Does anyone have a clue WHERE "list" is? Meaning the one for this one (there are obviously serveral "list" entries in the xml. I've dug around the xml looking at the various entries trying to determine if this is where it is and if so where the code is where the listed entries values are set but ... after several hours of debugging and throwing all kinds of output to console I've hit a wall.

Am I even on the right track (is it set elsewhere?)

This is a very "in the weeds" sorta thing so I can understand if folks just say "huh?" and scratch their head. I do have a hacky/kludge I use right now (when the damage value is changed for any damage node a function will rescan ALL of them on that item and set "damage" on the item itself with a sane string) but... that itch gets me and I wanna try and do it a little better. Might just be easier to let it go but... hoping someone might have a thought.

Trenloe
December 3rd, 2018, 09:42
I suspect it's being set with "list" which I am assuming is a value from and xml entry and uses some other functions in another .lua or inline script to actually grab the values and list them.

Does anyone have a clue WHERE "list" is?
Look at line 182 of ref/scripts/ref_groupedlist.lua

This is where the grouplist control is created using the list_refgroupedlist template. grouplist is later used to create the rList.aGroupings[sGroup] window a few lines before the code you mention. Therefore the list_refgroupedlist template is where the "list" windowlist control is defined.

celestian
December 4th, 2018, 05:11
So, I was able to find what I was looking for and learned a good bit during the process. The bad news is it was not really what I was hoping for ;(

The spot I was looking for was in ref_groupedlist_groupitem.lua. Specifically in the function setColumnInfo(aColumns, nDefaultColumnWidth) round about here local cField = createControl(sControlClass, rColumn.sName);.

createControl creates a a control using the defined xml template(something like string_refgroupedlistgroupitem_wrap). The template's name (rColumn.sName) is the name of the new control and also it's source so in this case it was item.id-00001.damage.

So, I wrote a template of my own, added fGetValue to the rColumn variable and added a check to set the sControlClass to it...



table.insert(rList.aColumns, { fGetValue = "Something.function", sName = "damage", sType = "string", sHeading = "Damage", nWidth=150, bCentered=true });


And did some debug output to script portion of the template to figure out how things worked.

The problem is I couldn't really also handoff the "Something.function" to the template. I could write a very specific flag like "bItemDamage=true" and then within the template script..script run some custom work to setValue() after doing all the node tree negotiation. I'd need to add some handlers to watch for the node.weaponsList.damageList.* changes but otherwise maybe not so bad. I'll think about it. I was hoping I could write something that would be useful to more than just this one situation (thus others).

Moon Wizard
December 4th, 2018, 06:27
Can you step back about five steps for me; and describe the use case and a specific example? ;)

Cheers,
JPG

celestian
December 4th, 2018, 07:17
Can you step back about five steps for me; and describe the use case and a specific example? ;)

Cheers,
JPG

Haha, sure. As I said originally, in the weeds ;)

Currently in my ruleset my items have a multi-node weaponlist. Each weapon can have multiple damage types. For example you have a dagger which can be used hand to hand or thrown.

https://i.imgur.com/gSoyHJe.png

I wanted to be able to capture ALL of those damage values for display in the "items" quick buttons like this.

https://i.imgur.com/Fnd7xO0.png

5E uses a single string to store that entire value so it's a bit easier to just tell it to use string and the name of the value is "damage" and it works. For mine its a bit more complex. My original thought was to try and setup a method to call a function like is used for the "search filters" (block posted in previous post) but that turned out to be a bust as it used a method I was hitherto unaware of (createControl()).

Once I figured out how it worked I did a bit of jiggerypokery and added a new column value "bItemDamage=true" for that specific need and within that template I used my own script to get the fields, put them in a string value that could be displayed for this situation.

It is very specific to how I have items. Mostly because I went away from string values for damage because of my requirements/needs.

I certainly try and avoid going into ref_* because it's very difficult to follow at times (it's all very generic which means it's all variables and hard to just trace looking... which is similar to the masterindex/record list stuff) tho it did turn into a pretty good learning experience ;)