[Library] LövelyMoon v2

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

[Library] LövelyMoon v2

Post by Davidobot »

Welcome to my first library: LövelyMoon! Basicly this library is based around a lua engine called "DaisyMoon". LövelyMoon adds a very neat way of handling gamestates, in fact, it is made to make your game focus on gamestates and such.

The credit for the new version goes to the wonderful bVictor7364

Changes from version 1:
  • Updated to LÖVE 0.10.2
  • lovelyMoon.lua & stateManager.lua are now merged in one module "lovelyMoon".
  • All "lovelyMoon.*" functions (update, draw, etc.) are moved to "lovelyMoon.events.*".
  • All the functions that were in a global scope (from stateManager) were moved to "lovelyMoon.*"
  • Simplified adding state procedure.
  • Added a "switchState(currentID, nextID)", which basically calls "disableState(id)" and then "enableState(id)".
  • Added a "lovelyMoon.new(self)" function.
  • Simplified "state:new()" function. all you have to do now is: "return lovelyMoon.new(self)"
Reference:

Code: Select all

lovelyMoon.event.update(dt)
lovelyMoon.event.draw()
lovelyMoon.event.keypressed(key, unicode)
lovelyMoon.event.keyreleased(key, unicode)
lovelyMoon.event.mousepressed(x, y, button)
lovelyMoon.event.mousereleased(x, y, button)

lovelyMoon.new(self) -- Initializes a new state; call from: function state:new()
lovelyMoon.addState(file, id) -- return state; file argument is used for require.
lovelyMoon.isStateEnabled(id) -- return bool
lovelyMoon.getState(id) -- return state
lovelyMoon.enableState(id)
lovelyMoon.disableState(id)
lovelyMoon.switchState(currentID, nextID)
lovelyMoon.toggleState(id)
lovelyMoon.destroyState(id)
Usage:
0. Place "lovelyMoon.lua" library somewhere in source folder (e.g. "/lib/lovelyMoon.lua")
1. In main.lua add a variable to require the lovelyMoon library and preferable create a table for states:

Code: Select all

lovelyMoon = require("lib.lovelyMoon")
states = {}
2. In function love.load() add states and enable first one:

Code: Select all

function love.load()
	states.menu = lovelyMoon.addState("states.menu", "menu") -- Argument 1 is file path for require
	states.game = lovelyMoon.addState("states.game", "game")
	
	lovelyMoon.enableState("menu")
end
3. Replace love event states by lovelyMoon ones:

Code: Select all

function love.update(dt)
	lovelyMoon.event.update(dt)
end

function love.draw()
	lovelyMoon.event.draw()
end

function love.keypressed(key, unicode)
	lovelyMoon.event.keypressed(key, unicode)
end

function love.keyreleased(key, unicode)
	lovelyMoon.event.keyreleased(key, unicode)
end

function love.mousepressed(x, y, button)
	lovelyMoon.event.mousepressed(x, y, button)
end

function love.mousereleased(x, y, button)
	lovelyMoon.event.mousereleased(x, y, button)
end
4. Create the state script (e.g. "/states/menu.lua"):

Code: Select all

local state = {}

function state:new()
	return lovelyMoon.new(self)
end

function state:load()
	
end

function state:close()
	
end

function state:enable()
	
end

function state:disable()
	
end

function state:update(dt)
	
end

function state:draw()
	
end

function state:keypressed(key, unicode)
	
end

function state:keyreleased(key, unicode)
	
end

function state:mousepressed(x, y, button)
	
end

function state:mousereleased(x, y, button)
	
end

return state
5.That's all. Add game code to states' functions.

Thanks again to bVictor7364! This is all his work!
I hope this library proves to be useful to you all!
Attachments
lovelyMoon.lua
Current Version
(3.41 KiB) Downloaded 827 times
lovelyMoon_v2.love
Current Example
(7.38 KiB) Downloaded 824 times
lovelyMoon.love
OLD VERSION 1
(2.3 KiB) Downloaded 1130 times
Last edited by Davidobot on Mon Jun 19, 2017 5:30 pm, edited 7 times in total.
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: [Library] LövelyMoon

Post by substitute541 »

Can't open "states/Gamestate.lua". No such file or directory.
Currently designing themes for WordPress.

Sometimes lurks around the forum.
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: [Library] LövelyMoon

Post by Davidobot »

substitute541 wrote:Can't open "states/Gamestate.lua". No such file or directory.
Whoops :oops: .
Sorry, remind me to never use dofile again (Well, actually, it can prove useful for making a game mod-friendly, hmmmm). Fixed.
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: [Library] LövelyMoon

Post by Roland_Yonaba »

Putting aside the fact that it spawns lots of globals to the main code, I like it.
Have you considered stackable states ? I don't use them by myself, but it seems some people are fond of them.
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: [Library] LövelyMoon

Post by Davidobot »

Roland_Yonaba wrote:Putting aside the fact that it spawns lots of globals to the main code, I like it.
Have you considered stackable states ? I don't use them by myself, but it seems some people are fond of them.
Thanks! :awesome:
What do you exactly mean by "stackable states"? You can have multiple gamestates running at the same time if that is what you mean?
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: [Library] LövelyMoon

Post by Roland_Yonaba »

Davidobot wrote:Thanks! :awesome:
What do you exactly mean by "stackable states"?
You can have multiple gamestates running at the same time if that is what you mean?
Yes.
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: [Library] LövelyMoon

Post by Davidobot »

Well, as far as I tested, this is possible with this library. :crazy:
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Re: [Library] LövelyMoon

Post by Eamonn »

Looks awesome! I'll defiantly be using it in some of my projects! None that I've already gotten into, because I'm too lazy to change the code, but in some other projects this'll be really useful! :)
"In those quiet moments, you come into my mind" - Liam Reilly
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

Re: [Library] LövelyMoon

Post by Davidobot »

Eamonn wrote:Looks awesome! I'll defiantly be using it in some of my projects! None that I've already gotten into, because I'm too lazy to change the code, but in some other projects this'll be really useful! :)
Thanks! :D
If you need any help with the library, feel free to ask me. :3
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: [Library] LövelyMoon

Post by jjmafiae »

i think i will use some time staring at your code. who knows, it might inspire me to do another unreleased commie library?
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests