Sie sind nicht angemeldet.

Lieber Besucher, herzlich willkommen bei: krpano.com Forum. Falls dies Ihr erster Besuch auf dieser Seite ist, lesen Sie sich bitte die Hilfe durch. Dort wird Ihnen die Bedienung dieser Seite näher erläutert. Darüber hinaus sollten Sie sich registrieren, um alle Funktionen dieser Seite nutzen zu können. Benutzen Sie das Registrierungsformular, um sich zu registrieren oder informieren Sie sich ausführlich über den Registrierungsvorgang. Falls Sie sich bereits zu einem früheren Zeitpunkt registriert haben, können Sie sich hier anmelden.

kme

Fortgeschrittener

  • »kme« ist der Autor dieses Themas

Beiträge: 310

Wohnort: Belgium

Beruf: Long time coder, product manager and 3D enthousiast

  • Nachricht senden

1

Donnerstag, 23. März 2023, 10:46

Handling duplicate functions across plugins

While write some plugins, I have encountered a few times that there are conflicts in terms of functions/actions/styles.

For example:

Plugin 1: (simpleplugin.xml)
<action name="dosomething" scope="local"> doA() </action>

Plugin 1: (anotherplugin.xml)
<action name="dosomething" scope="local"> doB() </action>

in tour.xml, we have
<include url='simpleplugin.xml' />
<include url='anotherplugin.xml' />
<action name="dosomething" scope="local"> doC() </action>

What happens is that the functionality of "dosomething" is determined by the one that is "seen" last by krpano. Even if it is called from plugin 1, the functionality executed will be the one that is last "seen/loaded" by krpano.

I have not tested it with javascript plugins yet. But I assume that (global) actions defined withing the javascript plugin will have the same behaviour.

Same with layers/styles/...

For example,

Plugin 1:
<layer name="overlay"></layer>

Plugin 2:
<layer name="overlay"></layer>

Is not going to end up well *rolleyes*

I have read https://krpano.com/docu/xml/#action.scope, but that scope only applies to variables defined within the action.

My question
- is there a way to define private scopes for functions (and layers/hotspots/...) so that when I call an action from plugin1, the action from plugin1 is executed (and not the action from plugin2)
- any other suggestions? I now work around this with a naming convention (plugin1_dosomething()), but that adds a lot of typing *squint*

Looking forward to your suggestions!
KME

kme

Fortgeschrittener

  • »kme« ist der Autor dieses Themas

Beiträge: 310

Wohnort: Belgium

Beruf: Long time coder, product manager and 3D enthousiast

  • Nachricht senden

2

Donnerstag, 23. März 2023, 11:05

Tested with javascript plugins:

plugin1:
krpano.actions.dosomething = function() { ... };

plugin2:
krpano.actions.dosomething = function() { ... };

And in tour.xml I have

<plugin name="simpleplugin" url="simpleplugin.js"/>
<plugin name="simpleplugin2" url="simpleplugin2.js"/>
<action name="dosomething"> ... </action>

when i call "dosomething", the action from plugin2 is used.

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »kme« (23. März 2023, 11:16)


3

Donnerstag, 23. März 2023, 12:21

all the xml you load is merged,
so when you define the same action (name) in multiple xmls,
only the last one will exist.

actions are stored in the action array, you can check them by

Quellcode

1
2
3
for(set(i,0), i LT action.count, inc(i), 
trace(action[get(i)].name);
);

there can't be 2 actions with the same name.
this works exactly the same as with layers and hotspots
(check the docs about krpano arrays)

also mind that an included xml is not a krpano plugin.
real plugins are only possible in js and offer more possibilities
there you could create "local" actions like plugin[myname].dosomething()