Skip to content

Commit 2ca679a

Browse files
committed
Small changes before Luven v1.1 release
1 parent f9676be commit 2ca679a

1 file changed

Lines changed: 12 additions & 40 deletions

File tree

luven/luven.lua

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -186,30 +186,6 @@ luven.lightShapes = {}
186186
-- /// Luven utils local functions
187187
-- ///////////////////////////////////////////////
188188

189-
local function calculateLightOrigin(lightId)
190-
local light = currentLights[lightId]
191-
192-
local origin = { x = 0, y = 0 }
193-
194-
if (light.shape.originX == "center") then
195-
origin.x = light.shape.sprite:getWidth() / 2
196-
elseif (light.shape.originX == "min") then
197-
origin.x = 0
198-
elseif (light.shape.originX == "max") then
199-
origin.x = light.shape.sprite:getWidth()
200-
end -- if
201-
202-
if (light.shape.originY == "center") then
203-
origin.y = light.shape.sprite:getHeight() / 2
204-
elseif (light.shape.originY == "min") then
205-
origin.y = 0
206-
elseif (light.shape.originY == "max") then
207-
origin.y = light.shape.sprite:getHeight()
208-
end -- if
209-
210-
return origin
211-
end -- function
212-
213189
local function getLastEnabledLightIndex()
214190
for i = NUM_LIGHTS, 1, -1 do
215191
if (currentLights[i].enabled) then
@@ -231,7 +207,7 @@ local function drawLights()
231207
if (currentLights[i].enabled) then
232208
local light = currentLights[i]
233209
lgSetColor(light.color)
234-
lgDraw(light.shape.sprite, light.x, light.y, light.angle, light.scaleX * light.power, light.scaleY * light.power, light.origin.x, light.origin.y)
210+
lgDraw(light.shape.sprite, light.x, light.y, light.angle, light.scaleX * light.power, light.scaleY * light.power, light.shape.originX, light.shape.originY)
235211
end -- if
236212
end -- for
237213

@@ -292,12 +268,10 @@ function luven.init(screenWidth, screenHeight, useCamera)
292268

293269
luven.registerLightShape("round", luvenPath .. "lights/round.png")
294270
luven.registerLightShape("rectangle", luvenPath .. "lights/rectangle.png")
295-
luven.registerLightShape("cone", luvenPath .. "lights/cone.png", "min", "center")
271+
luven.registerLightShape("cone", luvenPath .. "lights/cone.png", 0)
296272

297273
lightMap = lg.newCanvas(screenWidth, screenHeight)
298274

299-
luvenShader:send("lightsCount", lightsCount)
300-
301275
for i = 1, NUM_LIGHTS do
302276
currentLights[i] = { enabled = false }
303277
end -- for
@@ -309,24 +283,25 @@ function luven.setAmbientLightColor(color)
309283
ambientLightColor = color
310284
end -- function
311285

312-
-- param : originX, originY : TEXT : "center", "min", "max"
313286
function luven.registerLightShape(name, spritePath, originX, originY)
314-
originX = originX or "center"
315-
originY = originY or originX
316-
287+
local functionName = "luven.registerLightShape( name, spritePath, [ originX ], [ originY ] )"
317288
assertLightShape(name)
289+
assertType(functionName, "spritePath", spritePath, "string")
290+
291+
local lightSprite = lg.newImage(spritePath)
292+
originX = originX or (lightSprite:getWidth() / 2)
293+
originY = originY or (lightSprite:getHeight() / 2)
294+
295+
assertPositiveNumber(functionName, "originX", originX)
296+
assertPositiveNumber(functionName, "originY", originY)
318297

319298
luven.lightShapes[name] = {
320-
sprite = lg.newImage(spritePath),
299+
sprite = lightSprite,
321300
originX = originX,
322301
originY = originY
323302
}
324303
end -- function
325304

326-
function luven.sendCustomViewMatrix(viewMatrix)
327-
error("luven.sendCustomViewMatrix : Not implemented anymore. Stop use it.")
328-
end -- function
329-
330305
function luven.update(dt)
331306
if (useIntegratedCamera) then
332307
cameraUpdate(dt)
@@ -435,7 +410,6 @@ function luven.addNormalLight(x, y, color, power, lightShape, angle, sx, sy)
435410
light.power = power
436411
light.type = lightTypes.normal
437412
light.shape = lightShape
438-
light.origin = calculateLightOrigin(light.id)
439413

440414
light.enabled = true
441415

@@ -484,7 +458,6 @@ function luven.addFlickeringLight(x, y, colorRange, powerRange, speedRange, ligh
484458
light.power = 0
485459
light.type = lightTypes.flickering
486460
light.shape = lightShape
487-
light.origin = calculateLightOrigin(light.id)
488461

489462
light.flickTimer = 0
490463
light.colorRange = colorRange
@@ -530,7 +503,6 @@ function luven.addFlashingLight(x, y, color, maxPower, speed, lightShape, angle,
530503
light.power = 0
531504
light.type = lightTypes.flashing
532505
light.shape = lightShape
533-
light.origin = calculateLightOrigin(light.id)
534506

535507
light.maxPower = maxPower
536508
light.speed = speed

0 commit comments

Comments
 (0)