Skip to content

Commit

Permalink
Magic_Palette (1.1): removed parameter 'tbl' of the function 'save'
Browse files Browse the repository at this point in the history
  • Loading branch information
duckafire committed Mar 2, 2024
1 parent f166445 commit 0304526
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Collection/Compacted/!Magic_Palette.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- [COMPACTED] Copy and paste the code in your cart [v: 1.0]
-- [COMPACTED] Copy and paste the code in your cart [v: 1.1]

local DAMIT,DA="github.com/DuckAfire/TinyLibrary/blob/main/LICENSE",{}

do local _U,_L,_S,_T,Tn,_F,Po,Pk=string.upper,string.lower,string.sub,type,tonumber,math.floor,poke,peek DA.sortCode=function(C,O,l) local o,c,c=O or 0,{} if _T(c)=="string" then local t,f,I=c,l and _L or _U,{1,3,5} for i=#t+1,6 do t=t.."0" end for i=1,3 do c[i]=f(_S(t,I[i],I[i]+1)) end else c=C end for i=1,3 do if not c[i] then c[i]=0 end end if o==0 then return c[1],c[2],c[3] elseif o==1 then c=c elseif o==2 then c={red=c[1],green=c[2],blue=c[3]} elseif o==3 then if hex then c="#"..c[1]..c[2]..c[3] else c=c[1]..", "..c[2]..", "..c[3] end else error('[ Magic_Palette ] The parameter "O" is invalid, try values between 0-3. In function "pale.sortCode", argument #2.') end return c end DA.save=function(t,h) if h then t="" else t={} end for i=0,15 do if not h then t[i]={} end for j=0,2 do if h then t=t..string.format("%x",Pk(0x03FC0+i*3+j)) else t[i][j]=Pk(0x03FC0+i*3+j) end end end return t end DA.toDec=function(C,O) local d={} local c=_T(C)=="table" and C[1] or C c=_S(c,1,1)=="#" and _S(c,2) or c for i=0,2 do local l=i+1+(i*1) d[i+1]=Tn(_S(c,l,l+1),16) end return DA.sortCode(d,O) end DA.toHex=function(C,O,L) local h="" for i=1,3 do if C[i]<0 then C[i]=0 elseif C[i]>255 then C[i]=255 end h=h..string.format("%x",_F(C[i])) end return DA.sortCode(h,O,L) end DA.swap=function(C,id) local c=C if _S(C,1,4)=="000:" then c=_S(C,5) elseif _S(C,1,1)=="#" then c=_S(C,2) end local function R(v,p) local a=p or 0 for i=0,2 do local l=i+1+(i*1) local k=Tn(_S(c,l+a,l+1+a),16) Po(0x03fc0+v*3+i,k) end end if id=="palette" then for id=0,15 do R(id,6*id) end elseif id=="equal" then for id=0,15 do R(id) end else R(Tn(id)) end end DA.light=function(S,t) local s,q=S and _F(S) or 1,0 for i=0,15 do for j=0,2 do local c,m,M=Pk(0x03FC0+i*3+j),_T(t)=="table" and t[i][j] or 0,_T(t)=="table" and t[i][j] or 255 local v=(c+s>=m) and c+s or m if s>0 then v=(c+s<=M) and c+s or M end Po(0x03FC0+i*3+j,v) if v==m or v==M then q=q+1 end end end return q==48 end end
do local _U,_L,_S,_T,Tn,_F,Po,Pk=string.upper,string.lower,string.sub,type,tonumber,math.floor,poke,peek DA.sortCode=function(C,O,l) local o,c,c=O or 0,{} if _T(c)=="string" then local t,f,I=c,l and _L or _U,{1,3,5} for i=#t+1,6 do t=t.."0" end for i=1,3 do c[i]=f(_S(t,I[i],I[i]+1)) end else c=C end for i=1,3 do if not c[i] then c[i]=0 end end if o==0 then return c[1],c[2],c[3] elseif o==1 then c=c elseif o==2 then c={red=c[1],green=c[2],blue=c[3]} elseif o==3 then if hex then c="#"..c[1]..c[2]..c[3] else c=c[1]..", "..c[2]..", "..c[3] end else error('[ Magic_Palette ] The parameter "O" is invalid, try values between 0-3. In function "pale.sortCode", argument #2.') end return c end DA.save=function(h) local v if h then v="" else v={} end for i=0,15 do if not h then v[i]={} end for j=0,2 do if h then v=v..string.format("%x",Pk(0x03FC0+i*3+j)) else v[i][j]=Pk(0x03FC0+i*3+j) end end end return v end DA.toDec=function(C,O) local d={} local c=_T(C)=="table" and C[1] or C c=_S(c,1,1)=="#" and _S(c,2) or c for i=0,2 do local l=i+1+(i*1) d[i+1]=Tn(_S(c,l,l+1),16) end return DA.sortCode(d,O) end DA.toHex=function(C,O,L) local h="" for i=1,3 do if C[i]<0 then C[i]=0 elseif C[i]>255 then C[i]=255 end h=h..string.format("%x",_F(C[i])) end return DA.sortCode(h,O,L) end DA.swap=function(C,id) local c=C if _S(C,1,4)=="000:" then c=_S(C,5) elseif _S(C,1,1)=="#" then c=_S(C,2) end local function R(v,p) local a=p or 0 for i=0,2 do local l=i+1+(i*1) local k=Tn(_S(c,l+a,l+1+a),16) Po(0x03fc0+v*3+i,k) end end if id=="palette" then for id=0,15 do R(id,6*id) end elseif id=="equal" then for id=0,15 do R(id) end else R(Tn(id)) end end DA.light=function(S,t) local s,q=S and _F(S) or 1,0 for i=0,15 do for j=0,2 do local c,m,M=Pk(0x03FC0+i*3+j),_T(t)=="table" and t[i][j] or 0,_T(t)=="table" and t[i][j] or 255 local v=(c+s>=m) and c+s or m if s>0 then v=(c+s<=M) and c+s or M end Po(0x03FC0+i*3+j,v) if v==m or v==M then q=q+1 end end end return q==48 end end

local pale=DA
18 changes: 9 additions & 9 deletions Collection/Not compacted/#Magic_Palette.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- [NOT COMPACTED] Copy and paste the code in your cart [v: 1.0]
-- [NOT COMPACTED] Copy and paste the code in your cart [v: 1.1]

local magicPalette = {}
local DA_LICENSE = "github.com/DuckAfire/TinyLibrary/blob/main/LICENSE"-- There's no need to copy "DA_LICENSE" if they are already in the code.
Expand Down Expand Up @@ -48,25 +48,25 @@ do
return c
end

local function save(tbl, hex)
local function save(hex)
local var

if hex then tbl = "" else tbl = {} end
if hex then var = "" else var = {} end

for i = 0, 15 do
if not hex then tbl[i] = {} end
if not hex then var[i] = {} end

for j = 0, 2 do
if hex then
tbl = tbl..string.format("%x", peek(0x03FC0 + i * 3 + j))-- hexadecimal
var = var..string.format("%x", peek(0x03FC0 + i * 3 + j))-- hexadecimal
else
tbl[i][j] = peek(0x03FC0 + i * 3 + j)-- decimal (in sub-tables)
var[i][j] = peek(0x03FC0 + i * 3 + j)-- decimal (in sub-tables)
end
end

end

return tbl

return var
end

----- CONVERSION -----
Expand Down Expand Up @@ -159,8 +159,8 @@ do

magicPalette.sortCode = sortCode
magicPalette.save = save
magicPalette.toHex = toHex
magicPalette.toDec = toDec
magicPalette.toHex = toHex
magicPalette.swap = swap
magicPalette.light = light

Expand Down
18 changes: 9 additions & 9 deletions Collection/lua-default/Magic_Palette.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- NAME: Magic Pallete
-- AUTHOR: DuckAfire
-- VERSION: 1.0
-- VERSION: 1.1

-- FOLLOW_ME:
-- Itch: http://duckafire.itch.io
Expand Down Expand Up @@ -77,25 +77,25 @@ local function sortCode(code, order, low)
return c
end

local function save(tbl, hex)
local function save(hex)
local var

if hex then tbl = "" else tbl = {} end
if hex then var = "" else var = {} end

for i = 0, 15 do
if not hex then tbl[i] = {} end
if not hex then var[i] = {} end

for j = 0, 2 do
if hex then
tbl = tbl..string.format("%x", peek(0x03FC0 + i * 3 + j))-- hexadecimal
var = var..string.format("%x", peek(0x03FC0 + i * 3 + j))-- hexadecimal
else
tbl[i][j] = peek(0x03FC0 + i * 3 + j)-- decimal (in sub-tables)
var[i][j] = peek(0x03FC0 + i * 3 + j)-- decimal (in sub-tables)
end
end

end

return tbl

return var
end


Expand Down Expand Up @@ -196,8 +196,8 @@ local magicPalette = {}

magicPalette.sortCode = sortCode
magicPalette.save = save
magicPalette.toHex = toHex
magicPalette.toDec = toDec
magicPalette.toHex = toHex
magicPalette.swap = swap
magicPalette.light = light

Expand Down
Binary file modified tinylibrary.tic
Binary file not shown.

0 comments on commit 0304526

Please sign in to comment.