media.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. local ModularTextureHandler =
  2. dofile(minetest.get_modpath("dwarf_characters") .. "/modular_texture_api.lua")
  3. ModularTextureHandler("skin")
  4. ModularTextureHandler("beard")
  5. ModularTextureHandler("hair")
  6. ModularTextureHandler("armor")
  7. ModularTextureHandler("helmet")
  8. do --Skins
  9. local apply_color = function(self, mod)
  10. return self[1] .. mod
  11. end
  12. local normal_skin = {"dwarf_characters_skin.png", process = apply_color}
  13. dwarf_characters.register_skin("normal",
  14. {
  15. arm_skin_left = normal_skin,
  16. arm_skin_right = normal_skin,
  17. leg_skin_left = normal_skin,
  18. leg_skin_right = normal_skin,
  19. head =
  20. {
  21. "dwarf_characters_skin.png",
  22. process =
  23. function(self, colormod)
  24. return "(" .. self[1]..colormod .. ")^dwarf_characters_eyes.png"
  25. end
  26. },
  27. torso_skin =
  28. {
  29. "dwarf_characters_skin.png^dwarf_characters_torso_defined.png",
  30. process = apply_color
  31. },
  32. })
  33. end
  34. do --Beards
  35. --[[
  36. For dwarves, female beards are softer and don't grow as big as
  37. male beards so we need a distinction.
  38. ]]
  39. local oldregb = dwarf_characters.register_beard
  40. local oldgetrb = dwarf_characters.get_random_beard
  41. local masculinebeards = {}
  42. local femininebeards = {}
  43. function dwarf_characters.register_beard(name, def)
  44. local sex = def.sex
  45. if sex == "m"
  46. then
  47. table.insert(masculinebeards, name)
  48. elseif sex == "f"
  49. then
  50. table.insert(femininebeards, name)
  51. else
  52. table.insert(masculinebeards, name)
  53. table.insert(femininebeards, name)
  54. end
  55. def.sex = nil --save a little memory
  56. oldregb(name, def)
  57. end
  58. function dwarf_characters.get_random_beard(sex)
  59. if sex == "m"
  60. then
  61. return masculinebeards[math.random(#masculinebeards)]
  62. elseif sex == "f"
  63. then
  64. return femininebeards[math.random(#femininebeards)]
  65. else
  66. return oldgetrb()
  67. end
  68. end
  69. dwarf_characters.register_beard("masc_long",
  70. {
  71. hair = {"dwarf_characters_beard.png"},
  72. sex = "m"
  73. })
  74. dwarf_characters.register_beard("gerold",
  75. {
  76. hair = {"dwarf_characters_gerold_beard.png"}
  77. })
  78. end
  79. do --Hair
  80. dwarf_characters.register_hair("short_ponytail",
  81. {
  82. hair = {"dwarf_characters_hair_short_ponytail.png"}
  83. })
  84. end
  85. do --Armors
  86. dwarf_characters.register_armor("berserker_pants",
  87. {
  88. leg_armor_left = {"dwarf_characters_armor_legs.png"},
  89. leg_armor_right = {"dwarf_characters_armor_legs.png"},
  90. torso_armor = {"dwarf_characters_armor.png"}
  91. })
  92. end
  93. do --Helmets
  94. dwarf_characters.register_helmet("cockatoo_helmet",
  95. {
  96. helmet = {"dwarf_characters_helmet.png"},
  97. })
  98. dwarf_characters.register_helmet("nothing",
  99. {
  100. helmet = {"dwarf_characters_blank.png"},
  101. })
  102. end
  103. do --Models
  104. dwarf_characters.register_model(
  105. "dwarf_characters_masc.b3d", "Masculine Dwarf", "m")
  106. dwarf_characters.register_model(
  107. "dwarf_characters_fem.b3d", "Feminine Dwarf", "f")
  108. end