Skip to content

gui/mod-manager improvements #1481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

ong-yinggao98
Copy link
Contributor

@ong-yinggao98 ong-yinggao98 commented Jul 12, 2025

Requires DFHack/dfhack#5500

The manager also notifies users when a version of a vanilla module in their preset has been changed. This way they should know to update the preset to avoid the popup in future. Since mod manager no longer gives a hoot about the vanilla module versions, an entirely vanilla preset for 51.13 should theoretically also be backwards compatible with an older version.

image

TODO

@ab9rf
Copy link
Member

ab9rf commented Jul 12, 2025

I suspect the reason why fields.src_dir[i].value:startswith('data/vanilla') does not work is because fields.src_dir[i].value is a C++ string (being accessed via proxy), not a Lua string, and so the Lua method startswith (which is defined for Lua strings but not for C++ strings) doesn't work.

@ong-yinggao98
Copy link
Contributor Author

ong-yinggao98 commented Jul 12, 2025

I suspect the reason why fields.src_dir[i].value:startswith('data/vanilla') does not work is because fields.src_dir[i].value is a C++ string (being accessed via proxy), not a Lua string, and so the Lua method startswith (which is defined for Lua strings but not for C++ strings) doesn't work.

Interesting, but in that case why does it work in script-manager.lua::get_active_mods()? It seems to call startswith just fine and the target seems to also be a C++ string.

-- local ol = df.global.world.object_loader
        local path = ol.object_load_order_src_dir[idx].value
        table.insert(mods, {
            id=ol.object_load_order_id[idx].value,
            name=ol.object_load_order_name[idx].value,
            version=ol.object_load_order_displayed_version[idx].value,
            numeric_version=ol.object_load_order_numeric_version[idx],
            path=path,
            vanilla=path:startswith('data/vanilla/'), -- windows also uses forward slashes
        })

@SilasD
Copy link

SilasD commented Jul 12, 2025

maybe forcing it into a Lua string would work? untested code.

tostring(fields.src_dir[i].value):startswith('data/vanilla')

Edit: Your comment in gui/mod-manager.lua shows this code:
from_fields.src_dir[i].startswith('data/vanilla')
That doesn't work the same as this edited code:
from_fields.src_dir[i]:startswith('data/vanilla')
The . was changed to :, to comply with Lua's object-oriented style string functions.

@ab9rf
Copy link
Member

ab9rf commented Jul 13, 2025

Interesting, but in that case why does it work in script-manager.lua::get_active_mods()? It seems to call startswith just fine and the target seems to also be a C++ string.

-- local ol = df.global.world.object_loader
        local path = ol.object_load_order_src_dir[idx].value
        table.insert(mods, {
            id=ol.object_load_order_id[idx].value,
            name=ol.object_load_order_name[idx].value,
            version=ol.object_load_order_displayed_version[idx].value,
            numeric_version=ol.object_load_order_numeric_version[idx],
            path=path,
            vanilla=path:startswith('data/vanilla/'), -- windows also uses forward slashes
        })

Because local path = ol.object_load_order_src_dir[idx].value results in it being converted from a C++ string to a Lua string, and so path:startswith is looking for that named method on a Lua string.

This is an artifact of how our C++ object proxying into Lua works. When you directly "read" from a C++ string in order to use its value as a Lua value, the proxy handler automatically converts it into a Lua string. However, when you call a method directly on an object, this doesn't happen: instead, the metatable of the C++ proxy object is consulted, and as there is no startswith method in the C++ string proxy object metatable, the method call fails.

It might be an idea to "chain" the Lua string metatable onto the C++ string proxy metatable, but I'm not at all sure how to go about doing this. Will require considerable thought.

Copying the proxy object into a local variable before calling the method should provide a workaround since the C++ proxy object will be converted to a Lua object at that time.

@ong-yinggao98
Copy link
Contributor Author

I haven't tried SilasD's suggestion, but ab9rf's works like a charm.

@ong-yinggao98 ong-yinggao98 changed the title Edits to the mod manager gui/mod-manager version compatibility Jul 13, 2025
@ong-yinggao98 ong-yinggao98 changed the title gui/mod-manager version compatibility gui/mod-manager improvements Jul 13, 2025
@ong-yinggao98 ong-yinggao98 marked this pull request as ready for review July 13, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mod Manager does not automatically update vanilla mods gui/mod-manager should be able to automatically apply mods to the Object Testing Arena
3 participants