diff options
author | orwell <orwell@bleipb.de> | 2025-05-27 21:17:10 +0200 |
---|---|---|
committer | orwell <orwell@bleipb.de> | 2025-05-27 21:17:10 +0200 |
commit | 3470687be0af7254aca478ead1e9c72757edf070 (patch) | |
tree | 41781361c979cfda61a924d7471978037d68005e /ch_core/hotbar.lua | |
parent | 8506dd2825b715293138976a5ad1fa11a46206a7 (diff) | |
download | advtrains-cesky-hvozd.tar.gz advtrains-cesky-hvozd.tar.bz2 advtrains-cesky-hvozd.zip |
Add CH dependencies temporarily.cesky-hvozd
Before merge to master should remove them again and split out util functions (e.g. formspec lib)
Diffstat (limited to 'ch_core/hotbar.lua')
-rw-r--r-- | ch_core/hotbar.lua | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/ch_core/hotbar.lua b/ch_core/hotbar.lua new file mode 100644 index 0000000..054210f --- /dev/null +++ b/ch_core/hotbar.lua @@ -0,0 +1,49 @@ +ch_core.open_submod("hotbar") + +function ch_core.predmety_na_liste(player, jako_pole) + local result = {} + if not player then + return result + end + local inv = player:get_inventory() + if not inv then + return result + end + local hotbar = inv:get_list("main") + if not hotbar then + return result + end + local hotbar_length = player:hud_get_hotbar_itemcount() + + if not hotbar_length then + hotbar_length = 8 + elseif hotbar_length > 32 then + hotbar_length = 32 + elseif hotbar_length < 1 then + hotbar_length = 1 + end + + if jako_pole then + for i = 1, hotbar_length, 1 do + local name = hotbar[i]:get_name() + if name and name ~= "" then + local t = result[name] + if t then + table.insert(t, i) + else + result[name] = {i} + end + end + end + else + for i = hotbar_length, 1, -1 do + local name = hotbar[i]:get_name() + if name and name ~= "" then + result[name] = i + end + end + end + return result +end + +ch_core.close_submod("hotbar") |