diff --git a/changelog.txt b/changelog.txt index ed8173e73..0ebd730bb 100644 --- a/changelog.txt +++ b/changelog.txt @@ -38,6 +38,7 @@ Template for new versions: - `caravan`: fix doubled "total value of items marked for trade" after toggling filter options, and keep item marks when switching between filter views in the ``Bring goods to depot`` overlay - `fix/loyaltycascade`: guard against citizens that are not historical figures and emit a warning. - `gui/siegemanager`: fix nil index if there are no siege engines on the map +- `source`: report a useful error when no keyboard cursor is active ## Misc Improvements - `caravan`: the ``Bring goods to depot``, ``Trade``, and ``Assign items for display`` overlays now allow searching for items with non-ASCII characters in their description diff --git a/source.lua b/source.lua index 67d052f95..711c7324c 100644 --- a/source.lua +++ b/source.lua @@ -132,12 +132,12 @@ function main(args) end local targetPos = guidm.getCursorPos() - local index = find_liquid_source_at_pos(targetPos) if command == 'delete' then if not targetPos then qerror("Please place the cursor where there is a source to delete") end + local index = find_liquid_source_at_pos(targetPos) if index then delete_liquid_source(targetPos) print(('Deleted source at %s'):format(formatPos(targetPos))) diff --git a/test/source.lua b/test/source.lua new file mode 100644 index 000000000..10554899c --- /dev/null +++ b/test/source.lua @@ -0,0 +1,23 @@ +config = { + mode = 'fortress', + target = 'source', +} + +local guidm = require('gui.dwarfmode') +local source = reqscript('source') + +function test.delete_requires_cursor() + mock.patch(guidm, 'getCursorPos', function() end, function() + expect.error_match( + 'Please place the cursor where there is a source to delete', + function() source.main{'delete'} end) + end) +end + +function test.add_requires_cursor() + mock.patch(guidm, 'getCursorPos', function() end, function() + expect.error_match( + 'Please place the cursor where you would like a source', + function() source.main{'add', 'water'} end) + end) +end