Skip to content

Commit 947e208

Browse files
committed
convert colors from 0..255 scale to 0..1
Per the LÖVE 11.0 changelog: > Changed all color values to be in the range 0-1, rather than 0-255. All internal color values have been updated, which largely means that they are now divided by 255. In a future commit, it may be worth using decimal approximations to tidy up the code, as the `/255`s are rather unsightly. However, this would technically lead to the colors of some objects being ever so slightly changed. To avoid potentially undesirable behavior, the only legacy numbers to be replaced with decimals are 127 (0.5), 128 (0.5), and 255 (1.0). Instances of 127 which may have caused issues with community content were left intact as `127/255`. This commit also fixes some miscellaneous issues, namely sounds using `.isPlaying()` instead of `:isPlaying`. Known regressions: - Configs from older versions of the game which used 0..255 colors are not yet automatically updated. - When exiting the pause menu, the music plays from the beginning instead of resuming. - Custom character colors cannot be modified in the settings.
1 parent d15a541 commit 947e208

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1220
-1169
lines changed

andgate.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ end
5050

5151
function andgate:draw()
5252
if self.visible then
53-
love.graphics.setColor(255, 255, 255)
53+
love.graphics.setColor(1, 1, 1)
5454
love.graphics.draw(gateimg, gatequad[9], math.floor((self.x-1-xscroll)*16*scale), ((self.y-1-yscroll)*16-8)*scale, 0, scale, scale)
5555
--love.graphics.draw(andgateimg, math.floor((self.x-1-xscroll)*16*scale), ((self.y-yscroll-1)*16-8)*scale, 0, scale, scale)
5656
end
@@ -88,4 +88,4 @@ function andgate:input(t, input)
8888
self.outputstate = pass
8989
end
9090
end
91-
end
91+
end

android.lua

+6-6
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ function androidLoad()
9393
buttons["portal1"].portal = true
9494
buttons["portal2"] = touchButton:new("r", "2", t["portal2"][1],t["portal2"][2],t["portal2"][3],t["portal2"][4], "round")
9595
buttons["portal2"].portal = true
96-
buttons["portal1"].color = {60, 188, 252}
97-
buttons["portal2"].color = {232, 130, 30}
96+
buttons["portal1"].color = {60/255, 188/255, 252/255}
97+
buttons["portal2"].color = {232/255, 130/255, 30/255}
9898

9999
-- shift keys to left
100100
if fourbythree then
@@ -216,7 +216,7 @@ function androidDraw()
216216
local x, y, w, h = skin["center"][1]:getViewport()
217217
skinSpriteBatch:add(skin["center"][1], skinData["center"][1], skinData["center"][2], 0, skinData["center"][3]/w, skinData["center"][4]/h)
218218
end
219-
love.graphics.setColor(255,255,255)
219+
love.graphics.setColor(1,1,1)
220220
love.graphics.draw(skinSpriteBatch,0,0)
221221
for name, b in pairs(buttons) do
222222
if skinData.highlightonpress or not b.held then
@@ -231,12 +231,12 @@ function androidDraw()
231231
end
232232

233233
--[[touch debug
234-
love.graphics.setColor(255,0,0)
234+
love.graphics.setColor(1,0,0)
235235
local mx,my= androidGetCoords(mouseTouchX,mouseTouchY)
236236
love.graphics.circle("fill",mx,my,2)
237-
love.graphics.setColor(255,255,0)
237+
love.graphics.setColor(1,1,0)
238238
love.graphics.circle("fill",lastTouchX,lastTouchY,1)
239-
love.graphics.setColor(0,255,255)
239+
love.graphics.setColor(0,1,1)
240240
love.graphics.circle("fill",lastReleaseX,lastReleaseY,1)]]
241241

242242
if not androidLowRes then

androidbutton.lua

+7-7
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,27 @@ function touchButton:draw(spriteBatch, quad)
6464
love.graphics.setLineWidth(1)
6565
end
6666
if self.held then
67-
love.graphics.setColor(100, 100, 100, 140)
67+
love.graphics.setColor(100/255, 100/255, 100/255, 140/255)
6868
elseif highlight then
69-
love.graphics.setColor(90, 90, 90, 140)
69+
love.graphics.setColor(90/255, 90/255, 90/255, 140/255)
7070
elseif self.color then
71-
love.graphics.setColor(self.color[1], self.color[2], self.color[3], 80)
71+
love.graphics.setColor(self.color[1], self.color[2], self.color[3], 80/255)
7272
else
73-
love.graphics.setColor(30, 30, 30, 80)
73+
love.graphics.setColor(30/255, 30/255, 30/255, 80/255)
7474
end
7575
if self.round then
7676
local x, y, r = self.x+self.w/2, self.y+self.h/2,self.r
7777
love.graphics.circle("fill", x, y, r, 8)
78-
love.graphics.setColor(255, 255, 255, 140)
78+
love.graphics.setColor(1, 1, 1, 140/255)
7979
love.graphics.circle("line", x, y, r, 8)
8080
else
8181
local x, y, w, h = self.x, self.y, self.w, self.h
8282
love.graphics.rectangle("fill", x, y, w, h)
83-
love.graphics.setColor(255, 255, 255, 140)
83+
love.graphics.setColor(1, 1, 1, 140/255)
8484
love.graphics.rectangle("line", x+.5, y+.5, w, h)
8585
end
8686

87-
love.graphics.setColor(255, 255, 255)
87+
love.graphics.setColor(1, 1, 1)
8888
if self.text then
8989
properprintfast(self.text, math.floor(self.x+self.w/2-string.len(self.text)*4), math.floor(self.y+self.h/2-4))
9090
elseif self.img then

animation.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ disableanimation disables this animation from triggering
5252
enableanimation enables this animation to trigger
5353
playerjump[:player] makes players jump (as high as possible)
5454
playerstopjump[:player] makes players abort the jump (for small jumps)
55-
dialogbox:text[:speaker] creates a dialogbox with <text> and <speaker>
55+
dialogbox:text[:speaker][:color] creates a dialogbox with <text> and <speaker> and <color> (from textcolors in variables.lua)
5656
removedialogbox removes the dialogbox
5757
playmusic:i plays music <i>
5858
screenshake:power makes the screen shake with <power>
5959
addcoins:coins adds <coins> coins
6060
addpoints:points adds <points> points
61-
changebackgroundcolor:r:g:b changes background color ro rgb
61+
changebackgroundcolor:r:g:b changes background color to rgb
6262
killplayer[:player] hurts player(s)
6363
changetime:time changes the time left to <time>
6464
loadlevel:world:level:sublevel:exit starts level <world>-<level>_<sublevel> pipeexitid:<exit>
@@ -592,7 +592,7 @@ function animation:update(dt)
592592
playmusic()
593593
end
594594
elseif v[1] == "changebackgroundcolor" then
595-
love.graphics.setBackgroundColor(tonumber(v[2]) or 255, tonumber(v[3]) or 255, tonumber(v[4]) or 255)
595+
love.graphics.setBackgroundColor((tonumber(v[2]) or 255)/255, (tonumber(v[3]) or 255)/255, (tonumber(v[4]) or 255)/255)
596596
elseif v[1] == "killplayer" then
597597
if v[2] == "everyone" then
598598
for i = 1, players do

animationguiline.lua

+5-5
Original file line numberDiff line numberDiff line change
@@ -1841,13 +1841,13 @@ function animationguiline:init(tabl, t2)
18411841
local firstwidth = 22--#animationstrings[self.type][start]
18421842

18431843
self.deletebutton = guielement:new("button", 0, 0, "x", function() self:delete() end, nil, nil, nil, 8, 0.1)
1844-
self.deletebutton.textcolor = {200, 0, 0}
1844+
self.deletebutton.textcolor = {200/255, 0, 0}
18451845

18461846
self.downbutton = guielement:new("button", 0, 0, "", function() self:movedown() end, nil, nil, nil, 8, 0.1)
1847-
self.downbutton.textcolor = {255, 255, 255}
1847+
self.downbutton.textcolor = {1, 1, 1}
18481848

18491849
self.upbutton = guielement:new("button", 0, 0, "", function() self:moveup() end, nil, nil, nil, 8, 0.1)
1850-
self.upbutton.textcolor = {255, 255, 255}
1850+
self.upbutton.textcolor = {1, 1, 1}
18511851

18521852
self.elements[1].gui = guielement:new("dropdown", 0, 0, firstwidth, function(val) self:changemainthing(val) end, start, unpack(animationstrings[self.type]))
18531853
self.elements[1].width = 14+firstwidth*8
@@ -2048,7 +2048,7 @@ end
20482048
function animationguiline:draw(x, y)
20492049
love.graphics.setColor(0, 0, 0)
20502050
love.graphics.rectangle("fill", x*scale, y*scale, (width*16-x)*scale, 11*scale)
2051-
love.graphics.setColor(255, 255, 255)
2051+
love.graphics.setColor(1, 1, 1)
20522052

20532053
local xadd = 0
20542054
self.deletebutton.x = x+xadd
@@ -2068,7 +2068,7 @@ function animationguiline:draw(x, y)
20682068

20692069
for i = 1, #self.elements do
20702070
if self.elements[i].t == "text" then
2071-
love.graphics.setColor(255, 255, 255)
2071+
love.graphics.setColor(1, 1, 1)
20722072
properprintF(self.elements[i].value, (x+xadd-1)*scale, (y+2)*scale)
20732073
xadd = xadd + self.elements[i].width
20742074
else

belt.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ function drawbelt(x, y, length, i, color) --for editor
205205
img = beltonimg
206206
row = tonumber(color) or 1
207207
end
208-
local x, y = x-1, y-1
209-
local length = math.min(99, math.max(2, math.floor(tonumber(length or 3))))
210-
love.graphics.setColor(255, 255, 255)
208+
x, y = x-1, y-1
209+
length = math.min(99, math.max(2, math.floor(tonumber(length or 3))))
210+
love.graphics.setColor(1, 1, 1)
211211
love.graphics.draw(img, beltquad[row][1], math.floor((x-xscroll)*16*scale), math.floor((y-yscroll-.5)*16*scale), 0, scale, scale)
212212
for i = 1, length-2 do
213213
love.graphics.draw(img, beltquad[row][2], math.floor((x+i-xscroll)*16*scale), math.floor((y-yscroll-.5)*16*scale), 0, scale, scale)
@@ -292,4 +292,4 @@ function belt:floorcollide(a, b)
292292
end
293293

294294
function belt:passivecollide(a, b)
295-
end
295+
end

blocktogglebutton.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ end
184184

185185
function blocktogglebutton:draw()
186186
if not self.drawable then
187-
love.graphics.setColor(255, 255, 255)
187+
love.graphics.setColor(1, 1, 1)
188188
love.graphics.draw(self.graphic, self.quad, math.floor(((self.x-xscroll)*16+self.offsetX)*scale), math.floor(((self.y-yscroll)*16-self.offsetY)*scale), self.rotation, scale, scale, self.quadcenterX, self.quadcenterY)
189189
end
190190
end
@@ -453,7 +453,7 @@ function buttonblock:init(x, y, color, solid)
453453
end
454454

455455
function buttonblock:draw()
456-
--love.graphics.setColor(255, 255, 255)
456+
--love.graphics.setColor(1, 1, 1)
457457
love.graphics.draw(self.graphic, self.quad, math.floor(((self.x-xscroll)*16+self.offsetX)*scale), math.floor(((self.y-yscroll)*16-self.offsetY)*scale), 0, scale, scale, self.quadcenterX, self.quadcenterY)
458458
end
459459

@@ -486,4 +486,4 @@ end
486486

487487
function buttonblock:floorcollide(a, b)
488488

489-
end
489+
end

cappy.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ function cappy:draw()
200200
if self.hat == 1 then
201201
love.graphics.setColor(self.player.colors[1])
202202
else
203-
love.graphics.setColor(255, 255, 255)
203+
love.graphics.setColor(1, 1, 1)
204204
end
205205
local graphic = hat[self.hat].graphic
206206
local quad = hat[self.hat].quad[1]
@@ -401,4 +401,4 @@ function cappy:globalcollide(a, b)
401401
end]]
402402
end
403403
return true
404-
end
404+
end

characters.lua

+36-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
11
--I have no idea what i'm even doing
2+
local colorvariables = {"colors", "defaultcolors", "starcolors", "flowercolor", "hammersuitcolor", "frogsuitcolor", "leafcolor", "iceflowercolor", "tanookisuitcolor", "statuecolor", "superballcolor", "blueshellcolor", "boomerangcolor"}
23
local animfiles = {"", "big", "fire", "ice", "superball", "hammer", "frog", "raccoon", "tiny", "tanooki", "skinny", "cape", "shell", "boomerang"}
34
local blankimg = love.graphics.newImage(love.image.newImageData(1, 1))
45
local splitimage
56

7+
local function iscolorvariable(key)
8+
for i, v in ipairs(colorvariables) do
9+
if v == key then
10+
return true
11+
end
12+
end
13+
return false
14+
end
15+
16+
local function convertcolors(table)
17+
if table == nil or #table == 0 then
18+
return
19+
end
20+
for i, v in ipairs(table) do
21+
if type(v) == "table" then
22+
convertcolors(v)
23+
else
24+
table[i] = tonumber(v)/255
25+
end
26+
end
27+
end
28+
629
function loadcustomplayers()
730
characters = {list = {}, data = {}}
831
local dir = love.filesystem.getDirectoryItems("alesans_entities/characters")
@@ -24,6 +47,8 @@ function loadcustomplayers()
2447
i = #characters["list"]+1,
2548

2649
--colors
50+
-- !! MAKE SURE to add any new RGB variables to `colorvariables` at the top !!
51+
-- !! to ensure they get automatically converted from 0..255 to 0..1 !!
2752
colorables = {"hat", "hair", "skin"},
2853
colors = {},
2954
defaultcolors = false,
@@ -347,6 +372,11 @@ function loadcustomplayers()
347372
temp = err
348373
--works! so set properties
349374
for i, v in pairs(temp) do
375+
-- convert numbers to 0..1
376+
if iscolorvariable(i) then
377+
convertcolors(v)
378+
end
379+
-- set properties
350380
playerstuff[i] = v
351381
if i == "health" or i == "fireenemy" then
352382
playerstuff["advanced"] = true
@@ -422,6 +452,7 @@ function loadcustomplayers()
422452
end
423453

424454
--local splitShader
455+
--`color` param is expected to be an array of 0..255 values (r, g, b) to maintain support for old community-created content
425456
function splitimage(img, color, exclude, imagedata) --split singe image into colorable images
426457
if false then --useShader then
427458
if not splitShader then
@@ -468,25 +499,26 @@ function splitimage(img, color, exclude, imagedata) --split singe image into col
468499
for x = 0, input:getWidth()-1 do
469500
for y = 0, input:getHeight()-1 do
470501
local r, g, b, a = input:getPixel(x, y)
502+
local rr, rg, rb = round(r*255), round(g*255), round(b*255)
471503
local place = false
472504
if exclude then
473505
place = true
474506
for i, c in pairs(color) do
475-
if r == c[1] and g == c[2] and b == c[3] then
507+
if rr == c[1] and rg == c[2] and rb == c[3] then
476508
place = false
477509
break
478510
end
479511
end
480512
else
481-
if r == color[1] and g == color[2] and b == color[3] then
513+
if rr == color[1] and rg == color[2] and rb == color[3] then
482514
place = true
483515
end
484516
end
485517
if place then
486518
if exclude then
487519
output:setPixel(x, y, r, g, b, a)
488520
else
489-
output:setPixel(x, y, 255, 255, 255, a)
521+
output:setPixel(x, y, 1, 1, 1, a)
490522
end
491523
end
492524
end
@@ -618,4 +650,4 @@ end
618650
--[[function getplayer() --sets abilities and sprites
619651
playerstuff = { playername, jumpheight, speed, grip(friction)}
620652
playerabilities = {raccoon}
621-
end]]
653+
end]]

checkpointflag.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function checkpointflag:init(x, y, r, i)
99
self.r = r
1010
self.i = i
1111
self.color = {0,0,0}
12-
self.symbolcolor = {255,255,255}
12+
self.symbolcolor = {1,1,1}
1313
self.activatetimer = false
1414

1515
local v = convertr(r[3], {"string", "num"}, true)
@@ -99,7 +99,7 @@ function checkpointflag:draw(drop)
9999
end
100100
end
101101
if not drop then
102-
love.graphics.setColor(255, 255, 255)
102+
love.graphics.setColor(1, 1, 1)
103103
end
104104
love.graphics.draw(checkpointflagimg, checkpointflagquad[spriteset][quadi], math.floor(((self.x+self.width/2-xscroll)*16+offx)*scale), math.floor(((self.y+self.height/2-yscroll-.5)*16+offy)*scale), self.rotation, scale, scale, 16, 16)
105105
end
@@ -159,4 +159,4 @@ function checkpointflag:activate(playeri)
159159
if (self.color[1]+self.color[2]+self.color[3])/3 > 200 then --is the color bright? if so, use a black symbol
160160
self.symbolcolor = {0, 0, 0}
161161
end
162-
end
162+
end

0 commit comments

Comments
 (0)