Skip to content

Commit 5c9ae29

Browse files
committed
fixes as per code review completed (3)
1 parent 54539fb commit 5c9ae29

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

mods/bones/init.lua

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
-- Load support for MT game translation.
77
local S = minetest.get_translator("bones")
88

9-
local theoretical_max_slots = minetest.settings:get("bones_max_slots") or 15 * 10
9+
local bones_max_slots = minetest.settings:get("bones_max_slots") or 15 * 10
1010
local dead_player_callbacks={}
11+
-- we're going to display no less than 4*8 slots, we'll also provide at least 4*8 slots in bones
12+
local min_inv_size = 4 * 8
1113

1214
bones = {}
1315

@@ -58,15 +60,15 @@ end
5860

5961
local function get_bones_formspec_for_size(numitems)
6062
--the absolute minimum is 4*8
61-
if numitems <= 4 * 8 then
63+
if numitems <= min_inv_size then
6264
return get_bones_formspec_wh(8, 4)
6365
end
6466
--if we're over 4*8, but below 4*15 we make it 4 rows and adjust the column count to make everything fit
6567
if numitems <= 4 * 15 then
66-
return get_bones_formspec_wh(math.floor((numitems + 3) / 4), 4)
68+
return get_bones_formspec_wh(math.ceil(numitems / 4), 4)
6769
end
6870
--if we're over 4*15 we'll make 15 columns and adjust the row count to make everything fit
69-
return get_bones_formspec_wh(15, math.floor ((numitems + 14) / 15))
71+
return get_bones_formspec_wh(15, math.ceil(numitems / 15))
7072
end
7173

7274

@@ -288,7 +290,7 @@ minetest.register_on_dieplayer(function(player)
288290
bones_meta = minetest.get_meta(bones_pos)
289291
bones_inv = bones_meta:get_inventory()
290292
--make it so big that anything reasonable will for sure fit inside
291-
bones_inv:set_size("main", theoretical_max_slots)
293+
bones_inv:set_size("main", bones_max_slots)
292294
else
293295
bones_mode = "drop"
294296
bones_pos = nil
@@ -304,45 +306,46 @@ minetest.register_on_dieplayer(function(player)
304306
end
305307
end
306308

307-
local bones_conclusion
308-
local public_conclusion
309+
local log_message
310+
local chat_message
309311

310-
if not bones_pos then
311-
drop(player_pos, ItemStack("bones:bones"))
312-
if not dropped then
313-
bones_conclusion = "No bones placed"
314-
public_conclusion = S("@1 died at @2.", player_name, pos_string)
312+
if bones_pos then
313+
if dropped then
314+
log_message = "Inventory partially dropped"
315+
chat_message = "@1 died at @2, and partially dropped their inventory."
315316
else
316-
bones_conclusion = "Inventory dropped"
317-
public_conclusion = S("@1 died at @2, and dropped their inventory.", player_name, pos_string)
317+
log_message = "Bones placed"
318+
chat_message = "@1 died at @2, and bones were placed."
318319
end
319320
else
320-
if not dropped then
321-
bones_conclusion = "Bones placed"
322-
public_conclusion = S("@1 died at @2, and bones were placed.", player_name, pos_string)
321+
drop(player_pos, ItemStack("bones:bones"))
322+
if dropped then
323+
log_message = "Inventory dropped"
324+
chat_message = "@1 died at @2, and dropped their inventory."
323325
else
324-
bones_conclusion = "Inventory partially dropped"
325-
public_conclusion = S("@1 died at @2, and partially dropped their inventory.", player_name, pos_string)
326+
log_message = "No bones placed"
327+
chat_message = "@1 died at @2."
326328
end
327329
end
328330

329331
if bones_position_message then
330-
minetest.chat_send_player(player_name, public_conclusion)
332+
chat_message = S(chat_message, player_name, pos_string)
333+
minetest.chat_send_player(player_name, chat_message)
331334
end
332335

333-
minetest.log("action", player_name .. " dies at " .. pos_string .. ". " .. bones_conclusion)
336+
minetest.log("action", player_name .. " dies at " .. pos_string .. ". " .. log_message)
334337

335338
if bones_inv then
336-
local inv_size = theoretical_max_slots
337-
for i = 1, theoretical_max_slots do
339+
local inv_size = bones_max_slots
340+
for i = 1, bones_max_slots do
338341
local stack = bones_inv:get_stack("main", i)
339342
if stack:get_count() == 0 then
340343
inv_size = i - 1
341344
break
342345
end
343346
end
344-
if inv_size <= 4 * 8 then
345-
bones_inv:set_size("main", 4 * 8)
347+
if inv_size <= min_inv_size then
348+
bones_inv:set_size("main", min_inv_size)
346349
else
347350
bones_inv:set_size("main", inv_size)
348351
end

0 commit comments

Comments
 (0)