Advertisement

How logic can wait the ui in a full separate architecture ?

Started by December 04, 2021 06:16 PM
2 comments, last by Shaarigan 3 years ago

Hello everyone, it's been a few days since I decided to separate the UI from the logic part in my turn-based battle game (j-rpg). I did this for two reasons, the first is code portability, the second because it is good practice. I had to because I can launch effects or use objects from the battle but also from the menu!

I manage the communicate like that :
- ui → logic: classic function calls
- logic → ui: event emissions

But now I'm stuck when it comes to the following use case: How do I get the logical part to wait for the interface? In my case, when launching an effect on a character, the interface must launch an animation, then the logic code must "wait" for the animation to be finished to continue and proceed with the damage.

I made a pseudo-solution with callbacks (because I work with js) however I am not satisfied because it forces me to pass the callback each time and everywhere, especially in a loop where it is impossible for me to do it.

It's ok, i just found the solution, magic word is service !

Advertisement

If you have to await completion of an async call to go further, why not use Promise.then instead?

This topic is closed to new replies.

Advertisement