Giter Site home page Giter Site logo

lovhot's Introduction

Lovhot

v1.1

Lovhot is a Hot Swap System.

System allows hot reload.

User have to save objects state in the _state table with function Hot.state.

  • Develop mode Hot Swap System use love.filesystem to create file tree and to determine modtime.

  • Release mode (OS X only) Hot Swap System use shell commands "ls" to create file and "stat" to determine modtime.

Made with LÖVE

To run source code: clone repository, download & install LÖVE 11.5 for your system.

Engine: LÖVE Development Team

Code: Aliaksandr Veledzimovich

Example

Copy lovhot.lua to the project dir.

main.lua

io.stdout:setvbuf('no')

local hot = require('lovhot')

-- Entry point to load Hot Swap System
function love.load()
    love.window.setPosition(0,0)
    -- By default hot swap disabled for main.lua and conf.lua
    -- After root.lua you can provide files to disable hot swap
    hot.load('root.lua')
end

Create root.lua as entry point for hot reload and game logic.

In this example root.lua used as scene manager.

root.lua

local hot = require('lib/lovhot')
-- Use dofile for all files which you want to hot swap
local Game = dofile('game.lua')

local Root = {
    tag='Root', models={}, activetag=nil, active=nil
}
-- Called by Hot Swap System
function Root.load()
    Root.addModel(Game)

    -- Tag to track state
    Root.activetag = Game.tag
    -- Track state of the Root object
    hot.state(Root.tag, Root, 'activetag')

    Root.activate(Root.activetag)
end

function Root.addModel(mod) Root.models[mod.tag] = mod end

function Root.activate(tag)
    Root.acttag = tag
    Root.active = Root.models[tag]
    Root.active.new()
end
-- Called by Hot Swap System
function Root.update(dt)
    love.window.setTitle(Root.tag)
    Root.active.update(dt)
end
-- Called by Hot Swap System
function Root.draw()
    Root.active.draw()
end

function Root.keyreleased(key, unicode)
   if Root.active == Game then
        local ball = Root.active.ball
        if key == 'space' then
            ball.speed = 10
        end
    end
end

return Root

game.lua

local Ball = dofile('ball.lua')

local Game = {
    tag='Game', objects={}
}
function Game.new()
    Game.ball = Ball
    Game.addObject(Ball)
end

function Game.addObject(obj) Game.objects[obj] = obj end

function Game.update(dt)
    for object in pairs(Game.objects) do
        object.update(dt)
    end

end

function Game.draw()
    for object in pairs(Game.objects) do
        object.draw()
    end
end

return Game

ball.lua

local hot = require('lovhot')

local Ball = {
    tag='Ball', x=400, y=300, speed=100, color={1, 0, 0, 1}
}
-- Track state of the Ball object
hot.state(Ball.tag, Ball, 'x', 'y')

function Ball.update(dt)
    Ball.x = Ball.x - Ball.speed * dt
end

function Ball.draw()
    love.graphics.setColor(Ball.color)
    love.graphics.circle('fill', Ball.x, Ball.y, 10)
end

return Ball

Warning

Check game structure in the example dir.

Screenshot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.