read_tool_config.lua 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. local S=minerdream.intllib
  2. local has_value = basic_functions.has_value
  3. local tier_cols={
  4. col_num={"name"},}
  5. local tier_definition = basic_functions.import_csv(minerdream.path.."/tiers.txt",tier_cols)
  6. local tool_cols={
  7. col_num={"range","uses"},
  8. as_numeric=1,
  9. }
  10. -- reading config table
  11. local tool_definition = basic_functions.import_csv(minerdream.path.."/tools.txt",tool_cols)
  12. for i,tdef in pairs(tool_definition) do
  13. if (i ~= "default") and (minerdream.items[i] ~= nil) then
  14. idef=table.copy(minerdream.items[i])
  15. local tooldef={}
  16. for col in pairs(tdef) do
  17. tooldef=basic_functions.parse_tree(tooldef,col,tdef[col])
  18. end
  19. if minerdream.itemdef[i]==nil then
  20. minerdream.itemdef[i]={}
  21. end
  22. -- check specific tools/weapons
  23. for _,tool in pairs({"pick","axe","sword","shovel","spear"}) do
  24. if tooldef[tool] ~= nil then
  25. local ttv=tooldef[tool]
  26. tdesc=core.colorize("#"..idef.tierdef.color, S(i:gsub("^%l", string.upper)).." "..S(tool:gsub("^%l", string.upper)).."\n")..
  27. core.colorize("#A0A0A0", "tier: "..idef.tierdef.name.." ("..idef.tierdef.desc..")")
  28. -- check special attributes of tool definition and use fallback definitions
  29. if tooldef.uses then
  30. tdesc=tdesc.."\n"..core.colorize("#A0A0A0",S("Uses")..": "..tooldef.uses)
  31. end
  32. if ttv.maxlevel then
  33. tdesc=tdesc.."\n"..core.colorize("#A0A0A0",S("Max. Level")..": "..ttv.maxlevel)
  34. end
  35. if ttv.fleshy then
  36. tdesc=tdesc.."\n"..core.colorize("#A0A0A0",S("Damage")..": "..ttv.fleshy)
  37. end
  38. tt_def={description=tdesc,
  39. inventory_image=minerdream.modname.."_"..tool.."_"..i..".png",
  40. range=tooldef.range or 2,
  41. groups={weapon=1},
  42. tool_capabilities={max_drop_level = 1,groupcaps={},
  43. damage_groups = {fleshy = ttv.fleshy or 4},},
  44. }
  45. -- check if values for capabitlites exist
  46. for _,gc in pairs({"cracky","crumbly","choppy","snappy"}) do
  47. if ttv[gc] ~= nil then
  48. local ml = 1
  49. if tooldef.maxlevel ~=nil then
  50. ml=tooldef.maxlevel
  51. end
  52. if ttv.maxlevel ~= nil then
  53. ml = ttv.maxlevel
  54. end
  55. tt_def.tool_capabilities.groupcaps[gc]={times=table.copy(ttv[gc]),
  56. uses=tooldef.uses,maxlevel=ml}
  57. end
  58. end
  59. toolname=minerdream.modname..":"..tool.."_"..i
  60. minetest.register_tool(toolname,tt_def)
  61. end
  62. end
  63. end
  64. end