2014-04-08 17:45:21 +00:00
|
|
|
--
|
|
|
|
-- EXF: Example Framework
|
|
|
|
--
|
|
|
|
-- This should make examples easier and more enjoyable to use.
|
|
|
|
-- All examples in one application! Yaay!
|
|
|
|
--
|
|
|
|
-- Updated by Dresenpai
|
|
|
|
require "lib/postshader"
|
2014-10-27 19:16:21 +00:00
|
|
|
local LightWorld = require "lib"
|
2014-12-11 02:42:04 +00:00
|
|
|
local ProFi = require 'examples.vendor.ProFi'
|
2021-11-08 21:36:38 +00:00
|
|
|
local List = require 'examples.vendor.list'
|
2014-04-08 17:45:21 +00:00
|
|
|
|
|
|
|
exf = {}
|
|
|
|
exf.current = nil
|
|
|
|
exf.available = {}
|
2014-03-04 13:52:51 +00:00
|
|
|
|
|
|
|
function love.load()
|
2014-11-07 14:21:41 +00:00
|
|
|
exf.list = List:new()
|
2016-02-03 14:45:22 +00:00
|
|
|
exf.smallfont = love.graphics.newFont(12)
|
|
|
|
exf.bigfont = love.graphics.newFont(24)
|
2014-11-07 14:21:41 +00:00
|
|
|
exf.list.font = exf.smallfont
|
2014-04-08 17:45:21 +00:00
|
|
|
|
2014-11-28 16:14:53 +00:00
|
|
|
exf.bigball = love.graphics.newImage("examples/gfx/love-big-ball.png")
|
2014-04-08 17:45:21 +00:00
|
|
|
|
2014-11-07 14:21:41 +00:00
|
|
|
-- Find available demos.
|
|
|
|
local files = love.filesystem.getDirectoryItems("examples")
|
2021-11-08 21:36:38 +00:00
|
|
|
local n = 0
|
2014-04-08 17:45:21 +00:00
|
|
|
|
2014-11-07 14:21:41 +00:00
|
|
|
for i, v in ipairs(files) do
|
2019-06-20 17:20:55 +00:00
|
|
|
is_file = (love.filesystem.getInfo("examples/".. v ).type == "file")
|
2014-11-28 16:14:53 +00:00
|
|
|
if is_file then
|
|
|
|
n = n + 1
|
|
|
|
table.insert(exf.available, v);
|
|
|
|
local file = love.filesystem.newFile(v, love.file_read)
|
|
|
|
file:open("r")
|
|
|
|
local contents = love.filesystem.read("examples/" .. v, 100)
|
|
|
|
local s, e, c = string.find(contents, "Example: ([%a%p ]-)[\r\n]")
|
|
|
|
file:close(file)
|
|
|
|
if not c then c = "Untitled" end
|
2021-11-08 21:36:38 +00:00
|
|
|
local title = string.format("%04d", n) .. " " .. c .. " (" .. v .. ")"
|
2014-11-28 16:14:53 +00:00
|
|
|
exf.list:add(title, v)
|
|
|
|
end
|
2014-11-07 14:21:41 +00:00
|
|
|
end
|
|
|
|
|
2021-11-08 21:36:38 +00:00
|
|
|
exf.load()
|
2014-04-08 17:45:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function exf.empty() end
|
2021-11-08 21:36:38 +00:00
|
|
|
function exf.keypressed(k) end
|
|
|
|
function exf.keyreleased(k) end
|
|
|
|
function exf.mousepressed(x, y, b) exf.list:mousepressed(x, y, b) end
|
|
|
|
function exf.mousereleased(x, y, b) exf.list:mousereleased(x, y, b) end
|
2014-04-08 17:45:21 +00:00
|
|
|
|
2021-11-08 21:36:38 +00:00
|
|
|
function exf.load()
|
2014-12-11 02:42:04 +00:00
|
|
|
ProFi:stop()
|
|
|
|
ProFi:writeReport( 'light_world_profiling_report.txt' )
|
|
|
|
|
2014-11-07 14:21:41 +00:00
|
|
|
load = nil
|
|
|
|
love.update = exf.update
|
|
|
|
love.draw = exf.draw
|
|
|
|
love.keypressed = exf.keypressed
|
|
|
|
love.keyreleased = exf.keyreleased
|
|
|
|
love.mousepressed = exf.mousepressed
|
|
|
|
love.mousereleased = exf.mousereleased
|
2014-03-06 15:56:25 +00:00
|
|
|
|
2014-11-07 14:21:41 +00:00
|
|
|
love.mouse.setVisible(true)
|
|
|
|
love.window.setTitle("LOVE Example Browser")
|
2014-03-04 13:52:51 +00:00
|
|
|
|
2021-11-08 21:36:38 +00:00
|
|
|
lightWorld = LightWorld({ambient = {0.49, 0.49, 0.49}})
|
|
|
|
lightMouse = lightWorld:newLight(20, 20, 1, 0.49, 0.24, 500)
|
|
|
|
lightMouse:setSmooth(2)
|
|
|
|
circleTest = lightWorld:newCircle(800 - 128, 600 - 128, exf.bigball:getWidth()*0.5)
|
2014-04-08 17:45:21 +00:00
|
|
|
end
|
|
|
|
|
2021-11-08 21:36:38 +00:00
|
|
|
function exf.update(dt)
|
|
|
|
exf.list:update(dt)
|
|
|
|
lightMouse:setPosition(love.mouse.getX(), love.mouse.getY())
|
|
|
|
lightWorld:update(dt)
|
2014-04-08 17:45:21 +00:00
|
|
|
end
|
|
|
|
|
2021-11-08 21:36:38 +00:00
|
|
|
function exf.draw()
|
|
|
|
lightWorld:draw(function()
|
|
|
|
love.graphics.setBackgroundColor(0, 0, 0)
|
2014-04-08 17:45:21 +00:00
|
|
|
|
2021-11-08 21:36:38 +00:00
|
|
|
love.graphics.setColor(0.18, 0.61, 1)
|
|
|
|
love.graphics.rectangle("fill", 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
2014-11-07 14:21:41 +00:00
|
|
|
|
2021-11-08 21:36:38 +00:00
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
love.graphics.setFont(exf.bigfont)
|
|
|
|
love.graphics.print("Examples:", 50, 30)
|
2014-03-23 18:10:58 +00:00
|
|
|
|
2021-11-08 21:36:38 +00:00
|
|
|
love.graphics.setFont(exf.smallfont)
|
|
|
|
love.graphics.print("Browse and click on the example you \nwant to run. To return the the example \nselection screen, press escape.", 500, 80)
|
2014-03-28 02:32:32 +00:00
|
|
|
|
2021-11-08 21:36:38 +00:00
|
|
|
exf.list:draw()
|
2014-03-04 13:52:51 +00:00
|
|
|
|
2021-11-08 21:36:38 +00:00
|
|
|
love.graphics.setColor(1, 1, 1)
|
|
|
|
love.graphics.draw(exf.bigball, 800 - 128, 600 - 128, love.timer.getTime()/5, 1, 1, exf.bigball:getWidth() * 0.5, exf.bigball:getHeight() * 0.5)
|
|
|
|
end)
|
2014-04-08 17:45:21 +00:00
|
|
|
end
|
|
|
|
|
2021-11-08 21:36:38 +00:00
|
|
|
function exf.start(item, file)
|
|
|
|
love.load = exf.empty
|
|
|
|
love.update = exf.empty
|
|
|
|
love.draw = exf.empty
|
|
|
|
love.keypressed = exf.empty
|
|
|
|
love.keyreleased = exf.empty
|
|
|
|
love.mousepressed = exf.empty
|
|
|
|
love.mousereleased = exf.empty
|
|
|
|
|
|
|
|
love.filesystem.load("examples/" .. file)()
|
|
|
|
love.graphics.setBackgroundColor(0,0,0)
|
|
|
|
love.graphics.setColor(1, 1, 1)
|
|
|
|
love.graphics.setLineWidth(1)
|
|
|
|
love.graphics.setLineStyle("smooth")
|
|
|
|
love.graphics.setBlendMode("alpha")
|
|
|
|
love.mouse.setVisible(true)
|
2014-04-08 17:45:21 +00:00
|
|
|
|
2021-11-08 21:36:38 +00:00
|
|
|
local o_keypressed = love.keypressed
|
|
|
|
love.keypressed = function(k)
|
|
|
|
if k == "escape" then
|
|
|
|
exf.load()
|
2014-04-08 17:45:21 +00:00
|
|
|
end
|
2021-11-08 21:36:38 +00:00
|
|
|
o_keypressed(k)
|
2014-11-07 14:21:41 +00:00
|
|
|
end
|
2014-04-08 17:45:21 +00:00
|
|
|
|
2021-11-08 21:36:38 +00:00
|
|
|
love.load()
|
2014-04-08 17:45:21 +00:00
|
|
|
end
|