util.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. timer = {}
  2. timer.rot = function(v, fn)
  3. if v > 0 then
  4. v = v - ls.tickrate
  5. if v <= 0 then
  6. v = 0
  7. v = f.exe(fn) or 0
  8. end
  9. end
  10. return v
  11. end
  12. function isa(instance, class)
  13. return getmetatable(instance) and getmetatable(instance).__index == class
  14. end
  15. function math.insideCircle(x, y, cx, cy, r)
  16. return math.distance(x, y, cx, cy) < r
  17. end
  18. function toTime(x, format)
  19. x = math.floor(x)
  20. local seconds = math.floor(x % 60)
  21. local minutes = math.floor(x / 60)
  22. if format then
  23. if minutes < 10 then minutes = '0' .. minutes end
  24. end
  25. if seconds < 10 then seconds = '0' .. seconds end
  26. return minutes .. ':' .. seconds
  27. end
  28. if love.graphics then
  29. local g = love.graphics
  30. function g.printCenter(what, x, y)
  31. local font = g.getFont()
  32. g.print(what, x, y, 0, 1, 1, math.round(font:getWidth(what) / 2), math.round(font:getHeight(what) / 2))
  33. end
  34. function g.printShadow(what, x, y, center, shadowColor)
  35. local f = center and g.printCenter or g.print
  36. local color = {g.getColor()}
  37. g.setColor(shadowColor or {0, 0, 0, color[4]})
  38. f(what, x + 1, y + 1)
  39. g.setColor(color)
  40. f(what, x, y)
  41. end
  42. function g.drawRune(rune, x, y, stoneSize, runeSize, glow)
  43. if not rune then return end
  44. local atlas = data.atlas.hud
  45. local _, _, _, a = g.getColor()
  46. a = a or 255
  47. -- Stone
  48. local quad = 'runeBg' .. rune.background:capitalize()
  49. local w, h = atlas:getDimensions(quad)
  50. local scale = stoneSize / h
  51. g.setColor(255, 255, 255, a)
  52. g.draw(atlas.texture, atlas.quads[quad], x, y, 0, scale, scale, w / 2, h / 2)
  53. if glow then
  54. g.setBlendMode('additive')
  55. g.setColor(255, 255, 255, 80 * (a / 255))
  56. g.draw(atlas.texture, atlas.quads[quad], x, y, 0, scale, scale, w / 2, h / 2)
  57. g.setBlendMode('alpha')
  58. end
  59. -- Rune
  60. local quad = 'rune' .. rune.image
  61. local w, h = atlas:getDimensions(quad)
  62. local scale = runeSize / h
  63. local color = config.runes.colors[rune.color]
  64. g.setColor(color[1], color[2], color[3], a)
  65. g.draw(atlas.texture, atlas.quads[quad], x, y, 0, scale, scale, w / 2, h / 2)
  66. if glow then
  67. g.setBlendMode('additive')
  68. g.setColor(255, 255, 255, 80 * (a / 255))
  69. g.draw(atlas.texture, atlas.quads[quad], x, y, 0, scale, scale, w / 2, h / 2)
  70. g.setBlendMode('alpha')
  71. end
  72. end
  73. end