Spacetime-Meta / spacetime-sdk

The spacetime-sdk is a turnkey virtual environment package for building in the Spacetime Metaverse
https://www.spacetimemeta.io/metaverse/spawn-planet
MIT License
11 stars 2 forks source link

Bring interface logic in StdEnv #60

Closed Liquid-Blocks closed 2 years ago

Liquid-Blocks commented 2 years ago

As of now, the elements of UI are hard coded in the examples index.html as seen in the picture below Image

This is very inconvenient for the manipulation and upgrades of the menu. For this reason we should migrate the UI logic inside the StdEnv.

The approach I propose is to create a UIController class. Then, inside that class, create individual class for each menu panel. Each class should look something like:

The UIController should be able to insert elements in the HTML dom with createElement() and appendChild().

For the simplification of this issue, only the graphic button should be implemented. The two other menu panels (id="fly-out" and id="blocker") can be ignored, the UI will be rebuild in coming issues.

Liquid-Blocks commented 2 years ago

After experimenting with the proposed approach, I have problems with the event listener for the button.

The problem is because when handling the click event, the button must call functions that belongs to the StdEnv class. Now even if the called function is passed as a builder argument, it is not executed in the right context and can not access the StdEnv attributes it is suppose to update.

This is the implementation I first tried with and did not work because of the problem stated above. image

The second solution is to simply create buttons as functions of the StdEnv as seen bellow: image

This second solution does not block the increaseGraphicSettings from accessing the other StdEnv methods. I will keep experimenting with this approach and look for solutions to send this UI logic in a different file.

Liquid-Blocks commented 2 years ago

This is the solution for now, later we ca transfer the logic in an other class if we find how image