textures.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. local intramodcom = dwarf_characters.intramodcom
  2. --turns red, green and blue number value into a multiply tag with
  3. --rgb as a ColorString.
  4. local function get_color_mod(r, g, b)
  5. local hex = string.format("%.2X%.2X%.2X", r, g, b)
  6. return "^[multiply:#" .. hex
  7. end
  8. local function get_skin_color_rgb(brightness)
  9. local red = 255 * brightness
  10. local green = red * 0.86
  11. local blue = green * 0.83
  12. return red, green, blue
  13. end
  14. local function get_textures_naked(skin_color)
  15. local skin_color_mod = get_color_mod(get_skin_color_rgb(skin_color))
  16. --local skin = "(dwarf_characters_skin.png"..skin_color_mod .. ")"
  17. local blank = "dwarf_characters_blank.png"
  18. local skin = {}
  19. for i = 1, 15
  20. do
  21. skin[i] = blank
  22. end
  23. dwarf_characters.apply_skin(skin, "normal", skin_color_mod)
  24. return skin
  25. end
  26. local function get_hair_color_rgb(brightness, redness)
  27. local r = 255
  28. local g = 255 - redness * 55
  29. local b = 83
  30. local a1 = g / r
  31. r = r * brightness
  32. local a2 = b / g
  33. g = g * a1 * brightness
  34. b = b * a2 * brightness
  35. return r, g, b
  36. end
  37. local function apply_beard_and_hair(base, appearance)
  38. local color_mod =
  39. get_color_mod(get_hair_color_rgb(appearance.hair_brightness,
  40. appearance.hair_redness))
  41. local beard = {}
  42. dwarf_characters.apply_beard(beard, appearance.beard)
  43. local hair = {}
  44. dwarf_characters.apply_hair(hair, appearance.hair)
  45. for k, v in pairs(beard)
  46. do
  47. base[k] = hair[k] .. "^" .. v .. color_mod
  48. end
  49. end
  50. local function get_textures(appearance)
  51. local textures = get_textures_naked(appearance.skin_color)
  52. apply_beard_and_hair(textures, appearance)
  53. --armor and helmet mods can do anything, depending on the
  54. --processing function passed to the definition.
  55. dwarf_characters.apply_armor(textures, appearance.armor, appearance.armor_mod)
  56. dwarf_characters.apply_helmet(textures, appearance.helmet, appearance.helmet_mod)
  57. return textures
  58. end
  59. intramodcom.get_textures = get_textures