-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.moon
118 lines (100 loc) · 4.09 KB
/
init.moon
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
path = ...
love = love
filesystem = love.filesystem
ext = assert require path .. ".ext"
tools = assert require path .. ".tools"
-- config
conf = {
debug: true
delim: '/' or package.config\sub 1,1
}
Mage = {}
with Mage
.loadAsset = (path, ...) ->
assert path, "Path should not be nil."
fileType = tools.getExt path
if tools.exists ext.image, fileType
return love.graphics.newImage path, ...
elseif tools.exists ext.audio, fileType
return love.audio.newSource path, ... or 'static'
elseif tools.exists ext.font, fileType
return love.graphics.newFont path, ...
elseif tools.exists ext.video, fileType
return love.graphics.newVideo path, ...
else
for k, v in pairs ext
for i = 1, #ext[k]
p = path .. '.' .. ext[k][i]
info = love.filesystem.getInfo p
if info
if info.type == "file"
return Mage.loadAsset p, ...
print "AssetMage couldn't load the asset."
.requireLib = (path,recurse,tbl,rename,except,isPackage,debugTab) ->
assert filesystem.getInfo(path), "Path does not exist : "..path
libTab = tbl or {}
dir, libName = filesystem.getDirectoryItems path
rename = rename or (tbl and tools.getWord or tools.removeExt)
except = except or -> return false
debugT = debugTab or ''
if debugT == '' and conf.debug
print "<== AssetsMage DEBUG INFO ==>"
for _, file in ipairs dir
if tools.isFile path..conf.delim..file
libName = rename file
if tools.getExt(file) == "lua" and file ~= "init.lua" and except(file) == false
file = tools.removeExt file
print type(require(path..conf.delim..file ))
if type(require(path..conf.delim..file )) ~= 'boolean'
libTab[libName] = require path .. conf.delim .. file
if conf.debug
print debugT.. "Loaded Module : " ..libName.. ' ('..path..conf.delim..file..') ...'
else
require path .. conf.delim .. file
if conf.debug
print debugT..libName..' is a non-returning lib !!!'
else
if isPackage
pName = rename(file)
if tools.isFile(path..conf.delim..file..conf.delim..'init.lua') and except(file) == false
if type(require(path..conf.delim..file )) ~= 'boolean'
libTab[pName] = require path .. conf.delim .. file
if conf.debug
print debugT.. "Loaded Package : " ..pName.. ' ('..path..conf.delim..file..') ...'
else
require path .. conf.delim .. file
if conf.debug
print debugT..' '..pName..' is a non-returning package !!!'
else
if recurse
if tools.isFile(path..conf.delim..file..conf.delim..'init.lua')
if conf.debug
print debugT..path..conf.delim..file.."is ignored (as it's a package)"
else
if conf.debug
print debugT.."Recursing.. "..path..conf.delim..file
tools.mergeTabs libTab, Mage.requireLib path..delim..file,recurse,tbl,rename,except,isPackage,debugTab..'\t'
return libTab
.load = (assetType,path,recurse,tbl,rename,except,param) =>
assert filesystem.getInfo(path), "Path does not exist : "..path
tbl = tbl
recurse = recurse or false
rename = rename or (tbl and tools.getWord or tools.removeExt)
except = except or -> return false
param = param or ->
local libName
dir, assetTab = filesystem.getDirectoryItems(path), tbl or {}
for i = 1, #dir
if isFile path..conf.delim..dir[i]
libName = rename dir[i]
if except(dir[i]) == false and tools.exists(assetType, getExtension(dir[i]))
if libName and assetTab[libName] == false
assetTab[libName] = Mage.loadAsset path..conf.delim..dir[i], param(dir[i])
else
if conf.debug
print "Asset "..libName.." already loaded."
else
if recurse
tools.mergeTabs assetTab, Mage.load assetType, path..conf.delim..dir[i], recurse, tbl, rename, except, param
return assetTab
Mage