Editor API - How to assign the existing event listener to button element?

I made the new ‘Texture element’ but I am so confused at how to add the event listener that exists on other ‘Texture elements’. I do know that I would assign it with:

[span/div/button name].addEventListener('click', () => /* this I miss */));

I just can’t seem to find the function that is responsible for assigning the textures. Here is the image on where I am stuck.

Do I need to create my own function for it or is there a way to assign the existing function/listener?

Ok, step back for a moment. What do you want to achieve? Forget about JavaScript

I think you are trying to automate something in the editor, or add a function.

If you want to do that, stop trying to hack it, there is an API.

I am not trying to automate anything, I am trying to create sprite sheet editor using userscripts (learning how do it as I go, I am terrible but it’s more fun that way).

When you click on add texture button, in inspector, it lets you choose which texture you want to assign to the element. I created a brand new texture element (with divs/spans/buttons) but it doesn’t listen to anything (clicks, drags, etc.) like it does on their texture elements. I am just trying to find which function does their add texture button listen to so that I can assign it as well and use it.

I suggest you to use the API, it’s literally for your use scenario.

I’m not familiar with it, but there you have the necessary functions to do that. In the link I shared you have an example where they use ViolentMonkey (to manage the userscripts) and a link to the documentation.

I am using ViolentMonkey for the scripts because they are using it, but, I somehow missed their GitHub API documentation… my bad on that one (I was going trough console like a lunatic).

Will look for how the texture asset is assigned and slowly go from there. Probably somewhere in api/asset :smiley:

@JustVlaxx I found the function to do the asset picking when you click on the pencil. I don’t think it is part of the official Editor API though

In picker-asset.js, you can find the method and others yourself.


Wow, you really didn’t have to go trough all that for me. I still don’t know how to bind their methods to the button so I made my own function to handle the assignment of textures by doing:

editor.selection.item._observer.entity....... :smiley:

Still, thank you very, very much man! You’re a saint. Will definitely use their methods once I realize how to call them with my buttons!

1 Like

This is what I have for now, did show to Leonidas, he really is a wealth of information…

It really is a blast messing with this.