-
Notifications
You must be signed in to change notification settings - Fork 10
/
openfantasy.js
126 lines (100 loc) · 3.36 KB
/
openfantasy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"use strict";
var fs = require('fs'),
async = require('async'),
path = require('path'),
nconf = require('nconf'),
winston = require('winston'),
data = require('./data/data'),
meta = module.parent.require('./meta'),
plugins = module.parent.require('./plugins'),
templates = module.parent.require('templates.js'),
translator = module.parent.require('../public/src/modules/translator');
var OF = {
templates: {},
data: data
};
var constants = Object.freeze({
"image_path": nconf.get('url') + "/plugins/nodebb-plugin-openfantasy/static/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, data.shops_items_type, data.shops_items_quality);
require('./lib/monsters').init(data.battle_monsters);
require('./lib/races').init(data.races);
require('./lib/skills').init(data.skills);
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 {
if (typeof data[d] === 'string') {
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(params, callback) {
var router = params.router,
middleware = params.middleware,
controllers = params.controllers;
plugins.isActive('nodebb-plugin-cash', function(err, isActive) {
if (!isActive) {
return winston.error('[openfantasy] Cash MOD not installed, OpenFantasy has been deactivated');
}
templates.setGlobal('l_points', meta.config['cash:currency_name'] ? meta.config['cash:currency_name'] : 'points');
initialize(router, middleware, controllers);
callback();
});
router.get('/admin/openfantasy/home', middleware.admin.buildHeader, renderAdmin);
router.get('/api/admin/openfantasy/home', renderAdmin);
};
OF.addNavigation = function(menu, callback) {
menu.push({
"route": "/rpg/character",
"title": "RPG",
"enabled": true,
"iconClass": "fa-compass",
"text": "\\[\\[openfantasy:rpg\\]\\]",
"properties": {
"loggedIn": true
}
});
callback (null, menu);
};
OF.addAdminNavigation = function(header, callback) {
header.plugins.push({
route: '/openfantasy/home',
icon: 'fa-compass',
name: 'OpenFantasy'
});
callback(null, header);
};
function renderAdmin(req, res, next) {
res.render('admin/openfantasy/home', {});
}
module.exports = OF;