Skip to content

Commit b23113e

Browse files
author
Matt Karl
committed
Implemented template modules
1 parent 4a2b1ad commit b23113e

File tree

14 files changed

+415
-249
lines changed

14 files changed

+415
-249
lines changed

deploy/assets/js/preview.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/assets/templates/default/springroll

Lines changed: 0 additions & 6 deletions
This file was deleted.

deploy/assets/templates/default/springroll-template.json

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,102 +4,96 @@
44
"version" : "1.2.0",
55
"rename" : {
66
"gitignore" : ".gitignore",
7-
"bowerrc" : ".bowerrc",
8-
"springroll": ".springroll"
7+
"bowerrc" : ".bowerrc"
98
},
109
"modules": {
1110
"springroll.Core": {
1211
"name": "SpringRoll Core",
12+
"main": "components/springroll/core.min.js",
13+
"mainDebug": "components/springroll/core.js",
1314
"required": true,
1415
"bower": {
1516
"springroll": "*"
1617
},
17-
"libraries": [
18-
"components/preloadjs/lib/preload.min.js",
19-
"components/springroll/core.min.js"
20-
],
21-
"librariesDebug": [
22-
"components/preloadjs/lib/preload.combined.js",
23-
"components/springroll/core.js"
24-
]
18+
"libraries": "components/preloadjs/lib/preload.min.js",
19+
"librariesDebug": "components/preloadjs/lib/preload.combined.js"
2520
},
2621
"springroll.CreateJSDisplay": {
2722
"name": "CreateJS Display Module",
23+
"main": "components/springroll/dist/modules/display-createjs.min.js",
24+
"mainDebug": "components/springroll/dist/modules/display-createjs.js",
2825
"bower": {
2926
"easeljs": "https://github.com/SpringRoll/EaselJS.git",
3027
"tweenjs": "https://github.com/SpringRoll/TweenJS.git"
3128
},
3229
"libraries": [
3330
"components/tweenjs/lib/tweenjs.min.js",
3431
"components/easeljs/lib/easeljs.min.js",
35-
"components/easeljs/lib/movieclip.min.js",
36-
"components/springroll/dist/modules/display-createjs.min.js"
32+
"components/easeljs/lib/movieclip.min.js"
3733
],
3834
"librariesDebug": [
3935
"components/tweenjs/lib/tweenjs.combined.js",
4036
"components/easeljs/lib/easeljs.combined.js",
41-
"components/easeljs/lib/movieclip.combined.js",
42-
"components/springroll/dist/modules/display-createjs.js"
37+
"components/easeljs/lib/movieclip.combined.js"
4338
],
4439
"depends": "springroll.Core"
4540
},
4641
"springroll.PixiDisplay": {
4742
"name": "Pixi.js Display Module",
43+
"main": "components/springroll/dist/modules/display-pixi.min.js",
44+
"mainDebug": "components/springroll/dist/modules/display-pixi.js",
4845
"bower": {
4946
"pixi.js":"https://github.com/SpringRoll/pixi.js.git"
5047
},
51-
"libraries": [
52-
"components/pixi.js/bin/pixi.js",
53-
"components/springroll/dist/modules/display-pixi.min.js"
54-
],
55-
"librariesDebug": [
56-
"components/pixi.js/bin/pixi.dev.js",
57-
"components/springroll/dist/modules/display-pixi.js"
58-
],
48+
"libraries": "components/pixi.js/bin/pixi.js",
49+
"librariesDebug": "components/pixi.js/bin/pixi.dev.js",
5950
"depends": "springroll.Core"
6051
},
6152
"springroll.NativeDisplay": {
6253
"name": "Native Display Module",
63-
"libraries": "components/springroll/dist/modules/display-native.min.js",
64-
"librariesDebug": "components/springroll/dist/modules/display-native.js",
54+
"main": "components/springroll/dist/modules/display-native.min.js",
55+
"mainDebug": "components/springroll/dist/modules/display-native.js",
6556
"depends": "springroll.Core"
6657
},
6758
"springroll.Sound": {
6859
"name": "Sound Module",
6960
"bower": {
7061
"soundjs": "https://github.com/SpringRoll/SoundJS.git"
7162
},
63+
"main":"components/springroll/dist/modules/sound.min.js",
64+
"mainDebug":"components/springroll/dist/modules/sound.js",
7265
"libraries": [
7366
"components/soundjs/lib/soundjs.min.js",
74-
"components/soundjs/lib/flashaudioplugin.min.js",
75-
"components/springroll/dist/modules/sound.min.js"
67+
"components/soundjs/lib/flashaudioplugin.min.js"
7668
],
7769
"librariesDebug": [
7870
"components/soundjs/lib/soundjs.min.js",
79-
"components/soundjs/lib/flashaudioplugin.combined.js",
80-
"components/springroll/dist/modules/sound.js"
71+
"components/soundjs/lib/flashaudioplugin.combined.js"
8172
],
73+
"librariesCopy": {
74+
"components/soundjs/lib/FlashAudioPlugin.swf": "deploy/assets/swfs/"
75+
},
8276
"depends": "springroll.Core"
8377
},
8478
"springroll.Interface": {
8579
"name": "Interface Module",
86-
"libraries": "components/springroll/dist/modules/interface.min.js",
87-
"librariesDebug": "components/springroll/dist/modules/interface.js",
80+
"main": "components/springroll/dist/modules/interface.min.js",
81+
"mainDebug": "components/springroll/dist/modules/interface.js",
8882
"depends": [
8983
"springroll.Core",
9084
"springroll.CreateJSDisplay|springroll.PixiDisplay"
9185
]
9286
},
9387
"springroll.Captions": {
9488
"name": "Captions Module",
95-
"libraries": "components/springroll/dist/modules/captions.min.js",
96-
"librariesDebug": "components/springroll/dist/modules/captions.js",
89+
"main": "components/springroll/dist/modules/captions.min.js",
90+
"mainDebug": "components/springroll/dist/modules/captions.js",
9791
"depends": "springroll.Core"
9892
},
9993
"springroll.Game": {
10094
"name": "Game Module",
101-
"libraries": "components/springroll/dist/modules/game.min.js",
102-
"librariesDebug": "components/springroll/dist/modules/game.js",
95+
"main": "components/springroll/dist/modules/game.min.js",
96+
"mainDebug": "components/springroll/dist/modules/game.js",
10397
"depends": [
10498
"springroll.Sound",
10599
"springroll.Core",
@@ -108,20 +102,20 @@
108102
},
109103
"springroll.Tasks": {
110104
"name": "Tasks Module",
111-
"libraries": "components/springroll/dist/modules/tasks.min.js",
112-
"librariesDebug": "components/springroll/dist/modules/tasks.js",
105+
"main": "components/springroll/dist/modules/tasks.min.js",
106+
"mainDebug": "components/springroll/dist/modules/tasks.js",
113107
"depends": "springroll.Core"
114108
},
115109
"springroll.Translate": {
116110
"name": "Translate Module",
117-
"libraries": "components/springroll/dist/modules/translate.min.js",
118-
"librariesDebug": "components/springroll/dist/modules/translate.js",
111+
"main": "components/springroll/dist/modules/translate.min.js",
112+
"mainDebug": "components/springroll/dist/modules/translate.js",
119113
"depends": "springroll.Core"
120114
},
121115
"springroll.Worker": {
122116
"name": "Worker Module",
123-
"libraries": "components/springroll/dist/modules/worker.min.js",
124-
"librariesDebug": "components/springroll/dist/modules/worker.js"
117+
"main": "components/springroll/dist/modules/worker.min.js",
118+
"mainDebug": "components/springroll/dist/modules/worker.js"
125119
}
126120
}
127121
}

deploy/new.html

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,21 @@ <h1>Create New Project</h1>
9494
</div>
9595
</div>
9696
<div class="form-group">
97+
<label for="output" class="col-sm-2 col-xs-4 control-label">Modules</label>
98+
<div class="col-sm-10 col-xs-8"><div id="modules"></div></div>
99+
<script type="text/html" id="moduleTemplate">
100+
<div class="checkbox">
101+
<label>
102+
<input type="checkbox" class="module" checked="checked">
103+
<span class="name"></span>
104+
</label>
105+
</div>
106+
</script>
107+
</div>
108+
<!-- <div class="form-group">
97109
<label for="output" class="col-sm-2 col-xs-4 control-label">Renderer</label>
98110
<div class="col-sm-10 col-xs-8">
99111
100-
<!-- Including core module first -->
101112
<input type="checkbox" class="hidden module" checked disabled value="components/springroll/dist/core">
102113
103114
<div class="btn-group" data-toggle="buttons">
@@ -149,7 +160,7 @@ <h1>Create New Project</h1>
149160
<label><input type="checkbox" class="module" value="components/springroll/dist/modules/worker" checked="checked"> Worker Module</label>
150161
</div>
151162
</div>
152-
</div>
163+
</div> -->
153164
</div>
154165
<div class="modal-footer">
155166
<button type="button" class="btn btn-default" id="closeButton">Close</button>

project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@
8282
"new": [
8383
"components/node-webkit-app/src/utils/Browser.js",
8484
"src/springroll/Module.js",
85-
"src/springroll/new/Module.js",
85+
"src/springroll/new/JSONUtils.js",
86+
"src/springroll/new/TemplateModule.js",
8687
"src/springroll/new/Template.js",
8788
"src/springroll/new/TemplateManager.js",
8889
"src/springroll/new/Installer.js",

src/springroll/Module.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
* @static
4444
* @param {funtion} func The module to create
4545
*/
46-
Module.create = function(func)
46+
Module.create = function(classRef)
4747
{
48-
$(function(){ window.module = new func(); });
48+
$(function(){ window.appModule = new classRef(); });
4949
};
5050

5151
// Reference to the prototype

src/springroll/ModuleButton.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,14 @@
144144
*/
145145
var onFocus = function()
146146
{
147-
this.window.module.focus();
147+
if (this.window.appModule)
148+
{
149+
this.window.appModule.focus();
150+
}
151+
else
152+
{
153+
console.error("Unable to find appModule on window");
154+
}
148155
};
149156

150157
/**

src/springroll/new/Installer.js

Lines changed: 37 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
var glob = require("glob");
1010
}
1111

12-
var TemplateManager = springroll.new.TemplateManager;
12+
// Import classes
13+
var JSONUtils = include('springroll.new.JSONUtils');
1314

1415
/**
1516
* Script to install the new springroll project
@@ -37,10 +38,19 @@
3738
*/
3839
Installer.FILE = 'springroll.json';
3940

41+
/**
42+
* The meta project file
43+
* @property {String} META_FILE
44+
* @readOnly
45+
* @static
46+
* @default ".springroll"
47+
*/
48+
Installer.META_FILE = '.springroll';
49+
4050
/**
4151
* The main execution point for creating a new project
4252
* @method run
43-
* @param {array} templates The path to the template to use
53+
* @param {springroll.new.Template} template The path to the template to use
4454
* @param {object} options The collection of options
4555
* @param {int} options.width The width of the new game
4656
* @param {int} options.height The height of the new game
@@ -55,57 +65,18 @@
5565
* @param {object} options.bower The addition bower files to add
5666
* @param {function} complete The function to call when done
5767
*/
58-
p.run = function(templates, options, complete)
68+
p.run = function(template, options, complete)
5969
{
6070
this.options = options;
6171
var dest = options.destination;
6272

63-
if (DEBUG)
64-
{
65-
console.log("Copy " + template + " to " + dest);
66-
}
73+
// Copy the template files
74+
template.copyTo(dest);
6775

68-
// loop through the templates from back to front,
69-
// that is from parent (general) to child (specific)
70-
var template, file, j, i;
71-
for (i = templates.length - 1; i >= 0; i--)
72-
{
73-
template = templates[i];
74-
75-
// Copy the files from the template to the destination
76-
fs.copySync(template.path, dest);
77-
78-
// Add subsitution options for the version and name
79-
options.templateVersion = template.version;
80-
options.templateName = template.name;
81-
options.templateId = template.id;
82-
83-
// Rename any local files that should actually
84-
// be hidden
85-
if (template.rename)
86-
{
87-
for(file in template.rename)
88-
{
89-
fs.renameSync(
90-
path.join(dest, file),
91-
path.join(dest, template.rename[file])
92-
);
93-
}
94-
}
95-
96-
// Any files to remove, this can be if we're overriding
97-
// another template, we can delete things in the parent
98-
if (template.remove)
99-
{
100-
for (j = 0; j < template.remove.length; i++)
101-
{
102-
fs.unlinkSync(path.join(dest, template.remove[i]));
103-
}
104-
}
105-
106-
// Remove the template file
107-
fs.unlinkSync(path.join(dest, TemplateManager.FILE));
108-
}
76+
// Add subsitution options for the version and name
77+
options.templateVersion = template.version;
78+
options.templateName = template.name;
79+
options.templateId = template.id;
10980

11081
if (Object.keys(options.bower).length > 0)
11182
{
@@ -117,6 +88,11 @@
11788

11889
// Update the build file with libraries and modules
11990
var build = this.readJSON(Installer.FILE);
91+
92+
// Save the template we're using
93+
this.writeJSON(Installer.META_FILE, {
94+
"template": template.toJSON()
95+
});
12096

12197
// Replace tokens with the list of depdendencies
12298
insertAt(
@@ -198,8 +174,12 @@
198174
*/
199175
p.readJSON = function(file)
200176
{
201-
var filePath = path.join(this.options.destination, file);
202-
return JSON.parse(fs.readFileSync(filePath));
177+
return JSONUtils.read(
178+
path.join(
179+
this.options.destination,
180+
file
181+
)
182+
);
203183
};
204184

205185
/**
@@ -210,8 +190,13 @@
210190
*/
211191
p.writeJSON = function(file, obj)
212192
{
213-
var filePath = path.join(this.options.destination, file);
214-
fs.writeFileSync(filePath, JSON.stringify(obj, null, "\t"));
193+
JSONUtils.write(
194+
path.join(
195+
this.options.destination,
196+
file
197+
),
198+
obj
199+
);
215200
};
216201

217202
/**

0 commit comments

Comments
 (0)