Advertisement
DabDaddy6223

os_utils

Mar 24th, 2023 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.80 KB | None | 0 0
  1. function midpoint(width, height)
  2.     local x = math.floor(width / 2)
  3.     local y = math.floor(height / 2)
  4.  
  5.     return x, y
  6. end
  7.  
  8. function getXPosOfString(str, startX)
  9.     local length = string.len(str)
  10.     local midpoint
  11.     if length % 2 == 0 then
  12.         -- Accept that the string can't be centered on a single character, so generate a best guess
  13.         midpoint = length / 2
  14.     else
  15.         -- The string can be centered on a single character, so select that character
  16.         midpoint = math.floor(length / 2) - 1
  17.     end
  18.     return startX - midpoint
  19. end
  20.  
  21. function hasKey(table, key)
  22.     for k,v in pairs(table) do
  23.         if k == key then
  24.             return true
  25.         end
  26.     end
  27.  
  28.     return false
  29. end
  30.  
  31. return { midpoint = midpoint, hasKey = hasKey, getXPosOfString = getXPosOfString }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement