Skip to content

Commit

Permalink
I believe this takes care of #962 booting problem
Browse files Browse the repository at this point in the history
  • Loading branch information
ktiedt committed Mar 21, 2018
1 parent 742a2f8 commit f73643b
Show file tree
Hide file tree
Showing 10 changed files with 397 additions and 805 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Expand Up @@ -34,7 +34,7 @@ module.exports = {
'for-direction': 'error',
'func-name-matching': 'error',
'func-names': ['error', 'never'],
'func-style': 'error',
'func-style': ['error', 'declaration'],
'function-paren-newline': 'off',
'getter-return': 'error',
'global-require': 'error',
Expand Down Expand Up @@ -140,7 +140,7 @@ module.exports = {
'no-unmodified-loop-condition': 'error',
'no-unneeded-ternary': 'off',
'no-unused-expressions': 'error',
'no-use-before-define': 'error',
'no-use-before-define': ['error', { functions: false, classes: true }],
'no-useless-call': 'error',
'no-useless-computed-key': 'error',
'no-useless-concat': 'error',
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc.json
Expand Up @@ -6,7 +6,7 @@
"no-undef": "error"
},
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": 2017,
"sourceType": "module"
},
"env": {
Expand Down
310 changes: 155 additions & 155 deletions LICENSE.md

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -7,13 +7,15 @@
[![Code Triagers Badge](https://www.codetriage.com/freezingmoon/ancientbeast/badges/users.svg)](https://www.codetriage.com/freezingmoon/ancientbeast)

![1vs1 Dark Forest](https://raw.github.com/FreezingMoon/AncientBeast-Website/master/media/screenshots/v0.3%20Dark%20Forest.jpg)
**"We all die. The goal isn't to live forever. The goal is to create something that will."** *Chuck Palahniuk*
**"We all die. The goal isn't to live forever. The goal is to create something that will."** _Chuck Palahniuk_

### Intro

<p>
<b>Ancient Beast</b> is a turn based strategy indie game project, played online against other people, featuring a wide variety of creatures to acquire and items to equip onto, putting them to use in order to defeat your opponents.<br>This project was carefully designed to be easy to learn, fun to play and hard to master. We hope you'll enjoy it!

### Tools

<p>
The project is developed with the use of free open source cross platform applications and freeware services.
<a href="https://mega.co.nz/#F!GAJAjAzL!AhBUayQndZbH_j2IL2B-nA"><b>Mega</b></a> comes in very handy when working on the game assets collaboratively, while <a href="https://github.com/FreezingMoon/AncientBeast"><b>Github</b></a> handles the code part and stores the final assets. Art contributions can be made as well in our <a href="http://Ancient-Beast.deviantart.com"><b>deviantArt</b></a> group. Drop by our <a href="https://discord.gg/x78rKen"><b>Discord chat</b></a> and be a part of the community!<br>
Expand All @@ -35,6 +37,7 @@ The project is developed with the use of free open source cross platform applica
</table>

### License

<table border=1 width=100%>
<tr>
<td><a href="http://www.FreezingMoon.org"><img src="https://raw.github.com/FreezingMoon/AncientBeast-Website/master/images/FreezingMoon.png" alt="Freezing Moon"></a></td>
Expand All @@ -51,6 +54,7 @@ The project is developed with the use of free open source cross platform applica
</table>

### [Contribute](docs/CONTRIBUTING.md#readme)

<p>
You can help out the project by just ★ starring this repository from the <a href="#">upper right corner</a> and also by pinning it to your profile.<br>
If you wish to set-up a local copy of the game in order to patch it, go read the "<a href="https://github.com/FreezingMoon/AncientBeast/blob/master/docs/CONTRIBUTING.md#readme">CONTRIBUTING.md</a>" file from this repository.<br>
Expand Down
27 changes: 11 additions & 16 deletions app.json
@@ -1,18 +1,13 @@
{
"name": "AncientBeast",
"description": ":wolf: Turn Based Strategy Game. Master your beasts!",
"scripts": {
},
"env": {
},
"formation": {
},
"addons": [

],
"buildpacks": [
{
"url": "heroku/nodejs"
}
]
"name": "AncientBeast",
"description": ":wolf: Turn Based Strategy Game. Master your beasts!",
"scripts": {},
"env": {},
"formation": {},
"addons": [],
"buildpacks": [
{
"url": "heroku/nodejs"
}
]
}
159 changes: 81 additions & 78 deletions manifestGenerator.js
@@ -1,45 +1,46 @@
// automaticly generates the manifest that contains all the assets
const { promisify } = require("util");
const fs = require("fs");
const path = require("path");
const { promisify } = require('util');
const fs = require('fs');
const path = require('path');
const stat = promisify(fs.stat);
const readDir = promisify(fs.readdir);
const prettier = require("prettier");
const prettier = require('prettier');

/**
* Read the directory
*
* @param {string} dirPath the path of the directory
* Generate entity
* @param {String} filePath The path to the file to convert to an entity.
* @return {Object} A file entity.
*/
async function readDirectory(dirPath) {
const result = [];
for (const child of await readDir(dirPath)) {
const childPath = path.join(dirPath, child);
const stats = await stat(childPath);
if (stats.isDirectory()) {
result.push({
name: child,
children: await readDirectory(childPath),
});
} else {
result.push(fileToEntity(childPath));
}
}
return result;
function fileToEntity(filePath) {
const extension = path.extname(filePath);
const name = path.basename(filePath, extension);
return {
name,
url: path.relative(path.join(__dirname, 'assets'), filePath)
};
}


/**
* Generate entity
* @param {String} filePath
* Read the directory
*
* @param {string} dirPath the path of the directory
* @return {Array} An array of asset objects.
*/
function fileToEntity(filePath) {
const extension = path.extname(filePath);
const name = path.basename(filePath, extension);
return {
name,
url: path.relative(path.join(__dirname, 'assets'), filePath)
}
async function readDirectory(dirPath) {
const result = [];
for (const child of await readDir(dirPath)) {
const childPath = path.join(dirPath, child);
const stats = await stat(childPath); // eslint-disable-line no-await-in-loop
if (stats.isDirectory()) {
result.push({
name: child,
children: await readDirectory(childPath) // eslint-disable-line no-await-in-loop
});
} else {
result.push(fileToEntity(childPath));
}
}
return result;
}

/**
Expand All @@ -48,65 +49,67 @@ function fileToEntity(filePath) {
* @returns {boolean} Wether the entity is a dir
*/
function entityIsDir(entity) {
return entity.children !== undefined;
return entity.children !== undefined;
}

/**
* Write an entity to a string
* @param {Object} entity
* Convert an entity object to a string.
* @param {Object} entity The entity object to convert.
* @return {string} The entity object as a string.
*/
const entityToString = (entity) => {
let string = "";
if (entityIsDir(entity)) {
string += dirToString(entity);
}
else {
string += fileToString(entity)
};

string += ",";
return string;
function entityToString(entity) {
return (entityIsDir(entity) ? dirToString(entity) : fileToString(entity)) + ',';
}

/**
* Convert a dir entity to a string
* @param {Object} dirEntity Entity to write to string
* Convert a tree of entities to a string
* @param {Object} tree A tree of entities.
* @param {boolean} root Is this the root of a tree?
* @returns {string} The tree converted to a string.
*/
const dirToString = (dirEntity) => `{id: "${dirEntity.name}", children:[${dirEntity.children.map(child => writeToString(child)).reduce((prev, curr) => prev + curr)}] }`;
function writeToString(tree, root = false) {
let string = root ? '[' : '';

if (Array.isArray(tree)) {
string += tree.map(entityToString).reduce((prev, curr) => prev + curr);
} else {
string += entityToString(tree);
}

if (root) {
string += ']';
}

return string;
}

/**
* Convert an file entity to a string
* @param {Object} fileEntity Entity to write to string
* Convert a dir entity to a string.
* @param {Object} dirEntity Entity object to conver to a string.
* @return {string} The dir entity as a string.
*/
const fileToString = (fileEntity) => `{id: "${fileEntity.name}", url: require("assets/${fileEntity.url}") }`;
function dirToString(dirEntity) {
return `{id: "${dirEntity.name}", children:[${dirEntity.children
.map(child => writeToString(child))
.reduce((prev, curr) => prev + curr)}] }`;
}

/**
* Convert a tree of entities to a string
* @param {Object} tr
entry: path.resolve(__dirname, 'src', 'script.js'),ee Tree of entitites
* @returns {String}
* Convert an file entity to a string.
* @param {Object} fileEntity Entity to write to string.
* @return {string} The file entity as a string.
*/
function writeToString(tree, root = false) {
let string = "";
if (root) string += "[";
if (Array.isArray(tree)) {
string += tree
.map(entityToString)
.reduce((prev, curr) => prev + curr);
} else {
string += entityToString(tree);
}
if (root) string += "]";
return string;
function fileToString(fileEntity) {
return `{id: "${fileEntity.name}", url: require("assets/${fileEntity.url}") }`;
}

readDirectory(path.join(__dirname, "assets"))
// Generate the javascript
.then(result => `export default ${writeToString(result, true)}`)
// Add path fix for windows
.then(result => result.replace(/\\/g,'\\\\'))
// Format the javascript so it"s readable
.then(prettier.format)
// We only need to write one file so it doesnt matter that it"s sync
.then(result => fs.writeFileSync(path.resolve(__dirname, "src", "manifest.js"), result))
.catch(console.error);
readDirectory(path.join(__dirname, 'assets'))
// Generate the javascript
.then(result => `export default ${writeToString(result, true)}`)
// Add path fix for windows
.then(result => result.replace(/\\/g, '\\\\'))
// Format the javascript so it"s readable
.then(prettier.format)
// We only need to write one file so it doesnt matter that it"s sync
.then(result => fs.writeFileSync(path.resolve(__dirname, 'src', 'manifest.js'), result)) // eslint-disable-line no-sync
.catch(console.error);
12 changes: 6 additions & 6 deletions package.json
Expand Up @@ -16,32 +16,32 @@
"keywords": ["game", "strategy", "phaser"],
"dependencies": {
"compression": "^1.7.2",
"css-loader": "^0.28.11",
"expose-loader": "^0.7.5",
"express": "^4.16.3",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.0.7",
"jquery": "3.3.1",
"jquery-mousewheel": "3.1.13",
"jquery-ui": "^1.12.1",
"jquery.kinetic": "2.2.4",
"jquery.transit": "0.9.12",
"less": "^3.0.1",
"less-loader": "^4.1.0",
"phaser-ce": "2.10.2",
"socket.io": "^2.0.4",
"socket.io-client": "2.0.4",
"style-loader": "^0.20.3",
"webpack-cli": "^2.0.12"
},
"devDependencies": {
"css-loader": "^0.28.11",
"eslint": "^4.19.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-prettier": "^2.6.0",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.0.6",
"husky": "^0.14.3",
"less": "^3.0.1",
"less-loader": "^4.1.0",
"lint-staged": "^7.0.0",
"prettier": "^1.11.1",
"prettier-eslint-cli": "^4.7.1",
"style-loader": "^0.20.3",
"uglifyjs-webpack-plugin": "^1.2.4",
"webpack": "^4.1.1",
"webpack-dev-middleware": "^3.0.1",
Expand Down
27 changes: 23 additions & 4 deletions server.js
Expand Up @@ -2,7 +2,6 @@
const compression = require('compression');
const express = require('express');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const app = express();
const config = require('./webpack.config.js');
const compiler = webpack(config);
Expand All @@ -13,20 +12,40 @@ const ip = process.env.IP || '127.0.0.1';
// const gameManager = require('./server/gamemanager.js');
const qManager = require('./server/queuemanager.js');

/**
* Require a module if it's available, returns the module if so, otherwise, false.
* @param {string} path Path to the module.
* @return {Object|boolean} Return either the module or false.
*/
function requireIfAvailable(path) {
try {
require.resolve(path);
return require(path); // eslint-disable-line global-require
} catch (e) {
return false;
}
}

const webpackDevMiddleware = requireIfAvailable('webpack-dev-middleware');

// Enable gzip compression.
app.use(compression());

// Tell express to use the webpack-dev-middleware and use the webpack.config.js
// configuration file as a base, but only if we are not in a production environment.
if (process.env.NODE_ENV !== 'production') {
if (process.env.NODE_ENV !== 'production' && webpackDevMiddleware) {
app.use(
webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath
})
);
}

let makeId = function() {
/**
* Generate a random id for each player that connects to the game.
* @return {string} The id.
*/
function makeId() {
let text = '';
let possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

Expand All @@ -35,7 +54,7 @@ let makeId = function() {
}

return text;
};
}

// Setup the game queue and connection details
io.on('connection', function(session) {
Expand Down

0 comments on commit f73643b

Please sign in to comment.