Update eventful.lua (#2203)

* Update eventful.lua

Had wrong function. Fixes https://github.com/DFHack/dfhack/issues/2202

* Update Lua API.rst

Update docs to add onReactionCompleting and remove outdated info

* Update Lua API.rst

Some more minor doc fixes

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add changelog entry

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
develop
Warmist 2022-06-12 17:12:49 +03:00 committed by GitHub
parent 1a629a26bf
commit fc384fd1a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 12 deletions

@ -4587,35 +4587,40 @@ on DF world events.
List of events List of events
-------------- --------------
1. ``onReactionComplete(reaction,reaction_product,unit,input_items,input_reagents,output_items,call_native)`` 1. ``onReactionCompleting(reaction,reaction_product,unit,input_items,input_reagents,output_items,call_native)``
Auto activates if detects reactions starting with ``LUA_HOOK_``. Is called when reaction finishes. Is called once per reaction product, before reaction had a chance to call native code for item creation.
Setting ``call_native.value=false`` cancels further processing: no items are created and ``onReactionComplete`` is not called.
2. ``onItemContaminateWound(item,unit,wound,number1,number2)`` 2. ``onReactionComplete(reaction,reaction_product,unit,input_items,input_reagents,output_items)``
Is called once per reaction product, when reaction finishes and has at least one product.
3. ``onItemContaminateWound(item,unit,wound,number1,number2)``
Is called when item tries to contaminate wound (e.g. stuck in). Is called when item tries to contaminate wound (e.g. stuck in).
3. ``onProjItemCheckMovement(projectile)`` 4. ``onProjItemCheckMovement(projectile)``
Is called when projectile moves. Is called when projectile moves.
4. ``onProjItemCheckImpact(projectile,somebool)`` 5. ``onProjItemCheckImpact(projectile,somebool)``
Is called when projectile hits something. Is called when projectile hits something.
5. ``onProjUnitCheckMovement(projectile)`` 6. ``onProjUnitCheckMovement(projectile)``
Is called when projectile moves. Is called when projectile moves.
6. ``onProjUnitCheckImpact(projectile,somebool)`` 7. ``onProjUnitCheckImpact(projectile,somebool)``
Is called when projectile hits something. Is called when projectile hits something.
7. ``onWorkshopFillSidebarMenu(workshop,callnative)`` 8. ``onWorkshopFillSidebarMenu(workshop,callnative)``
Is called when viewing a workshop in 'q' mode, to populate reactions, useful for custom viewscreens for shops. Is called when viewing a workshop in 'q' mode, to populate reactions, useful for custom viewscreens for shops.
8. ``postWorkshopFillSidebarMenu(workshop)`` 9. ``postWorkshopFillSidebarMenu(workshop)``
Is called after calling (or not) native fillSidebarMenu(). Useful for job button Is called after calling (or not) native fillSidebarMenu(). Useful for job button
tweaking (e.g. adding custom reactions) tweaking (e.g. adding custom reactions)
@ -4683,7 +4688,7 @@ Functions
1. ``registerReaction(reaction_name,callback)`` 1. ``registerReaction(reaction_name,callback)``
Simplified way of using onReactionComplete; the callback is function (same params as event). Simplified way of using onReactionCompleting; the callback is function (same params as event).
2. ``removeNative(shop_name)`` 2. ``removeNative(shop_name)``
@ -4715,7 +4720,7 @@ Reaction complete example::
b=require "plugins.eventful" b=require "plugins.eventful"
b.registerReaction("LUA_HOOK_LAY_BOMB",function(reaction,unit,in_items,in_reag,out_items,call_native) b.registerReaction("LAY_BOMB",function(reaction,unit,in_items,in_reag,out_items,call_native)
local pos=copyall(unit.pos) local pos=copyall(unit.pos)
-- spawn dragonbreath after 100 ticks -- spawn dragonbreath after 100 ticks
dfhack.timeout(100,"ticks",function() dfhack.maps.spawnFlow(pos,6,0,0,50000) end) dfhack.timeout(100,"ticks",function() dfhack.maps.spawnFlow(pos,6,0,0,50000) end)

@ -40,6 +40,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Fixes ## Fixes
- ``widgets.CycleHotkeyLabel``: allow initial option values to be specified as an index instead of an option value - ``widgets.CycleHotkeyLabel``: allow initial option values to be specified as an index instead of an option value
- ``job.removeJob()``: fixes regression in DFHack 0.47.05-r5 where items/buildings associated with the job were not getting disassociated when the job is removed. Now `build-now` can build buildings and `gui/mass-remove` can cancel building deconstruction again - ``job.removeJob()``: fixes regression in DFHack 0.47.05-r5 where items/buildings associated with the job were not getting disassociated when the job is removed. Now `build-now` can build buildings and `gui/mass-remove` can cancel building deconstruction again
- `eventful`: fix ``eventful.registerReaction`` to correctly pass ``call_native`` argument thus allowing canceling vanilla item creation. Updated related documentation.
## Misc Improvements ## Misc Improvements
- `confirm`: added a confirmation dialog for removing manager orders - `confirm`: added a confirmation dialog for removing manager orders

@ -93,7 +93,7 @@ end
function registerReaction(reaction_name,callback) function registerReaction(reaction_name,callback)
_registeredStuff.reactionCallbacks=_registeredStuff.reactionCallbacks or {} _registeredStuff.reactionCallbacks=_registeredStuff.reactionCallbacks or {}
_registeredStuff.reactionCallbacks[reaction_name]=callback _registeredStuff.reactionCallbacks[reaction_name]=callback
onReactionComplete._library=onReact onReactionCompleting._library=onReact
dfhack.onStateChange.eventful=unregall dfhack.onStateChange.eventful=unregall
end end