Advertisement
nucular

TPTools

Mar 29th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.38 KB | None | 0 0
  1. -- [[ TPTools ]]--
  2. -- by nucular, licensed under MIT
  3. --VER 0.1 UPDATE http://pastebin.com/raw.php?i=mgRkqLaT
  4.  
  5. tptools = {}
  6.  
  7. tptools.COLOR_TAGS = {
  8.     -- Some color codes
  9.     reset = 0x0E, r = 0x0E,
  10.     invert = 0x01,
  11.  
  12.     white = "\bw",
  13.     green = "\bg",
  14.     yellow = "\bo",
  15.     red = "\br",
  16.     lred = "\bl",
  17.     blue = "\bb",
  18.     lblue = "\bt"
  19.  
  20. }
  21.  
  22. tptools.ICON_TAGS = {
  23.     -- More or less complete map of the TPT font space!
  24.     play = 128,
  25.     open = 129,
  26.     save = 130,
  27.     tag = 131,
  28.     signin = 132,
  29.     delete = 133,
  30.     -- 134 delete colors
  31.     dropup = 135,
  32.     -- 136 dropup colors
  33.     add = 137,
  34.     player = 138,
  35.     -- 139 player colors
  36.     -- 140 signin colors
  37.     dot = 141,
  38.     circle = 142,
  39.     search2 = 143,
  40.     pause = 144,
  41.     reload = 145,
  42.     new = 146,
  43.     own = 147,
  44.     -- 148 own colors
  45.     right = 149,
  46.     left = 150,
  47.     amd = 151, -- relict from the first versions (lets finds the intel logo!)
  48.     wind = 152,
  49.     pressure = 153,
  50.     persist = 154,
  51.     fire = 155,
  52.     -- 156 fire colors
  53.     leftalign = 157,
  54.     centeralign = 158,
  55.     rightalign = 159,
  56.     sign = 160, -- 161
  57.     dropdown = 162,
  58.     skylarkinati = 163,
  59.     -- 164 skylarkinati colors
  60.     oe = 165, -- used in the old TPT to draw some latin stuff
  61.     date = 166,
  62.     votes = 167,
  63.     square = 168,
  64.     resize = 169,
  65.     cancel = 170,
  66.     -- 171 unused
  67.     lbrace = 172,
  68.     rbrace = 173,
  69.     -- 174?
  70.     zero = 175, one = 176, two = 177, three = 178, four = 179, five = 180,
  71.     six = 181, seven = 182, eight = 183, nine = 184,
  72.     block = 185,
  73.     -- 186
  74.     -- 187 These three are used to draw the vote bars
  75.     -- 188
  76.     heat = 189,
  77.     -- 190?
  78.     blob = 191,
  79.     -- 192 unused?
  80.     walls = 193,
  81.     electronics = 194,
  82.     explosives = 195,
  83.     liquids = 196,
  84.     gasses = 197,
  85.     radioactive = 198,
  86.     shield = 199,
  87.     smalldot = 200,
  88.     -- 201 shield colors
  89.     votedown = 202,
  90.     voteup = 203,
  91.     special = 204, favourite = 204,
  92.     lock = 205,
  93.     -- 206 lock colors
  94.     check = 207, options = 207,
  95.     powders = 208,
  96.     solids = 209,
  97.     life = 210,
  98.     heatgrad = 211,
  99.     -- 212 These two are the cracker air
  100.     -- 213 display mode icon
  101.     powered = 214,
  102.     tools = 215,
  103.     gradleft = 216,
  104.     gradmiddle = 217,
  105.     gradright = 218,
  106.     block3 = 219, --?
  107.     grid = 220,
  108.     -- 221?
  109.     lensing = 222,
  110.     glow = 223,
  111.     lifeval = 224,
  112.     flare = 225,
  113.     force = 226,
  114.     warning = 227,
  115.     deco = 228,
  116.     search = 229,
  117.     sample = 230
  118.     -- 231 - 255 unused
  119. }
  120.  
  121. function tptools.icon(name)
  122.     return string.char(tptools.ICON_TAGS[name])
  123. end
  124.  
  125. function tptools.text(text, tstart, tend)
  126.     tstart = tstart or "{"
  127.     tend = tend or "}"
  128.  
  129.     -- rgb
  130.     text = text:gsub(tstart .. "(%d+),(%d+),(%d+)" .. tend, function(r, g, b)
  131.         -- don't allow 0x00 or 0x100+
  132.         r = math.max(math.min(r, 255), 1)
  133.         g = math.max(math.min(g, 255), 1)
  134.         b = math.max(math.min(b, 255), 1)
  135.         return string.char(0x0F, r, g, b)
  136.     end)
  137.    
  138.     text = text:gsub(tstart .. "(.-)" .. tend, function(c)
  139.         local v = tptools.COLOR_TAGS[c] or tptools.ICON_TAGS[c]
  140.  
  141.         if not v then
  142.             return nil
  143.         end
  144.        
  145.         if type(v) ~= "string" then
  146.             return string.char(v)
  147.         else
  148.             return v
  149.         end
  150.     end)
  151.     return text
  152. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement