This wiki is archived from 2021-09-05

New game user interface scene: Difference between revisions

From Planetary Annihilation: TITANS and Classic PA Wiki
Jump to navigation Jump to search
(Created page with "Category:Modding = 50px Planetary Annihilation New Game User Interface Scene = '''Path''': /ui/main/game/new_game/ '''Scene name''': New Game '...")
 
Line 26: Line 26:
* include the new game modifications in both the server mod and a dependent client mod
* include the new game modifications in both the server mod and a dependent client mod
* check if the client mod has already been loaded
* 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)


'''server modinfo.json snippet'''
  <nowiki>
  <nowiki>
{
{
Line 35: Line 37:
     {
     {
         "new_game": "coui://ui/mods/com.pa.my-unique-mod-name/new_game.js"
         "new_game": "coui://ui/mods/com.pa.my-unique-mod-name/new_game.js"
...
  "dependencies":
  [
      "com.pa.my-unique-mod-name-client"
...
...
</nowiki>
</nowiki>
 
'''client modinfo.json snippet'''
  <nowiki>
  <nowiki>
{
{
Line 46: Line 52:
     {
     {
         "new_game": "coui://ui/mods/com.pa.my-unique-mod-name/new_game.js"
         "new_game": "coui://ui/mods/com.pa.my-unique-mod-name/new_game.js"
...
...
  "dependencies":
  [
      "com.pa.my-unique-mod-name"
...
...
</nowiki>
</nowiki>
 
'''shared new_game.js snippet'''
  <nowiki>
  <nowiki>


Line 60: Line 71:
     }
     }


    loadCss( '
     myUniqueModNameLoaded = true;
     myUniqueModNameLoaded = true;


Line 76: Line 86:


</nowiki>
</nowiki>
My personal preference is a named function in preference to an immediately-invoked function expression (IIFE).

Revision as of 19:32, 1 April 2016

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)

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).