Skip to content

Commit

Permalink
support removing river sources
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Sep 3, 2023
1 parent af4cef2 commit aa5adbb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Template for new versions:
- `caravan`: optionally display items within bins in bring goods to depot screen
- `gui/gm-editor`: display in the title bar whether the editor window is scanning for live updates
- `gui/design`: change "auto commit" hotkey from ``c`` to ``Alt-c`` to avoid conflict with the default keybinding for z-level down
- `gui/liquids`: support removing river sources by converting them into stone floors

## Removed

Expand Down
49 changes: 41 additions & 8 deletions gui/liquids.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function SpawnLiquid:init()
{ label = "Magma", value = df.tile_liquid.Magma, pen = COLOR_RED },
{ label = "River", value = df.tiletype.RiverSource, pen = COLOR_BLUE },
},
initial_option = 0,
initial_option = df.tile_liquid.Water,
on_change = function(new, _)
self.type = new
self.tile = SpawnLiquidCursor[new]
Expand All @@ -84,10 +84,11 @@ function SpawnLiquid:init()
{ label = "Click", value = SpawnLiquidPaintMode.CLICK, pen = COLOR_WHITE },
{ label = "Drag ", value = SpawnLiquidPaintMode.DRAG, pen = COLOR_WHITE },
},
initial_option = 1,
initial_option = SpawnLiquidPaintMode.DRAG,
on_change = function(new, _) self.paint_mode = new end,
},
widgets.CycleHotkeyLabel{
view_id = 'mode1',
frame = {l = 18, b = 2},
label = 'Mode:',
auto_width = true,
Expand All @@ -98,9 +99,28 @@ function SpawnLiquid:init()
{ label = "Remove", value = SpawnLiquidMode.REMOVE, pen = COLOR_WHITE },
{ label = "Clean ", value = SpawnLiquidMode.CLEAN, pen = COLOR_WHITE },
},
initial_option = 1,
on_change = function(new, _) self.mode = new end,
disabled = function() return self.type == df.tiletype.RiverSource end
initial_option = SpawnLiquidMode.SET,
on_change = function(new, _)
self.mode = new
self.subviews.mode2:setOption(new)
end,
visible = function() return self.type ~= df.tiletype.RiverSource end
},
widgets.CycleHotkeyLabel{
view_id = 'mode2',
frame = {l = 18, b = 2},
label = 'Mode:',
auto_width = true,
key = 'CUSTOM_X',
options = {
{ label = "Set ", value = SpawnLiquidMode.SET, pen = COLOR_WHITE },
{ label = "Remove", value = SpawnLiquidMode.REMOVE, pen = COLOR_WHITE },
},
on_change = function(new, _)
self.mode = new
self.subviews.mode1:setOption(new)
end,
visible = function() return self.type == df.tiletype.RiverSource end
},
}
end
Expand Down Expand Up @@ -143,9 +163,22 @@ function SpawnLiquid:spawn(pos)
tile.water_salt = false
tile.water_stagnant = false
elseif self.type == df.tiletype.RiverSource then
map_block.tiletype[pos.x % 16][pos.y % 16] = df.tiletype.RiverSource

liquids.spawnLiquid(pos, 7, df.tile_liquid.Water)
if self.mode == SpawnLiquidMode.REMOVE then
local commands = {
'f', 'any', ';',
'f', 'sp', 'river_source', ';',
'p', 'any', ';',
'p', 's', 'floor', ';',
'p', 'sp', 'normal', ';',
'p', 'm', 'stone', ';',
}
dfhack.run_command('tiletypes-command', table.unpack(commands))
dfhack.run_command('tiletypes-here', '--quiet', ('--cursor=%d,%d,%d'):format(pos2xyz(pos)))
liquids.spawnLiquid(pos, 0, df.tile_liquid.Water)
else
map_block.tiletype[pos.x % 16][pos.y % 16] = df.tiletype.RiverSource
liquids.spawnLiquid(pos, 7, df.tile_liquid.Water)
end
else
liquids.spawnLiquid(pos, self:getLiquidLevel(pos), self.type)
end
Expand Down

0 comments on commit aa5adbb

Please sign in to comment.