forked from karai17/Simple-Tiled-Implementation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
45 lines (37 loc) · 1.14 KB
/
Copy pathinit.lua
File metadata and controls
45 lines (37 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
--- Simple and fast Tiled map loader and renderer.
-- @module sti
-- @author Landon Manning
-- @copyright 2015
-- @license MIT/X11
local STI = {
_LICENSE = "STI is distributed under the terms of the MIT license. See LICENSE.md.",
_URL = "https://github.com/karai17/Simple-Tiled-Implementation",
_VERSION = "0.13.1.4",
_DESCRIPTION = "Simple Tiled Implementation is a Tiled Map Editor library designed for the *awesome* LÖVE framework."
}
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.
-- @return table The loaded Map.
function STI.new(map, plugins)
-- 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
))
-- Get path to map
local path = map:reverse():find("[/\\]") or ""
if path ~= "" then
path = map:sub(1, 1 + (#map - path))
end
-- Load map
map = love.filesystem.load(map)
setfenv(map, {})
map = setmetatable(map(), {__index = Map})
map:init(path, plugins)
return map
end
return STI