This wiki is archived from 2021-09-05
New game user interface scene
File:Titans-icon.png Planetary Annihilation New Game User Interface Scene
Path: /ui/main/game/new_game/
Scene name: New Game
Server script state: /server-script/states/lobby.js
The new_game user interface is loaded when:
- host creates a new game
- player or spectator joins a game in the lobby state
File:Gold-rank-icon.png Preventing the need for a host refresh
When a host creates a new game the user interface is displayed before any server mods are loaded requiring a host refresh to load any updated user interface provided by a server mod.
A refresh can be triggered by the host using any of the following:
- manual refresh (default binding of F5)
- navigating to another user interface scene eg load_planet when selecting a system
The current approach to avoid the need for a host refresh is:
- include the new game modifications in both the server mod and a dependent client mod
- check if the client mod has already been loaded
- load any assets manually using loadCss, loadHtml, etc (to prevent double loading if specified in modinfo scenes.new_game)
Note: This may change when side loading of companion client mods is implemented.
server modinfo.json snippet
{
"identifier": "com.pa.my-unique-mod-name",
"context": "server",
...
"scenes":
{
"new_game": "coui://ui/mods/com.pa.my-unique-mod-name/new_game.js"
...
"dependencies":
[
"com.pa.my-unique-mod-name-client"
...
client modinfo.json snippet
{
"identifier": "com.pa.my-unique-mod-name-client",
"context": "client",
...
"scenes":
{
"new_game": "coui://ui/mods/com.pa.my-unique-mod-name/new_game.js"
...
...
"dependencies":
[
"com.pa.my-unique-mod-name"
...
shared new_game.js snippet
var myUniqueModNameLoaded;
function myUniqueModName()
{
if myUniqueModNameLoaded )
{
return;
}
myUniqueModNameLoaded = true;
// do stuff
}
try
{
myUniqueModName();
}
catch (e)
{
console.error(e);
}
My personal preference is a named function in preference to an immediately-invoked function expression (IIFE).