Skip to content

Commit 7965444

Browse files
committed
add --no-ask-name
1 parent c7a3db1 commit 7965444

6 files changed

Lines changed: 87 additions & 23 deletions

File tree

docs/api-versions.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,5 +244,10 @@ the correct version
244244
you'd like other files to have info inserted you can add a
245245
`happyFunTimes.templateUrls` field to your `package.json`
246246

247+
* --no-ask-name
248+
249+
For installations where you don't need to display the user's name
250+
you can add --no-ask-name when you start the system and players
251+
will not be asked enter their name.
247252

248253

public/enter-name.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<div class="center"><div class="button-like" id="okay">Okay</div></div>
5555
</div>
5656
</body>
57-
<script data-main="scripts/enter-name.js" src="3rdparty/require.js"></script>
57+
<script data-main="%(enterNameScript)s" src="3rdparty/require.js"></script>
5858
<script>
5959
requirejs.config({
6060
paths: {

public/scripts/enter-name.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,18 @@
3131

3232
"use strict";
3333

34-
var main = function(Cookie, Misc, MobileHacks) {
34+
35+
// Start the main app logic.
36+
requirejs(
37+
[ 'hft/misc/cookies',
38+
'hft/misc/misc',
39+
'hft/misc/mobilehacks',
40+
'hft/io',
41+
], function(
42+
Cookie,
43+
Misc,
44+
MobileHacks,
45+
IO) {
3546

3647
var $ = function(id) {
3748
return document.getElementById(id);
@@ -98,17 +109,6 @@ var main = function(Cookie, Misc, MobileHacks) {
98109
}
99110

100111

101-
};
102-
103-
// Start the main app logic.
104-
requirejs(
105-
[ 'hft/misc/cookies',
106-
'hft/misc/misc',
107-
'hft/misc/mobilehacks',
108-
'hft/io',
109-
],
110-
main
111-
);
112-
112+
});
113113

114114

public/scripts/go-to-index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2014, Gregg Tavares.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* * Redistributions in binary form must reproduce the above
12+
* copyright notice, this list of conditions and the following disclaimer
13+
* in the documentation and/or other materials provided with the
14+
* distribution.
15+
* * Neither the name of Gregg Tavares. nor the names of its
16+
* contributors may be used to endorse or promote products derived from
17+
* this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
32+
window.location.href = "/";
33+
34+

server/common-cli-options.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ exports.options = [
3838
{ option: 'app-mode', type: 'Boolean', description: 'run as an app'},
3939
{ option: 'show', type: 'String', description: 'html file to launch, default "games"'},
4040
{ option: 'system-name', type: 'String', description: 'name used if multiple happyFunTimes servers are running on the same network. Default = computer name'},
41+
{ option: 'ask-name', type: 'Boolean', description: 'ask for name on start, use --no-ask-name to set to false', default: "true"},
4142
];
4243

server/hft-server.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,21 @@ var HFTServer = function(options, startedCallback) {
323323
sendRequestedFile(req, res);
324324
};
325325

326-
var sendRequestedFileFullPath = function(req, res, fullPath, runtimeInfo) {
326+
// Send Templated File
327+
var sendTemplatedFile = function(req, res) {
328+
sendRequestedFile(req, res, {
329+
params: {
330+
"enterNameScript": (options.askName ? "scripts/enter-name.js" : "scripts/go-to-index.js"),
331+
},
332+
});
333+
};
334+
335+
// Blargs! What a mess. This needs to be cleaned up
336+
var sendRequestedFileFullPath = function(req, res, fullPath, runtimeInfo, options) {
337+
var options = options || {};
327338
var parsedUrl = url.parse(req.url);
328339
var filePath = parsedUrl.pathname;
329-
var isTemplate = runtimeInfo && runtimeInfo.templateUrls[filePath];
340+
var isTemplate = (runtimeInfo && runtimeInfo.templateUrls[filePath]) || options.params;
330341
var isQuery = parsedUrl.query !== null;
331342
var isAnchor = parsedUrl.hash !== null;
332343
if (runtimeInfo && runtimeInfo.features.es6 && es6Support.isES6(fullPath)) {
@@ -348,19 +359,32 @@ var HFTServer = function(options, startedCallback) {
348359
fullPath += "index.html";
349360
}
350361
}
351-
var prepFn = isTemplate ? function(str) {
352-
return strings.replaceParams(str, [{
362+
var prepFn = isTemplate ? (function() {
363+
var params = [{
353364
localhost: g.address,
354-
}, runtimeInfo]);
355-
} : undefined;
365+
}];
366+
if (runtimeInfo) {
367+
params.push([runtimeInfo]);
368+
}
369+
if (options.params) {
370+
if (options.params.length) {
371+
params = params.concat(options.params);
372+
} else {
373+
params.push(options.params);
374+
}
375+
};
376+
return function(str) {
377+
return strings.replaceParams(str, params);
378+
}
379+
}()) : undefined;
356380
sendFileResponse(req, res, fullPath, prepFn, runtimeInfo);
357381
};
358382

359-
var sendRequestedFile = function(req, res) {
383+
var sendRequestedFile = function(req, res, options) {
360384
var parsedUrl = url.parse(req.url);
361385
var filePath = parsedUrl.pathname;
362386
var fullPath = path.normalize(path.join(g.cwd, g.baseDir, filePath));
363-
sendRequestedFileFullPath(req, res, fullPath);
387+
sendRequestedFileFullPath(req, res, fullPath, undefined, options);
364388
};
365389

366390
var send404 = function(res, msg) {
@@ -433,7 +457,7 @@ var HFTServer = function(options, startedCallback) {
433457
sendRequestedFileFullPath(req, res, nonPath);
434458
});
435459
app.get(/^\/games\/(.*?)\//, sendGameRequestedFile);
436-
460+
app.get(/^\/enter-name.html/, sendTemplatedFile);
437461
app.get(/.*/, sendSystemRequestedFile);
438462
app.post(/.*/, handlePOST);
439463
app.options(/.*/, handleOPTIONS);

0 commit comments

Comments
 (0)