2016-04-26 13:23:11 +00:00
|
|
|
--- Simple and fast Tiled map loader and renderer.
|
|
|
|
-- @module sti
|
|
|
|
-- @author Landon Manning
|
|
|
|
-- @copyright 2015
|
|
|
|
-- @license MIT/X11
|
2014-12-06 04:35:32 +00:00
|
|
|
|
|
|
|
local STI = {
|
2016-04-26 13:23:11 +00:00
|
|
|
_LICENSE = "MIT/X11",
|
|
|
|
_URL = "https://github.com/karai17/Simple-Tiled-Implementation",
|
|
|
|
_VERSION = "0.14.1.12",
|
|
|
|
_DESCRIPTION = "Simple Tiled Implementation is a Tiled Map Editor library designed for the *awesome* LÖVE framework.",
|
|
|
|
cache = {}
|
2014-12-06 04:35:32 +00:00
|
|
|
}
|
|
|
|
|
2016-04-26 13:23:11 +00:00
|
|
|
local path = (...):gsub('%.init$', '') .. "."
|
|
|
|
local Map = require(path .. "map")
|
|
|
|
|
|
|
|
--- Instance a new map.
|
|
|
|
-- @param path Path to the map file.
|
|
|
|
-- @param plugins A list of plugins to load.
|
|
|
|
-- @param ox Offset of map on the X axis (in pixels)
|
|
|
|
-- @param oy Offset of map on the Y axis (in pixels)
|
|
|
|
-- @return table The loaded Map.
|
|
|
|
function STI.new(map, plugins, ox, oy)
|
|
|
|
-- Check for valid map type
|
|
|
|
local ext = map:sub(-4, -1)
|
|
|
|
assert(ext == ".lua", string.format(
|
|
|
|
"Invalid file type: %s. File must be of type: lua.",
|
|
|
|
ext
|
|
|
|
))
|
2014-12-06 04:35:32 +00:00
|
|
|
|
|
|
|
-- Get path to map
|
|
|
|
local path = map:reverse():find("[/\\]") or ""
|
|
|
|
if path ~= "" then
|
|
|
|
path = map:sub(1, 1 + (#map - path))
|
|
|
|
end
|
2016-04-26 13:23:11 +00:00
|
|
|
|
2014-12-06 04:35:32 +00:00
|
|
|
-- Load map
|
2016-04-26 13:23:11 +00:00
|
|
|
map = love.filesystem.load(map)
|
2014-12-06 04:35:32 +00:00
|
|
|
setfenv(map, {})
|
|
|
|
map = setmetatable(map(), {__index = Map})
|
2016-04-26 13:23:11 +00:00
|
|
|
|
|
|
|
map:init(STI, path, plugins, ox, oy)
|
|
|
|
|
2014-12-06 04:35:32 +00:00
|
|
|
return map
|
|
|
|
end
|
|
|
|
|
2016-04-26 13:23:11 +00:00
|
|
|
--- Flush image cache.
|
|
|
|
function STI:flush()
|
|
|
|
self.cache = {}
|
2014-12-06 04:35:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return STI
|