Page 1 of 1

Fixing color 'issues' brought in by 11.0

Posted: Fri May 11, 2018 9:00 am
by Ducktor Cid
So, while trying my game in the latest version of love2d there's some color 'issues' caused by the latest version due to the fact I'm still using values from 0-255.

At first I thought it would be easy, just adding /255 to each love.setColor call. And then I remembered I have a huge dictionary filled with 'material design' colors. Obviously, adding /255 manually is too much of a hassle.

Here's the dictionary

One of the ways I thought of fixing this is with notepads regex functionality and just use a regex expression to find all the hexadecimal values and add /255 next to them. Sadly, I have no idea how to do that. I've found some regex expressions for finding hexadecimal values but I have no idea how to make it so I can add /255 to the end of each of them.

Any help would be appreciated!

Re: Fixing color 'issues' brought in by 11.0

Posted: Fri May 11, 2018 10:12 am
by raidho36

Code: Select all

for c, ct in pairs ( colors ) do
	for v, vt in pairs ( ct ) do
		for i = 1, #v do
			v[ i ] = v[ i ] / 255 
		end
	end
end

Re: Fixing color 'issues' brought in by 11.0

Posted: Fri May 11, 2018 10:50 am
by NotARaptor
In Notepad++ (it's probably similar in other editors) you can do a regex search/replace easily enough.

Search : (0x[0-9a-f][0-9a-f])
Replace : \1/255

That would work nicely on your dictionary file - for more general use-cases you'd need to make a better regexp - that one would for example see "0x1234" and match the first two hex characters, and the result would be "0x12/25534". But for your file it will be fine

Re: Fixing color 'issues' brought in by 11.0

Posted: Fri May 11, 2018 10:56 am
by Ducktor Cid
Thanks Raptor!