Merge: gamnit: refactor the `flat` 2D API to include more services by default
authorJean Privat <jean@pryen.org>
Fri, 30 Jun 2017 13:51:00 +0000 (09:51 -0400)
committerJean Privat <jean@pryen.org>
Fri, 30 Jun 2017 13:51:00 +0000 (09:51 -0400)
The use of `import gamnit::flat` will now include more services useful to most games: `Sound`, `Font`, `pressed_keys`, etc. If a project doesn't want to include them for any reason, it can still `import gamnit::flat_core` and hand pick other services.

Pull-Request: #2522

contrib/action_nitro/src/action_nitro.nit
contrib/asteronits/src/asteronits.nit
contrib/tinks/src/client/client3d.nit
lib/gamnit/depth/depth.nit
lib/gamnit/depth/depth_core.nit
lib/gamnit/examples/template/src/template.nit
lib/gamnit/flat/flat.nit [new file with mode: 0644]
lib/gamnit/flat/flat_core.nit [moved from lib/gamnit/flat.nit with 97% similarity]
lib/gamnit/font.nit

index 2c6afdc..5ddeea6 100644 (file)
@@ -21,8 +21,6 @@ module action_nitro is
 end
 
 import gamnit::depth
-import gamnit::keys
-import gamnit::limit_fps
 
 import game
 
index 02cb3f4..1c148db 100644 (file)
@@ -26,7 +26,6 @@ import gamnit::flat
 
 import game_logic
 import spritesheet
-import app::audio
 
 redef class Spritesheet
        # Largest meteors, organized by color
index b37fc69..3b272d6 100644 (file)
@@ -23,8 +23,6 @@ module client3d is
 end
 
 import gamnit::depth
-import gamnit::keys
-import app::audio
 
 import base
 
index 9b4be47..4139949 100644 (file)
@@ -15,6 +15,7 @@
 # Framework for 3D games in Nit
 module depth
 
+import flat
 intrude import more_materials
 import more_models
 import model_dimensions
index 890395a..c1c1619 100644 (file)
@@ -15,7 +15,7 @@
 # Base entities of the depth 3D game framework
 module depth_core
 
-intrude import gamnit::flat
+import gamnit::flat_core
 
 # Visible 3D entity in the game world
 #
index 9c2c220..a0f37a0 100644 (file)
@@ -13,9 +13,7 @@ module template is
        android_api_target 10
 end
 
-import gamnit::flat # For `Texture, Sprite`, etc.
-import gamnit::keys # For `pressed_keys`
-import app::audio # For `Sound`
+import gamnit::flat # The 2D API, use `gamnit::depth` for 3D
 
 redef class App
 
diff --git a/lib/gamnit/flat/flat.nit b/lib/gamnit/flat/flat.nit
new file mode 100644 (file)
index 0000000..4094333
--- /dev/null
@@ -0,0 +1,44 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Simple API for 2D games, built around `Sprite` and `App::update`
+#
+# Client programs should implement `App::update` to execute game logic and
+# add instances of `Sprite` to `App::sprites` and `App::ui_sprites`.
+# At each frame, all sprites are drawn to the screen.
+#
+# This system relies on two cameras `App::world_camera` and `App::ui_camera`.
+#
+# * `App::world_camera` applies a perspective effect to draw the game world.
+#   This camera is designed to be moved around to see the world as well as to
+#   zoom in and out. It is used to position the sprites in `App::sprites`.
+#
+# * `App::ui_camera` is a simple orthogonal camera to display UI objects.
+#   This camera should mostly be still, it can still move for chock effects
+#   and the like. It can be used to standardize the size of the UI across
+#   devices. It is used to position the sprites in `App::ui_sprites`.
+#
+# See the sample game at `contrib/asteronits/` and the basic project template
+# at `lib/gamnit/examples/template/`.
+module flat
+
+import gamnit::flat_core
+
+# Extra optional features
+import gamnit::limit_fps
+import gamnit::keys
+import gamnit::camera_control
+import gamnit::tileset
+import gamnit::bmfont
+import app::audio
similarity index 97%
rename from lib/gamnit/flat.nit
rename to lib/gamnit/flat/flat_core.nit
index 3911092..e45f8d1 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Simple API for 2D games, built around `Sprite` and `App::update`
-#
-# Client programs should implement `App::update` to execute game logic and
-# add instances of `Sprite` to `App::sprites` and `App::ui_sprites`.
-# At each frame, all sprites are drawn to the screen.
-#
-# This system relies on two cameras `App::world_camera` and `App::ui_camera`.
-#
-# * `App::world_camera` applies a perspective effect to draw the game world.
-#   This camera is designed to be moved around to see the world as well as to
-#   zoom in and out. It is used to position the sprites in `App::sprites`.
-#
-# * `App::ui_camera` is a simple orthogonal camera to display UI objects.
-#   This camera should mostly be still, it can still move for chock effects
-#   and the like. It can be used to standardize the size of the UI across
-#   devices. It is used to position the sprites in `App::ui_sprites`.
-#
-# See the sample game at `contrib/asteronits/` and the basic project template
-# at `lib/gamnit/examples/template/`.
-module flat
+# Core services for the `flat` API for 2D games
+module flat_core
 
 import glesv2
 intrude import geometry::points_and_lines # For _x, _y and _z
@@ -44,8 +26,6 @@ import gamnit
 intrude import gamnit::cameras
 intrude import gamnit::cameras_cache
 import gamnit::dynamic_resolution
-import gamnit::limit_fps
-import gamnit::camera_control
 
 # Visible 2D entity in the game world or UI
 #
index df46590..3f30cb2 100644 (file)
@@ -15,7 +15,7 @@
 # Abstract font drawing services, implemented by `bmfont` and `tileset`
 module font
 
-import flat
+import gamnit::flat_core
 
 # Abstract font, drawn by a `TextSprites`
 abstract class Font