/zoeplat

To get this branch, use:
bzr branch http://9ix.org/bzr/zoeplat

« back to all changes in this revision

Viewing changes to zoetrope/core/cached.lua

  • Committer: Josh C
  • Date: 2013-04-16 00:27:10 UTC
  • Revision ID: josh@9ix.org-20130416002710-4soqj70ln7hdrzdb
testing audio

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
        --              Love image object
37
37
 
38
38
        image = function (self, path)
39
 
                assert(type(path) == 'string', 'path must be a string')
40
 
 
41
 
                if not self._library.image[path] then
42
 
                        self._library.image[path] = love.graphics.newImage(path)
43
 
                end
44
 
 
45
 
                return self._library.image[path]
 
39
                if STRICT then
 
40
                        assert(type(path) == 'string', 'path must be a string')
 
41
                end
 
42
 
 
43
                local realPath = self:_absolutePath(path)
 
44
 
 
45
                if not self._library.image[realPath] then
 
46
                        self._library.image[realPath] = love.graphics.newImage(realPath)
 
47
                end
 
48
 
 
49
                return self._library.image[realPath]
46
50
        end,
47
51
 
48
52
        -- Method: text
55
59
        --              string
56
60
 
57
61
        text = function (self, path)
58
 
                assert(type(path) == 'string', 'path must be a string')
59
 
 
60
 
                if not self._library.text[path] then
61
 
                        self._library.text[path] = love.filesystem.read(path)
62
 
                end
63
 
 
64
 
                return self._library.text[path]
 
62
                if STRICT then
 
63
                        assert(type(path) == 'string', 'path must be a string')
 
64
                end
 
65
 
 
66
                local realPath = self:_absolutePath(path)
 
67
 
 
68
                if not self._library.text[realPath] then
 
69
                        self._library.text[realPath] = love.filesystem.read(realPath)
 
70
                end
 
71
 
 
72
                return self._library.text[realPath]
65
73
        end,
66
74
 
67
75
        -- Method: sound
85
93
        --              <playSound>, <sound>
86
94
 
87
95
        sound = function (self, path, length)
88
 
                assert(type(path) == 'string', 'path must be a string')
89
 
 
90
 
                if not self._library.sound[path] then
 
96
                if STRICT then
 
97
                        assert(type(path) == 'string', 'path must be a string')
 
98
                end
 
99
 
 
100
                local realPath = self:_absolutePath(path)
 
101
 
 
102
                if not self._library.sound[realPath] then
91
103
                        if length == 'short' then
92
 
                                self._library.sound[path] = love.sound.newSoundData(path)
 
104
                                self._library.sound[realPath] = love.sound.newSoundData(realPath)
93
105
                        elseif length == 'long' then
94
 
                                self._library.sound[path] = love.sound.newDecoder(path)
 
106
                                self._library.sound[realPath] = love.sound.newDecoder(realPath)
95
107
                        else
96
108
                                error('length must be either "short" or "long"')
97
109
                        end
121
133
                local arg = {...}
122
134
                local libKey = arg[1]
123
135
 
 
136
                if type(libKey) == 'string' then
 
137
                        libKey = self:_absolutePath(libKey)
 
138
                end
 
139
 
124
140
                if #arg > 1 then libKey = libKey .. arg[2] end
125
141
 
126
142
                if not self._library.font[libKey] then
203
219
        
204
220
                self._library.binds[{func, obj, arg}] = result
205
221
                return result
 
222
        end,
 
223
 
 
224
        -- internal function: _absolutePath
 
225
        -- Replaces any .. references in a path, where possible. 
 
226
        --
 
227
        -- Arguments:
 
228
        --              rawPath - string path to expand
 
229
        --
 
230
        -- Returns:
 
231
        --              string
 
232
 
 
233
        _absolutePath = function (self, rawPath)
 
234
                local matches
 
235
                local result = rawPath
 
236
 
 
237
                repeat
 
238
                        result, matches = string.gsub(result, '[^/]+/%.%./', '')
 
239
                until matches == 0
 
240
 
 
241
                return result
206
242
        end
207
243
}