melonjs / melonJS

a fresh, modern & lightweight HTML5 game engine
https://melonjs.org
MIT License
5.92k stars 643 forks source link

feat: handle assets load error #1204

Closed z0mb1 closed 1 year ago

z0mb1 commented 1 year ago

Userstory: I am trying to load project, but due to problems with the internet connection some of my assets load fails. I don't want to reload page and load whole project again. I want to upload again only failed assets.

Example decision: add notification about load failure with button to upload this asset again using rePreload function

obiot commented 1 year ago

Hi, I like this idea of indeed being able to retry preloading assets in case the network is not stable.

Just one thing not clear in the example you provided in the source code where to you put the below code ? My only concern is about this feature being a user choice. what I mean is that by default we still have the current behaviour, but then you can choose to try re-preloading certain element.

@example 
   event.on(
       event.LOADER_ERROR,
       (res) => {
           // custom function
           showErrorNotification({
               text: `Error during loading content: ${res.name}`,
               done: loader.rePreload(res.src);
           })
       }
   );
z0mb1 commented 1 year ago

Hi, I like this idea of indeed being able to retry preloading assets in case the network is not stable.

Just one thing not clear in the example you provided in the source code where to you put the below code ? My only concern is about this feature being a user choice. what I mean is that by default we still have the current behaviour, but then you can choose to try re-preloading certain element.

@example 
   event.on(
       event.LOADER_ERROR,
       (res) => {
           // custom function
           showErrorNotification({
               text: `Error during loading content: ${res.name}`,
               done: loader.rePreload(res.src);
           })
       }
   );

Hi. We could put the code itself in the onload function, or any other function that is called when the application is initialized. my example is really quite specific. But this is due to the fact that the processing of unloaded assets can be implemented at the discretion of the user. In my example, as in my project, the function calls a notification with a button to reload. But you can do it in another way. For example, on a custom loading screen, display all unloaded assets. Also, I didn't use the standard UI, and I can assume that the implementation of this function will depend on the frameworks and libraries used. I would appreciate it if we could come up with a more understandable example together.

Снимок экрана 2023-10-11 в 14 42 27
obiot commented 1 year ago

Hi Sorry, for the late feedback, and got it, and I will definitely give it a try once merged and think about how I would use it (to come up with an example)

Last comment or request before merging, can we maybe rename rePreload() to reload() ? I just feel the name rePreload is kind of strange :P

z0mb1 commented 1 year ago

Hi Sorry, for the late feedback, and got it, and I will definitely give it a try once merged and think about how I would use it (to come up with an example)

Last comment or request before merging, can we maybe rename rePreload() to reload() ? I just feel the name rePreload is kind of strange :P

sure, done

obiot commented 1 year ago

merged ! :)

thank you so much again for your contribution !