Advertisement
guitarplayer616

uWords API Rework

Jun 24th, 2015
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.54 KB | None | 0 0
  1. function getColors()
  2.   for i,v in pairs(colors) do
  3.         if tonumber(v) then
  4.           loadstring(i.."="..v)()
  5.         end
  6.   end
  7.   grey = gray
  8.   lightGrey = lightGray
  9. end
  10.  
  11. function draw(words,x,y,txtcol,backcol)
  12.         --put at top of file/program: local c,r,l = 'c','r','l'; local deftxt,defback
  13.         local w,h = term.getSize()
  14.         local offset = 0
  15.         local writeLn
  16.     words = tostring(words)
  17.         deftxt = deftxt or colors.white
  18.         defback = defback or colors.black
  19.         words = words or " "
  20.         if not (x and y) then
  21.                 x,y = term.getCursorPos()
  22.                 writeLn = true
  23.         elseif not x then
  24.                 x,_ = term.getCursorPos()
  25.                 writeLn = true
  26.         elseif not y then
  27.                 _,y = term.getCursorPos()
  28.                 writeLn = true
  29.         end
  30.         txtcol = txtcol or deftxt
  31.         backcol = backcol or defback
  32.         if not tonumber(x) then
  33.                 x = x:gsub(" ", "")
  34.                 if x:sub(1, 1) == "l" then
  35.                         if x:find("+") then
  36.                                 offset = tonumber(x:sub(x:find("+") + 1))
  37.                                 term.setCursorPos(1 + offset, y)
  38.                         else
  39.                                 term.setCursorPos(1, y)
  40.                         end
  41.                 elseif x:sub(1, 1) == "c" then
  42.                         if x:find("+") then
  43.                                 offset = tonumber(x:sub(x:find("+") + 1))
  44.                                 term.setCursorPos(w/2 - #words/2 + 1 + offset, y)
  45.                         elseif x:find("-") then
  46.                                 offset = tonumber(x:sub(x:find("-") + 1))
  47.                                 term.setCursorPos(w/2 - #words/2 + 1 - offset, y)
  48.                         else
  49.                                 term.setCursorPos(w/2 - #words/2 + 1, y)
  50.                         end
  51.                 elseif x:sub(1, 1) == "r" then
  52.                         if x:find("-") then
  53.                                 offset = tonumber(x:sub(x:find("-") + 1))
  54.                                 term.setCursorPos(w - #words+ 1 - offset, y)
  55.                         else
  56.                                 term.setCursorPos(w - #words+ 1, y)
  57.                         end
  58.                 end
  59.         else
  60.                 term.setCursorPos(x, y)
  61.         end
  62.         term.setTextColor(txtcol)
  63.         term.setBackgroundColor(backcol)
  64.         if writeLn then
  65.                 write(words..'\n')
  66.         else
  67.                 write(words)
  68.         end
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement