/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-03-02 20:40:57 UTC
  • Revision ID: josh@9ix.org-20130302204057-yrra0a51zgtpq2v2
zoetrope 1.3.1

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
 
                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]
 
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]
50
46
        end,
51
47
 
52
48
        -- Method: text
59
55
        --              string
60
56
 
61
57
        text = function (self, 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]
 
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]
73
65
        end,
74
66
 
75
67
        -- Method: sound
93
85
        --              <playSound>, <sound>
94
86
 
95
87
        sound = function (self, path, length)
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
 
88
                assert(type(path) == 'string', 'path must be a string')
 
89
 
 
90
                if not self._library.sound[path] then
103
91
                        if length == 'short' then
104
 
                                self._library.sound[realPath] = love.sound.newSoundData(realPath)
 
92
                                self._library.sound[path] = love.sound.newSoundData(path)
105
93
                        elseif length == 'long' then
106
 
                                self._library.sound[realPath] = love.sound.newDecoder(realPath)
 
94
                                self._library.sound[path] = love.sound.newDecoder(path)
107
95
                        else
108
96
                                error('length must be either "short" or "long"')
109
97
                        end
133
121
                local arg = {...}
134
122
                local libKey = arg[1]
135
123
 
136
 
                if type(libKey) == 'string' then
137
 
                        libKey = self:_absolutePath(libKey)
138
 
                end
139
 
 
140
124
                if #arg > 1 then libKey = libKey .. arg[2] end
141
125
 
142
126
                if not self._library.font[libKey] then
219
203
        
220
204
                self._library.binds[{func, obj, arg}] = result
221
205
                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
242
206
        end
243
207
}