Skip to content
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

Plugins in Main Menu #6386

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

Conversation

bunnybot
Copy link

NordfrieseMirrored from Codeberg
Created on Thu Feb 29 11:49:44 CET 2024 by Benedikt Straub (Nordfriese)


Type of change
New feature for v1.3

Issue(s) closed
Plugins can now also be used in the main menu.

How it works
Example add-on

The main class for the main menu is called wl.ui.MainMenu. It offers all the usual Lua UI functions (including create_child() and get_child() and all others), and support for timers.

Plugin scripts are run in the main menu automatically like in the game and editor. Check for the existence of the classes wl.ui.MainMenu or wl.ui.MapView to determine whether you're in the menu or game/editor. All game modules such as wl.Game, wl.Editor, and wl.Descriptions are not available (nil) in the main menu.

When you modify enabled or installed plugin add-ons in the add-ons manager, the Lua interface is reset and all plugins reloaded. It is not however possible to keep track of modifications made by scripts; therefore, it is up to the script to check that it does not repeat interface modifications from earlier runs (see the example add-on's init.lua to see what I mean).

As a bonus, Lua's built-in print() now redirects to our own log_dbg() for better Lua debug logging.

Possible regressions

  • Timers (also in-game)
  • The main menu's UI and Lua interfacing
  • Error handling for main menu Lua scripts

Screenshots
shot0000.png

@bunnybot bunnybot added this to the v1.3 milestone Feb 29, 2024
@bunnybot bunnybot self-assigned this Feb 29, 2024
@bunnybot
Copy link
Author

Assigned to Nordfriese

@bunnybot bunnybot added enhancement New feature or request lua Lua scripts and scripting interface addon Problems and requests related to add-ons labels Feb 29, 2024
@bunnybot
Copy link
Author

bunnybot commented Feb 29, 2024

tothxaMirrored from Codeberg
On Thu Feb 29 13:38:44 CET 2024, Tóth András (tothxa) wrote:


As a bonus, Lua's built-in print() now redirects to our own log_dbg() for better Lua debug logging.

Shouldn't this get its own log type? (LogType::kLua / log_lua() / prefix "LUA") print() may be used for any log level, not just debug. (well, that also means that we may consider adding *log_*() to the lua API, including the verb_* and *_time variants in addition to this — probably in a separate log lua module)

Actually I think this would normally be better separated into its own PR if we were in the middle of a release cycle, and could merge it quickly.

(sigh... I liked how lua output stood out... :) but of course I understand that this is the right thing to do)

@bunnybot
Copy link
Author

NordfrieseMirrored from Codeberg
On Thu Feb 29 18:25:37 CET 2024, Benedikt Straub (Nordfriese) wrote:


Real *log* functions are non-trivial because of the passthrough of variadic arguments. Separating it out into a new PR also doesn't make sense during feature freeze, though I can do that if desired after the release. Will push a commit for the new log type.

@bunnybot
Copy link
Author

tothxaMirrored from Codeberg
On Thu Feb 29 19:07:08 CET 2024, Tóth András (tothxa) wrote:


Real *log* functions are non-trivial because of the passthrough of variadic arguments.

The messages can be assembled in lua, so the lua log functions would only accept a single string. (pass it on as log_info("%s", arg_from_lua.c_str())) Even the gametime can be added in the C++ implementation for the *_time() variants.

@bunnybot
Copy link
Author

bunnybot commented Feb 29, 2024

tothxaMirrored from Codeberg
On Thu Feb 29 23:06:20 CET 2024, Tóth András (tothxa) wrote:


Re last commit: Could you please make it like lua does it, and log a single line with all arguments to print() concatenated with tabs (like lua) or spaces (probably suffices)? I think usually that's the intention of the user. (at least I often use it lazily like that)

Also lua reports the object type too, not just the pointer address, which is often very useful...

edit: and I believe nil is missing too

@bunnybot
Copy link
Author

bunnybot commented Mar 1, 2024

tothxaMirrored from Codeberg
On Fri Mar 01 10:36:13 CET 2024, Tóth András (tothxa) wrote:


Thank you very much! :) Printing code now looks good, but not tested yet.

@bunnybot bunnybot changed the title WIP: Plugins in Main Menu Plugins in Main Menu Mar 23, 2024
@bunnybot bunnybot added the ci:success CI checks succeeded label Apr 2, 2024
@bunnybot bunnybot removed the ci:success CI checks succeeded label Apr 4, 2024
@bunnybot bunnybot added ci:success CI checks succeeded and removed ci:success CI checks succeeded labels Apr 22, 2024
@bunnybot bunnybot added ci:success CI checks succeeded and removed ci:success CI checks succeeded labels May 1, 2024
@bunnybot bunnybot added ci:success CI checks succeeded and removed ci:success CI checks succeeded labels May 4, 2024
@bunnybot bunnybot added ci:success CI checks succeeded and removed ci:success CI checks succeeded labels May 12, 2024
@bunnybot bunnybot added ci:success CI checks succeeded and removed ci:success CI checks succeeded labels May 19, 2024
@bunnybot bunnybot added ci:success CI checks succeeded and removed ci:success CI checks succeeded labels May 22, 2024
@bunnybot bunnybot removed the ci:success CI checks succeeded label May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addon Problems and requests related to add-ons enhancement New feature or request lua Lua scripts and scripting interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants