diff --git a/compat/game21/custom_walls.lua b/compat/game21/custom_walls.lua index 8c2c4c0..db581cf 100644 --- a/compat/game21/custom_walls.lua +++ b/compat/game21/custom_walls.lua @@ -25,7 +25,7 @@ local function create_cw(deadly, collision) cw.collision = collision cw.deadly = deadly cw.killing_side = 0 - return handle + return handle - 1 end cws.cw_create = function() return create_cw(false, true) @@ -36,28 +36,30 @@ end cws.cw_createNoCollision = function() return create_cw(false, false) end -local function is_valid_handle(handle) +local function process_handle(handle) + handle = handle + 1 if custom_walls[handle] == nil then error("Trying to access invalid cw handle: " .. handle) end + return handle end cws.cw_destroy = function(handle) - is_valid_handle(handle) + handle = process_handle(handle) custom_walls[handle].visible = false free_handles[#free_handles + 1] = handle end cws.cw_setVertexPos = function(handle, vertex, x, y) - is_valid_handle(handle) + handle = process_handle(handle) custom_walls[handle].vertices[vertex * 2 + 1] = x custom_walls[handle].vertices[vertex * 2 + 2] = y end cws.cw_moveVertexPos = function(handle, vertex, offset_x, offset_y) - is_valid_handle(handle) + handle = process_handle(handle) custom_walls[handle].vertices[vertex * 2 + 1] = custom_walls[handle].vertices[vertex * 2 + 1] + offset_x custom_walls[handle].vertices[vertex * 2 + 2] = custom_walls[handle].vertices[vertex * 2 + 2] + offset_y end cws.cw_moveVertexPos4Same = function(handle, offset_x, offset_y) - is_valid_handle(handle) + handle = process_handle(handle) custom_walls[handle].vertices[1] = custom_walls[handle].vertices[1] + offset_x custom_walls[handle].vertices[2] = custom_walls[handle].vertices[2] + offset_y custom_walls[handle].vertices[3] = custom_walls[handle].vertices[3] + offset_x @@ -68,14 +70,14 @@ cws.cw_moveVertexPos4Same = function(handle, offset_x, offset_y) custom_walls[handle].vertices[8] = custom_walls[handle].vertices[8] + offset_y end cws.cw_setVertexColor = function(handle, vertex, r, g, b, a) - is_valid_handle(handle) + handle = process_handle(handle) custom_walls[handle].colors[vertex * 4 + 1] = r custom_walls[handle].colors[vertex * 4 + 2] = g custom_walls[handle].colors[vertex * 4 + 3] = b custom_walls[handle].colors[vertex * 4 + 4] = a end cws.cw_setVertexPos4 = function(handle, x0, y0, x1, y1, x2, y2, x3, y3) - is_valid_handle(handle) + handle = process_handle(handle) custom_walls[handle].vertices[1] = x0 custom_walls[handle].vertices[2] = y0 custom_walls[handle].vertices[3] = x1 @@ -86,7 +88,7 @@ cws.cw_setVertexPos4 = function(handle, x0, y0, x1, y1, x2, y2, x3, y3) custom_walls[handle].vertices[8] = y3 end cws.cw_setVertexColor4 = function(handle, r0, g0, b0, a0, r1, g1, b1, a1, r2, g2, b2, a2, r3, g3, b3, a3) - is_valid_handle(handle) + handle = process_handle(handle) custom_walls[handle].colors[1] = r0 custom_walls[handle].colors[2] = g0 custom_walls[handle].colors[3] = b0 @@ -105,7 +107,7 @@ cws.cw_setVertexColor4 = function(handle, r0, g0, b0, a0, r1, g1, b1, a1, r2, g2 custom_walls[handle].colors[16] = a3 end cws.cw_setVertexColor4Same = function(handle, r, g, b, a) - is_valid_handle(handle) + handle = process_handle(handle) for i = 0, 3 do custom_walls[handle].colors[i * 4 + 1] = r custom_walls[handle].colors[i * 4 + 2] = g @@ -114,35 +116,35 @@ cws.cw_setVertexColor4Same = function(handle, r, g, b, a) end end cws.cw_setCollision = function(handle, collision) - is_valid_handle(handle) + handle = process_handle(handle) custom_walls[handle].collision = collision end cws.cw_setDeadly = function(handle, deadly) - is_valid_handle(handle) + handle = process_handle(handle) custom_walls[handle].deadly = deadly end cws.cw_setKillingSide = function(handle, side) - is_valid_handle(handle) + handle = process_handle(handle) custom_walls[handle].killing_side = side end cws.cw_getCollision = function(handle) - is_valid_handle(handle) + handle = process_handle(handle) return custom_walls[handle].collision end cws.cw_getDeadly = function(handle) - is_valid_handle(handle) + handle = process_handle(handle) return custom_walls[handle].deadly end cws.cw_getKillingSide = function(handle) - is_valid_handle(handle) + handle = process_handle(handle) return custom_walls[handle].killing_side end cws.cw_getVertexPos = function(handle, vertex) - is_valid_handle(handle) + handle = process_handle(handle) return custom_walls[handle].vertices[vertex * 2 + 1], custom_walls[handle].vertices[vertex * 2 + 2] end cws.cw_getVertexPos4 = function(handle) - is_valid_handle(handle) + handle = process_handle(handle) return custom_walls[handle].vertices[1], custom_walls[handle].vertices[2], custom_walls[handle].vertices[3],