-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
addon.lua
68 lines (57 loc) · 1.6 KB
/
addon.lua
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
--=========== Copyright © 2019, Planimeter, All rights reserved. ===========--
--
-- Purpose: Addon interface
--
--==========================================================================--
local hook = hook
local love = love
local print = print
local require = require
local string = string
local table = table
local ipairs = ipairs
module( "addon" )
function load( arg )
local addons = love.filesystem.getDirectoryItems( "addons" )
for i = #addons, -1, 1 do
local v = addons[ i ]
local info = love.filesystem.getInfo( v )
local isDirectory = info and info.type == "directory" or false
if ( string.fileextension( v ) ~= "zip" or not isDirectory ) then
table.remove( addons, i )
end
end
for _, v in ipairs( addons ) do
mount( v )
end
end
_addons = _addons or {}
function getAddons()
return _addons
end
function mount( addon )
if ( love.filesystem.mount( "addons/" .. addon, "" ) ) then
table.insert( getAddons(), addon )
print( "Mounted \"" .. addon .. "\"!" )
require( "addons." .. addon )
hook.call( "shared", "onAddonMounted", addon )
return true
end
print( "Failed to mount \"" .. addon .. "\"!" )
return false
end
function unmount( addon )
local mounted = table.hasvalue( getAddons(), addon )
if ( not mounted ) then
print( "Addon \"" .. addon .. "\" is not mounted!" )
return false
end
if ( love.filesystem.unmount( "addons/" .. addon ) ) then
hook.call( "shared", "onAddonUnmounted", addon )
unrequire( "addons." .. addon )
print( "Unmounted \"" .. addon .. "\"!" )
return true
end
print( "Failed to unmount \"" .. addon .. "\"!" )
return false
end