-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
154 lines (132 loc) · 4.21 KB
/
main.lua
File metadata and controls
154 lines (132 loc) · 4.21 KB
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
-- main.lua
local pprint = require 'pprint'
local composer = require 'composer'
function _G.trace(...)
if system.getInfo('environment') == 'simulator' then
local lst = {...}
if #lst == 1 and type(lst[1]) == 'table' then
pprint(lst[1]) -- doesn't take varargs
else
print(...)
end
end
end
if system.getInfo('environment') == 'simulator' then
composer.isDebug = true
end
if system.getInfo('platform') == 'win32' or system.getInfo('environment') == 'simulator' then
print('_VERSION', _VERSION)
print('screenOrigin', display.screenOriginX, display.screenOriginY)
print('safeAreaInsets', display.getSafeAreaInsets())
print('content', display.contentWidth, display.contentHeight)
print('actualContent', display.actualContentWidth, display.actualContentHeight)
print('safeActualContent', display.safeActualContentWidth, display.safeActualContentHeight)
print('viewableContent', display.viewableContentWidth, display.viewableContentHeight)
print('pixelWidth/Height', display.pixelWidth, display.pixelHeight)
-- print('maxTextureSize', system.getInfo('maxTextureSize'))
print('platformName', system.getInfo('platformName'))
print('architectureInfo', system.getInfo('architectureInfo'))
print('model', system.getInfo('model'))
print('appName', system.getInfo('appName'))
print('appVersionString', system.getInfo('appVersionString'))
-- print('androidDisplayApproximateDpi', system.getInfo('androidDisplayApproximateDpi'))
end
--[[
_G.onTablet = system.getInfo('model') == 'iPad'
if not _G.onTablet then
local approximateDpi = system.getInfo('androidDisplayApproximateDpi')
if approximateDpi then
local width = display.pixelWidth / approximateDpi
local height = display.pixelHeight / approximateDpi
if width > 4.5 and height > 7 then
_G.onTablet = true
end
end
end
]]
native.setProperty('windowTitleText', 'Twitty') -- Win32
math.randomseed(os.time())
-- ugly globals
--[[
const.FONTS.ROBOTO_MEDIUM = nil
_G.BOLDFONT = nil
local systemFonts = native.getFontNames()
for _, fontName in ipairs(systemFonts) do
trace(fontName)
if fontName == 'Roboto-Medium' then
const.FONTS.ROBOTO_MEDIUM = native.newFont(fontName)
elseif fontName == 'Roboto-Bold' then
_G.BOLDFONT = native.newFont(fontName)
end
end
if nil == const.FONTS.ROBOTO_MEDIUM then const.FONTS.ROBOTO_MEDIUM = native.systemFont end
if nil == _G.BOLDFONT then const.FONTS.ROBOTO_MEDIUM = native.systemFontBold end
]]
if not _G.table.contains then
function _G.table.contains(tab, val)
for index, value in ipairs(tab) do
if value == val then
return true, index
end
end
return false, 0
end
end
-- trace('table contains', type(_G.table.contains))
if not _G.table.length then
function _G.table.length(tbl)
local count = 0
for _ in pairs(tbl) do count = count + 1 end
return count
end
end
-- trace('table length', type(_G.table.length))
if not table.filter then
-- for use on array-style tables
function _G.table.filter(tbl, func)
local out = {}
for _,v in ipairs(tbl) do
if func(v) then
table.insert(out, v)
end
end
return out
end
end
-- trace('table filter', type(_G.table.filter))
if not table.clone then
function _G.table.clone(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in pairs(orig) do
copy[orig_key] = orig_value
end
else -- number, string, boolean, etc
copy = orig
end
return copy
end
end
--[[
if not string.split then
function _G.string:split( inSplitPattern )
-- https://docs.coronalabs.com/tutorial/data/luaStringMagic/index.html
local outResults = {}
local theStart = 1
local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
while theSplitStart do
table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
theStart = theSplitEnd + 1
theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
end
table.insert( outResults, string.sub( self, theStart ) )
return outResults
end
end
]]
-- for k,v in pairs( _G ) do
-- print( k , v )
-- end
composer.gotoScene('Splash', {params={scene='ModeMenu'}})