Add nodevoxel array

master
Le Sanglier des Ardennes 2018-01-25 23:39:51 +01:00
parent 90f18e89b6
commit 1872abd76f
1 changed files with 42 additions and 16 deletions

View File

@ -1,3 +1,21 @@
-- Array functions
function tprint(t)
for key,value in pairs(t) do
print(key, value)
end
end
function has_value (tab, val)
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
-- File functions
-- http://lua-users.org/wiki/FileInputOutput
@ -26,11 +44,19 @@ end
function generateNodeVoxel(file)
local lines = lines_from(file)
local aNodevoxel = {}
-- print all line numbers and their contents
for k,v in pairs(lines) do
if k >= 4 then -- Pass the description header
x, y, z, cubeColor = v:match("([^,]+) ([^,]+) ([^,]+) ([^,]+)")
if has_value(aNodevoxel, cubeColor) then
print 'Nodevoxel exists, does not create it'
else
print("Nodevoxel does not exist, create it: " .. cubeColor)
table.insert(aNodevoxel, cubeColor)
minetest.register_node("nodevoxel:cube" .. cubeColor, {
description = "Nodevoxel Cube" .. cubeColor,
tiles = {
@ -47,7 +73,7 @@ function generateNodeVoxel(file)
cracky = 3
},
})
end
print (k .. ' : ', x, y, z, cubeColor)
end
end