Passer au contenu principal
Version: bleeding-edge 🩸

Écran de chargement

In nanos world it is possible to add a customized and dynamic Loading Screen to your Server using WebUI.

Création d'un écran de chargement

Pour cela, vous devez créer un nouveau Package de type loading-screen, et ajouter vos fichiers HTML/CSS/JS dans le dossier racine du Package. Votre fichier HTML principal doit s'appeler index.html. Votre dossier devrait ressembler à cela :

Packages/
└── my-loading-screen/
├── Package.toml
├── index.html
├── style.css
└── ...

Accéder à la progression de chargement/téléchargement

To be able to display dynamic information in the screen, you can listen to the Event UpdateScreen (which will trigger every few ms):

L'évènement UpdateScreen

ParamètreDescription
messageDisplay the current state (loading, validating, downloading...)
message_secondaryAffiche le fichier/asset actuel en cours de chargement/téléchargement
progress_smallProgression du fichier en cours de chargement/téléchargement
progress_small_totalTaille du fichier en cours de chargement/téléchargement
progressProgression actuelle
progress_totalProgression totale
current_stageThe number value representing the current stage of the load (0 = None, 1 = Connecting, 2 = Fetching, 3 = Validating, 4 = Downloading, 5 = LoadingAssets, 6 = LoadingLevel, 7 = LoadingEntities, 8 = CompilingShaders, 9 = Finishing)
Packages/my-loading-screen/index.js
Events.Subscribe("UpdateScreen", function(message, message_secondary, progress_small, progress_small_total, progress, progress_total, current_stage) {
// Mettre à jour l'HTML ici
});
tip

You can use progress and progress_total for filling up the main loading bar, and progress_small for a small/sub loading bar.

info

Toujours utiliser progress / progress_total pour récupérer le pourcentage % actuel, car progress_total représente le nombre total de fichiers en cours de téléchargement.

Informations sur le joueur

Also, it is possible to fetch Player’s information by accessing a global variable called LoadingScreen:

var LoadingScreen = {
server: {
ip,
port,
name,
description,
},
player: {
nanos_id,
nanos_username,
steam_id,
}
}
tip

The LoadingScreen var is only available a few frames after the Loading Screen browser is created.

Arrêter la musique du menu

Il est possible de désactiver la musique du menu intégré en appelant un événement à partir du JS de l'écran de chargement:

Packages/my-loading-screen/index.js
Events.Call("StopMenuMusic")

Configurer votre serveur pour utiliser l'écran de chargement

Note

Currently Loading Screens only work in Dedicated Servers.
Make sure you configure your server's Config.toml as dedicated_server = true.

After creating your loading-screen package, you will need to configure your server to load it in your Config.toml. Dans loading_screen, mettez simplement le nom du dossier de votre Package.

Server/Config.toml
# le package loading-screen à charger (l'écran de chargement sera affiché quand les joueurs rejoindront votre serveur)
loading_screen = "my-loading-screen"

Or start it with --loading_screen "my-loading-screen".