<commit_before>"use strict";

var	fs = require('fs'),
	async = require('async'),
	path = require('path'),
	nconf = require('nconf'),
	data = require('./data/data.js'),
	templates = module.parent.require('../public/src/templates.js'),
	translator = module.parent.require('../public/src/translator.js');




var OF = {
	templates: {},
	data: data
};

var constants = Object.freeze({
	"image_path": nconf.get('url') + "/plugins/nodebb-plugin-openfantasy/images/"
});

OF.init = function(app, middleware, controllers) {
	//todo: check here if cash mod is activated.
	require('./lib/nodebb');
	
	require('./lib/middleware')(app, middleware);
	require('./lib/controllers')(controllers);
	require('./lib/routes/main')(app, middleware, controllers);

	require('./lib/alignments').init(data.alignments);
	require('./lib/classes').init(data.classes);
	require('./lib/config').init(data.config);
	require('./lib/elements').init(data.elements);
	require('./lib/items').init(data.shops_items);
	require('./lib/monsters').init(data.monsters);
	require('./lib/races').init(data.races);
	require('./lib/stores').init(data.stores);

	function setupTranslations() {
		// todo: need to add all translations in directory
		var lang = 'en_GB';
		translator.addTranslation(lang, 'of', require('./static/language/' + lang + '/openfantasy.json'));

		app.get('/language/' + lang + '/of.json', function(req, res, next) {
			res.send(200, require('./static/language/' + lang + '/openfantasy.json'));
		});
	}

	function normalizeImagePaths(data) {
		for (var d in data) {
			if (data.hasOwnProperty(d)) {
				if (data[d].constructor === Array || data[d] instanceof Object) {
					data[d] = normalizeImagePaths(data[d]);
				} else {
					var extension = data[d].substr(data[d].length - 4).toLowerCase();
					if (extension === '.png' || extension === '.jpg' || extension === '.jpeg' || extension === '.gif') {
						data[d] = constants.image_path + data[d];
					}
				}
			}
		}

		return data;
	}
	
	setupTranslations();
	OF.data = normalizeImagePaths(OF.data);
};

OF.addNavigation = function(custom_header, callback) {
	custom_header.navigation.push({
			"class": "",
			"route": "/rpg/character",
			"text": "RPG"
		});

	callback(null, custom_header);
};

OF.addRoute = function(custom_routes, callback) {
	var templatesToLoad = ["shops.tpl", "temple.tpl", "character.tpl", "header.tpl", "footer.tpl", "battle.tpl", "equipment.tpl", "inventory.tpl", "skills.tpl", "courthouse.tpl", "vault.tpl", "stock.tpl", "forge.tpl", "mining.tpl", "enchant.tpl", "warehouse.tpl", "training.tpl"];

	function loadTemplate(template, next) {
		fs.readFile(path.resolve(__dirname, './static/templates/' + template), function (err, data) {
			OF.templates[template] = data.toString();
			next(err);
		});
	}

	function buildHeader(data) {
		data.content = OF.templates["header.tpl"] + data.content + OF.templates["footer.tpl"];
		return data;
	}<commit_msg>added check for cash mod<commit_after>"use strict";

var	fs = require('fs'),
	async = require('async'),
	path = require('path'),
	nconf = require('nconf'),
	winston = require('winston'),
	data = require('./data/data'),
	plugins = module.parent.require('./plugins'),
	templates = module.parent.require('../public/src/templates'),
	translator = module.parent.require('../public/src/translator');




var OF = {
	templates: {},
	data: data
};

var constants = Object.freeze({
	"image_path": nconf.get('url') + "/plugins/nodebb-plugin-openfantasy/images/"
});

function initialize(app, middleware, controllers) {
	require('./lib/nodebb');
	
	require('./lib/middleware')(app, middleware);
	require('./lib/controllers')(controllers);
	require('./lib/routes/main')(app, middleware, controllers);

	setupTranslations(app);
	data = normalizeImagePaths(data);

	require('./lib/alignments').init(data.alignments);
	require('./lib/classes').init(data.classes);
	require('./lib/config').init(data.config);
	require('./lib/elements').init(data.elements);
	require('./lib/items').init(data.shops_items);
	require('./lib/monsters').init(data.monsters);
	require('./lib/races').init(data.races);
	require('./lib/stores').init(data.stores);
}

function setupTranslations(app) {
	// todo: need to add all translations in directory
	var lang = 'en_GB';
	translator.addTranslation(lang, 'of', require('./static/language/' + lang + '/openfantasy.json'));

	app.get('/language/' + lang + '/of.json', function(req, res, next) {
		res.send(200, require('./static/language/' + lang + '/openfantasy.json'));
	});
}

function normalizeImagePaths(data) {
	for (var d in data) {
		if (data.hasOwnProperty(d)) {
			if (data[d].constructor === Array || data[d] instanceof Object) {
				data[d] = normalizeImagePaths(data[d]);
			} else {
				var extension = data[d].substr(data[d].length - 4).toLowerCase();
				if (extension === '.png' || extension === '.jpg' || extension === '.jpeg' || extension === '.gif') {
					data[d] = constants.image_path + data[d];
				}
			}
		}
	}

	return data;
}

OF.init = function(app, middleware, controllers) {
	plugins.isActive('nodebb-plugin-cash', function(err, isActive) {
		if (!isActive) {
			return winston.error('[openfantasy] Cash MOD not installed, OpenFantasy has been deactivated');
		}

		initialize(app, middleware, controllers);
	});
};

OF.addNavigation = function(custom_header, callback) {
	custom_header.navigation.push({
			"class": "",
			"route": "/rpg/character",
			"text": "RPG"
		});

	callback(null, custom_header);
};

OF.addRoute = function(custom_routes, callback) {
	var templatesToLoad = ["shops.tpl", "temple.tpl", "character.tpl", "header.tpl", "footer.tpl", "battle.tpl", "equipment.tpl", "inventory.tpl", "skills.tpl", "courthouse.tpl", "vault.tpl", "stock.tpl", "forge.tpl", "mining.tpl", "enchant.tpl", "warehouse.tpl", "training.tpl"];

	function loadTemplate(template, next) {
		fs.readFile(path.resolve(__dirname, './static/templates/' + template), function (err, data) {
			OF.templates[template] = data.toString();
			next(err);
		});
	}

	function buildHeader(data) {
		data.content = OF.templates["header.tpl"] + data.content + OF.templates["footer.tpl"];
		return data;
	}
{'fraction_non_alphanumeric': 0.204526950008142, 'fraction_numerical': 0.0013027194268034523, 'mean_word_length': 4.488829311885612, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5472867', 'n_tokens_mistral': 2175, 'n_tokens_neox': 2052, 'n_words': 372}