Fixing color 'issues' brought in by 11.0

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Ducktor Cid
Prole
Posts: 18
Joined: Wed Oct 05, 2016 8:08 pm

Fixing color 'issues' brought in by 11.0

Post 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!
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Fixing color 'issues' brought in by 11.0

Post 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
User avatar
NotARaptor
Citizen
Posts: 59
Joined: Thu Feb 22, 2018 3:15 pm

Re: Fixing color 'issues' brought in by 11.0

Post 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
User avatar
Ducktor Cid
Prole
Posts: 18
Joined: Wed Oct 05, 2016 8:08 pm

Re: Fixing color 'issues' brought in by 11.0

Post by Ducktor Cid »

Thanks Raptor!
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 55 guests