PDA

View Full Version : tabs_recordsheet question



SilentRuin
September 8th, 2020, 17:35
I'm trying to add a new tab onto a sheet with tabs already and I don't want to lose any of those tabs - and I want mine added to end so that if anyone else is playing this game mine does not interfere with theirs.

However, when I add in my tab with a merge="join" I'm somehow whacking the first tab instead of adding mine to the end of the list of tabs. In other words, I have 2 tabs already there - and when I do the following - it replaced the first tab with mine.

Which confuses me as I thought "join" would just add it to the bottom and not touch anything else - then when it processed it would see 3 tabs with mine at the bottom - not just two like I had before with mine replacing the first one.

I'm misunderstanding something here. Anyone know what it is? I thought merge was pretty dumb and just added things in to the bottom of things.




<root>
<windowclass name="oldclass" merge="join">
<sheetdata>
<subwindow_record name="newtab">
<class>mynewtab</class>
</subwindow_record>
<tabs_recordsheet name="tabs" merge="join">
<tab>
<icon>myicon</icon>
<subwindow>newtab</subwindow>
</tab>
</tabs_recordsheet>
</sheetdata>
</windowclass>
</root>

SilentRuin
September 8th, 2020, 17:43
I'm trying to add a new tab onto a sheet with tabs already and I don't want to lose any of those tabs - and I want mine added to end so that if anyone else is playing this game mine does not interfere with theirs.

However, when I add in my tab with a merge="join" I'm somehow whacking the first tab instead of adding mine to the end of the list of tabs. In other words, I have 2 tabs already there - and when I do the following - it replaced the first tab with mine.

Which confuses me as I thought "join" would just add it to the bottom and not touch anything else - then when it processed it would see 3 tabs with mine at the bottom - not just two like I had before with mine replacing the first one.

I'm misunderstanding something here. Anyone know what it is? I thought merge was pretty dumb and just added things in to the bottom of things.




<root>
<windowclass name="oldclass" merge="join">
<sheetdata>
<subwindow_record name="newtab">
<class>mynewtab</class>
</subwindow_record>
<tabs_recordsheet name="tabs" merge="join">
<tab>
<icon>myicon</icon>
<subwindow>newtab</subwindow>
</tab>
</tabs_recordsheet>
</sheetdata>
</windowclass>
</root>


And for ABSOLUTE SURE if you tell me its because the <tab> tag is finding the first match - please tell me how to make it NOT do that.

SilentRuin
September 8th, 2020, 19:03
And for ABSOLUTE SURE if you tell me its because the <tab> tag is finding the first match - please tell me how to make it NOT do that.

Another clue if anyone knows the answer to this mystery - if I don't do a merge="join" and simply copy the entire "oldclass" and add my things into it directly (ie. replacing the entire windowclass with what it originally had and my new stuff without trying to join it) then it works. If I take that entire copy of the windowclass and simply add merge="join" leaving everything still in it that worked before - then it fails. Something is weird here with tabs. I would have thought doing a join and giving it all the original data would simply replace all that data and do the exact same thing (work), yet simply adding join makes it fail in the exact same way that it fails when I just add my original example. I don't get it.

Replacing the whole thing obviously does not allow me to let other people's modifications work as I'd be stomping it and don't want that. I just want to add my new tab into it.

superteddy57
September 8th, 2020, 20:34
When making extensions, I rarely do the merge="join" method as I ran into similar issues as you have. If you investigate the code it runs through a script in creating them and I believe the merge="join" overwrites the first as it goes through that script. I personally haven't found a way around it. I would be happy to know of a way and was thinking of trying to expand tabs a bit further to be removed and added with code. Might be a great tool for various options and such showing only certain tabs, maybe a certain class needs a new tab to track something. I would only endorse the clone method when adding tabs to a sheet currently.

SilentRuin
September 8th, 2020, 20:43
When making extensions, I rarely do the merge="join" method as I ran into similar issues as you have. If you investigate the code it runs through a script in creating them and I believe the merge="join" overwrites the first as it goes through that script. I personally haven't found a way around it. I would be happy to know of a way and was thinking of trying to expand tabs a bit further to be removed and added with code. Might be a great tool for various options and such showing only certain tabs, maybe a certain class needs a new tab to track something. I would only endorse the clone method when adding tabs to a sheet currently.

I've had to expand the tabs lua code (low level) itself in another of my extensions since I needed to know when tabs actually changed (had to provide call back and support it in that code so I could get notifications) - but as you say - there is also a level of code I have no visibility on that does the actual logic driving the merge logic. So I'd be all for a way to flesh out tabs in a more friendly manner for external modification (extension writers).

In case you wondered, this was adding inventory to the NPC sheets along with a bunch of other features in my next extension to enable me to become the laziest DM ever. I just don't like the idea of having to overwrite code completely - I'd prefer to allow others to modify it without me interfering with them or visa versa. I'll see if I can trick it somehow (at least spend today doing it) then give up and move on with the stomping of the sheet if I have to. In the end, I can only make extensions work with the extensions I use myself, but I'd like to leave less "impact" on others when I do something like this.

SilentRuin
September 8th, 2020, 21:13
When making extensions, I rarely do the merge="join" method as I ran into similar issues as you have. If you investigate the code it runs through a script in creating them and I believe the merge="join" overwrites the first as it goes through that script. I personally haven't found a way around it. I would be happy to know of a way and was thinking of trying to expand tabs a bit further to be removed and added with code. Might be a great tool for various options and such showing only certain tabs, maybe a certain class needs a new tab to track something. I would only endorse the clone method when adding tabs to a sheet currently.

Actually, I think I found the "why" of it in code I'm already familiar with (template_buttons.xml,.lua). It has a mergerule of "resetandadd". Looking it up in the old documents I see it defined as follows:



Simply merging is not sufficient for some uses in templates. Therefore, any tag in a template may contain a "mergerule" attribute taking one of the following values. When a tag in the definition contains multiple children with the same name (i.e. a list of similar child tags), only the topmost is checked when looking for a merge rule.

"merge": Synonymous with the default operation
"replace": If the implementing control contains a tag in the same position as this one, removes the tag in the template and all its children. This is useful if a tag in the definition should contain values for e.g. multiple states as children of a parent tag, and an override should replace the child values as well as the main tag.
"add": Instead of replacing a value as a result of a merge, a tag in the same position as this one is instead created as another similar tag in the result. This is useful if a template presents a default list of states or values, but the implementing control is allowed to add new values to the list.
"resetandadd": This is similar to "replace", but after one replace, reverts to "add" mode. The result is that a set of similar tags in an implementing control will override a similar set in the template.
When a template is inherited by another template, care should be taken to confirm that the outer template provides any necessary merge rules as well.


I'll see if I can't somehow get a simple add working for this or trick this "resetandadd" into doing what I want. Might not be able to but it's at least a clue as to why I'm getting a join to always whack the first value.

SilentRuin
September 8th, 2020, 21:36
When making extensions, I rarely do the merge="join" method as I ran into similar issues as you have. If you investigate the code it runs through a script in creating them and I believe the merge="join" overwrites the first as it goes through that script. I personally haven't found a way around it. I would be happy to know of a way and was thinking of trying to expand tabs a bit further to be removed and added with code. Might be a great tool for various options and such showing only certain tabs, maybe a certain class needs a new tab to track something. I would only endorse the clone method when adding tabs to a sheet currently.

Trulyi I want to scream right now. What the heck...

AHHHHHHHHHHHHHHHH!!!!!

Solved it for me at least. Total guess based on what I thought was happening lucked into a solution...



<root>
<windowclass name="oldclass" merge="join">
<sheetdata>
<subwindow_record name="newtab">
<class>mynewtab</class>
</subwindow_record>

<tabs_recordsheet name="tabs" merge="join">
<tab mergerule="add" />
<tab>
<icon>myicon</icon>
<subwindow>newtab</subwindow>
</tab>
</tabs_recordsheet>
</sheetdata>
</windowclass>
</root>


This is why it takes me forever to code these things - I've barely started and already blown hours figuring out this one line I needed to overwrite several layers below what is even visible to me.

superteddy57
September 9th, 2020, 07:14
Good find. Glad it worked out for you and posting the solution.