Jump to content

Modding pregame page in 0 A.D. 28


Mentula
 Share

Recommended Posts

Hi devs and modders,

In 0 A.D. 27 and before it was possible to mod the pregame page by adding scripts to the gui/pregame folder. Example of applications are: adding items to the main menu; running startup scripts.

Since commit 0fcc4f5fc5 the gui/pregame directory is not loaded anymore, in favour of loading the mainmenu.js file only. It is not clear how mod scripts can run in this page after this change.

 It is not an option to override mainmenu.js, mainmenu.xml, page_pregame.xml or other files. This will of course break the compatibility with other mods, as only the last loaded mod will execute the code.

Maybe @phosit, do you have an idea? I am pinging you as the author of the change.

Thanks.

  • Like 1
Link to comment
Share on other sites

20 minutes ago, Stan` said:

Can't you add a file like autociv like so ~mainmenu.js to extend it ?

That's the point. If the directory gui/pregame was loaded by the xml - like it was before:

<script directory="gui/pregame/"/>

then one could create a file named mainmenu~MyMod.js and do all sort of scripting therein (for example making proxies of existing functions).

But this is not the case anymore for the pregame page. At first glance, this is the only page which changed behaviour. To make a comparison, session.xml is still loading the entire directory gui/session:

<script directory="gui/session/"/>

 

32 minutes ago, Stan&#x60; said:

Nice to see you're still active!

I wish I was! :) New release, new work for porting mods. I played my last game in 2023, but 0 A.D. is always in my heart. :heart:

Link to comment
Share on other sites

There is an example in "binaries/data/mods/test.scriptinterface/module/modified/".

In your example you would write a file "mainmenu~local_rating.append.js".

In that file you can override the init-fuction or anything else.

init = function()
{
	// new init code.
}

 

Link to comment
Share on other sites

With "any content" do you mean "no content"? Then that's expected. An empty file shouldn't change the behaviour. eg: appending nothing to the mainmenu.js doesn't change anything.

When adding a `warn` call at global scope of the "append" file, it works for me.

Link to comment
Share on other sites

@phosit right, I was too quick. So, what works and what does not:

 gui/pregame/mainmenu~MyMod.append.js

✖ gui/pregame/mainmenu~MyMod.js

The second approach has worked in all versions prior 28 - and this was "the" established practice, as far as I could see. It looks like the "append" keyword has a special meaning for evaluation of files (I tried with other keywords). Then I have two questions:

  1. Should modders be advised to rename all files of the form "module~MyMod.js" with "module~MyMod.append.js"?
  2. If so, could this be explicited somewhere? Probably not so relevant here https://gitea.wildfiregames.com/0ad/0ad/wiki/PortA27ToR28, but it would have helped.
  • Like 1
Link to comment
Share on other sites

I was dabbling into this too. In my case i simply needed an extra main menu button, doing 

let grapejuice =  {
        "caption": translate("Grapejuice Info"),
        "tooltip": translate("View the changes that this mod brings to the game."),
        "onPress": () => {
            Engine.OpenChildPage("page_grapejuice.xml");
        }
    };

mainMenuItems.unshift(grapejuice)

into `MainMenuItems~grapejuice.append` Seems to be clean and works well if i do the same in another mod. However if the variable name is the same in some other mod it will hardcrash on startup. Even if you let the variable out of it and just do 

mainMenuItems.unshift
(
    {
        "caption": translate("Grapejuice Info"),
        "tooltip": translate("View the changes that this mod brings to the game."),
        "onPress": () => {
            Engine.OpenChildPage("page_grapejuice.xml");
        }
    }
)

in 2 different mods it will hardcrash aswell. Not sure why and if this the recommended way of doing it anyway.

Edited by Grapjas
Link to comment
Share on other sites

The "append" keyword has to be used where modules are used. It's tracked here. Note: Modules are enabled in the GUI doesn't mean that in the whole GUI modules are used (IIRC in R28 only in pregame and splashscreen). I wouldn't make .append the default. It serves as distinction between appendixes and plain files.

@GrapjasYes that's the (my) desired way of doing it. And it's weird that it doesn't work. (I tested appending multiple files. I think it's something about the content of the files. The next line is appended without a newline. Maybe the implicit semicolon doesn't work at the end of a file.)

When the file would get to big you could also import some variables:

import { menuEntry } from "gui/pregame/grapjasAdditions.js";

mainMenuItems.unshift(menuEntry);

 

Edited by phosit
De-recomend defaulting to .append
  • Like 2
Link to comment
Share on other sites

Thank you for the clarification @phosit

I think the info you just provided should be added to this guide: https://gitea.wildfiregames.com/0ad/0ad/wiki/PortA27ToR28

And possibly to this guide too: https://gitea.wildfiregames.com/0ad/0ad/wiki/Modding_Guide

Porting mods to R28 is not straightforward without this piece of information.

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