Jump to content

About modding public components


Hoze
 Share

Recommended Posts

Hi!

The modding guide explains that public components can be changed by re-defining it's functions in the prototype global objects.

ModdingGuiAndSimulation

Autociv is a mod that seems to modify public components, but it isn't clear for me what it's doing. I couldn't find the matching functions, in the game's public components, that Autociv is redefining.

I hoped to learn from an example as my attempts with the syntax gathered no useful informations.

I try to mod g_SelectionPanels.Alert mods/public/gui/session/selection_panels.js that starts like this:

// Cache some formation info
// Available formations per player
var g_AvailableFormations = new Map();
var g_FormationsInfo = new Map();

var g_SelectionPanels = {};

var g_SelectionPanelBarterButtonManager;

g_SelectionPanels.Alert = {
    "getMaxNumberOfItems": function()
    {
        return 2;
    },

[...]

How should I go about it?

Edited by Hoze
Link to comment
Share on other sites

Well those aren't components, they are GUI files, so either they have a functional style or they use ES2015 class syntax.

To override them you need to create a file that will be called after the one you wanna change and just add the variables you wanna change.

  • Like 1
Link to comment
Share on other sites

Thanks!
I did try to put the file in my mod folder:
   /MyMod/gui/session/selection_panels.js

Like it is in the public folder of the game:
   /public/gui/session/selection_panels.js

But I was getting js errors (the file selection_panels.js HASN'T been edited yet from the source, and the error won't occur when I remove the file again)

ERROR: Error calling component script function ScriptCall

ERROR: Errors executing script event "SimulationUpdate"

ERROR: JavaScript error: gui/session/selection_panels.js line 1051 getRequirementsTooltip is not defined setupButton@gui/session/selection_panels.js:1051:1 setupUnitPanel@gui/session/unit_commands.js:94:35 updateUnitCommands@gui/session/unit_commands.js:152:18 updateSelectionDetails@gui/session/selection_details.js:537:20 updateGUIObjects@gui/session/session.js:730:2 onSimulationUpdate@gui/session/session.js:680:2 __eventhandler54 (SimulationUpdate)@session SimulationUpdate:1:1

So my guess was that I still have to do something special because it's a file in /public?

Edited by Hoze
Link to comment
Share on other sites

If I overwrite the whole file, is this expected to cause issues?

1. If I overwrite the whole file (with a unmodified copy of itself for simplicity) I get errors:

    "redeclaration of 'let g_panelsOrder'."

In short I'm doing just that: putting the "selection_panels.js" unmodified into /MyMod/gui/session/

So It must be something about it I'm missing...

2. If I remove the declaration of 'let g_PanelsOrder' as only modification in "selection_panels.js"  I get new js errors, of undeclared methods, such as:

   "getRequirementsTooltip is not defined"

 

I'm just trying to add a new button on the game's alert panel, and I feel stuck on it! :ok: I haven't found any mods that do something similar that I can check on. The modding guide has an exemple where a ressource is added to the Batter Panel, but following it didn't help me understand what am I doing wrong above.

 

Link to comment
Share on other sites

Hellooo @Hoze!

If you want to add a button as a mod the same way autociv does it you can do this:

1. Look for the xml file that defines the buttons where you want to add the new button.
2. Create a copy of that file with same folder structure and same file name in your mod (we do this due to 0ad pyrogenesis engine limitaton, we can't create gui objects with javascript on the fly)
3. Add your button on the xml 

 On the javascript side, you said you want to modify selection_panels.js . To do that create a new file with same folder structure with the name like this selection_panels~myMod.js

We add ~ so that is loaded after selection_panels.js and then add suffix  myMod  so that you can identify the file is yours and not another mod or random file.

Inside the file do any runtime modification necessary for you button

Remember: the original file selection_panel.js will be executed before yours so code accordingly to that assumption.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Wow thanks @nani!

I had the list of files to modify right, as they are listed in the modding guide.
But I wasn't realizing the original selection_panel.js would still be executed! I was taking the therm "overwrite the file" literally, when actually you are just redefining the the stuff in it. This was causing me to not understand the errors popping up.

Now I can get it to work thanks to you, and it's fun! Thanks you so much! :weee:

 

I'm grateful 0AD is that good of a game and project. B)

Edited by Hoze
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...