notherbase-fs 1.2.15 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/controllers/explorer.js +93 -130
- package/controllers/game.js +2 -1
- package/controllers/inventory.js +9 -5
- package/controllers/the-front.js +73 -91
- package/models/index.js +2 -1
- package/models/poi.js +18 -0
- package/notherbase-fs.js +87 -0
- package/package.json +2 -2
- package/test/coast/tall-beach/nono-cove/local-scripts/nono.js +2 -5
- package/test/coast/tall-beach/nono-cove/server-scripts/addToTimer.js +31 -0
- package/test/coast/tall-beach/nono-cove/server-scripts/getTimer.js +31 -0
- package/test/coast/tall-beach/nono-cove/views/index.ejs +49 -5
- package/test/coast/tall-beach/nono-cove/views/nono-og.ejs +6 -0
- package/test/test-index.js +2 -65
- package/test/views/check.ejs +7 -0
- package/test/views/index.ejs +4 -0
- package/views/explorer.ejs +0 -29
- package/views/inventory.ejs +22 -7
- package/index.js +0 -22
- package/server.js +0 -83
package/controllers/explorer.js
CHANGED
|
@@ -1,150 +1,113 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
for (let k = 0; k < area.pois.length; k++) {
|
|
21
|
-
let poi = area.pois[k];
|
|
22
|
-
currentPoi = poi.name;
|
|
23
|
-
|
|
24
|
-
for (let l = 0; l < poi.details.length; l++) {
|
|
25
|
-
let detail = poi.details[l];
|
|
26
|
-
|
|
27
|
-
let currentDir = `${dir}/${currentRegion}/${currentArea}/${currentPoi}`;
|
|
28
|
-
let currentRoute = `/${currentRegion}/${currentArea}/${currentPoi}/${detail.name}`;
|
|
29
|
-
|
|
30
|
-
detail.options = {
|
|
31
|
-
styles: [],
|
|
32
|
-
externalStyles: [],
|
|
33
|
-
localScripts: [],
|
|
34
|
-
serverScripts: [],
|
|
35
|
-
requiredItems: [],
|
|
36
|
-
needsKey: "",
|
|
37
|
-
dropOff: "",
|
|
38
|
-
...detail.options
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
detail.options.styles = detail.options.styles.map(style => {
|
|
42
|
-
style = `${currentDir}/styles/${style}`;
|
|
43
|
-
return style;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
detail.options.externalStyles = detail.options.externalStyles.map(style => {
|
|
47
|
-
style = `${currentDir}/${style}`;
|
|
48
|
-
return style;
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
detail.options.localScripts = detail.options.localScripts.map(script => {
|
|
52
|
-
script = `${currentDir}/local-scripts/${script}`;
|
|
53
|
-
return script;
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
detail.options.serverScripts = detail.options.serverScripts.map(script => {
|
|
57
|
-
script = require(`${currentDir}/server-scripts/${script}`);
|
|
58
|
-
return script;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
detail.options.main = "index";
|
|
62
|
-
if (detail.name !== "") detail.options.main = detail.name;
|
|
63
|
-
detail.options.main = `${currentDir}/views/${detail.options.main}`;
|
|
64
|
-
|
|
65
|
-
router.get(currentRoute, async function(req, res) {
|
|
66
|
-
try {
|
|
67
|
-
const foundUser = await user.findById(req.session.currentUser);
|
|
68
|
-
const foundInventory = await inventory.findOne({ user: req.session.currentUser }).populate("items.item");
|
|
69
|
-
|
|
70
|
-
let serverScriptReturns = [];
|
|
71
|
-
|
|
72
|
-
for (let m = 0; m < detail.options.serverScripts.length; m++) {
|
|
73
|
-
serverScriptReturns.push(await detail.options.serverScripts[m]({
|
|
74
|
-
game: game,
|
|
75
|
-
inventory: inventory,
|
|
76
|
-
item: item
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let foundItemIDs = [];
|
|
81
|
-
for (let m = 0; m < detail.options.requiredItems.length; m++) {
|
|
82
|
-
let foundItem = await item.findOne({name: detail.options.requiredItems[m]});
|
|
83
|
-
|
|
84
|
-
foundItemIDs.push(foundItem._id);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
let context = {
|
|
88
|
-
siteTitle: "NotherBase",
|
|
89
|
-
user: foundUser,
|
|
90
|
-
styles: detail.options.styles,
|
|
91
|
-
externalStyles: detail.options.externalStyles,
|
|
92
|
-
main: detail.options.main,
|
|
93
|
-
localScripts: detail.options.localScripts,
|
|
94
|
-
serverScriptReturns: serverScriptReturns,
|
|
95
|
-
itemIDs: foundItemIDs,
|
|
96
|
-
pov: req.query.pov,
|
|
97
|
-
inventory: foundInventory,
|
|
98
|
-
query: req.query,
|
|
99
|
-
dir: dir,
|
|
100
|
-
path: path
|
|
101
|
-
}
|
|
1
|
+
const explorer = async function explorer(worldPath, voidPath) {
|
|
2
|
+
const db = require("../models");
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
let router = require("express").Router();
|
|
6
|
+
|
|
7
|
+
router.post(`/:region/:area/:poi/:detail/serve/:script`, async function(req, res) {
|
|
8
|
+
try {
|
|
9
|
+
let currentAreaRoute = `${req.params.region}/${req.params.area}/${req.params.poi}`;
|
|
10
|
+
let currentRoute = `${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}`;
|
|
11
|
+
|
|
12
|
+
if (await db.poi.exists({ route: currentRoute, type: "global" }) === false) {
|
|
13
|
+
await db.poi.create({
|
|
14
|
+
route: currentRoute,
|
|
15
|
+
name: req.params.detail,
|
|
16
|
+
type: "global",
|
|
17
|
+
data: {}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
102
20
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
else res.render(`explorer`, context);
|
|
112
|
-
}
|
|
113
|
-
else res.render(`explorer`, context);
|
|
114
|
-
}
|
|
115
|
-
catch(err) {
|
|
116
|
-
console.log(err);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}
|
|
21
|
+
if (await db.poi.exists({ route: currentRoute, user: req.session.currentUser }) === false) {
|
|
22
|
+
await db.poi.create({
|
|
23
|
+
route: currentRoute,
|
|
24
|
+
name: req.params.detail,
|
|
25
|
+
type: "local",
|
|
26
|
+
user: req.session.currentUser,
|
|
27
|
+
data: {}
|
|
28
|
+
});
|
|
120
29
|
}
|
|
30
|
+
|
|
31
|
+
let scriptResult = await require(`${worldPath}/${currentAreaRoute}/server-scripts/${req.params.script}.js`)(db, currentRoute, req.session.currentUser, req.body);
|
|
32
|
+
res.send({ scriptResult: scriptResult });
|
|
121
33
|
}
|
|
122
|
-
|
|
123
|
-
|
|
34
|
+
catch(err) {
|
|
35
|
+
console.log(err);
|
|
36
|
+
res.status(500).end();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
router.get(`/:region/:area/:poi/:detail`, async function(req, res) {
|
|
41
|
+
try {
|
|
42
|
+
const foundUser = await db.user.findById(req.session.currentUser);
|
|
43
|
+
const foundInventory = await db.inventory.findOne({ user: req.session.currentUser }).populate("items.item");
|
|
44
|
+
|
|
45
|
+
let main = `${worldPath}/${req.params.region}/${req.params.area}/${req.params.poi}/views/${req.params.detail}`;
|
|
46
|
+
|
|
47
|
+
let context = {
|
|
48
|
+
siteTitle: `NotherBase - ${req.params.detail}`,
|
|
49
|
+
user: foundUser,
|
|
50
|
+
main: main,
|
|
51
|
+
pov: req.query.pov,
|
|
52
|
+
inventory: foundInventory,
|
|
53
|
+
query: req.query,
|
|
54
|
+
dir: worldPath,
|
|
55
|
+
path: path
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
await res.render(`explorer`, context);
|
|
59
|
+
}
|
|
60
|
+
catch(err) {
|
|
61
|
+
console.log(err);
|
|
62
|
+
res.status(500).end();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
router.get(`/:region/:area/:poi`, async function(req, res) {
|
|
67
|
+
try {
|
|
68
|
+
const foundUser = await db.user.findById(req.session.currentUser);
|
|
69
|
+
const foundInventory = await db.inventory.findOne({ user: req.session.currentUser }).populate("items.item");
|
|
70
|
+
|
|
71
|
+
let main = `${worldPath}/${req.params.region}/${req.params.area}/${req.params.poi}/views/index`;
|
|
72
|
+
|
|
73
|
+
let context = {
|
|
74
|
+
siteTitle: `NotherBase - ${req.params.poi}`,
|
|
75
|
+
user: foundUser,
|
|
76
|
+
main: main,
|
|
77
|
+
pov: req.query.pov,
|
|
78
|
+
inventory: foundInventory,
|
|
79
|
+
query: req.query,
|
|
80
|
+
dir: worldPath,
|
|
81
|
+
path: path
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
await res.render(`explorer`, context);
|
|
85
|
+
}
|
|
86
|
+
catch(err) {
|
|
87
|
+
console.log(err);
|
|
88
|
+
res.status(500).end();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
124
92
|
// start location
|
|
125
93
|
router.get("/", function(req, res) {
|
|
126
94
|
res.redirect("/the-front");
|
|
127
95
|
});
|
|
128
|
-
|
|
96
|
+
|
|
129
97
|
//the void
|
|
130
98
|
router.use(function(req, res, next){
|
|
131
99
|
res.render(`explorer`,
|
|
132
100
|
{
|
|
133
101
|
siteTitle: "NotherBase | The Void",
|
|
134
102
|
user: null,
|
|
135
|
-
styles: [`${dir}/${explorerBuild.void}/styles/void`],
|
|
136
|
-
externalStyles: [],
|
|
137
|
-
localScripts: [],
|
|
138
103
|
inventory: null,
|
|
139
|
-
|
|
140
|
-
main: `${dir}/${explorerBuild.void}/index`,
|
|
104
|
+
main: `${voidPath}/index`,
|
|
141
105
|
dir: dir,
|
|
142
106
|
path: path
|
|
143
107
|
});
|
|
144
108
|
});
|
|
109
|
+
|
|
110
|
+
return router;
|
|
145
111
|
}
|
|
146
112
|
|
|
147
|
-
module.exports =
|
|
148
|
-
router: router,
|
|
149
|
-
complete: complete
|
|
150
|
-
}
|
|
113
|
+
module.exports = explorer;
|
package/controllers/game.js
CHANGED
|
@@ -47,11 +47,12 @@ router.post("/", async function(req, res) {
|
|
|
47
47
|
foundGame.markModified("data");
|
|
48
48
|
await foundGame.save();
|
|
49
49
|
|
|
50
|
-
res.status(200).
|
|
50
|
+
res.status(200).end();
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
catch(err) {
|
|
54
54
|
res.status(500).end();
|
|
55
|
+
console.log(req.query);
|
|
55
56
|
console.log(err);
|
|
56
57
|
}
|
|
57
58
|
});
|
package/controllers/inventory.js
CHANGED
|
@@ -30,13 +30,15 @@ router.post("/", async function(req, res) {
|
|
|
30
30
|
if (connectionSuccess) {
|
|
31
31
|
try {
|
|
32
32
|
if (req.body.item && req.body.amount) {
|
|
33
|
-
|
|
33
|
+
let foundItem = await item.findOne({name: req.body.item});
|
|
34
|
+
|
|
35
|
+
if (foundItem) {
|
|
34
36
|
let foundInventory = await inventory.findOne({user: req.session.currentUser}).populate("items.item");
|
|
35
37
|
|
|
36
38
|
let holding = false;
|
|
37
39
|
|
|
38
40
|
for (let j = 0; j < foundInventory.items.length; j++) {
|
|
39
|
-
if (foundInventory.items[j].item.
|
|
41
|
+
if (foundInventory.items[j].item.name === req.body.item) {
|
|
40
42
|
holding = true;
|
|
41
43
|
|
|
42
44
|
if (foundInventory.items[j].amount >= -Math.floor(req.body.amount)) {
|
|
@@ -74,7 +76,7 @@ router.post("/", async function(req, res) {
|
|
|
74
76
|
if (!holding) {
|
|
75
77
|
if (req.body.amount > 0) {
|
|
76
78
|
foundInventory.items.push({
|
|
77
|
-
item:
|
|
79
|
+
item: foundItem._id,
|
|
78
80
|
amount: req.body.amount
|
|
79
81
|
});
|
|
80
82
|
|
|
@@ -94,11 +96,13 @@ router.post("/", async function(req, res) {
|
|
|
94
96
|
};
|
|
95
97
|
}
|
|
96
98
|
else {
|
|
97
|
-
|
|
99
|
+
console.log(`${req.body.item} doesn't exist!`);
|
|
100
|
+
res.status(400).send(`${req.body.item} doesn't exist!`);
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
103
|
else {
|
|
101
|
-
|
|
104
|
+
console.log(`${req.body.item} ${req.body.amount} Check Input!`);
|
|
105
|
+
res.status(400).send(`${req.body.item} ${req.body.amount} Check Input!`);
|
|
102
106
|
}
|
|
103
107
|
}
|
|
104
108
|
catch(err) {
|
package/controllers/the-front.js
CHANGED
|
@@ -1,104 +1,86 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
styles: [],
|
|
11
|
-
externalStyles: [],
|
|
12
|
-
localScripts: [],
|
|
13
|
-
requiredItems: [],
|
|
14
|
-
needsKey: "",
|
|
15
|
-
dropOff: "",
|
|
16
|
-
...detail.options
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
detail.options.styles = detail.options.styles.map(style => {
|
|
20
|
-
style = `${dir}/styles/${style}`;
|
|
21
|
-
return style;
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
detail.options.externalStyles = detail.options.externalStyles.map(style => {
|
|
25
|
-
style = `${dir}/${style}`;
|
|
26
|
-
return style;
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
detail.options.localScripts = detail.options.localScripts.map(script => {
|
|
30
|
-
script = `${dir}/local-scripts/${script}`;
|
|
31
|
-
return script;
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
router.get(`/${detail.name}`, async function(req, res) {
|
|
35
|
-
detail.options.main = "index";
|
|
36
|
-
if (detail.name !== "") detail.options.main = detail.name;
|
|
37
|
-
detail.options.main = `${dir}/views/${detail.options.main}`;
|
|
1
|
+
const front = async function front(dir) {
|
|
2
|
+
const db = require("../models");
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
let router = require("express").Router();
|
|
6
|
+
|
|
7
|
+
router.post(`/serve/:script`, async function(req, res) {
|
|
8
|
+
try {
|
|
9
|
+
let currentRoute = `/${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}`;
|
|
38
10
|
|
|
39
|
-
|
|
40
|
-
for (let m = 0; m < detail.options.requiredItems.length; m++) {
|
|
41
|
-
let foundItem = await item.findOne({name: detail.options.requiredItems[m]});
|
|
11
|
+
let foundPoi = await db.poi.findOne({ route: currentRoute, type: "global" });
|
|
42
12
|
|
|
43
|
-
|
|
13
|
+
if (foundPoi === null) {
|
|
14
|
+
db.poi.create({
|
|
15
|
+
route: currentRoute,
|
|
16
|
+
name: req.params.detail,
|
|
17
|
+
type: "global",
|
|
18
|
+
global: {}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let scriptResult = await require(`${worldPath}/${currentRoute}/server-scripts/${req.params.script}.js`)(db, currentRoute, req.session.currentUser, req.body);
|
|
23
|
+
res.send(scriptResult);
|
|
44
24
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
user: null,
|
|
49
|
-
styles: detail.options.styles,
|
|
50
|
-
externalStyles: detail.options.externalStyles,
|
|
51
|
-
main: detail.options.main,
|
|
52
|
-
localScripts: detail.options.localScripts,
|
|
53
|
-
itemIDs: foundItemIDs,
|
|
54
|
-
inventory: null,
|
|
55
|
-
query: req.query,
|
|
56
|
-
dir: dir,
|
|
57
|
-
path: path
|
|
25
|
+
catch(err) {
|
|
26
|
+
console.log(err);
|
|
27
|
+
res.status(500).end();
|
|
58
28
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (detail.options.needsKey !== "" && context.inventory) {
|
|
66
|
-
let hasKey = false;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
router.get(`/:detail`, async function(req, res) {
|
|
32
|
+
try {
|
|
33
|
+
const foundUser = await db.user.findById(req.session.currentUser);
|
|
34
|
+
const foundInventory = await db.inventory.findOne({ user: req.session.currentUser }).populate("items.item");
|
|
67
35
|
|
|
68
|
-
|
|
69
|
-
if (foundInventory.items[i].item.name === detail.options.needsKey) hasKey = true;
|
|
70
|
-
}
|
|
36
|
+
let main = `${dir}/views/${req.params.detail}`;
|
|
71
37
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
38
|
+
let context = {
|
|
39
|
+
siteTitle: `NotherBase - ${req.params.detail}`,
|
|
40
|
+
user: foundUser,
|
|
41
|
+
main: main,
|
|
42
|
+
pov: req.query.pov,
|
|
43
|
+
inventory: foundInventory,
|
|
44
|
+
query: req.query,
|
|
45
|
+
dir: dir,
|
|
46
|
+
path: path
|
|
76
47
|
}
|
|
77
|
-
|
|
78
|
-
|
|
48
|
+
|
|
49
|
+
await res.render(`explorer`, context);
|
|
50
|
+
}
|
|
51
|
+
catch(err) {
|
|
52
|
+
console.log(err);
|
|
53
|
+
res.status(500).end();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
router.get(`/`, async function(req, res) {
|
|
58
|
+
try {
|
|
59
|
+
const foundUser = await db.user.findById(req.session.currentUser);
|
|
60
|
+
const foundInventory = await db.inventory.findOne({ user: req.session.currentUser }).populate("items.item");
|
|
61
|
+
|
|
62
|
+
let main = `${dir}/views/index`;
|
|
63
|
+
|
|
64
|
+
let context = {
|
|
65
|
+
siteTitle: `NotherBase - The Front`,
|
|
66
|
+
user: foundUser,
|
|
67
|
+
main: main,
|
|
68
|
+
pov: req.query.pov,
|
|
69
|
+
inventory: foundInventory,
|
|
70
|
+
query: req.query,
|
|
71
|
+
dir: dir,
|
|
72
|
+
path: path
|
|
79
73
|
}
|
|
74
|
+
|
|
75
|
+
await res.render(`explorer`, context);
|
|
80
76
|
}
|
|
81
|
-
|
|
82
|
-
console.log(
|
|
83
|
-
|
|
84
|
-
res.render(`explorer`, context);
|
|
77
|
+
catch(err) {
|
|
78
|
+
console.log(err);
|
|
79
|
+
res.status(500).end();
|
|
85
80
|
}
|
|
86
81
|
});
|
|
82
|
+
|
|
83
|
+
return router;
|
|
87
84
|
}
|
|
88
85
|
|
|
89
|
-
|
|
90
|
-
dir = frontBuild.dirname;
|
|
91
|
-
|
|
92
|
-
for (let i = 0; i < frontBuild.details.length; i++) {
|
|
93
|
-
front(frontBuild.details[i]);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
module.exports = {
|
|
98
|
-
setDir: function setDir(newDir) {
|
|
99
|
-
dir = newDir;
|
|
100
|
-
},
|
|
101
|
-
router: router,
|
|
102
|
-
front: front,
|
|
103
|
-
complete: complete
|
|
104
|
-
}
|
|
86
|
+
module.exports = front;
|
package/models/index.js
CHANGED
package/models/poi.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// This allows us to use Mongoose to connect to MongoDB
|
|
2
|
+
const mongoose = require("mongoose");
|
|
3
|
+
|
|
4
|
+
const poi = new mongoose.Schema({
|
|
5
|
+
route: String,
|
|
6
|
+
name: String,
|
|
7
|
+
type: String,
|
|
8
|
+
user: {
|
|
9
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
10
|
+
ref: "users",
|
|
11
|
+
required: false
|
|
12
|
+
},
|
|
13
|
+
data: {}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// This tells Mongoose to use the exampleSchema to access the examples collection
|
|
17
|
+
// in our db and then exports the model so we can use it.
|
|
18
|
+
module.exports = mongoose.model('pois', poi);
|
package/notherbase-fs.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
require("dotenv").config();
|
|
2
|
+
|
|
3
|
+
class NotherBaseFS {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.express = require("express");
|
|
6
|
+
this.session = require('express-session');
|
|
7
|
+
this.methodOverride = require('method-override');
|
|
8
|
+
this.MongoStore = require('connect-mongo');
|
|
9
|
+
this.favicon = require('serve-favicon');
|
|
10
|
+
this.http = require('http');
|
|
11
|
+
this.app = this.express();
|
|
12
|
+
this.server = this.http.createServer(this.app);
|
|
13
|
+
this.io = new (require("socket.io").Server)(this.server);
|
|
14
|
+
this.db = require("./models");
|
|
15
|
+
this.started = false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async start(worldPath, voidPath, frontPath, pagesPath) {
|
|
19
|
+
if (!this.started) {
|
|
20
|
+
//set views path
|
|
21
|
+
this.app.set("view engine", "ejs");
|
|
22
|
+
this.app.set("views", `${__dirname}/views`);
|
|
23
|
+
|
|
24
|
+
// allows us to delete
|
|
25
|
+
this.app.use(this.methodOverride('_method'));
|
|
26
|
+
|
|
27
|
+
// allows us to use post body data
|
|
28
|
+
this.app.use(this.express.urlencoded({ extended: true }));
|
|
29
|
+
|
|
30
|
+
// allows us to get static files like css
|
|
31
|
+
this.app.use(this.express.static('public'));
|
|
32
|
+
this.app.use(this.express.static(`${__dirname}/public`));
|
|
33
|
+
|
|
34
|
+
// sets the favicon image
|
|
35
|
+
this.app.use(this.favicon(__dirname + '/public/img/logo.png'));
|
|
36
|
+
|
|
37
|
+
// Import my Controller
|
|
38
|
+
const controllers = require("./controllers");
|
|
39
|
+
|
|
40
|
+
//enable cookies
|
|
41
|
+
if (this.db.connectionSuccess) {
|
|
42
|
+
this.app.use(this.session({
|
|
43
|
+
store: this.MongoStore.create({ mongoUrl: process.env.MONGODB_URI }),
|
|
44
|
+
secret: process.env.SECRET || "won",
|
|
45
|
+
resave: false,
|
|
46
|
+
saveUninitialized: false
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
console.log("sessions enabled");
|
|
50
|
+
}
|
|
51
|
+
else console.log("sessions disabled");
|
|
52
|
+
|
|
53
|
+
this.io.on('connection', (socket) => {
|
|
54
|
+
socket.join(socket.handshake.query.room);
|
|
55
|
+
|
|
56
|
+
socket.on('disconnect', () => {});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
this.app.use("/user", controllers.user);
|
|
60
|
+
|
|
61
|
+
this.app.use("/chat", controllers.chat(this.io));
|
|
62
|
+
|
|
63
|
+
this.app.use("/contact", controllers.contact);
|
|
64
|
+
|
|
65
|
+
this.app.use("/game", controllers.game);
|
|
66
|
+
|
|
67
|
+
this.app.use("/inventory", controllers.authCheck, controllers.inventory);
|
|
68
|
+
|
|
69
|
+
this.app.use("/item", controllers.item);
|
|
70
|
+
|
|
71
|
+
this.app.use("/the-front", await controllers.front(frontPath));
|
|
72
|
+
|
|
73
|
+
this.app.use("/", controllers.pages(pagesPath));
|
|
74
|
+
|
|
75
|
+
this.app.use("/", controllers.authCheck, await controllers.explorer(worldPath, voidPath));
|
|
76
|
+
|
|
77
|
+
this.server.listen(process.env.PORT, function () {
|
|
78
|
+
console.log(`Server started at ${process.env.PORT}`);
|
|
79
|
+
this.started = true;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
else console.log("Server already started!");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = new NotherBaseFS();
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "notherbase-fs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Functions to help make developing for NotherBase easier.",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "notherbase-fs.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "nodemon test/test-index.js",
|
|
8
8
|
"gmail-auth": "node gmail-auth.js",
|
|
@@ -52,7 +52,7 @@ class NonoGame {
|
|
|
52
52
|
this.tiles = [];
|
|
53
53
|
this.nonoSize = 100;
|
|
54
54
|
this.maxNonoId = 4;
|
|
55
|
-
this.goldItem =
|
|
55
|
+
this.goldItem = "Gold Coin";
|
|
56
56
|
|
|
57
57
|
this.startNew();
|
|
58
58
|
}
|
|
@@ -185,10 +185,7 @@ class NonoGame {
|
|
|
185
185
|
|
|
186
186
|
tryFinishGame() {
|
|
187
187
|
if (this.checkForSolve()) {
|
|
188
|
-
playerInventory.change(
|
|
189
|
-
item: this.goldItem,
|
|
190
|
-
amount: this.level + this.difficulty
|
|
191
|
-
});
|
|
188
|
+
playerInventory.change(this.goldItem, this.level + this.difficulty);
|
|
192
189
|
|
|
193
190
|
let $tiles = $(".nono-tile");
|
|
194
191
|
$tiles.off("click");
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module.exports = async function addToTimer(db, route, user, params) {
|
|
2
|
+
try {
|
|
3
|
+
let poi = await db.poi.findOne({ route: route, user: user });
|
|
4
|
+
|
|
5
|
+
let now = Date.now();
|
|
6
|
+
|
|
7
|
+
if (!poi.data) poi.data = {
|
|
8
|
+
timer: 0,
|
|
9
|
+
lastTime: now
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
if (!poi.data.lastTime) poi.data.lastTime = now;
|
|
13
|
+
if (!poi.data.timer) poi.data.timer = 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let difference = (now - poi.data.lastTime) / 1000;
|
|
17
|
+
poi.data.timer -= difference;
|
|
18
|
+
if (poi.data.timer < 0) poi.data.timer = 0;
|
|
19
|
+
|
|
20
|
+
poi.data.timer = poi.data.timer + 10;
|
|
21
|
+
poi.data.lastTime = Date.now();
|
|
22
|
+
|
|
23
|
+
poi.markModified("data");
|
|
24
|
+
await poi.save();
|
|
25
|
+
return poi.data.timer;
|
|
26
|
+
}
|
|
27
|
+
catch(err) {
|
|
28
|
+
console.log(err);
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module.exports = async function getTimer(db, route, user, params) {
|
|
2
|
+
try {
|
|
3
|
+
let poi = await db.poi.findOne({ route: route, user: user });
|
|
4
|
+
|
|
5
|
+
let now = Date.now();
|
|
6
|
+
|
|
7
|
+
if (!poi.data) poi.data = {
|
|
8
|
+
timer: 0,
|
|
9
|
+
lastTime: now
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
if (!poi.data.lastTime) poi.data.lastTime = now;
|
|
13
|
+
if (!poi.data.timer) poi.data.timer = 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let difference = (now - poi.data.lastTime) / 1000;
|
|
17
|
+
|
|
18
|
+
poi.data.timer -= difference;
|
|
19
|
+
if (poi.data.timer < 0) poi.data.timer = 0;
|
|
20
|
+
poi.data.lastTime = now;
|
|
21
|
+
|
|
22
|
+
poi.markModified("data");
|
|
23
|
+
await poi.save();
|
|
24
|
+
|
|
25
|
+
return poi.data.timer;
|
|
26
|
+
}
|
|
27
|
+
catch(err) {
|
|
28
|
+
console.log(err);
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
<hr>
|
|
6
6
|
|
|
7
|
-
<
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
</
|
|
7
|
+
<h3>Game Test</h3>
|
|
8
|
+
|
|
9
|
+
<button onclick="addToTime()">Add</button>
|
|
10
|
+
<p id="timer">0:00</p>
|
|
11
|
+
|
|
12
|
+
<hr>
|
|
13
|
+
|
|
14
|
+
<button onclick="tradeForDoll()">Trade 5g for a doll</button>
|
|
11
15
|
|
|
12
16
|
<hr>
|
|
13
17
|
|
|
@@ -61,4 +65,44 @@
|
|
|
61
65
|
|
|
62
66
|
<a href="/coast/tall-beach/nono-cove/nono-og" class="to">
|
|
63
67
|
Go to Nono Cove
|
|
64
|
-
</a>
|
|
68
|
+
</a>
|
|
69
|
+
|
|
70
|
+
<script>
|
|
71
|
+
let tradeForDoll = async function tradeForDoll() {
|
|
72
|
+
if (await playerInventory.change(itemIDs[0], -5)) await playerInventory.change(itemIDs[1], 1);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let time = 0;
|
|
76
|
+
|
|
77
|
+
let addToTime = async function addToTime() {
|
|
78
|
+
try {
|
|
79
|
+
await $.post(`/coast/tall-beach/nono-cove/index/serve/addToTimer`, function (data) {
|
|
80
|
+
time = Math.floor(data.scriptResult);
|
|
81
|
+
$("#timer").text(time);
|
|
82
|
+
});
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.log(error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let getTime = async function getTime() {
|
|
89
|
+
try {
|
|
90
|
+
await $.post(`/coast/tall-beach/nono-cove/index/serve/getTimer`, function (data) {
|
|
91
|
+
time = Math.floor(data.scriptResult);
|
|
92
|
+
$("#timer").text(time);
|
|
93
|
+
});
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.log(error);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let updateTime = function updateTime() {
|
|
100
|
+
if (time > 0) {
|
|
101
|
+
time--;
|
|
102
|
+
$("#timer").text(time);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
setInterval(updateTime, 1000);
|
|
107
|
+
getTime();
|
|
108
|
+
</script>
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
<style>
|
|
2
|
+
<%- include("../styles/nono.css"); %>
|
|
3
|
+
</style>
|
|
4
|
+
|
|
1
5
|
<p>
|
|
2
6
|
A random nono washes up on shore. Will you solve it?
|
|
3
7
|
</p>
|
|
@@ -34,4 +38,6 @@
|
|
|
34
38
|
moveNono();
|
|
35
39
|
|
|
36
40
|
setInterval(moveNono, 2000);
|
|
41
|
+
|
|
42
|
+
<%- include("../local-scripts/nono.js"); %>
|
|
37
43
|
</script>
|
package/test/test-index.js
CHANGED
|
@@ -1,67 +1,4 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
-
const
|
|
2
|
+
const notherBaseFS = require("../notherbase-fs");
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
explorer: {
|
|
6
|
-
name: "explorer",
|
|
7
|
-
dirname: __dirname,
|
|
8
|
-
options: {},
|
|
9
|
-
void: "void",
|
|
10
|
-
regions: [
|
|
11
|
-
{
|
|
12
|
-
name: "coast",
|
|
13
|
-
dirname: __dirname,
|
|
14
|
-
options: {},
|
|
15
|
-
areas: [
|
|
16
|
-
{
|
|
17
|
-
name: "tall-beach",
|
|
18
|
-
dirname: __dirname,
|
|
19
|
-
options: {},
|
|
20
|
-
pois: [
|
|
21
|
-
{
|
|
22
|
-
name: "nono-cove",
|
|
23
|
-
dirname: __dirname,
|
|
24
|
-
options: {},
|
|
25
|
-
details: [
|
|
26
|
-
{
|
|
27
|
-
name: "",
|
|
28
|
-
options: {
|
|
29
|
-
localScripts: ["game", "items"],
|
|
30
|
-
styles: ["items-floor"],
|
|
31
|
-
serverScripts: ["game"]
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
name: "nono-og",
|
|
36
|
-
options: {
|
|
37
|
-
localScripts: ["nono"],
|
|
38
|
-
styles: ["nono"],
|
|
39
|
-
requiredItems: [
|
|
40
|
-
"Gold Coin"
|
|
41
|
-
]
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
]
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
}
|
|
50
|
-
]
|
|
51
|
-
},
|
|
52
|
-
theFront: {
|
|
53
|
-
name: "the-front",
|
|
54
|
-
dirname: __dirname,
|
|
55
|
-
options: {},
|
|
56
|
-
details: [
|
|
57
|
-
{
|
|
58
|
-
name: "",
|
|
59
|
-
options: {
|
|
60
|
-
requiredItems: ["Gold Coin"]
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
]
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
notherbase.start(world, path.resolve(__dirname, "pages"));
|
|
4
|
+
notherBaseFS.start(__dirname, `${__dirname}/void`, __dirname, `${__dirname}/pages`);
|
package/test/views/index.ejs
CHANGED
package/views/explorer.ejs
CHANGED
|
@@ -1,28 +1,5 @@
|
|
|
1
1
|
<%- include("./head.ejs"); %>
|
|
2
2
|
|
|
3
|
-
<style>
|
|
4
|
-
<%- //include(path.resolve(dir, "../../", "public/styles/main.css")); %>
|
|
5
|
-
<%- //include(path.resolve(dir, "../../", "public/styles/menu.css")); %>
|
|
6
|
-
<%- //include(path.resolve(dir, "../../", "public/styles/inventory.css")); %>
|
|
7
|
-
<%- //include(path.resolve(dir, "../../", "public/styles/player.css")); %>
|
|
8
|
-
<%- //include(path.resolve(dir, "../../", "public/styles/account.css")); %>
|
|
9
|
-
<%- //include(path.resolve(dir, "../../", "public/styles/more.css")); %>
|
|
10
|
-
|
|
11
|
-
<% for (let i = 0; i < styles.length; i++) { %>
|
|
12
|
-
<%- include(`${styles[i]}.css`); %>
|
|
13
|
-
<% } %>
|
|
14
|
-
<% for (let i = 0; i < externalStyles.length; i++) { %>
|
|
15
|
-
<%- include(`${externalStyles[i]}.css`); %>
|
|
16
|
-
<% } %>
|
|
17
|
-
</style>
|
|
18
|
-
|
|
19
|
-
<script>
|
|
20
|
-
let itemIDs = [];
|
|
21
|
-
<% for (let i = 0; i < itemIDs.length; i++) { %>
|
|
22
|
-
itemIDs.push("<%= itemIDs[i] %>");
|
|
23
|
-
<% } %>
|
|
24
|
-
</script>
|
|
25
|
-
|
|
26
3
|
<main class="override">
|
|
27
4
|
<%- include(`${main}.ejs`); %>
|
|
28
5
|
</main>
|
|
@@ -31,10 +8,4 @@
|
|
|
31
8
|
<%- include("./menu.ejs", {user: user}); %>
|
|
32
9
|
</div>
|
|
33
10
|
|
|
34
|
-
<script>
|
|
35
|
-
<% for (let i = 0; i < localScripts.length; i++) { %>
|
|
36
|
-
<%- include(`${localScripts[i]}.js`); %>
|
|
37
|
-
<% } %>
|
|
38
|
-
</script>
|
|
39
|
-
|
|
40
11
|
<%- include("./footer.ejs"); %>
|
package/views/inventory.ejs
CHANGED
|
@@ -38,14 +38,14 @@
|
|
|
38
38
|
setInterval(this.update, this.updateCooldown);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
async change(
|
|
41
|
+
async change(itemName, amount) {
|
|
42
42
|
let change = {
|
|
43
|
-
item:
|
|
43
|
+
item: itemName,
|
|
44
44
|
amount: amount
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
try {
|
|
48
|
+
await $.post("/inventory", change, (data, status) => {
|
|
49
49
|
let holding = false;
|
|
50
50
|
|
|
51
51
|
for (let i = 0; i < this.items.length; i++) {
|
|
@@ -62,9 +62,14 @@
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
this.render();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
catch(err) {
|
|
70
|
+
console.log(err);
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
async getData() {
|
|
@@ -144,6 +149,16 @@
|
|
|
144
149
|
});
|
|
145
150
|
}
|
|
146
151
|
}
|
|
152
|
+
|
|
153
|
+
hasItem(itemName, minAmount = 1) {
|
|
154
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
155
|
+
if (this.items[i].item.name === itemName) {
|
|
156
|
+
if (this.items[i].amount >= minAmount) return true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
147
162
|
}
|
|
148
163
|
|
|
149
164
|
let playerInventory = new Inventory();
|
package/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require("dotenv").config();
|
|
2
|
-
|
|
3
|
-
let db = require("./models");
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
explore: function explore(path) {
|
|
7
|
-
return `./${path}/${path}.js`;
|
|
8
|
-
},
|
|
9
|
-
data: db,
|
|
10
|
-
chat: null,
|
|
11
|
-
start: function start(world, pagesPath) {
|
|
12
|
-
let theFront = require("./controllers/the-front");
|
|
13
|
-
let explorer = require("./controllers/explorer");
|
|
14
|
-
|
|
15
|
-
explorer.complete(world.explorer);
|
|
16
|
-
theFront.complete(world.theFront);
|
|
17
|
-
|
|
18
|
-
let pagesRouter = require("./controllers/pages")(pagesPath);
|
|
19
|
-
|
|
20
|
-
require("./server")(theFront.router, explorer.router, pagesRouter, db.connectionSuccess);
|
|
21
|
-
}
|
|
22
|
-
}
|
package/server.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
let started = false;
|
|
2
|
-
|
|
3
|
-
module.exports = function start(frontRouter, exploreRouter, pagesRouter, dbConnected) {
|
|
4
|
-
if (!started) {
|
|
5
|
-
// Setup for Express
|
|
6
|
-
const express = require("express");
|
|
7
|
-
const app = express();
|
|
8
|
-
app.set("view engine", "ejs");
|
|
9
|
-
app.set("views", `${__dirname}/views`);
|
|
10
|
-
|
|
11
|
-
//setup for sockets
|
|
12
|
-
const http = require('http');
|
|
13
|
-
const server = http.createServer(app);
|
|
14
|
-
const { Server } = require("socket.io");
|
|
15
|
-
const io = new Server(server);
|
|
16
|
-
|
|
17
|
-
// allows us to delete
|
|
18
|
-
const methodOverride = require('method-override');
|
|
19
|
-
app.use(methodOverride('_method'));
|
|
20
|
-
|
|
21
|
-
//auth
|
|
22
|
-
const session = require('express-session');
|
|
23
|
-
const MongoStore = require('connect-mongo');
|
|
24
|
-
|
|
25
|
-
// allows us to use post body data
|
|
26
|
-
app.use(express.urlencoded({ extended: true }));
|
|
27
|
-
|
|
28
|
-
// allows us to get static files like css
|
|
29
|
-
app.use(express.static('public'));
|
|
30
|
-
app.use(express.static(`${__dirname}/public`));
|
|
31
|
-
|
|
32
|
-
// sets the favicon image
|
|
33
|
-
const favicon = require('serve-favicon');
|
|
34
|
-
app.use(favicon(__dirname + '/public/img/logo.png'));
|
|
35
|
-
|
|
36
|
-
// Import my Controller
|
|
37
|
-
const controllers = require("./controllers");
|
|
38
|
-
|
|
39
|
-
//enable cookies
|
|
40
|
-
if (dbConnected) {
|
|
41
|
-
app.use(session({
|
|
42
|
-
store: MongoStore.create({ mongoUrl: process.env.MONGODB_URI }),
|
|
43
|
-
secret: process.env.SECRET || "won",
|
|
44
|
-
resave: false,
|
|
45
|
-
saveUninitialized: false
|
|
46
|
-
}));
|
|
47
|
-
|
|
48
|
-
console.log("sessions enabled");
|
|
49
|
-
}
|
|
50
|
-
else console.log("sessions disabled");
|
|
51
|
-
|
|
52
|
-
io.on('connection', (socket) => {
|
|
53
|
-
socket.join(socket.handshake.query.room);
|
|
54
|
-
|
|
55
|
-
socket.on('disconnect', () => {});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
app.use("/user", controllers.user);
|
|
59
|
-
|
|
60
|
-
app.use("/chat", controllers.chat(io));
|
|
61
|
-
|
|
62
|
-
app.use("/contact", controllers.contact);
|
|
63
|
-
|
|
64
|
-
app.use("/game", controllers.game);
|
|
65
|
-
|
|
66
|
-
app.use("/inventory", controllers.inventory);
|
|
67
|
-
|
|
68
|
-
app.use("/item", controllers.item);
|
|
69
|
-
|
|
70
|
-
app.use("/the-front", frontRouter);
|
|
71
|
-
|
|
72
|
-
app.use("/", pagesRouter);
|
|
73
|
-
|
|
74
|
-
app.use("/", controllers.authCheck, exploreRouter);
|
|
75
|
-
|
|
76
|
-
server.listen(process.env.PORT, function () {
|
|
77
|
-
console.log(`Server started at ${process.env.PORT}`);
|
|
78
|
-
started = true;
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
else console.log("Server already started!");
|
|
83
|
-
}
|