Skip to content

Commit 12e8617

Browse files
committed
Base code for jumpy
1 parent 0f754c6 commit 12e8617

File tree

10 files changed

+464
-5
lines changed

10 files changed

+464
-5
lines changed

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.architect
2-
bootstrap.json
3-
build/
4-
ext/
1+
.DS_Store
2+
platforms/*
3+
plugins/*

README.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,54 @@
11
# mobilegamedev
2-
Mobile Game - Jumpy
2+
3+
CoderDojo Mobile Game Development Course
4+
5+
In this course we are going to create a game called Jumpy, it will should you now create a simple but awesome action game that will enable you create any mobile game you want.
6+
7+
In this course we will show you how to get your first game buid in hours, on IPhone or Android devices. T
8+
9+
Getting started with developing with mobile development is alot of fun is and in this project I will get up and running quickly so can start developing.
10+
11+
## Install Node.js
12+
13+
Go to https://nodejs.org/en/ and Install Node on your laptop
14+
15+
## Install and Setup Cordova
16+
17+
Its time to open your terminal and we have got some installation and setup to do.
18+
19+
Firstly, lets install cordova by running
20+
21+
```bash
22+
sudo npm install -g cordova
23+
```
24+
25+
## Create your Cordova Project
26+
27+
You add the package name in our case org.coolestprojects.projects and we will call our project Jumpy
28+
29+
cordova create mobilegamedev org.coolestprojects.projects Jumpy
30+
Now on the command prompt move into the directory
31+
32+
```bash
33+
cd mobilegamedev
34+
```
35+
36+
You now need to setup your projects for ios (IPhone dev) by running the following command.
37+
38+
```bash
39+
cordova platform add ios
40+
```
41+
42+
Or to setup for Android run
43+
44+
```bash
45+
cordova platform add android
46+
```
47+
48+
## References
49+
50+
https://cordova.apache.org/docs/en/4.0.0/guide_cli_index.md.html
51+
https://cordova.apache.org/docs/en/4.0.0/guide_platforms_ios_index.md.html
52+
https://cordova.apache.org/docs/en/2.5.0/guide_getting-started_ios_index.md.html
53+
54+

config.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<widget id="org.coolestprojects.projects" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
3+
<name>Jumpy</name>
4+
<description>
5+
A sample Apache Cordova application that responds to the deviceready event.
6+
</description>
7+
<author email="[email protected]" href="http://cordova.io">
8+
Apache Cordova Team
9+
</author>
10+
<content src="index.html" />
11+
<plugin name="cordova-plugin-whitelist" version="1" />
12+
<access origin="*" />
13+
<allow-intent href="http://*/*" />
14+
<allow-intent href="https://*/*" />
15+
<allow-intent href="tel:*" />
16+
<allow-intent href="sms:*" />
17+
<allow-intent href="mailto:*" />
18+
<allow-intent href="geo:*" />
19+
<platform name="android">
20+
<allow-intent href="market:*" />
21+
</platform>
22+
<platform name="ios">
23+
<allow-intent href="itms:*" />
24+
<allow-intent href="itms-apps:*" />
25+
</platform>
26+
</widget>

hooks/README.md

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
<!--
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
-->
21+
# Cordova Hooks
22+
23+
Cordova Hooks represent special scripts which could be added by application and plugin developers or even by your own build system to customize cordova commands. Hook scripts could be defined by adding them to the special predefined folder (`/hooks`) or via configuration files (`config.xml` and `plugin.xml`) and run serially in the following order:
24+
* Application hooks from `/hooks`;
25+
* Application hooks from `config.xml`;
26+
* Plugin hooks from `plugins/.../plugin.xml`.
27+
28+
__Remember__: Make your scripts executable.
29+
30+
__Note__: `.cordova/hooks` directory is also supported for backward compatibility, but we don't recommend using it as it is deprecated.
31+
32+
## Supported hook types
33+
The following hook types are supported:
34+
35+
after_build/
36+
after_compile/
37+
after_docs/
38+
after_emulate/
39+
after_platform_add/
40+
after_platform_rm/
41+
after_platform_ls/
42+
after_plugin_add/
43+
after_plugin_ls/
44+
after_plugin_rm/
45+
after_plugin_search/
46+
after_plugin_install/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being installed
47+
after_prepare/
48+
after_run/
49+
after_serve/
50+
before_build/
51+
before_compile/
52+
before_docs/
53+
before_emulate/
54+
before_platform_add/
55+
before_platform_rm/
56+
before_platform_ls/
57+
before_plugin_add/
58+
before_plugin_ls/
59+
before_plugin_rm/
60+
before_plugin_search/
61+
before_plugin_install/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being installed
62+
before_plugin_uninstall/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being uninstalled
63+
before_prepare/
64+
before_run/
65+
before_serve/
66+
pre_package/ <-- Windows 8 and Windows Phone only.
67+
68+
## Ways to define hooks
69+
### Via '/hooks' directory
70+
To execute custom action when corresponding hook type is fired, use hook type as a name for a subfolder inside 'hooks' directory and place you script file here, for example:
71+
72+
# script file will be automatically executed after each build
73+
hooks/after_build/after_build_custom_action.js
74+
75+
76+
### Config.xml
77+
78+
Hooks can be defined in project's `config.xml` using `<hook>` elements, for example:
79+
80+
<hook type="before_build" src="scripts/appBeforeBuild.bat" />
81+
<hook type="before_build" src="scripts/appBeforeBuild.js" />
82+
<hook type="before_plugin_install" src="scripts/appBeforePluginInstall.js" />
83+
84+
<platform name="wp8">
85+
<hook type="before_build" src="scripts/wp8/appWP8BeforeBuild.bat" />
86+
<hook type="before_build" src="scripts/wp8/appWP8BeforeBuild.js" />
87+
<hook type="before_plugin_install" src="scripts/wp8/appWP8BeforePluginInstall.js" />
88+
...
89+
</platform>
90+
91+
<platform name="windows8">
92+
<hook type="before_build" src="scripts/windows8/appWin8BeforeBuild.bat" />
93+
<hook type="before_build" src="scripts/windows8/appWin8BeforeBuild.js" />
94+
<hook type="before_plugin_install" src="scripts/windows8/appWin8BeforePluginInstall.js" />
95+
...
96+
</platform>
97+
98+
### Plugin hooks (plugin.xml)
99+
100+
As a plugin developer you can define hook scripts using `<hook>` elements in a `plugin.xml` like that:
101+
102+
<hook type="before_plugin_install" src="scripts/beforeInstall.js" />
103+
<hook type="after_build" src="scripts/afterBuild.js" />
104+
105+
<platform name="wp8">
106+
<hook type="before_plugin_install" src="scripts/wp8BeforeInstall.js" />
107+
<hook type="before_build" src="scripts/wp8BeforeBuild.js" />
108+
...
109+
</platform>
110+
111+
`before_plugin_install`, `after_plugin_install`, `before_plugin_uninstall` plugin hooks will be fired exclusively for the plugin being installed/uninstalled.
112+
113+
## Script Interface
114+
115+
### Javascript
116+
117+
If you are writing hooks in Javascript you should use the following module definition:
118+
```javascript
119+
module.exports = function(context) {
120+
...
121+
}
122+
```
123+
124+
You can make your scipts async using Q:
125+
```javascript
126+
module.exports = function(context) {
127+
var Q = context.requireCordovaModule('q');
128+
var deferral = new Q.defer();
129+
130+
setTimeout(function(){
131+
console.log('hook.js>> end');
132+
deferral.resolve();
133+
}, 1000);
134+
135+
return deferral.promise;
136+
}
137+
```
138+
139+
`context` object contains hook type, executed script full path, hook options, command-line arguments passed to Cordova and top-level "cordova" object:
140+
```json
141+
{
142+
"hook": "before_plugin_install",
143+
"scriptLocation": "c:\\script\\full\\path\\appBeforePluginInstall.js",
144+
"cmdLine": "The\\exact\\command\\cordova\\run\\with arguments",
145+
"opts": {
146+
"projectRoot":"C:\\path\\to\\the\\project",
147+
"cordova": {
148+
"platforms": ["wp8"],
149+
"plugins": ["com.plugin.withhooks"],
150+
"version": "0.21.7-dev"
151+
},
152+
"plugin": {
153+
"id": "com.plugin.withhooks",
154+
"pluginInfo": {
155+
...
156+
},
157+
"platform": "wp8",
158+
"dir": "C:\\path\\to\\the\\project\\plugins\\com.plugin.withhooks"
159+
}
160+
},
161+
"cordova": {...}
162+
}
163+
164+
```
165+
`context.opts.plugin` object will only be passed to plugin hooks scripts.
166+
167+
You can also require additional Cordova modules in your script using `context.requireCordovaModule` in the following way:
168+
```javascript
169+
var Q = context.requireCordovaModule('q');
170+
```
171+
172+
__Note__: new module loader script interface is used for the `.js` files defined via `config.xml` or `plugin.xml` only.
173+
For compatibility reasons hook files specified via `/hooks` folders are run via Node child_process spawn, see 'Non-javascript' section below.
174+
175+
### Non-javascript
176+
177+
Non-javascript scripts are run via Node child_process spawn from the project's root directory and have the root directory passes as the first argument. All other options are passed to the script using environment variables:
178+
179+
* CORDOVA_VERSION - The version of the Cordova-CLI.
180+
* CORDOVA_PLATFORMS - Comma separated list of platforms that the command applies to (e.g.: android, ios).
181+
* CORDOVA_PLUGINS - Comma separated list of plugin IDs that the command applies to (e.g.: org.apache.cordova.file, org.apache.cordova.file-transfer)
182+
* CORDOVA_HOOK - Path to the hook that is being executed.
183+
* CORDOVA_CMDLINE - The exact command-line arguments passed to cordova (e.g.: cordova run ios --emulate)
184+
185+
If a script returns a non-zero exit code, then the parent cordova command will be aborted.
186+
187+
## Writing hooks
188+
189+
We highly recommend writing your hooks using Node.js so that they are
190+
cross-platform. Some good examples are shown here:
191+
192+
[http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/](http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/)
193+
194+
Also, note that even if you are working on Windows, and in case your hook scripts aren't bat files (which is recommended, if you want your scripts to work in non-Windows operating systems) Cordova CLI will expect a shebang line as the first line for it to know the interpreter it needs to use to launch the script. The shebang line should match the following example:
195+
196+
#!/usr/bin/env [name_of_interpreter_executable]

0 commit comments

Comments
 (0)