Skip to content

Commit fee9466

Browse files
committedNov 25, 2015
added gulp script, small SASS test, cleaned JS for linting
1 parent 50c9b54 commit fee9466

17 files changed

+44303
-132
lines changed
 

‎entitymoduleapi.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ function EntityModuleAPI() {
77
// returns the Entity object with the specified id
88
EntityModuleAPI.prototype.getEntityById = function(id) {
99
return this.environment.entities[id];
10-
}
10+
};
1111

1212
// focus camera!
1313
EntityModuleAPI.prototype.focusCamera = function(position) {
1414
// TODO
15-
}
15+
};
1616

1717
// dispatch a message to all modules
1818
EntityModuleAPI.prototype.dispatchMessage = function(message, data) {
1919
this.environment.dispatchMessage(message, data);
20-
}
20+
};
2121

2222
// dispatch a message to a specific entity
2323
EntityModuleAPI.prototype.dispatchMessageToEntity = function(entity_id, message, data) {
2424
this.environment.dispatchMessageToEntity(entity_id, message, data);
25-
}
25+
};
2626

2727
// returns the geometry buffer for this entity
2828
// there can only be one buffer by entity
@@ -37,12 +37,12 @@ EntityModuleAPI.prototype.requestGeometryBuffer = function(entity_id) {
3737
var buffer = this.getEntityById(entity_id).geometry_buffer;
3838
buffer.changed = true;
3939
return buffer;
40-
}
40+
};
4141

4242
// returns nearby entities
4343
EntityModuleAPI.prototype.getNearbyEntities = function(entity_id) {
4444
return this.environment.getNearbyEntities(entity_id);
45-
}
45+
};
4646

4747

4848

‎entitymodulebuilder.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ EntityModuleBuilder.prototype.createModule = function(module_name) {
5656
this.module_build_functions[module_name](new_module);
5757

5858
return new_module;
59-
}
59+
};
6060

6161
// this is used to register custom modules in the builder
6262
// module_name is a string
@@ -76,10 +76,10 @@ EntityModuleBuilder.prototype.registerModule = function(module_name, description
7676
// registering build function & description
7777
this.module_build_functions[module_name] = build_function;
7878
this.module_descriptions[module_name] = description;
79-
}
79+
};
8080

8181

8282
// export module
8383
module.exports = function(entity_module_api) {
8484
return new EntityModuleBuilder(entity_module_api);
85-
}
85+
};

‎environment.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Environment.prototype.init = function() {
7575
this.entities[i] = new Entity(i);
7676
}
7777
*/
78-
}
78+
};
7979

8080
Environment.prototype.update = function() {
8181

@@ -102,24 +102,24 @@ Environment.prototype.update = function() {
102102

103103

104104
// reschedule update
105-
setTimeout(function() { instance.update() }, UPDATE_DELTA_TIME * 1000);
106-
}
105+
setTimeout(function() { instance.update(); }, UPDATE_DELTA_TIME * 1000);
106+
};
107107

108108

109109
// collections manipulation
110110
Environment.prototype.createNewEntity = function(entity_id) {
111111
var new_entity = new Entity(entity_id);
112112
this.entities[entity_id] = new Entity(entity_id);
113113
return new_entity;
114-
}
114+
};
115115
Environment.prototype.attachModuleToEntity = function(entity_id, module_name) {
116116
var module = this.module_builder.createModule(module_name);
117117
if(module) {
118118
module.entity_id = entity_id;
119119
this.entity_modules.push(module);
120120
}
121121
return module;
122-
}
122+
};
123123

124124

125125
// this sends a message to all entity modules
@@ -128,7 +128,7 @@ Environment.prototype.dispatchMessage = function(message, data) {
128128
for(var i=0; i<this.entity_modules.length; i++) {
129129
this.entity_modules[i].respondToMessage(message, data);
130130
}
131-
}
131+
};
132132

133133
// dispatch a message only to a certain entity
134134
Environment.prototype.dispatchMessageToEntity = function(entity_id, message, data) {
@@ -137,7 +137,7 @@ Environment.prototype.dispatchMessageToEntity = function(entity_id, message, dat
137137
this.entity_modules[i].respondToMessage(message, data);
138138
}
139139
}
140-
}
140+
};
141141

142142
// returns an array of modules attached ton this entity
143143
Environment.prototype.getModulesList = function(entity_id) {
@@ -148,7 +148,7 @@ Environment.prototype.getModulesList = function(entity_id) {
148148
}
149149
}
150150
return result;
151-
}
151+
};
152152

153153
// returns entities close to the specified one, i.e. in the same quadtree cell
154154
// TODO: actually implement quadtree
@@ -157,7 +157,7 @@ Environment.prototype.getNearbyEntities = function(entity_id) {
157157
var id;
158158
for(id in this.entities) { entities.push(this.entities[id]); }
159159
return entities;
160-
}
160+
};
161161

162162

163163

@@ -172,16 +172,16 @@ function GeometryBuffer() {
172172

173173
// blocks are created along the way when redrawing the geometry
174174
this.blocks = [new GeometryBlock()];
175-
this.current_block;
176-
this.block_cursor;
175+
this.current_block = null;
176+
this.block_cursor = -1;
177177
this.changed = true;
178178
}
179179

180180
// reset cursors: we're ready for refilling the buffers
181181
GeometryBuffer.prototype.start = function() {
182182
this.current_block = this.blocks[0];
183183
this.block_cursor = 0;
184-
}
184+
};
185185

186186
// we're done filling the buffers
187187
GeometryBuffer.prototype.end = function() {
@@ -197,14 +197,14 @@ GeometryBuffer.prototype.end = function() {
197197
this.blocks.splice(this.block_cursor + 1, this.blocks.length);
198198

199199
this.changed = false;
200-
}
200+
};
201201

202202
// returns the current amount of vertices injected in the buffer
203203
//GeometryBuffer.prototype.getVertexCount = function() { return this.positions_cursor / 3; }
204204
//GeometryBuffer.prototype.getTriangleCount = function() { return this.indices_cursor / 3; }
205205
GeometryBuffer.prototype.getBaseIndex = function() {
206206
return this.current_block.positions_cursor / 3;
207-
}
207+
};
208208

209209
// these functions make sure that there is enough space in the current block, otherwise they add a new one
210210
GeometryBuffer.prototype.prepareNewVertex = function() {
@@ -217,7 +217,7 @@ GeometryBuffer.prototype.prepareNewVertex = function() {
217217
this.current_block = this.blocks[this.block_cursor];
218218
}
219219
}
220-
}
220+
};
221221
GeometryBuffer.prototype.prepareNewTriangle = function() {
222222
if(this.current_block.indices_cursor >= GEOMETRYBLOCK_TRIANGLE_COUNT * 3) {
223223
this.block_cursor++;
@@ -228,32 +228,32 @@ GeometryBuffer.prototype.prepareNewTriangle = function() {
228228
this.current_block = this.blocks[this.block_cursor];
229229
}
230230
}
231-
}
231+
};
232232

233233
// short methods for adding a position, normal, color, index
234234
GeometryBuffer.prototype.p = function(x, y, z) {
235235
this.prepareNewVertex();
236236
this.current_block.positions[this.current_block.positions_cursor++] = x;
237237
this.current_block.positions[this.current_block.positions_cursor++] = y;
238238
this.current_block.positions[this.current_block.positions_cursor++] = z;
239-
}
239+
};
240240
GeometryBuffer.prototype.n = function(x, y, z) {
241241
this.current_block.normals[this.current_block.normals_cursor++] = x;
242242
this.current_block.normals[this.current_block.normals_cursor++] = y;
243243
this.current_block.normals[this.current_block.normals_cursor++] = z;
244-
}
244+
};
245245
GeometryBuffer.prototype.c = function(r, g, b, a) {
246246
this.current_block.colors[this.current_block.colors_cursor++] = r;
247247
this.current_block.colors[this.current_block.colors_cursor++] = g;
248248
this.current_block.colors[this.current_block.colors_cursor++] = b;
249249
this.current_block.colors[this.current_block.colors_cursor++] = a;
250-
}
250+
};
251251
GeometryBuffer.prototype.i = function(f0, f1, f2) {
252252
this.prepareNewTriangle();
253253
this.current_block.indices[this.current_block.indices_cursor++] = f0;
254254
this.current_block.indices[this.current_block.indices_cursor++] = f1;
255255
this.current_block.indices[this.current_block.indices_cursor++] = f2;
256-
}
256+
};
257257

258258

259259
// geometry drawing functions
@@ -290,7 +290,7 @@ GeometryBuffer.prototype.drawBox = function(x, y, z, r, g, b, sx, sy, sz) {
290290
this.i(base_index+12, base_index+13, base_index+14); this.i(base_index+14, base_index+15, base_index+12);
291291
this.i(base_index+16, base_index+17, base_index+18); this.i(base_index+18, base_index+19, base_index+16);
292292
this.i(base_index+20, base_index+21, base_index+22); this.i(base_index+22, base_index+23, base_index+20);
293-
}
293+
};
294294

295295
// a disc is originally facing Y+
296296
// rd is radius
@@ -311,7 +311,7 @@ GeometryBuffer.prototype.drawDisc = function(x, y, z, r, g, b, rd) {
311311
else { this.i(base_index, base_index + i + 1, base_index + 1); }
312312
}
313313

314-
}
314+
};
315315

316316

317317

@@ -335,7 +335,7 @@ function GeometryBlock() {
335335
// serialize method
336336
GeometryBlock.prototype.toJSON = function() {
337337
// TODO
338-
}
338+
};
339339

340340
// placeholder (unused)
341341
// GeometryBlock.prototype.dispose() { }

‎gulpfile.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// todo
2+
// - css & js minifier + sourcemaps
3+
// - automated release with gulp-git
4+
5+
// note: the current file is not watched nor linted
6+
7+
'use strict';
8+
9+
var gulp = require('gulp');
10+
var jshint = require('gulp-jshint');
11+
var browsersync = require('browser-sync');
12+
var nodemon = require('gulp-nodemon');
13+
var sass = require('gulp-sass');
14+
var cache = require('gulp-cached');
15+
16+
17+
// linting
18+
// this task is ran at launch (on all files) and on changed files
19+
gulp.task('lint', function() {
20+
gulp.src(['*.js', 'public/*.js', '!./gulpfile.js'])
21+
.pipe(cache('linting'))
22+
.pipe(jshint())
23+
.pipe(jshint.reporter('jshint-stylish'));
24+
});
25+
26+
// launch nodemon
27+
gulp.task('nodemon', function() {
28+
nodemon({
29+
ignore: ['public/*', './gulpfile.js'],
30+
ext: 'js json'
31+
});
32+
});
33+
34+
// launch browser-sync & watch public files for change
35+
gulp.task('browser-sync', function() {
36+
37+
browsersync({
38+
proxy: "http://localhost:8080",
39+
files: ["public/**/*.*"],
40+
port: 8000,
41+
});
42+
43+
gulp.watch(['public/{*.js,*.css,*.html}'], browsersync.reload);
44+
});
45+
46+
// compile scss to css
47+
gulp.task('compile-css', function() {
48+
gulp.src(['public/sass/*.scss'])
49+
.pipe(sass().on('error', sass.logError))
50+
.pipe(gulp.dest('public/'));
51+
52+
});
53+
54+
// entry point
55+
gulp.task('default', ['lint', 'nodemon', 'browser-sync'], function() {
56+
57+
// add a watch for css compiling
58+
gulp.watch('public/sass/*.scss',['compile-css']);
59+
60+
// add a watch for js linting
61+
gulp.watch(['*.js', 'public/*.js'], ['lint']);
62+
63+
});

‎module_appearance.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ entity_module_builder.registerModule(
5656

5757
}
5858

59-
}
59+
};
6060

6161
// this is the input code written by the client
6262
// it is then parsed into drawing instructions
@@ -80,5 +80,5 @@ entity_module_builder.registerModule(
8080
[] // registered channels
8181
);
8282

83-
}
83+
};
8484

‎module_article.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ entity_module_builder.registerModule(
88
function(module) {
99

1010
// overriding respond function
11-
module.respondToMessage = function(message, data) {}
11+
module.respondToMessage = function(message, data) {};
1212

1313
},
1414

1515
[] // registered channels
1616
);
1717

18-
}
18+
};

‎module_client.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = function(entity_module_builder) {
55
entity_module_builder.registerModule(
66

77
"client",
8-
"this module handles client interaction in the scene",
8+
"this module handles client interaction in the scene and sends environment update through the client socket",
99

1010
function(module) {
1111

@@ -33,14 +33,14 @@ entity_module_builder.registerModule(
3333
blocks: blocks
3434
});
3535

36-
console.log('i just sent '+blocks.length+' blocks (nearby = '+nearby_entities.length+')');
36+
//console.log('i just sent '+blocks.length+' blocks (nearby = '+nearby_entities.length+')');
3737

3838
break;
3939

4040

4141
}
4242

43-
}
43+
};
4444

4545
module.socket = null; // this must be set manually!
4646

@@ -49,4 +49,4 @@ entity_module_builder.registerModule(
4949
[] // registered channels
5050
);
5151

52-
}
52+
};

‎modules_list.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ module.exports = function(entity_module_builder) {
88
require('./module_article')(entity_module_builder);
99
require('./module_client')(entity_module_builder);
1010

11-
}
11+
};

‎package.json

+10
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,15 @@
88
"body-parser": "^1.14.1",
99
"express": "^4.13.3",
1010
"socket.io": "^1.3.7"
11+
},
12+
"devDependencies": {
13+
"browser-sync": "^2.10.0",
14+
"gulp": "^3.9.0",
15+
"gulp-cached": "^1.1.0",
16+
"gulp-jshint": "^2.0.0",
17+
"gulp-nodemon": "^2.0.4",
18+
"gulp-sass": "^2.1.0",
19+
"jshint": "^2.8.0",
20+
"jshint-stylish": "^2.1.0"
1121
}
1222
}

‎public/core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ window.onload = function() {
1212
// scene
1313
initScene();
1414

15-
}
15+
};
1616

1717
window.addEventListener("resize", function() {
1818
if(engine) {

‎public/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<link href="style.css" rel="stylesheet" type="text/css">
99
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
1010

11-
<script src="babylon.2.2.js"></script>
12-
<script src="socket.io.js"></script>
11+
<script src="lib/babylon.2.2.js"></script>
12+
<script src="lib/socket.io.js"></script>
1313
<script src="core.js"></script>
1414
</head>
1515

‎public/lib/babylon.2.2.js

+36,989
Large diffs are not rendered by default.

‎public/lib/babylon.2.2.min.js

+37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎public/lib/socket.io.js

+6,988
Large diffs are not rendered by default.

‎public/sass/style.scss

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
html {
2+
width: 100%;
3+
height: 100%;
4+
}
5+
6+
body {
7+
font-family: 'Open Sans', Sans;
8+
font-size: 13px;
9+
background-color: black;
10+
width: 100%;
11+
height: 100%;
12+
overflow: hidden;
13+
padding: 0;
14+
margin: 0;
15+
position: absolute;
16+
}
17+
18+
#game_canvas {
19+
width: 100%;
20+
height: 100%;
21+
}
22+
23+
24+
/* OVERLAY */
25+
26+
#overlay_root {
27+
position: absolute;
28+
top: 0;
29+
left: 0;
30+
}
31+
32+
.entity_block {
33+
position: absolute;
34+
transition: opacity 0.4s ease-in-out;
35+
/*transition: left 0.4s linear;*/
36+
/*transition: top 0.4s linear;*/
37+
transition: transform .2s ease-in-out;
38+
}
39+
40+
41+
/* ENTITY PANEL */
42+
43+
#entity_panel {
44+
position: absolute;
45+
width: 25%;
46+
height: auto;
47+
left: 10%;
48+
bottom: 10%;
49+
display: none;
50+
/*background-color: green;*/
51+
}
52+
53+
.module_block {
54+
border: 3px solid rgba(255, 255, 255, 0.23);
55+
border-radius: 8px;
56+
background-color: rgba(0, 0, 0, 0.3);
57+
color: white;
58+
padding: 8px;
59+
margin: 8px;
60+
61+
62+
p {
63+
margin-bottom: 0px
64+
}
65+
66+
.codeblock {
67+
background-color: rgba(0, 0, 0, 0.36);
68+
border-radius: 4px;
69+
padding: 4px 6px 4px 4px;
70+
box-shadow: inset 0px 2px 4px rgba(0, 0, 0, 0.27);
71+
color: #74D1FF;
72+
margin-bottom: 0px;
73+
counter-reset: line_number;
74+
resize: none;
75+
76+
code:before {
77+
counter-increment: line_number;
78+
content: counter(line_number) "0";
79+
font-size: 0.8em;
80+
padding-right: 5px;
81+
color: rgba(255, 255, 255, 0.23);
82+
text-align: right;
83+
width: 1.7em;
84+
display: inline-block;
85+
}
86+
87+
}
88+
89+
h1 {
90+
color: white;
91+
margin: 2px;
92+
font-size: 1.3em;
93+
}
94+
95+
}
96+
97+
98+
/* MODULE SPECIFICS */
99+
100+
.entity_block.article {
101+
background-color: red;
102+
border-radius: 14px;
103+
color: white;
104+
font-size: 1.1em;
105+
padding: 8px;
106+
width: 18em;
107+
}

‎public/style.css

+65-87
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,82 @@
11
html {
2-
width: 100%;
3-
height: 100%;
4-
}
2+
width: 100%;
3+
height: 100%; }
54

65
body {
7-
font-family: 'Open Sans', Sans;
8-
font-size: 13px;
9-
background-color: black;
10-
width: 100%;
11-
height: 100%;
12-
overflow: hidden;
13-
padding: 0;
14-
margin: 0;
15-
position: absolute;
16-
}
6+
font-family: 'Open Sans', Sans;
7+
font-size: 13px;
8+
background-color: black;
9+
width: 100%;
10+
height: 100%;
11+
overflow: hidden;
12+
padding: 0;
13+
margin: 0;
14+
position: absolute; }
1715

1816
#game_canvas {
19-
width: 100%;
20-
height: 100%;
21-
}
22-
17+
width: 100%;
18+
height: 100%; }
2319

2420
/* OVERLAY */
25-
2621
#overlay_root {
27-
position: absolute;
28-
top: 0;
29-
left: 0;
30-
}
31-
32-
.entity_block {
33-
position: absolute;
34-
transition: opacity 0.4s ease-in-out;
35-
/*transition: left 0.4s linear;*/
36-
/*transition: top 0.4s linear;*/
37-
transition: transform .2s ease-in-out;
38-
}
22+
position: absolute;
23+
top: 0;
24+
left: 0; }
3925

26+
.entity_block {
27+
position: absolute;
28+
transition: opacity 0.4s ease-in-out;
29+
/*transition: left 0.4s linear;*/
30+
/*transition: top 0.4s linear;*/
31+
transition: transform .2s ease-in-out; }
4032

4133
/* ENTITY PANEL */
42-
4334
#entity_panel {
44-
position: absolute;
45-
width: 25%;
46-
height: auto;
47-
left: 10%;
48-
bottom: 10%;
49-
display: none;
50-
/*background-color: green;*/
51-
}
35+
position: absolute;
36+
width: 25%;
37+
height: auto;
38+
left: 10%;
39+
bottom: 10%;
40+
display: none;
41+
/*background-color: green;*/ }
5242

5343
.module_block {
54-
border: 3px solid rgba(255, 255, 255, 0.23);
55-
border-radius: 8px;
56-
background-color: rgba(0, 0, 0, 0.3);
57-
color: white;
58-
padding: 8px;
59-
margin: 8px;
60-
}
61-
62-
.module_block p {
63-
margin-bottom: 0px
64-
}
65-
66-
.module_block .codeblock {
67-
background-color: rgba(0, 0, 0, 0.36);
68-
border-radius: 4px;
69-
padding: 4px 6px 4px 4px;
70-
box-shadow: inset 0px 2px 4px rgba(0, 0, 0, 0.27);
71-
color: #74D1FF;
72-
margin-bottom: 0px;
73-
counter-reset: line_number;
74-
resize: none;
75-
}
76-
77-
.module_block .codeblock > code:before {
78-
counter-increment: line_number;
79-
content: counter(line_number) "0";
80-
font-size: 0.8em;
81-
padding-right: 5px;
82-
color: rgba(255, 255, 255, 0.23);
83-
text-align: right;
84-
width: 1.7em;
85-
display: inline-block;
86-
}
87-
88-
.module_block h1 {
89-
color: white;
90-
margin: 2px;
91-
font-size: 1.3em;
92-
}
93-
44+
border: 3px solid rgba(255, 255, 255, 0.23);
45+
border-radius: 8px;
46+
background-color: rgba(0, 0, 0, 0.3);
47+
color: white;
48+
padding: 8px;
49+
margin: 8px; }
50+
.module_block p {
51+
margin-bottom: 0px; }
52+
.module_block .codeblock {
53+
background-color: rgba(0, 0, 0, 0.36);
54+
border-radius: 4px;
55+
padding: 4px 6px 4px 4px;
56+
box-shadow: inset 0px 2px 4px rgba(0, 0, 0, 0.27);
57+
color: #74D1FF;
58+
margin-bottom: 0px;
59+
counter-reset: line_number;
60+
resize: none; }
61+
.module_block .codeblock code:before {
62+
counter-increment: line_number;
63+
content: counter(line_number) "0";
64+
font-size: 0.8em;
65+
padding-right: 5px;
66+
color: rgba(255, 255, 255, 0.23);
67+
text-align: right;
68+
width: 1.7em;
69+
display: inline-block; }
70+
.module_block h1 {
71+
color: white;
72+
margin: 2px;
73+
font-size: 1.3em; }
9474

9575
/* MODULE SPECIFICS */
96-
9776
.entity_block.article {
98-
background-color: red;
99-
border-radius: 14px;
100-
color: white;
101-
font-size: 1.1em;
102-
padding: 8px;
103-
width: 18em;
104-
}
77+
background-color: red;
78+
border-radius: 14px;
79+
color: white;
80+
font-size: 1.1em;
81+
padding: 8px;
82+
width: 18em; }

‎server.js

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ io.on('connection', function(socket) {
6060
});
6161

6262

63-
6463
// SERVER LAUNCH
6564

6665
var server = http.listen(8080, function () {

0 commit comments

Comments
 (0)
Please sign in to comment.