From fc384fd1a2bee65315fe79831a55ca74c8e6717b Mon Sep 17 00:00:00 2001 From: Warmist Date: Sun, 12 Jun 2022 17:12:49 +0300 Subject: [PATCH] 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> --- docs/Lua API.rst | 27 ++++++++++++++++----------- docs/changelog.txt | 1 + plugins/lua/eventful.lua | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/docs/Lua API.rst b/docs/Lua API.rst index bbcf0b145..55a217757 100644 --- a/docs/Lua API.rst +++ b/docs/Lua API.rst @@ -4587,35 +4587,40 @@ on DF world 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). -3. ``onProjItemCheckMovement(projectile)`` +4. ``onProjItemCheckMovement(projectile)`` Is called when projectile moves. -4. ``onProjItemCheckImpact(projectile,somebool)`` +5. ``onProjItemCheckImpact(projectile,somebool)`` Is called when projectile hits something. -5. ``onProjUnitCheckMovement(projectile)`` +6. ``onProjUnitCheckMovement(projectile)`` Is called when projectile moves. -6. ``onProjUnitCheckImpact(projectile,somebool)`` +7. ``onProjUnitCheckImpact(projectile,somebool)`` 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. -8. ``postWorkshopFillSidebarMenu(workshop)`` +9. ``postWorkshopFillSidebarMenu(workshop)`` Is called after calling (or not) native fillSidebarMenu(). Useful for job button tweaking (e.g. adding custom reactions) @@ -4683,7 +4688,7 @@ Functions 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)`` @@ -4715,7 +4720,7 @@ Reaction complete example:: 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) -- spawn dragonbreath after 100 ticks dfhack.timeout(100,"ticks",function() dfhack.maps.spawnFlow(pos,6,0,0,50000) end) diff --git a/docs/changelog.txt b/docs/changelog.txt index 4c034b5bc..1302cf82e 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -40,6 +40,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Fixes - ``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 +- `eventful`: fix ``eventful.registerReaction`` to correctly pass ``call_native`` argument thus allowing canceling vanilla item creation. Updated related documentation. ## Misc Improvements - `confirm`: added a confirmation dialog for removing manager orders diff --git a/plugins/lua/eventful.lua b/plugins/lua/eventful.lua index 293874393..b1520dac1 100644 --- a/plugins/lua/eventful.lua +++ b/plugins/lua/eventful.lua @@ -93,7 +93,7 @@ end function registerReaction(reaction_name,callback) _registeredStuff.reactionCallbacks=_registeredStuff.reactionCallbacks or {} _registeredStuff.reactionCallbacks[reaction_name]=callback - onReactionComplete._library=onReact + onReactionCompleting._library=onReact dfhack.onStateChange.eventful=unregall end