-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresources.lua2p
87 lines (78 loc) · 1.74 KB
/
resources.lua2p
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
local Log = require("modules.log.log")
!if _CACHED_PRELOAD then
local Cache = require("cache")
!end
local Resources = {
meta = {},
data = {},
}
!if _DEV then
local mt = {}
mt.__index = function(t, i)
local id
for k, v in pairs(Resources.data) do
if t == v then
id = k
break
end
end
error(i .. " is invalid key for Resources:" .. id)
end
!end
Resources.meta = require("data.resources_list")
function Resources.get_meta(key)
@@assert(type(key) == "string")
@@assert(Resources.meta[key], key .. " is invalid")
local t = tablex.copy(Resources.meta[key])
!if not _GLSL_NORMALS then
t.images = tablex.append({}, t.images, t.array_images)
if t.array_images then
tablex.clear(t.array_images)
t.array_images = nil
end
!end
return t
end
function Resources.set_resources(t)
@@assert(type(t) == "table")
tablex.clear(Resources.data)
@@assert(#Resources.data == 0)
for k, _ in pairs(t) do
Resources.data[k] = t[k]
!if _DEV then
setmetatable(Resources.data[k], mt)
!end
end
end
!if _CACHED_PRELOAD then
function Resources.copy_array_images(resources)
@@assert(type(resources) == "table")
for k, v in pairs(resources.array_images) do
resources.images[k] = v
end
end
!end
function Resources.clean()
for k, t in pairs(Resources.data) do
for name, _ in pairs(t) do
!if _CACHED_PRELOAD then
if not Cache.has_resource(name) then
Resources.data[k][name]:release()
Resources.data[k][name] = nil
Log.trace("Cleaned:", k, name)
else
Log.trace("Cached, skipping:", k, name)
end
!else
Resources.data[k][name]:release()
Resources.data[k][name] = nil
Log.trace("Cleaned:", k, name)
!end
end
Resources.data[k] = nil
end
!if _CACHED_PRELOAD then
Cache.clean_resources()
!end
end
return Resources