PDA

View Full Version : Help with merging templates



damned
March 14th, 2020, 03:47
Hi team,

I have an extension that needs to modify the CoreRPG chatwindow_step template.
My requirement is to add new modeframes

I have added 7 lines like below to the existing 3

<modeframe mode="group" name="chatframe_group" offset="40,10,10,40" />

I have not been successful in doing any combinations of merge in regards to this and so included the whole template in my extension with the changes.

The issue is this breaks compatibility with other extensions that modify this template - namely the ondemand manual dice and the 2E ruleset

What is breaking there is that script replaces the script in this line

<script file="desktop/scripts/chat_window.lua">

Any suggestions on how I can merge in just the new modeframes?

celestian
March 14th, 2020, 04:04
I've also been tinkering with options to try and get around this. Currently the template I use for the chatwindow_step is....



<template name="chatwindow_step">
<chatwindow name="chat" merge="join">
<linkicon normal="button_link" pressed="button_link_down" mergerule="replace" />
<script file="desktop/scripts/chat_window_adnd.lua" mergerule="replace"/>
</chatwindow>
</template>



To be honest I'm not sure if merge/replace works in templates (not run extensive testing). That said the above does WORK. The script that runs from this does some replacement for onDrop to capture the dice drop and look for "control" being pressed and if so do something.

If there is something I can do to make these coexist I'll happily do it. I've tried various things but I've had no luck but I've not had time to do extensive testing.

Moon Wizard
March 14th, 2020, 05:31
The merge/mergerule attributes work within template definitions to define how templates are merged together when they are layered. The template definitions themselves (i.e. template name="...") do not support merge attributes.

When I need to do this, I just copy the original template, and make the changes to the copy in the new layer. You can get more complex, but that's the easiest.

Regards,
JPG

damned
March 14th, 2020, 06:04
Hi Moon Wizard,

That is what I have done. So the challenge is to make it co-exist with another extension that changes only the script file.
Can you think of a way to change which script the template will use based on something like this?


for k,v in pairs(Extension.getExtensions()) do
if string.find(v,"onDemandManualDice") then
**use ondemand extension script**
return true;
else **use corerpg script**
end
end


Or some other way?

Otherwise ill do two versions.

Moon Wizard
March 14th, 2020, 06:29
Yeah, working with another extension is challenging. I do have some near term stuff planned for extensions working with multiple rulesets, but nothing like what you need right now.

Usually, I check for existence of a global script to determine whether an extension is loaded, but the getExtensions() method works too. Usually, both extensions need to be written to work well with the other, so they can work together without stomping on each other. Needing custom templates makes that a little harder.

Two versions is probably simplest for short term.

Regards,
JPG

celestian
March 14th, 2020, 06:43
Yeah, working with another extension is challenging. I do have some near term stuff planned for extensions working with multiple rulesets, but nothing like what you need right now.

Usually, I check for existence of a global script to determine whether an extension is loaded, but the getExtensions() method works too. Usually, both extensions need to be written to work well with the other, so they can work together without stomping on each other. Needing custom templates makes that a little harder.

Two versions is probably simplest for short term.

Regards,
JPG

If the merge bits work shouldn't he be able to insert the bit he needs and they both will "include" the parts both added? Far as I know he's not changing the script that I am, just adding some modeframes.



<template name="chatwindow_step">
<chatwindow name="chat" merge="join">
<modeframe mode="world" name="chatframe_world" offset="40,10,10,40" />
<modeframe mode="place" name="chatframe_place" offset="40,10,10,40" />
<modeframe mode="group" name="chatframe_group" offset="40,10,10,40" />
<modeframe mode="religion" name="chatframe_religion" offset="40,10,10,40" />
<modeframe mode="clue" name="chatframe_clue" offset="40,10,10,40" />
</chatwindow>
</template>


But, he said that didn't work.

Moon Wizard
March 14th, 2020, 07:39
You can't merge two templates. They're purely layered. The merge/mergerule attributes just affect how each tag merges when they're layered.

Regards,
JPG

celestian
March 14th, 2020, 07:54
You can't merge two templates. They're purely layered. The merge/mergerule attributes just affect how each tag merges when they're layered.

Regards,
JPG

Ah, ok misunderstood then.

Bugger, this is going to be a pain ;)

LillySprout
October 25th, 2020, 00:24
For the modeframe issue, I recently ran into this myself - the solution seems to be to make the changes where the templates are used.

ie, I was trying in template_desktop.xml


<?xml version="1.0" encoding="iso-8859-1"?>

<root merge="join">
<template name="chatwindow_step" merge="join">
<chatwindow name="chat" merge="join">
<modeframe mode="lillabilities" name="chatframe_lillability" offset="5,5,5,5"/>
</chatwindow>
</template>
</root>

and ran into the issue where this would knock out all existing modeframes. What worked instead was going in desktop_classes.xml and doing


<root>
<windowclass name="chat" merge="join">
<sheetdata merge = "join">
<chatwindow name="chat" merge="join">
<modeframe mode="lillabilities" name="chatframe_lillability" offset="5,5,5,5" mergerule="add"/>
</chatwindow>
</sheetdata>
</windowclass>
<windowclass name="chatlocal" merge="join">
<sheetdata merge = "join">
<chatwindow name="chat" merge="join">
<modeframe mode="lillabilities" name="chatframe_lillability" offset="5,5,5,5" mergerule="add"/>
</chatwindow>
</sheetdata>
</windowclass>
</root>

with the caveat that I also had to go change the code of the other extension that added its own modeframe and do the same there for them to co-exist.