Mod API - allow mods to add strategic icons

Post here if you want to help developing something for FAF.

Mod API - allow mods to add strategic icons

Postby wodzu_93 » 28 Nov 2019, 19:05

Hello!
I'd like to request mounting an extra directory in init, to allow mods for adding new strategic icons.

Game only reads strategic icons from textures/ui/common/game/strategicicons (regular) and textures/ui/icons_strategic (optional big icons in building panel). The only way for modders to add them currently is to pack them into an .scd and put it in the gamedata folder, which has to be done manually and is prone to overlooking by the users.

I'm asking to mount mods/<mod_name>/textures/ui directories as textures/ui, which will enable us modders to remove the need for manual installation of strategic icons.

Following code added to init_faf.lua in bin folder works in achieving this. At least it did on my end.
Code: Select all
function mount_strategic_icons(MODFOLDER)
    for _,mod in io.dir( MODFOLDER..'\\*.*') do
        if mod != '.' and mod != '..' then
            for _,folder in io.dir(MODFOLDER..'\\'..mod..'\\*.*') do
                if folder == 'textures' then
          for _,folder in io.dir(MODFOLDER..'\\'..mod..'\\textures\\*.*') do
         if folder == 'ui' then
                          LOG('Found mod icons in: '..mod)
                          mount_dir(MODFOLDER..'\\'..mod..'\\textures\\ui', '/textures/ui')
                          break
         end
          end
                end
            end
        end
    end
end
mount_strategic_icons(SHGetFolderPath('PERSONAL') .. 'My Games\\Gas Powered Games\\Supreme Commander Forged Alliance\\mods')
mount_strategic_icons(InitFileDir .. '\\..\\user\\My Games\\Gas Powered Games\\Supreme Commander Forged Alliance\\mods')
User avatar
wodzu_93
 
Posts: 5
Joined: 30 Sep 2019, 17:18
Has liked: 0 time
Been liked: 1 time
FAF User Name: AdamK

Re: Mod API - allow mods to add strategic icons

Postby Uveso » 28 Nov 2019, 21:30

I like the idea.

How does it work ?

Can you overwrite original icon files, or only add new icons ?
Is it possible to add/change the optional big icons ?
Do we need a sim or a UI mod for this ?

Is there an working example mod to test this ?
User avatar
Uveso
Supreme Commander
 
Posts: 1600
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 60 times
Been liked: 253 times
FAF User Name: Uveso

Re: Mod API - allow mods to add strategic icons

Postby wodzu_93 » 28 Nov 2019, 22:07

It should allow to both add and override vanilla icons. Using an .scd works (advanced strategic icons mod does that) so this should too.

Scd files in gamedata folder have a path of "root" ( /), unlike mods ( /mods/<mod_name> ). Game expects strategic icons to be in textures/ui/common/game/strategicicons, so placing then in mod folder doesn't work ( /mods/<mod_name>/textures/ui/common/game/strategicicons ). What that code does is register textures in the mod folder as a root directory, so game can see those icons. Same goes for the big icons, and this should classify as an UI mod, as it is just textures.

Uveso, I'm asking for this because I added a lot of custom strategic icons to Total Mayhem Lite, and right now you have to manually install them by copying a file. If this is implemented it will be working without that step.
User avatar
wodzu_93
 
Posts: 5
Joined: 30 Sep 2019, 17:18
Has liked: 0 time
Been liked: 1 time
FAF User Name: AdamK

Re: Mod API - allow mods to add strategic icons

Postby Anihilnine » 29 Nov 2019, 00:52

this is awesome. did u make sure it doesn't desync when 2 players have different packs?
Anihilnine
Moderator
 
Posts: 2309
Joined: 16 Apr 2013, 10:10
Has liked: 274 times
Been liked: 409 times
FAF User Name: Anihilnine

Re: Mod API - allow mods to add strategic icons

Postby Uveso » 29 Nov 2019, 16:04

@wodzu_93:

The only problem i see; How can this mod be disabled ?
If we change the init file then those textures will be loaded no matter if the mod is switched on or off.

If this is the case then this mod is not different then placing a .SCD file somewhere.

@Anihilnine:
The changes folder is inside "textures/ui".
"UI" changes can't desync, they are not running through the sim.
User avatar
Uveso
Supreme Commander
 
Posts: 1600
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 60 times
Been liked: 253 times
FAF User Name: Uveso

Re: Mod API - allow mods to add strategic icons

Postby wodzu_93 » 29 Nov 2019, 18:21

@Uveso
Yes, you're right that textures will always be loaded. However it is JUST textures, so I think its fine. Main benefit of this would be simple installation/deinstallation - just hit "install" / "uninstall" in the vault and done. So for texture pack mods this is fine, as you'd want to use them all the time anyways.

Also, you can divide your mods if you want - I could, for example, publish my expanded strategic icon set as its own mod that is just a dependency for others and is not listed in the mod selection in game:
Code: Select all
selectable = false    <---- Not in the in-game mod list!
enabled = true
exclusive = false
ui_only = true
requires = {}

As it doesn't do anything by itself other than allocate some memory to the textures, it could just be left active with no problems.
User avatar
wodzu_93
 
Posts: 5
Joined: 30 Sep 2019, 17:18
Has liked: 0 time
Been liked: 1 time
FAF User Name: AdamK


Return to Contributors

Who is online

Users browsing this forum: No registered users and 1 guest