This wiki is archived from 2021-09-05

Example Mod Chat Alert

From Planetary Annihilation: TITANS and Classic PA Wiki
Revision as of 01:22, 15 December 2017 by DeathByDenim (talk | contribs) (Created page with "Category:Modding = 50px Example Mod: Chat Alert = This example will demonstrate how to make a client mod that changes how the user interface works...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

File:Titans-icon.png Example Mod: Chat Alert

This example will demonstrate how to make a client mod that changes how the user interface works.

File:Gold-rank-icon.png Chat Alert

Here we will modify the inner workings of the UI. We are going to play an audible alert when somebody types a new message in-game or in the lobby. This will also demonstrate how to add settings for the mod in the PA Settings screen.

File:Gold-rank-icon.png Mod structure

To create a new local client mod, navigate to the Planetary Annihilation Data Directory and if it does not already exist, create a new directory called "client_mods". Inside that directory create a directory for our new mod, for example: "com.pa.you.chat-alert". And inside of that directory, create a new text file called "modinfo.json". This will contain the information about our mod. It should look like this:

 {
   "context": "client",
   "identifier": "com.pa.you.chat-alert",
   "display_name": "Chat alert",
   "description": "Audible alerts when somebody type in lobby or in-game chat.",
   "author": "You",
   "version": "1.0",
   "build": "105067",
   "date": "2017-12-10",
   "signature": "not yet implemented",
   "forum": "",
   "priority": 100,
   "icon": "",
   "category": ["gameplay", "lobby", "ui"],
   "scenes":
   {
     "new_game":
     [
       "coui://ui/mods/com.pa.you.chatalert/new_game.js"
     ],
     "live_game_chat":
     [
       "coui://ui/mods/com.pa.you.chatalert/live_game_chat.js"
     ],
     "settings":
     [
       "coui://ui/mods/com.pa.you.chatalert/settings.js"
     ]
   }
 }


See here for more details on the meaning of these entries. However, important for this mod are the entries for `"scenes"`. Here will tell the mod manager which parts of the UI we will inject new JavaScript into.

Next, we are going to add the files we are going to add. Since we are defining new files, we should take care that we do not accidentally shadow existing PA files or of other mods. One way of doing that is adding our own subdirectory. So create a new folder "ui" and inside that folder create "mods", and inside of that folder create "com.pa.you.chat-alert". By reusing our mod identifier like this, we can be certain we are not affecting anything else. Notice that we already used this directory structure in the `"scenes"` above.

Now we should have the following structure:

File:Gold-rank-icon.png Adding JavaScript

File:Gold-rank-icon.png Testing

Start Planetary Annihilation and go to Community Mods. Under the Installed tab, you should see the mod you just created. Click on it and click the Enable button.

File:Gold-rank-icon.png Publishing

See Submitting Your Released Mod for details on how to publish your mod.