This repository has been archived by the owner on Dec 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
glove.lua
341 lines (271 loc) · 7.92 KB
/
glove.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
-- Glove is a compatibility layer
-- So that you can write LOVE modules
-- That work on 0.8.0, 0.9.0, and 0.9.1
--
-- The local functions are named after 0.8.0
local glove = {}
-- Features
local love9 = love._version == "0.9.0" or love._version == "0.9.1"
local love8 = love._version == "0.8.0"
require "love.filesystem"
require "love.graphics"
if love9 then
require "love.window"
require "love.system"
end
glove.system = {}
glove.filesystem = {}
glove.window = {}
glove.graphics = {}
glove.thread = {}
-- https://love2d.org/wiki/love.system.getOS
function getOS()
if love8 then
return love._os
end
return love.system.getOS()
end
glove._os = getOS()
glove.system.getOS = getOS
-- https://love2d.org/wiki/love.graphics.getFont
function getFont()
if love8 then
return love.graphics.newFont(love.graphics.getFont())
end
return love.graphics.getFont()
end
glove.graphics.getFont = getFont
--http://www.love2d.org/wiki/love.graphics.newStencil
local function newStencil (stencilFunction)
if love.graphics.newStencil then
return love.graphics.newStencil(stencilFunction)
else
return stencilFunction
end
end
glove.graphics.newStencil = newStencil
--http://www.love2d.org/wiki/love.graphics.setLine
local function setLine (width, style)
if love.graphics.setLine then
love.graphics.setLine(width, style)
else
love.graphics.setLineWidth(width)
love.graphics.setLineStyle(style)
end
end
glove.graphics.setLine = setLine
--http://www.love2d.org/wiki/love.graphics.setPoint
local function setPoint (size, style)
if love.graphics.setPoint then
love.graphics.setPoint(size, style)
else
love.graphics.setPointSize(size)
love.graphics.setPointStyle(style)
end
end
glove.graphics.setPoint = setPoint
--http://www.love2d.org/wiki/love.graphics.setDefaultImageFilter
local function setDefaultImageFilter (min, mag, anisotropy)
if love.graphics.setDefaultImageFilter then
love.graphics.setDefaultImageFilter(min, mag) --anisotropy is ignored
else
love.graphics.setDefaultFilter(min,mag,anisotropy)
end
end
glove.graphics.setDefaultImageFilter = setDefaultImageFilter
glove.graphics.setDefaultFilter = setDefaultImageFilter
--http://www.love2d.org/wiki/love.graphics.getDefaultImageFilter
local function getDefaultImageFilter ()
if love.graphics.getDefaultImageFilter then
return love.graphics.getDefaultImageFilter(),1 --anisotropy to default value
else
return love.graphics.getDefaultFilter()
end
end
glove.graphics.getDefaultImageFilter = getDefaultImageFilter
glove.graphics.getDefaultFilter = getDefaultImageFilter
--http://www.love2d.org/wiki/love.graphics.drawq
local function drawq (image, quad, x, y, r, sx, sy, ox, oy, kx, ky)
if love.graphics.drawq then
love.graphics.drawq (image, quad, x, y, r, sx, sy, ox, oy, kx, ky)
else
love.graphics.draw (image, quad, x, y, r, sx, sy, ox, oy, kx, ky)
end
end
glove.graphics.drawq = drawq
--http://www.love2d.org/wiki/love.graphics.draw
local function draw (image, quad, x, y, r, sx, sy, ox, oy, kx, ky)
if love8 then
if type(quad) == "number" then
love.graphics.draw(image, quad, x, y, r, sx, sy, ox, oy, kx, ky)
elseif quad:type() == "Quad" then
love.graphics.drawq(image, quad, x, y, r, sx, sy, ox, oy, kx, ky)
end
else
love.graphics.draw(image, quad, x, y, r, sx, sy, ox, oy, kx, ky)
end
end
glove.graphics.draw = draw
--http://www.love2d.org/wiki/love.graphics.quad
local function quad (mode, x1, y1, x2, y2, x3, y3, x4, y4)
if love.graphics.quad then
love.graphics.quad(mode, x1, y1, x2, y2, x3, y3, x4, y4)
else
love.graphics.polygon(mode, x1, y1, x2, y2, x3, y3, x4, y4)
end
end
glove.graphics.quad = quad
--http://www.love2d.org/wiki/love.graphics.triangle
local function triangle (mode, x1, y1, x2, y2, x3, y3)
if love.graphics.triangle then
love.graphics.triangle(mode, x1, y1, x2, y2, x3, y3)
else
love.graphics.polygon(mode, x1, y1, x2, y2, x3, y3)
end
end
glove.graphics.triangle = triangle
-- http://www.love2d.org/wiki/love.filesystem.enumerate
local function enumerate(dir)
if love.filesystem.enumerate then
return love.filesystem.enumerate(dir)
else
return love.filesystem.getDirectoryItems(dir)
end
end
glove.filesystem.enumerate = enumerate
glove.filesystem.getDirectoryItems = enumerate
-- http://www.love2d.org/wiki/love.filesystem.mkdir
local function mkdir(name)
if love.filesystem.mkdir then
return love.filesystem.mkdir(name)
else
return love.filesystem.createDirectory(name)
end
end
glove.filesystem.mkdir = mkdir
glove.filesystem.createDirectory = mkdir
function glove.filesystem.isFused()
if love.filesystem.isFused then
return love.filesystem.isFused()
else
local datadir = love.filesystem.getAppdataDirectory()
local savedir = love.filesystem.getSaveDirectory()
local fragment = savedir:sub(datadir:len() + 2)
local start, stop = nil
if love._os == "Linux" then
start, stop = fragment:find("love/")
else
start, stop = fragment:find("LOVE/")
end
return (start ~= 1 and stop ~= 5)
end
end
-- The NamedThread class provides the Love 0.8.0
-- thread interface in Love 0.9.0
local NamedThread = {}
NamedThread.__index = NamedThread
function NamedThread:init(name, filedata)
self.thread = love.thread.newThread(filedata)
self.name = name
end
function NamedThread:start()
return self.thread:start()
end
function NamedThread:wait()
return self.thread:wait()
end
function NamedThread:set(name, value)
local channel = love.thread.getChannel(name)
return channel:push(value)
end
function NamedThread:peek(name)
local channel = love.thread.getChannel(name)
return channel:peek()
end
function NamedThread:get(name)
if name == "error" then
return self.thread:getError()
end
local channel = love.thread.getChannel(name)
return channel:pop()
end
function NamedThread:demand(name)
local channel = love.thread.getChannel(name)
return channel:demand()
end
local _threads = {}
-- http://www.love2d.org/wiki/love.thread.newThread
local function newThread(name, filedata)
if love8 then
return love.thread.newThread(name, filedata)
end
if _threads[name] then
error("A thread with that name already exists.")
end
local thread = {}
setmetatable(thread, NamedThread)
thread:init(name, filedata)
-- Mark this name as taken
_threads[name] = true
return thread
end
local function getThread()
if love.thread.getThread then
return love.thread.getThread()
end
local thread = {}
setmetatable(thread, NamedThread)
return thread
end
glove.thread.newThread = newThread
glove.thread.getThread = getThread
--glove.window.getDesktopDimension
--glove.window.getFullscreen
--glove.window.getFullscreenModes
--glove.window.getIcon
--glove.window.getMode
local function getHeight()
return love.graphics.getHeight()
end
local function getWidth()
return love.graphics.getWidth()
end
glove.window.getHeight = getHeight
glove.window.getWidth = getWidth
glove.graphics.getHeight = getHeight
glove.graphics.getWidth = getWidth
local function getTitle()
if love.window and love.window.getTitle then
return love.window.getTitle()
else
return love.graphics.getCaption()
end
end
glove.window.getTitle = getTitle
glove.graphics.getCaption = getTitle
local function setTitle(title)
if love.window and love.window.setTitle then
return love.window.setTitle(title)
else
return love.graphics.setCaption(title)
end
end
glove.window.setTitle = setTitle
glove.graphics.setCaption = setTitle
local function getDimensions(title)
if love.graphics.getDimensions then
return love.graphics.getDimensions()
else
return love.graphics.getWidth(), love.graphics.getHeight()
end
end
glove.window.getDimensions = getDimensions
glove.graphics.getDimensions = getDimensions
--glove.window.hasFocus
--glove.window.hasMouseFocus
--glove.window.isCreated
--glove.window.isVisible
--glove.window.setFullscreen
--glove.window.setIcon
--glove.window.setMode
return glove