Commit e9271597 authored by Fedja Beader's avatar Fedja Beader
Browse files

WorldEdit: print bill of materials upon copy/load

parent 04645b1a
......@@ -28,10 +28,18 @@ function NodeStorage:new()
}
setmetatable(o, self)
self.__index = self
o:invalidate_info()
return o
end
function NodeStorage:invalidate_info()
self.info = {}
end
......@@ -52,6 +60,7 @@ function NodeStorage:convert_for_placement()
end
end
end
self:invalidate_info()
end
......@@ -79,6 +88,31 @@ function NodeStorage:from_bounding_box(bb)
end
end
end
self:print_bill_of_materials()
end
end
-- count number of stored nodes of each type = bill of materials
function NodeStorage:get_bill_of_materials()
if self.info.bill_of_materials then return self.info.bill_of_materials end
local BOM = {}
for i,node_data in pairs(self.nodes) do -- can an index be nil?
local node_name = node_data.node.name
BOM[node_name] = (BOM[node_name] or 0) + 1
end
self.info.bill_of_materials = BOM
return BOM
end
function NodeStorage:print_bill_of_materials()
local BOM = self:get_bill_of_materials()
for name,count in pairs(BOM) do
l:info(string.format("Bill of materials: need %8d of '%s'", count, name))
end
end
......@@ -95,6 +129,9 @@ function NodeStorage:load(fname)
object.fname = fname
setmetatable(object, self)
object.__index = self
object:invalidate_info()
object:print_bill_of_materials()
return object
else
l:err("Unable to open file '" .. fname .. "' for loading!")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment