models.lua 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. local models = {}
  2. local master = dwarf_characters
  3. --animations and textures are expected to work the same on all models
  4. --this is bad for modularity but this mod is currently only intended to
  5. --work with a masculine and a feminine version of the same model
  6. --we set this as metatable for all animations so we can call
  7. --them as functions even when they're tables.
  8. --This allows us to use actual functions as animations which we can use
  9. --to pick random animations
  10. local animation_table_meta =
  11. {
  12. __call = function(self)
  13. return self
  14. end
  15. }
  16. local animations =
  17. {
  18. stand = {x = 31, y = 31},
  19. die = {x = 81, y = 130},
  20. walk = {x = 0, y = 30},
  21. mine = {x = 71, y = 80},
  22. walk_mine = {x = 40, y = 69},
  23. sit = {x = 32, y = 32},
  24. }
  25. for _, v in pairs(animations)
  26. do
  27. if(type(v) == "table")
  28. then
  29. setmetatable(v, animation_table_meta)
  30. end
  31. end
  32. master.intramodcom.animations = animations
  33. function master.register_model(name, description, sex)
  34. assert(not models[name], "There is already a model registered with name "..name)
  35. models[name] = {description = description, sex = sex}
  36. end
  37. function master.get_models()
  38. local i = 0
  39. local ret = {}
  40. for k, v in pairs(models)
  41. do
  42. i = i + 1
  43. ret[i] = {name = k, description = v.description, sex = v.sex}
  44. end
  45. return ret
  46. end