Merge: grammar: support spaces and doc with the `in "Lang"` syntax
authorJean Privat <jean@pryen.org>
Fri, 13 Jun 2014 17:08:47 +0000 (13:08 -0400)
committerJean Privat <jean@pryen.org>
Fri, 13 Jun 2014 17:08:47 +0000 (13:08 -0400)
Enables:
~~~~
extern class A in "Java"
    `{ MyJavaClass `}

# ...
end
~~~~

Still needs work for `
` after imports...

Pull-Request: #504
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

examples/shoot/src/shoot.nit
lib/app.nit

index ee41363..f4001c8 100644 (file)
 
 # Space shooter.
 # This program is a fun game but also a good example of the scene2d module
-module shoot
+module shoot is
+       app_name("Space Shooter")
+       app_version(0, 1, git_revision)
+end
 
 import mnit
 import shoot_logic
@@ -23,16 +26,16 @@ redef class Sprite
        # mnit specific method to draw a sprite
        # app is used to optain the assets and the display
        # Each sprite should implements this method
-       fun draw_on_display(app: ShootApp) do end
+       fun draw_on_display(app: App) do end
 
        # Helper function to draw an image centered on the current sprite position
-       fun draw_image(app: ShootApp, img: Image)
+       fun draw_image(app: App, img: Image)
        do
                app.display.blit_centered(img, (self.x.to_f/app.scale).to_i, (self.y.to_f/app.scale).to_i)
        end
 
        # Helper function to draw an image translated and rotated on the current sprite position
-       fun draw_rotated_image(app: ShootApp, img: Image, dx, dy: Int, angle: Float)
+       fun draw_rotated_image(app: App, img: Image, dx, dy: Int, angle: Float)
        do
                app.display.blit_rotated(img, self.x.to_f/app.scale, self.y.to_f/app.scale, angle)
        end
@@ -166,8 +169,8 @@ redef class Star
 end
 
 redef class Scene
-       fun draw_on_display(app: ShootApp) do end
-       fun input(app: ShootApp, input_event: InputEvent): Bool do return false
+       fun draw_on_display(app: App) do end
+       fun input(app: App, input_event: InputEvent): Bool do return false
 end
 
 redef class PlayScene
@@ -265,8 +268,7 @@ end
 
 ###
 
-class ShootApp
-       super App
+redef class App
        super View
 
        var debug: Bool = false
@@ -283,8 +285,6 @@ class ShootApp
                end
        end
 
-       init do super
-
        var scene: ShotScene
 
        var img_hitbox: Image
@@ -321,6 +321,8 @@ class ShootApp
 
                scale = (800.0 * 600.0 / display.width.to_f / display.height.to_f).sqrt * 100.0
 
+               debug = args.length > 0 and args.first == "--debug"
+
                # TODO load assets here
                # ex: img = load_image( "img.png" )
                #     to get file located at assets/img.png before deployement
@@ -410,6 +412,5 @@ if args.length > 0 and args.first == "--headless" then
        return
 end
 
-var app = new ShootApp
-app.debug = args.length > 0 and args.first == "--debug"
+app.setup
 app.run
index 3e2d737..7ee9493 100644 (file)
@@ -29,7 +29,7 @@ class App
 
        # Starts the internal setup of graphical and other stuff
        # Is called just before run
-       protected fun setup do end
+       fun setup do end
 
        # Main entry point of your application
        fun run do end