nakor 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +2 -0
- data/lib/nakor/app.rb +0 -7
- data/lib/nakor/generators/app.rb +4 -4
- data/lib/nakor/generators/corona-game-template/io_ext.lua +34 -0
- data/lib/nakor/generators/corona-game-template/orm.lua +198 -0
- data/lib/nakor/generators/corona-game-template/radlib.lua +9 -56
- data/lib/nakor/generators/corona-game-template/string_ext.lua +21 -0
- data/lib/nakor/generators/corona-game-template/table_ext.lua +53 -0
- data/lib/nakor/generators/corona-game-template/time_ext.lua +20 -0
- data/lib/nakor/generators/corona-game-template/underscore.lua +425 -0
- data/lib/nakor/version.rb +1 -1
- data/nakor.gemspec +1 -0
- metadata +27 -11
- data/lib/nakor/generators/corona-game-template/newgame.rb +0 -56
data/Rakefile
CHANGED
data/lib/nakor/app.rb
CHANGED
data/lib/nakor/generators/app.rb
CHANGED
@@ -45,14 +45,14 @@ module Nakor
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def copy_source_files
|
48
|
-
TEMPLATE_FILES.each do |
|
49
|
-
template f, "#{app_name}/#{
|
48
|
+
TEMPLATE_FILES.each do |template_file|
|
49
|
+
template f, "#{app_name}/#{template_file}"
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
def copy_asset_files
|
54
|
-
ASSET_FILES.each do |
|
55
|
-
copy_file f, "#{app_name}/#{
|
54
|
+
ASSET_FILES.each do |asset_file|
|
55
|
+
copy_file f, "#{app_name}/#{asset_file}"
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
local http = require("socket.http")
|
2
|
+
local ltn12 = require("ltn12")
|
3
|
+
|
4
|
+
local M = {}
|
5
|
+
|
6
|
+
require "json"
|
7
|
+
local parseJson = function( filename )
|
8
|
+
local file = io.open( filename, "r" )
|
9
|
+
if file then
|
10
|
+
local contents = file:read( "*a" )
|
11
|
+
result = json.decode( contents )
|
12
|
+
io.close( file )
|
13
|
+
return result
|
14
|
+
else
|
15
|
+
return {}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
M.parseJson = parseJson
|
19
|
+
|
20
|
+
local parseRemoteJson = function( remoteUrl )
|
21
|
+
local tempFilename = system.pathForFile( "temp.json", system.TemporaryDirectory )
|
22
|
+
local tempFile = io.open( tempFilename, "w+b" )
|
23
|
+
|
24
|
+
http.request {
|
25
|
+
url = remoteUrl,
|
26
|
+
sink = ltn12.sink.file( tempFile )
|
27
|
+
}
|
28
|
+
|
29
|
+
return parseJson( tempFilename )
|
30
|
+
end
|
31
|
+
M.parseRemoteJson = parseRemoteJson
|
32
|
+
|
33
|
+
return M
|
34
|
+
|
@@ -0,0 +1,198 @@
|
|
1
|
+
local sqlite3 = require "sqlite3"
|
2
|
+
local radlib = require "radlib"
|
3
|
+
|
4
|
+
|
5
|
+
local M = {}
|
6
|
+
|
7
|
+
------------------------------------------------------------------------------
|
8
|
+
-- Initialize the database connection
|
9
|
+
------------------------------------------------------------------------------
|
10
|
+
local initialize = function( dbPath )
|
11
|
+
if dbPath ~= nil then
|
12
|
+
db = sqlite3.open( dbPath )
|
13
|
+
else
|
14
|
+
db = sqlite3.open_memory()
|
15
|
+
end
|
16
|
+
return db
|
17
|
+
end
|
18
|
+
M.initialize = initialize
|
19
|
+
|
20
|
+
------------------------------------------------------------------------------
|
21
|
+
-- Close the database
|
22
|
+
------------------------------------------------------------------------------
|
23
|
+
local close = function()
|
24
|
+
db:close()
|
25
|
+
end
|
26
|
+
M.close = close
|
27
|
+
|
28
|
+
------------------------------------------------------------------------------
|
29
|
+
-- Return all the contents of an SQLite table as a table structure
|
30
|
+
------------------------------------------------------------------------------
|
31
|
+
local selectAll = function(tableName)
|
32
|
+
local result = {}
|
33
|
+
for row in db:nrows("SELECT * FROM " .. tableName) do
|
34
|
+
result[#result+1] = row
|
35
|
+
end
|
36
|
+
return result
|
37
|
+
end
|
38
|
+
M.selectAll = selectAll
|
39
|
+
|
40
|
+
------------------------------------------------------------------------------
|
41
|
+
-- Return contents of an SQLite table filtered by a WHERE query
|
42
|
+
-- Return value is a table structure
|
43
|
+
------------------------------------------------------------------------------
|
44
|
+
local selectWhere = function(tableName, whereClause)
|
45
|
+
local result = {}
|
46
|
+
for row in db:nrows("SELECT * FROM " .. tableName .. " WHERE " .. whereClause) do
|
47
|
+
result[#result+1] = row
|
48
|
+
end
|
49
|
+
return result
|
50
|
+
end
|
51
|
+
M.selectWhere = selectWhere
|
52
|
+
|
53
|
+
------------------------------------------------------------------------------
|
54
|
+
-- Return the row from the given table,
|
55
|
+
-- selected from the given key/keyValue pair
|
56
|
+
------------------------------------------------------------------------------
|
57
|
+
local selectOne = function(tableName, key, keyValue)
|
58
|
+
local result = {}
|
59
|
+
for row in db:nrows(
|
60
|
+
"SELECT * FROM " .. tableName ..
|
61
|
+
" WHERE " .. key .. " = " .. keyValue ..
|
62
|
+
" LIMIT 1") do
|
63
|
+
result[1] = row
|
64
|
+
break
|
65
|
+
end
|
66
|
+
return result[1]
|
67
|
+
end
|
68
|
+
M.selectOne = selectOne
|
69
|
+
|
70
|
+
------------------------------------------------------------------------------
|
71
|
+
-- Returns the number of rows for the given table
|
72
|
+
------------------------------------------------------------------------------
|
73
|
+
local getTableRowCount = function(tableName)
|
74
|
+
local rowCount = 0
|
75
|
+
for row in db:nrows("SELECT COUNT(*) as rowcount FROM " .. tableName) do
|
76
|
+
rowCount = row.rowcount
|
77
|
+
end
|
78
|
+
return rowCount
|
79
|
+
end
|
80
|
+
M.getTableRowCount = getTableRowCount
|
81
|
+
|
82
|
+
------------------------------------------------------------------------------
|
83
|
+
-- Inserts a row into the given table
|
84
|
+
------------------------------------------------------------------------------
|
85
|
+
local insertRow = function( tableName, row )
|
86
|
+
-- temporary holding variables
|
87
|
+
local columnList = " ( "
|
88
|
+
local valuesList = " VALUES("
|
89
|
+
|
90
|
+
-- format column values into SQL-safe strings
|
91
|
+
-- then concatenate them together
|
92
|
+
for i,v in pairs(row) do
|
93
|
+
local colName = i
|
94
|
+
local colValue = v
|
95
|
+
if type(v) == 'string' then
|
96
|
+
colValue = radlib.string.toSqlString(v)
|
97
|
+
end
|
98
|
+
columnList = columnList .. colName .. ","
|
99
|
+
valuesList = valuesList .. colValue .. ","
|
100
|
+
end
|
101
|
+
|
102
|
+
-- strip off the trailing comma and add a closing parentheses
|
103
|
+
columnList = string.sub( columnList, 1, columnList:len()-1 ) .. ')'
|
104
|
+
valuesList = string.sub( valuesList, 1, valuesList:len()-1 ) .. ')'
|
105
|
+
|
106
|
+
-- prepare the complete SQL command
|
107
|
+
local sql = "INSERT INTO " .. tableName .. columnList .. valuesList
|
108
|
+
|
109
|
+
-- execute the SQL command for inserting the row
|
110
|
+
print("Running INSERT SQL: " .. sql)
|
111
|
+
db:exec( sql )
|
112
|
+
end
|
113
|
+
M.insertRow = insertRow
|
114
|
+
|
115
|
+
------------------------------------------------------------------------------
|
116
|
+
-- Updates a row on the given table
|
117
|
+
------------------------------------------------------------------------------
|
118
|
+
local updateRow = function( tableName, recordData )
|
119
|
+
-- format column values into SQL-safe strings
|
120
|
+
-- then concatenate them together
|
121
|
+
local updateStr = ''
|
122
|
+
for i,v in pairs(recordData) do
|
123
|
+
if i ~= 'id' then
|
124
|
+
local colName = i
|
125
|
+
local colValue = v
|
126
|
+
if type(v) == 'string' then
|
127
|
+
colValue = radlib.string.toSqlString(v)
|
128
|
+
end
|
129
|
+
updateStr = updateStr .. colName .. " = " .. colValue .. ","
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
-- remove the trailing comma
|
134
|
+
updateStr = string.sub( updateStr, 1, #updateStr-1 )
|
135
|
+
|
136
|
+
local sql = "UPDATE " .. tableName .. " SET " .. updateStr .. " WHERE id = " .. recordData.id
|
137
|
+
print( "UPDATE SQL: " .. sql )
|
138
|
+
db:exec( sql )
|
139
|
+
end
|
140
|
+
M.updateRow = updateRow
|
141
|
+
|
142
|
+
------------------------------------------------------------------------------
|
143
|
+
-- If a matching id already exists in the database, do an update
|
144
|
+
-- otherwise do an insert
|
145
|
+
------------------------------------------------------------------------------
|
146
|
+
local createOrUpdate = function( tableName, recordData )
|
147
|
+
local existingRecord = M.selectOne( tableName, 'id', recordData.id )
|
148
|
+
if existingRecord == nil then
|
149
|
+
M.insertRow( tableName, recordData )
|
150
|
+
else
|
151
|
+
M.updateRow( tableName, recordData )
|
152
|
+
end
|
153
|
+
end
|
154
|
+
M.createOrUpdate = createOrUpdate
|
155
|
+
|
156
|
+
------------------------------------------------------------------------------
|
157
|
+
-- Updates one column for one row in a given table
|
158
|
+
------------------------------------------------------------------------------
|
159
|
+
local updateAttribute = function( tablename, filter, columnName, columnValue )
|
160
|
+
if type(columnValue) == 'string' then
|
161
|
+
columnValue = radlib.string.toSqlString( columnValue )
|
162
|
+
end
|
163
|
+
local updateStr = "UPDATE " .. tablename ..
|
164
|
+
" SET " .. columnName .. " = " .. columnValue ..
|
165
|
+
" WHERE " .. filter
|
166
|
+
print("UPDATE SQL: " .. updateStr )
|
167
|
+
db:exec( updateStr )
|
168
|
+
end
|
169
|
+
M.updateAttribute = updateAttribute
|
170
|
+
|
171
|
+
------------------------------------------------------------------------------
|
172
|
+
-- Updates multiple columns for one row in a given table
|
173
|
+
------------------------------------------------------------------------------
|
174
|
+
local updateAttributes = function( tablename, filter, columns, columnValues )
|
175
|
+
local updateStr = ''
|
176
|
+
local newValue = nil
|
177
|
+
for i,v in ipairs(columns) do
|
178
|
+
if type(v) == 'string' then
|
179
|
+
newValue = radlib.string.toSqlString( columnValues[i] )
|
180
|
+
else
|
181
|
+
newValue = columnValues[i]
|
182
|
+
end
|
183
|
+
updateStr = updateStr .. v .. " = " .. newValue
|
184
|
+
if i < #columns then
|
185
|
+
updateStr = updateStr .. ", "
|
186
|
+
end
|
187
|
+
end
|
188
|
+
print("UPDATE SQL: " .. updateStr)
|
189
|
+
db:exec(
|
190
|
+
"UPDATE " .. tablename .. " SET " ..
|
191
|
+
updateStr ..
|
192
|
+
" WHERE " .. filter
|
193
|
+
)
|
194
|
+
end
|
195
|
+
M.updateAttributes = updateAttributes
|
196
|
+
|
197
|
+
return M
|
198
|
+
|
@@ -1,67 +1,19 @@
|
|
1
1
|
-- Rad's Library of awesome Lua functions to complement the awesome Corona SDK
|
2
2
|
|
3
3
|
local M = {}
|
4
|
-
M.io = {}
|
5
|
-
M.table = {}
|
6
4
|
|
7
|
-
require "
|
5
|
+
local ioExt = require "io_ext"
|
6
|
+
M.io = ioExt
|
8
7
|
|
9
|
-
local
|
10
|
-
|
11
|
-
if file then
|
12
|
-
local contents = file:read( "*a" )
|
13
|
-
result = json.decode( contents )
|
14
|
-
io.close( file )
|
15
|
-
return result
|
16
|
-
else
|
17
|
-
return {}
|
18
|
-
end
|
19
|
-
end
|
20
|
-
M.io.parseJson = parseJson
|
8
|
+
local stringExt = require "string_ext"
|
9
|
+
M.string = stringExt
|
21
10
|
|
22
|
-
|
23
|
-
|
24
|
-
for k,v in pairs(t2) do
|
25
|
-
if type(v) == "table" then
|
26
|
-
if type(t1[k] or false) == "table" then
|
27
|
-
table.merge(t1[k] or {}, t2[k] or {})
|
28
|
-
else
|
29
|
-
t1[k] = v
|
30
|
-
end
|
31
|
-
else
|
32
|
-
t1[k] = v
|
33
|
-
end
|
34
|
-
end
|
35
|
-
return t1
|
36
|
-
end
|
37
|
-
M.table.merge = tableMerge
|
11
|
+
local tableExt = require "table_ext"
|
12
|
+
M.table = tableExt
|
38
13
|
|
39
|
-
|
40
|
-
|
41
|
-
local tableFindAll = function( t, fx )
|
42
|
-
local result = {}
|
43
|
-
for i,v in ipairs(t) do
|
44
|
-
if fx(v) then
|
45
|
-
result[#result + 1] = v
|
46
|
-
end
|
47
|
-
end
|
48
|
-
return result
|
49
|
-
end
|
50
|
-
M.table.findAll = tableFindAll
|
14
|
+
local timeExt = require "time_ext"
|
15
|
+
M.time = timeExt
|
51
16
|
|
52
|
-
local tablePrint = function( t )
|
53
|
-
for i,v in pairs(t) do
|
54
|
-
if "table" == type(v) then
|
55
|
-
print(i .. " = [table]: ")
|
56
|
-
print("---")
|
57
|
-
table.print(v)
|
58
|
-
print("---")
|
59
|
-
else
|
60
|
-
print(i .. " = " .. v)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
M.table.print = tablePrint
|
65
17
|
|
66
18
|
local debug = function( msg )
|
67
19
|
native.showAlert("DEBUG", msg, {"OK"})
|
@@ -71,3 +23,4 @@ M.debug = debug
|
|
71
23
|
return M
|
72
24
|
|
73
25
|
|
26
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
local M = {}
|
2
|
+
M.string = {}
|
3
|
+
|
4
|
+
local doubleQuote = function( str )
|
5
|
+
return '"' .. str .. '"'
|
6
|
+
end
|
7
|
+
M.doubleQuote = doubleQuote
|
8
|
+
|
9
|
+
local singleQuote = function( str )
|
10
|
+
return "'" .. str .. "'"
|
11
|
+
end
|
12
|
+
M.singleQuote = singleQuote
|
13
|
+
|
14
|
+
local toSqlString = function( str )
|
15
|
+
local result = string.gsub( str, "'", "'''")
|
16
|
+
result = singleQuote( result )
|
17
|
+
return result
|
18
|
+
end
|
19
|
+
M.toSqlString = toSqlString
|
20
|
+
|
21
|
+
return M
|
@@ -0,0 +1,53 @@
|
|
1
|
+
local M = {}
|
2
|
+
|
3
|
+
------------------------------------------------------------------------------
|
4
|
+
-- Merge two tables
|
5
|
+
-- From: http://stackoverflow.com/questions/1283388/lua-merge-tables
|
6
|
+
------------------------------------------------------------------------------
|
7
|
+
local merge = function(t1, t2)
|
8
|
+
for k,v in pairs(t2) do
|
9
|
+
if type(v) == "table" then
|
10
|
+
if type(t1[k] or false) == "table" then
|
11
|
+
table.merge(t1[k] or {}, t2[k] or {})
|
12
|
+
else
|
13
|
+
t1[k] = v
|
14
|
+
end
|
15
|
+
else
|
16
|
+
t1[k] = v
|
17
|
+
end
|
18
|
+
end
|
19
|
+
return t1
|
20
|
+
end
|
21
|
+
M.merge = merge
|
22
|
+
|
23
|
+
------------------------------------------------------------------------------
|
24
|
+
-- Print the contents of a table
|
25
|
+
------------------------------------------------------------------------------
|
26
|
+
local tablePrint = function( t )
|
27
|
+
for i,v in pairs(t) do
|
28
|
+
if "table" == type(v) then
|
29
|
+
print(i .. " = [table]: ")
|
30
|
+
print("---")
|
31
|
+
M.print(v)
|
32
|
+
print("---")
|
33
|
+
else
|
34
|
+
print(i .. " = " .. v)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
M.print = tablePrint
|
39
|
+
|
40
|
+
------------------------------------------------------------------------------
|
41
|
+
-- Wrap the values of a table inside single quotes
|
42
|
+
------------------------------------------------------------------------------
|
43
|
+
local quoteValues = function( t )
|
44
|
+
local result = {}
|
45
|
+
for i,v in pairs(t) do
|
46
|
+
result[i] = "'" .. v .. "'"
|
47
|
+
end
|
48
|
+
return result
|
49
|
+
end
|
50
|
+
M.quoteValues = quoteValues
|
51
|
+
|
52
|
+
|
53
|
+
return M
|
@@ -0,0 +1,20 @@
|
|
1
|
+
local M = {}
|
2
|
+
|
3
|
+
------------------------------------------------------------------------------
|
4
|
+
-- Given a time duration in seconds, returns it in HH::MM::SS format
|
5
|
+
-- Assumes that duration is less than 24 hours
|
6
|
+
------------------------------------------------------------------------------
|
7
|
+
local formatTimeDuration = function( duration )
|
8
|
+
local d = duration
|
9
|
+
local hours = math.floor( duration / 3600 )
|
10
|
+
d = d - ( hours * 3600 )
|
11
|
+
local minutes = math.floor( d / 60 )
|
12
|
+
d = d - ( minutes * 60 )
|
13
|
+
local seconds = d
|
14
|
+
|
15
|
+
return string.format( "%02d:%02d:%02d", hours, minutes, seconds )
|
16
|
+
end
|
17
|
+
M.formatTimeDuration = formatTimeDuration
|
18
|
+
|
19
|
+
return M
|
20
|
+
|
@@ -0,0 +1,425 @@
|
|
1
|
+
-- Copyright (c) 2009 Marcus Irven
|
2
|
+
--
|
3
|
+
-- Permission is hereby granted, free of charge, to any person
|
4
|
+
-- obtaining a copy of this software and associated documentation
|
5
|
+
-- files (the "Software"), to deal in the Software without
|
6
|
+
-- restriction, including without limitation the rights to use,
|
7
|
+
-- copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
-- copies of the Software, and to permit persons to whom the
|
9
|
+
-- Software is furnished to do so, subject to the following
|
10
|
+
-- conditions:
|
11
|
+
--
|
12
|
+
-- The above copyright notice and this permission notice shall be
|
13
|
+
-- included in all copies or substantial portions of the Software.
|
14
|
+
--
|
15
|
+
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
-- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
-- OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
--- Underscore is a set of utility functions for dealing with
|
25
|
+
-- iterators, arrays, tables, and functions.
|
26
|
+
|
27
|
+
local Underscore = { funcs = {} }
|
28
|
+
Underscore.__index = Underscore
|
29
|
+
|
30
|
+
function Underscore.__call(_, value)
|
31
|
+
return Underscore:new(value)
|
32
|
+
end
|
33
|
+
|
34
|
+
function Underscore:new(value, chained)
|
35
|
+
return setmetatable({ _val = value, chained = chained or false }, self)
|
36
|
+
end
|
37
|
+
|
38
|
+
function Underscore.iter(list_or_iter)
|
39
|
+
if type(list_or_iter) == "function" then return list_or_iter end
|
40
|
+
|
41
|
+
return coroutine.wrap(function()
|
42
|
+
for i=1,#list_or_iter do
|
43
|
+
coroutine.yield(list_or_iter[i])
|
44
|
+
end
|
45
|
+
end)
|
46
|
+
end
|
47
|
+
|
48
|
+
function Underscore.range(start_i, end_i, step)
|
49
|
+
if end_i == nil then
|
50
|
+
end_i = start_i
|
51
|
+
start_i = 1
|
52
|
+
end
|
53
|
+
step = step or 1
|
54
|
+
local range_iter = coroutine.wrap(function()
|
55
|
+
for i=start_i, end_i, step do
|
56
|
+
coroutine.yield(i)
|
57
|
+
end
|
58
|
+
end)
|
59
|
+
return Underscore:new(range_iter)
|
60
|
+
end
|
61
|
+
|
62
|
+
--- Identity function. This function looks useless, but is used throughout Underscore as a default.
|
63
|
+
-- @name _.identity
|
64
|
+
-- @param value any object
|
65
|
+
-- @return value
|
66
|
+
-- @usage _.identity("foo")
|
67
|
+
-- => "foo"
|
68
|
+
function Underscore.identity(value)
|
69
|
+
return value
|
70
|
+
end
|
71
|
+
|
72
|
+
-- chaining
|
73
|
+
|
74
|
+
function Underscore:chain()
|
75
|
+
self.chained = true
|
76
|
+
return self
|
77
|
+
end
|
78
|
+
|
79
|
+
function Underscore:value()
|
80
|
+
return self._val
|
81
|
+
end
|
82
|
+
|
83
|
+
-- iter
|
84
|
+
|
85
|
+
function Underscore.funcs.each(list, func)
|
86
|
+
for i in Underscore.iter(list) do
|
87
|
+
func(i)
|
88
|
+
end
|
89
|
+
return list
|
90
|
+
end
|
91
|
+
|
92
|
+
function Underscore.funcs.map(list, func)
|
93
|
+
local mapped = {}
|
94
|
+
for i in Underscore.iter(list) do
|
95
|
+
mapped[#mapped+1] = func(i)
|
96
|
+
end
|
97
|
+
return mapped
|
98
|
+
end
|
99
|
+
|
100
|
+
function Underscore.funcs.reduce(list, memo, func)
|
101
|
+
for i in Underscore.iter(list) do
|
102
|
+
memo = func(memo, i)
|
103
|
+
end
|
104
|
+
return memo
|
105
|
+
end
|
106
|
+
|
107
|
+
function Underscore.funcs.detect(list, func)
|
108
|
+
for i in Underscore.iter(list) do
|
109
|
+
if func(i) then return i end
|
110
|
+
end
|
111
|
+
return nil
|
112
|
+
end
|
113
|
+
|
114
|
+
function Underscore.funcs.select(list, func)
|
115
|
+
local selected = {}
|
116
|
+
for i in Underscore.iter(list) do
|
117
|
+
if func(i) then selected[#selected+1] = i end
|
118
|
+
end
|
119
|
+
return selected
|
120
|
+
end
|
121
|
+
|
122
|
+
function Underscore.funcs.reject(list, func)
|
123
|
+
local selected = {}
|
124
|
+
for i in Underscore.iter(list) do
|
125
|
+
if not func(i) then selected[#selected+1] = i end
|
126
|
+
end
|
127
|
+
return selected
|
128
|
+
end
|
129
|
+
|
130
|
+
function Underscore.funcs.all(list, func)
|
131
|
+
func = func or Underscore.identity
|
132
|
+
|
133
|
+
-- TODO what should happen with an empty list?
|
134
|
+
for i in Underscore.iter(list) do
|
135
|
+
if not func(i) then return false end
|
136
|
+
end
|
137
|
+
return true
|
138
|
+
end
|
139
|
+
|
140
|
+
function Underscore.funcs.any(list, func)
|
141
|
+
func = func or Underscore.identity
|
142
|
+
|
143
|
+
-- TODO what should happen with an empty list?
|
144
|
+
for i in Underscore.iter(list) do
|
145
|
+
if func(i) then return true end
|
146
|
+
end
|
147
|
+
return false
|
148
|
+
end
|
149
|
+
|
150
|
+
function Underscore.funcs.include(list, value)
|
151
|
+
for i in Underscore.iter(list) do
|
152
|
+
if i == value then return true end
|
153
|
+
end
|
154
|
+
return false
|
155
|
+
end
|
156
|
+
|
157
|
+
function Underscore.funcs.invoke(list, function_name, ...)
|
158
|
+
local args = {...}
|
159
|
+
Underscore.funcs.each(list, function(i) i[function_name](i, unpack(args)) end)
|
160
|
+
return list
|
161
|
+
end
|
162
|
+
|
163
|
+
function Underscore.funcs.pluck(list, propertyName)
|
164
|
+
return Underscore.funcs.map(list, function(i) return i[propertyName] end)
|
165
|
+
end
|
166
|
+
|
167
|
+
function Underscore.funcs.min(list, func)
|
168
|
+
func = func or Underscore.identity
|
169
|
+
|
170
|
+
return Underscore.funcs.reduce(list, { item = nil, value = nil }, function(min, item)
|
171
|
+
if min.item == nil then
|
172
|
+
min.item = item
|
173
|
+
min.value = func(item)
|
174
|
+
else
|
175
|
+
local value = func(item)
|
176
|
+
if value < min.value then
|
177
|
+
min.item = item
|
178
|
+
min.value = value
|
179
|
+
end
|
180
|
+
end
|
181
|
+
return min
|
182
|
+
end).item
|
183
|
+
end
|
184
|
+
|
185
|
+
function Underscore.funcs.max(list, func)
|
186
|
+
func = func or Underscore.identity
|
187
|
+
|
188
|
+
return Underscore.funcs.reduce(list, { item = nil, value = nil }, function(max, item)
|
189
|
+
if max.item == nil then
|
190
|
+
max.item = item
|
191
|
+
max.value = func(item)
|
192
|
+
else
|
193
|
+
local value = func(item)
|
194
|
+
if value > max.value then
|
195
|
+
max.item = item
|
196
|
+
max.value = value
|
197
|
+
end
|
198
|
+
end
|
199
|
+
return max
|
200
|
+
end).item
|
201
|
+
end
|
202
|
+
|
203
|
+
function Underscore.funcs.to_array(list)
|
204
|
+
local array = {}
|
205
|
+
for i in Underscore.iter(list) do
|
206
|
+
array[#array+1] = i
|
207
|
+
end
|
208
|
+
return array
|
209
|
+
end
|
210
|
+
|
211
|
+
function Underscore.funcs.reverse(list)
|
212
|
+
local reversed = {}
|
213
|
+
for i in Underscore.iter(list) do
|
214
|
+
table.insert(reversed, 1, i)
|
215
|
+
end
|
216
|
+
return reversed
|
217
|
+
end
|
218
|
+
|
219
|
+
function Underscore.funcs.sort(iter, comparison_func)
|
220
|
+
local array = iter
|
221
|
+
if type(iter) == "function" then
|
222
|
+
array = Underscore.funcs.to_array(iter)
|
223
|
+
end
|
224
|
+
table.sort(array, comparison_func)
|
225
|
+
return array
|
226
|
+
end
|
227
|
+
|
228
|
+
-- arrays
|
229
|
+
|
230
|
+
function Underscore.funcs.first(array, n)
|
231
|
+
if n == nil then
|
232
|
+
return array[1]
|
233
|
+
else
|
234
|
+
local first = {}
|
235
|
+
n = math.min(n,#array)
|
236
|
+
for i=1,n do
|
237
|
+
first[i] = array[i]
|
238
|
+
end
|
239
|
+
return first
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
function Underscore.funcs.rest(array, index)
|
244
|
+
index = index or 2
|
245
|
+
local rest = {}
|
246
|
+
for i=index,#array do
|
247
|
+
rest[#rest+1] = array[i]
|
248
|
+
end
|
249
|
+
return rest
|
250
|
+
end
|
251
|
+
|
252
|
+
function Underscore.funcs.slice(array, start_index, length)
|
253
|
+
local sliced_array = {}
|
254
|
+
|
255
|
+
start_index = math.max(start_index, 1)
|
256
|
+
local end_index = math.min(start_index+length-1, #array)
|
257
|
+
for i=start_index, end_index do
|
258
|
+
sliced_array[#sliced_array+1] = array[i]
|
259
|
+
end
|
260
|
+
return sliced_array
|
261
|
+
end
|
262
|
+
|
263
|
+
function Underscore.funcs.flatten(array)
|
264
|
+
local all = {}
|
265
|
+
|
266
|
+
for ele in Underscore.iter(array) do
|
267
|
+
if type(ele) == "table" then
|
268
|
+
local flattened_element = Underscore.funcs.flatten(ele)
|
269
|
+
Underscore.funcs.each(flattened_element, function(e) all[#all+1] = e end)
|
270
|
+
else
|
271
|
+
all[#all+1] = ele
|
272
|
+
end
|
273
|
+
end
|
274
|
+
return all
|
275
|
+
end
|
276
|
+
|
277
|
+
function Underscore.funcs.push(array, item)
|
278
|
+
table.insert(array, item)
|
279
|
+
return array
|
280
|
+
end
|
281
|
+
|
282
|
+
function Underscore.funcs.pop(array)
|
283
|
+
return table.remove(array)
|
284
|
+
end
|
285
|
+
|
286
|
+
function Underscore.funcs.shift(array)
|
287
|
+
return table.remove(array, 1)
|
288
|
+
end
|
289
|
+
|
290
|
+
function Underscore.funcs.unshift(array, item)
|
291
|
+
table.insert(array, 1, item)
|
292
|
+
return array
|
293
|
+
end
|
294
|
+
|
295
|
+
function Underscore.funcs.join(array, separator)
|
296
|
+
return table.concat(array, separator)
|
297
|
+
end
|
298
|
+
|
299
|
+
-- objects
|
300
|
+
|
301
|
+
function Underscore.funcs.keys(obj)
|
302
|
+
local keys = {}
|
303
|
+
for k,v in pairs(obj) do
|
304
|
+
keys[#keys+1] = k
|
305
|
+
end
|
306
|
+
return keys
|
307
|
+
end
|
308
|
+
|
309
|
+
function Underscore.funcs.values(obj)
|
310
|
+
local values = {}
|
311
|
+
for k,v in pairs(obj) do
|
312
|
+
values[#values+1] = v
|
313
|
+
end
|
314
|
+
return values
|
315
|
+
end
|
316
|
+
|
317
|
+
function Underscore.funcs.extend(destination, source)
|
318
|
+
for k,v in pairs(source) do
|
319
|
+
destination[k] = v
|
320
|
+
end
|
321
|
+
return destination
|
322
|
+
end
|
323
|
+
|
324
|
+
function Underscore.funcs.is_empty(obj)
|
325
|
+
return next(obj) == nil
|
326
|
+
end
|
327
|
+
|
328
|
+
-- Originally based on penlight's deepcompare() -- http://luaforge.net/projects/penlight/
|
329
|
+
function Underscore.funcs.is_equal(o1, o2, ignore_mt)
|
330
|
+
local ty1 = type(o1)
|
331
|
+
local ty2 = type(o2)
|
332
|
+
if ty1 ~= ty2 then return false end
|
333
|
+
|
334
|
+
-- non-table types can be directly compared
|
335
|
+
if ty1 ~= 'table' then return o1 == o2 end
|
336
|
+
|
337
|
+
-- as well as tables which have the metamethod __eq
|
338
|
+
local mt = getmetatable(o1)
|
339
|
+
if not ignore_mt and mt and mt.__eq then return o1 == o2 end
|
340
|
+
|
341
|
+
local is_equal = Underscore.funcs.is_equal
|
342
|
+
|
343
|
+
for k1,v1 in pairs(o1) do
|
344
|
+
local v2 = o2[k1]
|
345
|
+
if v2 == nil or not is_equal(v1,v2, ignore_mt) then return false end
|
346
|
+
end
|
347
|
+
for k2,v2 in pairs(o2) do
|
348
|
+
local v1 = o1[k2]
|
349
|
+
if v1 == nil then return false end
|
350
|
+
end
|
351
|
+
return true
|
352
|
+
end
|
353
|
+
|
354
|
+
-- functions
|
355
|
+
|
356
|
+
function Underscore.funcs.compose(...)
|
357
|
+
local function call_funcs(funcs, ...)
|
358
|
+
if #funcs > 1 then
|
359
|
+
return funcs[1](call_funcs(_.rest(funcs), ...))
|
360
|
+
else
|
361
|
+
return funcs[1](...)
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
local funcs = {...}
|
366
|
+
return function(...)
|
367
|
+
return call_funcs(funcs, ...)
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
function Underscore.funcs.wrap(func, wrapper)
|
372
|
+
return function(...)
|
373
|
+
return wrapper(func, ...)
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
function Underscore.funcs.curry(func, argument)
|
378
|
+
return function(...)
|
379
|
+
return func(argument, ...)
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
function Underscore.functions()
|
384
|
+
return Underscore.keys(Underscore.funcs)
|
385
|
+
end
|
386
|
+
|
387
|
+
-- add aliases
|
388
|
+
Underscore.methods = Underscore.functions
|
389
|
+
|
390
|
+
Underscore.funcs.for_each = Underscore.funcs.each
|
391
|
+
Underscore.funcs.collect = Underscore.funcs.map
|
392
|
+
Underscore.funcs.inject = Underscore.funcs.reduce
|
393
|
+
Underscore.funcs.foldl = Underscore.funcs.reduce
|
394
|
+
Underscore.funcs.filter = Underscore.funcs.select
|
395
|
+
Underscore.funcs.every = Underscore.funcs.all
|
396
|
+
Underscore.funcs.some = Underscore.funcs.any
|
397
|
+
Underscore.funcs.head = Underscore.funcs.first
|
398
|
+
Underscore.funcs.tail = Underscore.funcs.rest
|
399
|
+
|
400
|
+
local function wrap_functions_for_oo_support()
|
401
|
+
local function value_and_chained(value_or_self)
|
402
|
+
local chained = false
|
403
|
+
if getmetatable(value_or_self) == Underscore then
|
404
|
+
chained = value_or_self.chained
|
405
|
+
value_or_self = value_or_self._val
|
406
|
+
end
|
407
|
+
return value_or_self, chained
|
408
|
+
end
|
409
|
+
|
410
|
+
local function value_or_wrap(value, chained)
|
411
|
+
if chained then value = Underscore:new(value, true) end
|
412
|
+
return value
|
413
|
+
end
|
414
|
+
|
415
|
+
for fn, func in pairs(Underscore.funcs) do
|
416
|
+
Underscore[fn] = function(obj_or_self, ...)
|
417
|
+
local obj, chained = value_and_chained(obj_or_self)
|
418
|
+
return value_or_wrap(func(obj, ...), chained)
|
419
|
+
end
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
wrap_functions_for_oo_support()
|
424
|
+
|
425
|
+
return Underscore:new()
|
data/lib/nakor/version.rb
CHANGED
data/nakor.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nakor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
|
-
requirement: &
|
16
|
+
requirement: &70236708170220 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70236708170220
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: aruba
|
27
|
-
requirement: &
|
27
|
+
requirement: &70236708167960 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70236708167960
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: cucumber
|
38
|
-
requirement: &
|
38
|
+
requirement: &70236711984180 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,21 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70236711984180
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: metric_fu
|
49
|
+
requirement: &70236711983760 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70236711983760
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: rspec
|
49
|
-
requirement: &
|
60
|
+
requirement: &70236711983340 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,7 +65,7 @@ dependencies:
|
|
54
65
|
version: '0'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *70236711983340
|
58
69
|
description: ! "\n To create a new Corona SDK game using nakor, just run:\n\n nakor
|
59
70
|
generate awesome_game\n\n This will create an awesome_game directory in the current
|
60
71
|
directory, and copy all corona game template files into it.\n\n To run the generated
|
@@ -92,15 +103,20 @@ files:
|
|
92
103
|
- lib/nakor/generators/corona-game-template/director.lua
|
93
104
|
- lib/nakor/generators/corona-game-template/help.lua
|
94
105
|
- lib/nakor/generators/corona-game-template/init_buttons.lua
|
106
|
+
- lib/nakor/generators/corona-game-template/io_ext.lua
|
95
107
|
- lib/nakor/generators/corona-game-template/loadmenu.lua
|
96
108
|
- lib/nakor/generators/corona-game-template/main.lua
|
97
109
|
- lib/nakor/generators/corona-game-template/menu.lua
|
98
|
-
- lib/nakor/generators/corona-game-template/
|
110
|
+
- lib/nakor/generators/corona-game-template/orm.lua
|
99
111
|
- lib/nakor/generators/corona-game-template/play.lua
|
100
112
|
- lib/nakor/generators/corona-game-template/radlib.lua
|
101
113
|
- lib/nakor/generators/corona-game-template/settings.lua
|
102
114
|
- lib/nakor/generators/corona-game-template/splash_screen.png
|
115
|
+
- lib/nakor/generators/corona-game-template/string_ext.lua
|
116
|
+
- lib/nakor/generators/corona-game-template/table_ext.lua
|
117
|
+
- lib/nakor/generators/corona-game-template/time_ext.lua
|
103
118
|
- lib/nakor/generators/corona-game-template/ui.lua
|
119
|
+
- lib/nakor/generators/corona-game-template/underscore.lua
|
104
120
|
- lib/nakor/version.rb
|
105
121
|
- nakor.gemspec
|
106
122
|
- spec/app_spec.rb
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
# Creates a new game at the parent directory.
|
4
|
-
# Usage:
|
5
|
-
# macruby newgame <appname>
|
6
|
-
# For example, if this template is on /Users/rad/Documents/games/corona-game-template,
|
7
|
-
# running "macruby newgame mygame"
|
8
|
-
# will create the directory /Users/rad/Documents/games/mygame
|
9
|
-
# and copy all files from the template to that directory
|
10
|
-
|
11
|
-
def generate_new_app(appname)
|
12
|
-
app_dir = "../#{appname}"
|
13
|
-
code_dir = "#{app_dir}/#{appname}"
|
14
|
-
assets_dir = "#{app_dir}/assets"
|
15
|
-
doc_dir = "#{app_dir}/doc"
|
16
|
-
|
17
|
-
# create the app directories
|
18
|
-
FileUtils.mkdir_p app_dir
|
19
|
-
FileUtils.mkdir_p code_dir
|
20
|
-
FileUtils.mkdir_p assets_dir
|
21
|
-
FileUtils.mkdir_p doc_dir
|
22
|
-
|
23
|
-
# copy the files to the app code directory
|
24
|
-
FileUtils.cp_r './.', code_dir
|
25
|
-
|
26
|
-
# copy README
|
27
|
-
FileUtils.cp_r 'README', app_dir
|
28
|
-
|
29
|
-
# Remove support files used only for corona-game-template development
|
30
|
-
FileUtils.rm_r "#{code_dir}/.git"
|
31
|
-
FileUtils.rm_r "#{code_dir}/README"
|
32
|
-
FileUtils.rm "#{code_dir}/newgame.rb"
|
33
|
-
end
|
34
|
-
|
35
|
-
def show_help
|
36
|
-
print %{
|
37
|
-
Creates a new game at the parent directory.
|
38
|
-
Usage:
|
39
|
-
macruby newgame.rb <appname>
|
40
|
-
For example, if this template is on /Users/rad/Documents/games/corona-game-template,
|
41
|
-
running "macruby newgame mygame"
|
42
|
-
will create the directory /Users/rad/Documents/games/mygame
|
43
|
-
and copy all files from the template to that directory
|
44
|
-
}
|
45
|
-
end
|
46
|
-
|
47
|
-
def main
|
48
|
-
appname = ARGV[0]
|
49
|
-
if appname && appname.strip != ''
|
50
|
-
generate_new_app(appname)
|
51
|
-
else
|
52
|
-
show_help
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
main()
|