[Script] Color |
Thanos « Citoyen » 1472169840000
| 0 | ||
O que é? Uma simples classe para trabalhar com códigos de cores simultaneamente nos formatos hex, númerico e RGB. Ela também possui suas próprias mensagens de erro para lhe dar mais noção de onde e por quê seu código falhou ao usá-la. Estrutura
Notas
Exemplos
tfm.exec.setNameColor(playerName, Color.Random().int) tfm.exec.chatMessage('<font color="#' .. algumaCor.hex .. '">oi</font>', playerName) Versão minimizada (1 linha) -------[Classe de Cores por Lynezx | rev 2 - 27/08/2016]------- Color={Random=function()return Color(math.random(0,255),math.random(0,255),math.random(0,255))end,Error=function(a,b)local c={"[Color Class] - Invalid hex parameter [%s].","[Color Class] - Invalid byte parameter [%s]. Value must be a number from 0 to 255.","[Color Class] - Invalid integer parameter [%s]. Value must be a number from 0 to 16777215.","[Color Class] - Invalid parameter for Color constructor [%s]. Value must be a hex string; a color integer; a R, G, B bytes sequence or nothing."}error(string.format(c[a]or"[Color Class] - Unknown error",b or""))end}setmetatable(Color,{__call=function(d,...)local e={...}local f={_int=0,_hex="000000",_r=0,_g=0,_b=0}setmetatable(f,{__index=function(self,g)return rawget(self,'_'..g)end,__newindex=function(self,g,h)local i=false;local j;if g=='int'then if not pcall(function()j=tonumber(h)end)or(j==nil or j<0 or j>0xffffff)then Color.Error(3,type(h)..' '..tostring(h))end;rawset(self,'_int',j)i=true elseif g=='hex'then if not pcall(function()j=tonumber("0x"..string.gsub(h,'#','',1))end)or j==nil then Color.Error(1,type(h)..' '..tostring(h))end;rawset(self,'_int',j)i=true elseif g=='r'or g=='g'or g=='b'then if not pcall(function()j=tonumber(h)end)or(j==nil or h<0 or h>0xff)then Color.Error(2,type(h)..' '..tostring(h))end;rawset(self,'_'..g,j)rawset(self,'_int',bit32.lshift(self.r,16)+bit32.lshift(self.g,8)+self.b)i=true elseif not i then rawset(self,g,h)end;if i then rawset(self,'_r',bit32.band(bit32.rshift(self.int,16),0xFF))rawset(self,'_g',bit32.band(bit32.rshift(self.int,8),0xFF))rawset(self,'_b',bit32.band(self.int,0xFF))rawset(self,'_hex',string.format('%02x%02x%02x',self.r,self.g,self.b))end end})if#e==1 and type(e[1])=='string'then f.hex=e[1]elseif#e==1 and type(e[1])=='number'then f.int=e[1]elseif#e==1 and type(e[1])=='table'and type(e[1].int)=='number'then f.int=e[1].int elseif#e==1 then Color.Error(4,type(e[1])..' '..tostring(e[1]))elseif#e==3 then f.r=e[1]f.g=e[2]f.b=e[3]end;return f end})Color.GAME_BACKGROUND=Color('6a7495')Color.UI_BACKGROUND=Color('0e242d')Color.UI_BACKGROUND2=Color('1c3c41') -------[Classe de Cores por Lynezx | rev 2 - 27/08/2016]------- Versão de desenvolvimento Changelog - última revisão em 27/08/2016
Introduction This is a simple class to work with color values in both hex, numeric or RGB format. The class also includes custom error messages, for giving you more control of your code in case of mistakes. Structure
Notes
Examples of usage
tfm.exec.setNameColor(playerName, Color.Random().int) tfm.exec.chatMessage('<font color="#' .. someColor.hex .. '">hi</font>', playerName) Minimized version (1 line) -------[Color Class by Lynezx | rev 2 - 27/08/2016]------- Color={Random=function()return Color(math.random(0,255),math.random(0,255),math.random(0,255))end,Error=function(a,b)local c={"[Color Class] - Invalid hex parameter [%s].","[Color Class] - Invalid byte parameter [%s]. Value must be a number from 0 to 255.","[Color Class] - Invalid integer parameter [%s]. Value must be a number from 0 to 16777215.","[Color Class] - Invalid parameter for Color constructor [%s]. Value must be a hex string; a color integer; a R, G, B bytes sequence or nothing."}error(string.format(c[a]or"[Color Class] - Unknown error",b or""))end}setmetatable(Color,{__call=function(d,...)local e={...}local f={_int=0,_hex="000000",_r=0,_g=0,_b=0}setmetatable(f,{__index=function(self,g)return rawget(self,'_'..g)end,__newindex=function(self,g,h)local i=false;local j;if g=='int'then if not pcall(function()j=tonumber(h)end)or(j==nil or j<0 or j>0xffffff)then Color.Error(3,type(h)..' '..tostring(h))end;rawset(self,'_int',j)i=true elseif g=='hex'then if not pcall(function()j=tonumber("0x"..string.gsub(h,'#','',1))end)or j==nil then Color.Error(1,type(h)..' '..tostring(h))end;rawset(self,'_int',j)i=true elseif g=='r'or g=='g'or g=='b'then if not pcall(function()j=tonumber(h)end)or(j==nil or h<0 or h>0xff)then Color.Error(2,type(h)..' '..tostring(h))end;rawset(self,'_'..g,j)rawset(self,'_int',bit32.lshift(self.r,16)+bit32.lshift(self.g,8)+self.b)i=true elseif not i then rawset(self,g,h)end;if i then rawset(self,'_r',bit32.band(bit32.rshift(self.int,16),0xFF))rawset(self,'_g',bit32.band(bit32.rshift(self.int,8),0xFF))rawset(self,'_b',bit32.band(self.int,0xFF))rawset(self,'_hex',string.format('%02x%02x%02x',self.r,self.g,self.b))end end})if#e==1 and type(e[1])=='string'then f.hex=e[1]elseif#e==1 and type(e[1])=='number'then f.int=e[1]elseif#e==1 and type(e[1])=='table'and type(e[1].int)=='number'then f.int=e[1].int elseif#e==1 then Color.Error(4,type(e[1])..' '..tostring(e[1]))elseif#e==3 then f.r=e[1]f.g=e[2]f.b=e[3]end;return f end})Color.GAME_BACKGROUND=Color('6a7495')Color.UI_BACKGROUND=Color('0e242d')Color.UI_BACKGROUND2=Color('1c3c41') -------[Color Class by Lynezx | rev 2 - 27/08/2016]------- Original version Dernière modification le 1474240680000 |
Malucarr « Citoyen » 1472170080000
| 0 | ||
Obrigado <3 eu li o tópico sim, ta? |
Daydream « Censeur » 1472172660000
| 0 | ||
Adorei!! |
Waaalaceee « Citoyen » 1472173860000
| 0 | ||
AMARRREI, CRIATIVO |
0 | ||
muito útil pra trabalhar |
0 | ||
Ótimo em pensar que veio do lynezx |
Ninguem « Consul » 1472223840000
| 0 | ||
Muito legal. Finalmente achei um exemplo legal pra aprender classes no lua. |
Laagaadoo « Citoyen » 1472226660000
| 0 | ||
Ficou muito legal :o |
Thanos « Citoyen » 1472315220000
| 0 | ||
Obrigado gente o/. Dei uma revisada no código, corrigi uma coisa, adicionei outra e melhorei um pouco os exemplos:
|
Fofinhoppp « Consul » 1480784460000
| 0 | ||
obg tava precisando |
0 | ||
Parabéns |