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

Allow passing in custom params to Item.create() that get set before on_init_params #206

Closed
Ruin0x11 opened this issue Mar 11, 2021 · 0 comments · Fixed by #286
Closed

Allow passing in custom params to Item.create() that get set before on_init_params #206

Ruin0x11 opened this issue Mar 11, 2021 · 0 comments · Fixed by #286
Labels
enhancement New feature or request modding Concerns new modding features beyond the scope of porting vanilla's codebase.

Comments

@Ruin0x11
Copy link
Owner

Ruin0x11 commented Mar 11, 2021

Say I want to change which character gets displayed on a card or figure, using an event hook. Normally I would want to run this code inside on_item_generate or something:

local mod_card_image(item)
   item.params.chara_id = "elona.putit"
end

But this doesn't work, because what actually happens is inside the code in LootDrops for generating cards/figures, the parameter gets set after the item has been fully built and then an IDrawable gets registered based on its value. The drawable has no knowledge of updates to item.params.chara_id.

The main problem is the fact that we have no good way of modifying params while the object is being built while also allowing callbacks that depend on params to be run with the custom values we want. To solve this, we could separate random generation of params and initialization of the item based on params into two separate callbacks. That way you could have an event handler that gets run before the IDrawable gets initialized in the example, but after the params have been given default values.

Taking advantage of this, the example issue would be solved by doing what we already do with IActivity objects (and ought to do with feats also, see #110) by passing in a params table to Item.create() and similar.

Item.create("elona.card", map, { params = { chara_id = "elona.putit" } })
@Ruin0x11 Ruin0x11 added enhancement New feature or request modding Concerns new modding features beyond the scope of porting vanilla's codebase. labels Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request modding Concerns new modding features beyond the scope of porting vanilla's codebase.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant