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

Request: Save event accessible to scripts #1733

Open
Atkana opened this issue Dec 19, 2020 · 1 comment
Open

Request: Save event accessible to scripts #1733

Atkana opened this issue Dec 19, 2020 · 1 comment
Labels
idea Suggestions, etc.

Comments

@Atkana
Copy link

Atkana commented Dec 19, 2020

It would be useful for scripts that save their own data if the pre-save hook open to plugins (or something similar) was also available in scripts. Currently, scripts can work around the lack of hooks for saving when the world is unloaded, but require hacky workarounds if they also want to save their data during autosaves.

@lethosor lethosor added the idea Suggestions, etc. label Dec 20, 2020
@lethosor
Copy link
Member

lethosor commented Dec 20, 2020

For reference:

  • Relevant logic that fires plugin_save_data callbacks defined in plugins:

    dfhack/library/Core.cpp

    Lines 2009 to 2013 in de21e0c

    if ((df::global::ui->main.autosave_request && !d->last_autosave_request) ||
    (is_load_save && !d->was_load_save && strict_virtual_cast<df::viewscreen_savegamest>(screen)))
    {
    doSaveData(out);
    }
  • Handling of the onStateChange event in Lua (a similar approach could probably work here - unsure if an event under dfhack or an eventful event would make more sense yet):
    Lua::Core::onStateChange(out, event);

    dfhack/library/LuaTools.cpp

    Lines 1849 to 1850 in de21e0c

    Lua::Push(State, code);
    Lua::Event::Invoke(out, State, (void*)onStateChange, 1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea Suggestions, etc.
Projects
None yet
Development

No branches or pull requests

2 participants