Permalink
Browse files

Replaced everything with version 2.0. Old version in 1.0 branch

  • Loading branch information...
radamanthus committed Jul 7, 2012
1 parent 7e4079b commit 7b0a6c26acfe64c4b09fdc4511ae238a67040454
Showing with 1,605 additions and 2,603 deletions.
  1. +0 −32 README
  2. +18 −0 README.md
  3. +46 −33 about.lua
  4. +155 −0 active_record.lua
  5. +24 −13 build.settings
  6. +12 −12 config.lua
  7. +0 −2,226 director.lua
  8. +76 −0 geometry.lua
  9. +47 −33 help.lua
  10. +34 −0 io_ext.lua
  11. +52 −23 loadmenu.lua
  12. +5 −9 main.lua
  13. +64 −44 menu.lua
  14. +139 −0 middleclass.lua
  15. +0 −56 newgame.rb
  16. +230 −0 orm.lua
  17. +47 −33 play.lua
  18. +11 −56 radlib.lua
  19. +47 −33 settings.lua
  20. BIN splash_screen.png
  21. +79 −0 sql.lua
  22. +21 −0 string_ext.lua
  23. +53 −0 table_ext.lua
  24. +20 −0 time_ext.lua
  25. +425 −0 underscore.lua
View
32 README
@@ -1,32 +0,0 @@
-Corona Game Template version 1.0
-(c) 2011 by Radamanthus Batnag
-
-This is a template project for building games using Ansca Mobile's Corona SDK (http://www.anscamobile.com/corona/)
-
-USAGE
-Out of the box, this is a working Corona project. It includes a splash screen (loadmenu.lua, displays images/splashScreen.png for 1 second) and the following menu buttons:
-- Play
-- Settings
-- Help
-- About
-
-Note the naming convention for button images: play.png is the button for Play, settings.png for Settings, etc.
-
-The project directory structure follows my personal convention for projects:
-
-appname
- +-- assets
- +-- appname
- +-- doc
-
-- All code is in appname/appname.
-- Game assets (e.g. Illustrator .ai files) are in appname/assets, finished PNGs are copied over to appname/appname because that's where Corona SDK expects them to be.
-- The game design document (yes you should have one) and all other documentation are in appname/doc
-
-CREDITS
-
-The code incorporates the latest version of Director class. Director class was written by Ricardo Rauber (http://developer.anscamobile.com/code/director-class-10)
-
-The code also includes some code adopted from the Ghosts vs. Monsters project by Beebe Games (http://blog.anscamobile.com/2010/12/ghosts-vs-monsters-open-source-game-in-corona-sdk/)
-
-This code is MIT licensed, see http://developer.anscamobile.com/code/license
View
@@ -0,0 +1,18 @@
+Corona Game Template version 1.0
+(c) 2011 by Radamanthus Batnag
+
+This is a template project for building games using Ansca Mobile's Corona SDK (http://www.anscamobile.com/corona/)
+
+USAGE
+Out of the box, this is a working Corona project. It includes a splash screen (loadmenu.lua, displays images/splash_screen.png for 1 second) and the following menu buttons:
+- Play
+- Settings
+- Help
+- About
+
+Note the naming convention for button images:
+The buttons for Play are btn_play.png and btn_play_over.png; the buttons for Settings are btn_settings.png and btn_settings_over.png, etc.
+
+CREDITS
+
+This code is MIT licensed, see http://developer.coronalabs.com/code/license
View
@@ -1,34 +1,47 @@
-module(..., package.seeall)
-
--- Main function - MUST return a display.newGroup()
-function new()
- local localGroup = display.newGroup()
-
- -- Background
- local background = display.newImageRect("bk_default.png", 480, 320)
- background.x = display.contentCenterX
- background.y = display.contentCenterY
- localGroup:insert(background)
-
- -- Title
- local title = display.newText("Touch to go back", 0, 0, native.systemFontBold, 16)
- title:setTextColor( 255,255,255)
- title.x = display.contentCenterX
- title.y = display.contentCenterY
- title.name = "title"
- localGroup:insert(title)
-
- -- Touch to go back
- local function touched ( event )
- if ("ended" == event.phase) then
- director:changeScene("menu","fade")
- end
- end
- background:addEventListener("touch",touched)
-
- unloadMe = function()
- end
-
- -- MUST return a display.newGroup()
- return localGroup
+local storyboard = require( "storyboard" )
+local scene = storyboard.newScene()
+
+local ui = require "ui"
+local radlib = require "radlib"
+
+---------------------------------------------------------------------------------
+-- BEGINNING OF YOUR IMPLEMENTATION
+---------------------------------------------------------------------------------
+function scene:createScene( event )
+ local screenGroup = self.view
+
+end
+
+function scene:enterScene( event )
+ print("About loaded...")
+
+ storyboard.removeAll()
+end
+
+function scene:exitScene( event )
end
+
+function scene:destroyScene( event )
+end
+
+---------------------------------------------------------------------------------
+-- END OF YOUR IMPLEMENTATION
+---------------------------------------------------------------------------------
+--
+-- "createScene" event is dispatched if scene's view does not exist
+scene:addEventListener( "createScene", scene )
+
+-- "enterScene" event is dispatched whenever scene transition has finished
+scene:addEventListener( "enterScene", scene )
+
+-- "exitScene" event is dispatched before next scene's transition begins
+scene:addEventListener( "exitScene", scene )
+
+-- "destroyScene" event is dispatched before view is unloaded, which can be
+-- automatically unloaded in low memory situations, or explicitly via a call to
+-- storyboard.purgeScene() or storyboard.removeScene().
+scene:addEventListener( "destroyScene", scene )
+---------------------------------------------------------------------------------
+
+return scene
+
View
@@ -0,0 +1,155 @@
+-- USAGE
+--
+-- Create a Lua file for your module. The file should look like this:
+--
+-- require 'ActiveRecord'
+-- Product = ActiveRecord:subclass('ActiveRecord')
+-- Product.tableName = 'products'
+-- Product.tableFields = {
+-- id = {type = 'integer', flags = {'primary_key', 'autoincrement', 'not_null'} },
+-- name = {type = 'string', flags = {'not_null'} }
+-- }
+--
+-- If the table does not yet exist, you can create it in your app initialization with this call:
+--
+-- orm.initialize()
+-- Product.createTable()
+--
+-- Sample API calls
+--
+-- local products = Product.findAll
+--
+-- p = Product.new{id = 1, name = 'test', description = ''} (NOT YET IMPLEMENTED)
+-- p.save
+--
+-- p.updateAttribute('name', 'newName')
+-- p.updateAttributes{name = 'newName', description = 'newDescription'} (NOT YET IMPLEMENTED)
+--
+-- p = Product.find(1)
+-- test_products = Product.where("name = 'test'")
+--
+-- numberOfProducts = Product.count()
+--
+
+require 'middleclass'
+local orm = require 'orm'
+local sql = require 'sql'
+
+ActiveRecord = class('ActiveRecord')
+
+------------------------------------------------------------------------------
+-- CLASS (STATIC) METHODS - START
+------------------------------------------------------------------------------
+function ActiveRecord:initialize(newRecord)
+ for k,v in pairs(newRecord) do
+ self[k] = v
+ end
+end
+
+------------------------------------------------------------------------------
+-- Returns the number of rows in the table
+------------------------------------------------------------------------------
+function ActiveRecord.static:count()
+ return orm.getTableRowCount(self.tableName)
+end
+
+------------------------------------------------------------------------------
+-- Creates the table
+-- TODO: If options.recreate = true, it drops the table if it already exists
+------------------------------------------------------------------------------
+function ActiveRecord.static:createTable(options)
+ local createSql = sql.generateCreateTable(self.tableName, self.tableFields)
+ db:exec( createSql )
+end
+
+------------------------------------------------------------------------------
+-- Returns the record matching the given id. Returns nil if no match is found.
+--
+-- NOTE: Until I figure out how to determine the caller's class,
+-- I'll have to resort to this ugliness of using the klass parameter
+------------------------------------------------------------------------------
+function ActiveRecord.static:find(klass, id)
+ local record = orm.selectOne(klass.tableName, 'id', id)
+ if not( record == nil ) then
+ result = klass:new(record)
+ end
+ return result
+end
+
+------------------------------------------------------------------------------
+-- Returns all rows in the table that match the given filter
+------------------------------------------------------------------------------
+function ActiveRecord.static:findAll( filter, orderBy )
+ local result = nil
+ if filter == nil then
+ result = orm.selectAll( self.tableName, {order = orderBy} )
+ else
+ result = orm.selectWhere( self.tableName, {where = filter, order = orderBy} )
+ end
+ return result
+end
+
+------------------------------------------------------------------------------
+-- Updates all rows in the table that match the given filter
+------------------------------------------------------------------------------
+function ActiveRecord.static:updateAll( updateSql, filter )
+ if filter == nil then
+ orm.updateAll( self.tableName, updateSql )
+ else
+ orm.updateWhere( self.tableName, updateSql, filter )
+ end
+end
+
+------------------------------------------------------------------------------
+-- CLASS (STATIC) METHODS - END
+------------------------------------------------------------------------------
+
+
+------------------------------------------------------------------------------
+-- INSTANCE METHODS - START
+------------------------------------------------------------------------------
+
+------------------------------------------------------------------------------
+-- Reloads the record values from the database
+------------------------------------------------------------------------------
+function ActiveRecord:reload()
+ local updatedRecord = orm.selectOne( self.class.tableName, 'id', self.id )
+ for k,v in pairs(updatedRecord) do
+ self[k] = v
+ end
+end
+
+------------------------------------------------------------------------------
+-- Saves the content of the object to the database.
+-- If a matching record already exists in the database, an UPDATE is done.
+-- Otherwise an INSERT is done.
+------------------------------------------------------------------------------
+function ActiveRecord:save()
+ local updateTable = {}
+ for k in pairs(self.class.tableFields) do
+ updateTable[k] = self[k]
+ end
+ orm.createOrUpdate( self.class.tableName, updateTable )
+end
+
+------------------------------------------------------------------------------
+-- Updates one column value
+------------------------------------------------------------------------------
+function ActiveRecord:updateAttribute( columnName, columnValue )
+ local filter = "id = " .. self.id
+ orm.updateAttribute( self.class.tableName, filter, columnName, columnValue )
+end
+
+------------------------------------------------------------------------------
+-- Updates an array of columns
+------------------------------------------------------------------------------
+function ActiveRecord:updateAttributes( updateTable )
+ print("IMPLEMENTATION PENDING...")
+end
+
+------------------------------------------------------------------------------
+-- INSTANCE METHODS - END
+------------------------------------------------------------------------------
+
+
+
View
@@ -1,15 +1,26 @@
-settings =
-{
- orientation =
- {
- default = "landscapeRight",
- supported =
- {
- "landscapeLeft", "landscapeRight",
+settings = {
+ orientation = {
+ default = "portrait",
+ supported = {
+ "portrait"
},
},
- androidPermissions =
- {
- "android.permission.INTERNET"
- },
-}
+ iphone = {
+ plist = {
+ UIStatusBarHidden = false,
+ UIApplicationExitsOnSuspend = true,
+ CFBundleIconFile = "Icon.png",
+ CFBundleIconFiles = {
+ "Icon.png",
+ "Icon@2x.png",
+ "Icon-72.png",
+ },
+ }
+ },
+ --[[ For Android:
+ androidPermissions = {
+ "android.permission.INTERNET",
+ },
+ ]]--
+}
+
View
@@ -1,13 +1,13 @@
-application =
+application =
{
- content =
- {
- width = 320,
- height = 480,
- scale = "letterbox",
- imageSuffix =
- {
- ["@2"] = 2,
- }
- }
-}
+ content =
+ {
+ width = 320,
+ height = 480,
+ scale = "letterbox",
+ imageSuffix =
+ {
+ ["@2"] = 2,
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 7b0a6c2

Please sign in to comment.