Fix some bugs and add some featurex
parent
6eb4dde2e0
commit
29279acf6a
|
@ -32,42 +32,39 @@ auriinventory.fragments["back"] = [[
|
|||
]]
|
||||
|
||||
function auriinventory.gen_fragment_recipebook(player)
|
||||
return '[]'
|
||||
if not player:get_attribute("rbook_page") then player:set_attribute("rbook_page", 0) end
|
||||
local cheat = player:get_attribute("cheatitems") or false
|
||||
|
||||
local inv_size = 6*10
|
||||
local page = tonumber(player:get_attribute("rbook_page"))
|
||||
if page < 0 then
|
||||
player:set_attribute("rbook_page",0)
|
||||
page = 0
|
||||
end
|
||||
if page*inv_size > auriinventory.itemcount then
|
||||
page = math.floor(auriinventory.itemcount / inv_size)
|
||||
player:set_attribute("rbook_page",page)
|
||||
end
|
||||
local start_index = page * inv_size
|
||||
|
||||
local ind = 1
|
||||
local fs = "label[12.6,0;Registered Items (" .. page+1 .. "/" .. math.floor(auriinventory.itemcount/inv_size)+1 .. ")]"
|
||||
for j = 0, 9 do
|
||||
for i = 0, 5 do
|
||||
if auriinventory.items[start_index + ind] then
|
||||
if cheat then
|
||||
fs = fs .. "item_image_button[" .. (12.6 + i*0.65) .. "," .. (0.45 + j*0.7) .. ";0.8,0.8;" .. auriinventory.items[start_index + ind] .. ";rbook_item_give_" .. (start_index + ind) .. ";]"
|
||||
else
|
||||
fs = fs .. "item_image_button[" .. (12.6 + i*0.65) .. "," .. (0.45 + j*0.7) .. ";0.8,0.8;" .. auriinventory.items[start_index + ind] .. ";rbook_item_recipe_" .. (start_index + ind) .. ";]"
|
||||
end
|
||||
end
|
||||
ind = ind + 1
|
||||
end
|
||||
end
|
||||
fs = fs .. "image_button[12.6,7.45;0.7,0.8;auriinventory_recipebook_icon_6.png;rbook_firstpage;;false;false;auriinventory_recipebook_icon_7.png]"
|
||||
fs = fs .. "image_button[13.1,7.45;0.7,0.8;auriinventory_recipebook_icon_0.png;rbook_prevpage;;false;false;auriinventory_recipebook_icon_1.png]"
|
||||
fs = fs .. "field[13.88,7.99;2.1,0.23;rbook_search;;]"
|
||||
fs = fs .. "image_button[15.45,7.45;0.7,0.8;auriinventory_recipebook_icon_2.png;rbook_nextpage;;false;false;auriinventory_recipebook_icon_3.png]"
|
||||
fs = fs .. "image_button[15.95,7.45;0.7,0.8;auriinventory_recipebook_icon_8.png;rbook_lastpage;;false;false;auriinventory_recipebook_icon_9.png]"
|
||||
return fs
|
||||
end
|
||||
|
||||
-- if not player:get_attribute("rbook_page") then player:set_attribute("rbook_page", 0) end
|
||||
-- local cheat = player:get_attribute("cheatitems") or false
|
||||
|
||||
-- local inv_size = 6*10
|
||||
-- local page = tonumber(player:get_attribute("rbook_page"))
|
||||
-- if page < 0 then
|
||||
-- player:set_attribute("rbook_page",0)
|
||||
-- page = 0
|
||||
-- end
|
||||
-- if page*inv_size > auriinventory.itemcount then
|
||||
-- page = math.floor(auriinventory.itemcount / inv_size)
|
||||
-- player:set_attribute("rbook_page",page)
|
||||
-- end
|
||||
-- local start_index = page * inv_size
|
||||
|
||||
-- local ind = 1
|
||||
-- local fs = "label[12.6,0;Registered Items (" .. page+1 .. "/" .. math.floor(auriinventory.itemcount/inv_size)+1 .. ")]"
|
||||
-- for j = 0, 9 do
|
||||
-- for i = 0, 5 do
|
||||
-- if auriinventory.items[start_index + ind] then
|
||||
-- if cheat then
|
||||
-- fs = fs .. "item_image_button[" .. (12.6 + i*0.65) .. "," .. (0.45 + j*0.7) .. ";0.8,0.8;" .. auriinventory.items[start_index + ind] .. ";rbook_item_give_" .. (start_index + ind) .. ";]"
|
||||
-- else
|
||||
-- fs = fs .. "item_image_button[" .. (12.6 + i*0.65) .. "," .. (0.45 + j*0.7) .. ";0.8,0.8;" .. auriinventory.items[start_index + ind] .. ";rbook_item_recipe_" .. (start_index + ind) .. ";]"
|
||||
-- end
|
||||
-- end
|
||||
-- ind = ind + 1
|
||||
-- end
|
||||
-- end
|
||||
-- fs = fs .. "image_button[12.6,7.45;0.7,0.8;auriinventory_recipebook_icon_6.png;rbook_firstpage;;false;false;auriinventory_recipebook_icon_7.png]"
|
||||
-- fs = fs .. "image_button[13.1,7.45;0.7,0.8;auriinventory_recipebook_icon_0.png;rbook_prevpage;;false;false;auriinventory_recipebook_icon_1.png]"
|
||||
-- fs = fs .. "field[13.88,7.99;2.1,0.23;rbook_search;;]"
|
||||
-- fs = fs .. "image_button[15.45,7.45;0.7,0.8;auriinventory_recipebook_icon_2.png;rbook_nextpage;;false;false;auriinventory_recipebook_icon_3.png]"
|
||||
-- fs = fs .. "image_button[15.95,7.45;0.7,0.8;auriinventory_recipebook_icon_8.png;rbook_lastpage;;false;false;auriinventory_recipebook_icon_9.png]"
|
||||
-- return fs
|
||||
-- end
|
||||
|
|
105
recipebook.lua
105
recipebook.lua
|
@ -1,30 +1,62 @@
|
|||
local function spairs(t, order)
|
||||
-- collect the keys
|
||||
local keys = {}
|
||||
for k in pairs(t) do keys[#keys+1] = k end
|
||||
--[[
|
||||
Ordered table iterator, allow to iterate on the natural order of the keys of a
|
||||
table.
|
||||
|
||||
-- if order function given, sort by it by passing the table and keys a, b,
|
||||
-- otherwise just sort the keys
|
||||
if order then
|
||||
table.sort(keys, function(a,b) return order(t, a, b) end)
|
||||
else
|
||||
table.sort(keys)
|
||||
end
|
||||
Example:
|
||||
]]
|
||||
|
||||
-- return the iterator function
|
||||
local i = 0
|
||||
return function()
|
||||
i = i + 1
|
||||
if keys[i] then
|
||||
return keys[i], t[keys[i]]
|
||||
local function __genOrderedIndex( t )
|
||||
local orderedIndex = {}
|
||||
for key in pairs(t) do
|
||||
table.insert( orderedIndex, key )
|
||||
end
|
||||
end
|
||||
table.sort( orderedIndex )
|
||||
return orderedIndex
|
||||
end
|
||||
|
||||
local function orderedNext(t, state)
|
||||
-- Equivalent of the next function, but returns the keys in the alphabetic
|
||||
-- order. We use a temporary ordered key table that is stored in the
|
||||
-- table being iterated.
|
||||
|
||||
local key = nil
|
||||
--print("orderedNext: state = "..tostring(state) )
|
||||
if state == nil then
|
||||
-- the first time, generate the index
|
||||
t.__orderedIndex = __genOrderedIndex( t )
|
||||
key = t.__orderedIndex[1]
|
||||
else
|
||||
-- fetch the next value
|
||||
for i = 1,table.getn(t.__orderedIndex) do
|
||||
if t.__orderedIndex[i] == state then
|
||||
key = t.__orderedIndex[i+1]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if key then
|
||||
return key, t[key]
|
||||
end
|
||||
|
||||
-- no more value to return, cleanup
|
||||
t.__orderedIndex = nil
|
||||
return
|
||||
end
|
||||
|
||||
local function orderedPairs(t)
|
||||
-- Equivalent of the pairs() function on tables. Allows to iterate
|
||||
-- in order
|
||||
return orderedNext, t, nil
|
||||
end
|
||||
|
||||
--[[
|
||||
Register recipebook items
|
||||
iterate through all items and return an ordered list
|
||||
]]
|
||||
|
||||
function auriinventory.load_recipebook_and_reload()
|
||||
local titems = {}
|
||||
--Get item list oboi
|
||||
for key, val in pairs(minetest.registered_items) do
|
||||
for key, val in orderedPairs(minetest.registered_items) do
|
||||
if key and key ~= "" and key ~= nil then
|
||||
if not val.groups.not_in_creative_inventory then
|
||||
table.insert(titems, key)
|
||||
|
@ -32,39 +64,8 @@ function auriinventory.load_recipebook_and_reload()
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
for x, y in spairs(titems, function(t, a, b)
|
||||
return string.byte(string.sub(t[b], string.find(t[b], ":", 1)+1, string.find(t[b], ":", 1)+1))
|
||||
< string.byte(string.sub(t[a], string.find(t[a], ":", 1)+1, string.find(t[a], ":", 1)+1),1)
|
||||
end) do
|
||||
table.insert(auriinventory.items, y)
|
||||
end
|
||||
|
||||
titems = auriinventory.items
|
||||
auriinventory.items = {}
|
||||
|
||||
for x, y in spairs(titems, function(t, a, b)
|
||||
local ind = 1
|
||||
while true do
|
||||
local sA = string.sub(t[a], 1, string.find(t[a], ":", 1) - 1)
|
||||
local sB = string.sub(t[b], 1, string.find(t[b], ":", 1) - 1)
|
||||
|
||||
if not string.byte(sA, ind) then return true end
|
||||
if not string.byte(sB, ind) then return false end
|
||||
|
||||
if ind >= math.max(string.len(sA),string.len(sB)) then return nil end
|
||||
|
||||
if string.byte(sB,ind) > string.byte(sA,ind) then
|
||||
return true
|
||||
elseif string.byte(sB,ind) < string.byte(sA,ind) then
|
||||
return false
|
||||
end
|
||||
|
||||
ind = ind + 1
|
||||
end
|
||||
end) do
|
||||
table.insert(auriinventory.items, y)
|
||||
end
|
||||
auriinventory.items = titems;
|
||||
|
||||
print("Auriinventory Initialized with " .. auriinventory.itemcount .. " items.")
|
||||
|
||||
|
|
Loading…
Reference in New Issue