I'm totaly new to Lua love/2D and I did like some explanation about the following code.
Here is a first class :
Code: Select all
local AtlasScheme = {}
--[[
Atlas constructor
@return object Atlas
]]
function AtlasScheme:new()
self.__index = self
return setmetatable(
{
mapsByName = {} -- Map object by name @var table{string name, object Map}
},
self
)
end
--[[
Add map to mapsByName
@param string name
@param object Map
]]
function AtlasScheme:addMap(name, map)
self.mapsByName[name] = map
end
--[[
Link map together
@param ... string arg (mapName)
]]
function AtlasScheme:linkMap(...)
end
--[[
@return AtlasScheme
]]
return AtlasScheme
Code: Select all
local Atlas = {}
--[[
Atlas constructor
@param object atlasScheme
@return object Atlas
]]
function Atlas:new(atlasScheme)
self.__index = self
return setmetatable(
{
mapsByName = atlasScheme.mapsByName -- Map object by name @var table{string name, object Map}
},
self
)
end
--[[
Load map
@param string name
@return object Map
]]
function Atlas:loadMap(name)
local Inspect = require('libraries.inspect.inspect')
print(Inspect(self.mapsByName))
self.mapsByName[name]:load()
end
--[[
Get map
@param string name
@return object Map
]]
function Atlas:getMap(name)
return mapsByName[name]
end
--[[
@return Atlas
]]
return Atlas
Code: Select all
local Atlas = require('classes.data.Atlas')
local AtlasScheme = require('classes.data.AtlasScheme')
local Map = require('classes.data.Map')
-- dependencies
local atlasScheme = AtlasScheme:new()
local atlas = Atlas
-- Create atlas scheme
atlasScheme:addMap('Village', Map:new('truc'))
atlasScheme:addMap('Forest', Map:new('bidule') )
atlasScheme:addMap('Mine', Map:new('chouette') )
atlasScheme:linkMap('village', 'Forest')
-- Create map from scheme
atlas:new(atlasScheme)
I figured out that the issue is here :
Code: Select all
local atlasScheme = AtlasScheme:new()
-- local atlas = Atlas -- nope
local atlas = Atlas:new() -- instead would work
I apologize for my French skills in english and thank's for any enlightenment.