implement clear tiles

develop
Myk Taylor 2023-10-30 16:27:14 -07:00
parent c98da947b8
commit 8ca03982d5
No known key found for this signature in database
3 changed files with 29 additions and 23 deletions

@ -110,3 +110,6 @@ select the entire volume instead of just the selected area on the z-level that
you are currently looking at. you are currently looking at.
In addition, double-clicking will start a flood fill from the target tile. In addition, double-clicking will start a flood fill from the target tile.
The box and flood fill actions respect the UI setting for whether the burrow is
being added to or erased.

@ -221,13 +221,36 @@ static bool get_bounds(lua_State *L, int idx, df::coord &pos1, df::coord &pos2)
get_int_field(L, idx, "z2", &pos2.z); get_int_field(L, idx, "z2", &pos2.z);
} }
static df::burrow* get_burrow(lua_State *L, int idx) {
df::burrow *burrow = NULL;
if (lua_isuserdata(L, idx))
burrow = Lua::GetDFObject<df::burrow>(L, idx);
else if (lua_isstring(L, idx))
burrow = Burrows::findByName(luaL_checkstring(L, idx));
else if (lua_isinteger(L, idx))
burrow = df::burrow::find(luaL_checkinteger(L, idx));
return burrow;
}
static int burrow_tiles_clear(lua_State *L) { static int burrow_tiles_clear(lua_State *L) {
color_ostream *out = Lua::GetOutput(L); color_ostream *out = Lua::GetOutput(L);
if (!out) if (!out)
out = &Core::getInstance().getConsole(); out = &Core::getInstance().getConsole();
DEBUG(status,*out).print("entering burrow_tiles_clear\n"); DEBUG(status,*out).print("entering burrow_tiles_clear\n");
// TODO
return 0; int32_t count = 0;
lua_pushnil(L); // first key
while (lua_next(L, 1)) {
df::burrow * burrow = get_burrow(L, -1);
if (burrow) {
count += burrow->block_x.size();
Burrows::clearTiles(burrow);
}
lua_pop(L, 1); // remove value, leave key
}
Lua::Push(L, count);
return 1;
} }
static int burrow_tiles_set(lua_State *L) { static int burrow_tiles_set(lua_State *L) {
@ -257,17 +280,6 @@ static int burrow_tiles_remove(lua_State *L) {
return 0; return 0;
} }
static df::burrow* get_burrow(lua_State *L, int idx) {
df::burrow *burrow = NULL;
if (lua_isuserdata(L, idx))
burrow = Lua::GetDFObject<df::burrow>(L, idx);
else if (lua_isstring(L, idx))
burrow = Burrows::findByName(luaL_checkstring(L, idx));
else if (lua_isinteger(L, idx))
burrow = df::burrow::find(luaL_checkinteger(L, idx));
return burrow;
}
static int box_fill(lua_State *L, bool enable) { static int box_fill(lua_State *L, bool enable) {
df::coord pos_start, pos_end; df::coord pos_start, pos_end;
bool dry_run = false, zlevel = false; bool dry_run = false, zlevel = false;

@ -2,20 +2,11 @@ local _ENV = mkmodule('plugins.burrow')
--[[ --[[
Native events: Provided events:
* onBurrowRename(burrow) * onBurrowRename(burrow)
* onDigComplete(job_type,pos,old_tiletype,new_tiletype) * onDigComplete(job_type,pos,old_tiletype,new_tiletype)
Native functions:
* findByName(name) -> burrow
* copyUnits(dest,src,enable)
* copyTiles(dest,src,enable)
* setTilesByKeyword(dest,kwd,enable) -> success
'enable' selects between add and remove modes
--]] --]]
local overlay = require('plugins.overlay') local overlay = require('plugins.overlay')