notherbase-fs 1.2.16 → 1.3.2

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.
@@ -1,150 +1,134 @@
1
- const { inventory, game, item, user } = require("../models");
1
+ const db = require("../models");
2
2
  const path = require('path');
3
+ const fs = require("fs");
4
+
5
+ let router = require("express").Router();
6
+
7
+ const explorer = async function explorer(worldPath, voidPath) {
8
+ router.post(`/:region/:area/:poi/:detail/serve/:script`, async function(req, res) {
9
+ try {
10
+ let currentAreaRoute = `${req.params.region}/${req.params.area}/${req.params.poi}`;
11
+ let currentRoute = `${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}`;
12
+
13
+ if (await db.poi.exists({ route: currentRoute, type: "global" }) === false) {
14
+ await db.poi.create({
15
+ route: currentRoute,
16
+ name: req.params.detail,
17
+ type: "global",
18
+ data: {}
19
+ });
20
+ }
3
21
 
4
- let router = require("express").Router();;
5
- let dir = "";
6
-
7
- let complete = function complete(explorerBuild) {
8
- dir = explorerBuild.dirname;
9
-
10
- let currentRegion, currentArea, currentPoi = "";
11
-
12
- for (let i = 0; i < explorerBuild.regions.length; i++) {
13
- let region = explorerBuild.regions[i];
14
- currentRegion = region.name;
15
-
16
- for (let j = 0; j < region.areas.length; j++) {
17
- let area = region.areas[j];
18
- currentArea = area.name;
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
- }
102
-
103
- if (detail.options.needsKey !== "" && foundInventory) {
104
- let hasKey = false;
105
-
106
- for (let i = 0; i < foundInventory.items.length; i++) {
107
- if (foundInventory.items[i].item.name === detail.options.needsKey) hasKey = true;
108
- }
109
-
110
- if (!hasKey) res.redirect(detail.options.dropOff);
111
- else res.render(`explorer`, context);
112
- }
113
- else res.render(`explorer`, context);
114
- }
115
- catch(err) {
116
- console.log(err);
117
- }
118
- });
22
+ if (await db.poi.exists({ route: currentRoute, user: req.session.currentUser }) === false) {
23
+ await db.poi.create({
24
+ route: currentRoute,
25
+ name: req.params.detail,
26
+ type: "local",
27
+ user: req.session.currentUser,
28
+ data: {}
29
+ });
30
+ }
31
+
32
+ let scriptResult = await require(`${worldPath}/${currentAreaRoute}/server-scripts/${req.params.script}.js`)(db, currentRoute, req.session.currentUser, req.body);
33
+ res.send({ scriptResult: scriptResult });
34
+ }
35
+ catch(err) {
36
+ console.log(err);
37
+ res.status(500).end();
38
+ }
39
+ });
40
+
41
+ router.get(`/:region/:area/:poi/:detail`, async function(req, res) {
42
+ try {
43
+ const foundUser = await db.user.findById(req.session.currentUser);
44
+ const foundInventory = await db.inventory.findOne({ user: req.session.currentUser }).populate("items.item");
45
+
46
+ let main = `${worldPath}/${req.params.region}/${req.params.area}/${req.params.poi}/views/${req.params.detail}`;
47
+
48
+ if (fs.existsSync(main + ".js")) {
49
+ let context = {
50
+ siteTitle: `NotherBase - ${req.params.detail}`,
51
+ user: foundUser,
52
+ main: main,
53
+ pov: req.query.pov,
54
+ inventory: foundInventory,
55
+ query: req.query,
56
+ dir: worldPath,
57
+ path: path
119
58
  }
59
+
60
+ await res.render(`explorer`, context);
61
+ }
62
+ else {
63
+ res.render(`explorer`,
64
+ {
65
+ siteTitle: "NotherBase | The Void",
66
+ user: null,
67
+ inventory: null,
68
+ main: `${voidPath}/index`
69
+ });
120
70
  }
121
71
  }
122
- }
123
-
72
+ catch(err) {
73
+ console.log(err);
74
+ res.status(500).end();
75
+ }
76
+ });
77
+
78
+ router.get(`/:region/:area/:poi`, async function(req, res) {
79
+ try {
80
+ const foundUser = await db.user.findById(req.session.currentUser);
81
+ const foundInventory = await db.inventory.findOne({ user: req.session.currentUser }).populate("items.item");
82
+
83
+ let main = `${worldPath}/${req.params.region}/${req.params.area}/${req.params.poi}/views/index`;
84
+
85
+ if (fs.existsSync(main + ".js")) {
86
+ let context = {
87
+ siteTitle: `NotherBase - ${req.params.poi}`,
88
+ user: foundUser,
89
+ main: main,
90
+ pov: req.query.pov,
91
+ inventory: foundInventory,
92
+ query: req.query,
93
+ dir: worldPath,
94
+ path: path
95
+ }
96
+
97
+ await res.render(`explorer`, context);
98
+ }
99
+ else {
100
+ res.render(`explorer`,
101
+ {
102
+ siteTitle: "NotherBase | The Void",
103
+ user: null,
104
+ inventory: null,
105
+ main: `${voidPath}/index`
106
+ });
107
+ }
108
+ }
109
+ catch(err) {
110
+ console.log(err);
111
+ res.status(500).end();
112
+ }
113
+ });
114
+
124
115
  // start location
125
116
  router.get("/", function(req, res) {
126
117
  res.redirect("/the-front");
127
118
  });
128
-
119
+
129
120
  //the void
130
121
  router.use(function(req, res, next){
131
122
  res.render(`explorer`,
132
123
  {
133
124
  siteTitle: "NotherBase | The Void",
134
125
  user: null,
135
- styles: [`${dir}/${explorerBuild.void}/styles/void`],
136
- externalStyles: [],
137
- localScripts: [],
138
126
  inventory: null,
139
- itemIDs: [],
140
- main: `${dir}/${explorerBuild.void}/index`,
141
- dir: dir,
142
- path: path
127
+ main: `${voidPath}/index`
143
128
  });
144
129
  });
130
+
131
+ return router;
145
132
  }
146
133
 
147
- module.exports = {
148
- router: router,
149
- complete: complete
150
- }
134
+ module.exports = explorer;
@@ -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).send();
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
  });
@@ -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
- if (req.session.currentUser) {
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._id.equals(req.body.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: req.body.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
- res.status(401).send("User not logged in!");
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
- res.status(400).send("Check input!");
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) {
@@ -1,104 +1,86 @@
1
- const { user, inventory, connectionSuccess, item } = require("../models");
2
- const path = require('path');
3
-
4
- let router = require("express").Router();
5
- let dir = "";
6
-
7
-
8
- let front = function front(detail) {
9
- detail.options = {
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
- let foundItemIDs = [];
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
- foundItemIDs.push(foundItem._id);
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
- let context = {
47
- siteTitle: "NotherBase | The Front",
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
- if (connectionSuccess) {
61
- try {
62
- context.user = await user.findById(req.session.currentUser);
63
- context.inventory = await inventory.findOne({ user: req.session.currentUser }).populate("items.item");
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
- for (let i = 0; i < foundInventory.items.length; i++) {
69
- if (foundInventory.items[i].item.name === detail.options.needsKey) hasKey = true;
70
- }
36
+ let main = `${dir}/views/${req.params.detail}`;
71
37
 
72
- if (!hasKey) res.redirect(detail.options.dropOff);
73
- else res.render(`explorer`, context);
74
- }
75
- else res.render(`explorer`, context);
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
- catch(err) {
78
- console.log(err);
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
- else {
82
- console.log("no db connection");
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
- let complete = function complete(frontBuild) {
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
@@ -6,5 +6,6 @@ module.exports = {
6
6
  contact: require("./contact"),
7
7
  inventory: require("./inventory"),
8
8
  game: require("./game"),
9
- sendMail: require("./send-mail")
9
+ sendMail: require("./send-mail"),
10
+ poi: require("./poi")
10
11
  }
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);
@@ -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.2.16",
3
+ "version": "1.3.2",
4
4
  "description": "Functions to help make developing for NotherBase easier.",
5
- "main": "index.js",
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 = itemIDs[0];
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,10 @@
4
4
 
5
5
  <hr>
6
6
 
7
- <div class="game">
8
- <h3><%= serverScriptReturns[0] %>Text</h3>
9
- <button>Click</button>
10
- </div>
7
+ <h3>Game Test</h3>
8
+
9
+ <button onclick="addToTime()">Add</button>
10
+ <p id="timer">0:00</p>
11
11
 
12
12
  <hr>
13
13
 
@@ -71,4 +71,38 @@
71
71
  let tradeForDoll = async function tradeForDoll() {
72
72
  if (await playerInventory.change(itemIDs[0], -5)) await playerInventory.change(itemIDs[1], 1);
73
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();
74
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>
@@ -1,71 +1,4 @@
1
1
  const path = require('path');
2
- const notherbase = require("../index");
2
+ const notherBaseFS = require("../notherbase-fs");
3
3
 
4
- const world = {
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
- requiredItems: [
33
- "Gold Coin",
34
- "Rag Doll"
35
- ]
36
- }
37
- },
38
- {
39
- name: "nono-og",
40
- options: {
41
- localScripts: ["nono"],
42
- styles: ["nono"],
43
- requiredItems: [
44
- "Gold Coin"
45
- ]
46
- }
47
- }
48
- ]
49
- }
50
- ]
51
- }
52
- ]
53
- }
54
- ]
55
- },
56
- theFront: {
57
- name: "the-front",
58
- dirname: __dirname,
59
- options: {},
60
- details: [
61
- {
62
- name: "",
63
- options: {
64
- requiredItems: ["Gold Coin"]
65
- }
66
- }
67
- ]
68
- }
69
- };
70
-
71
- notherbase.start(world, path.resolve(__dirname, "pages"));
4
+ notherBaseFS.start(__dirname, `${__dirname}/void`, __dirname, `${__dirname}/pages`);
@@ -0,0 +1,7 @@
1
+ <p>Hello</p>
2
+
3
+ <hr>
4
+
5
+ <a href="/the-front">
6
+ Go to The Front
7
+ </a>
@@ -45,6 +45,10 @@
45
45
  Go inside
46
46
  </a>
47
47
 
48
+ <a href="/the-front/check">
49
+ Go to The Check
50
+ </a>
51
+
48
52
  <script>
49
53
  let $resetPassword = $("#reset-password");
50
54
  let $loginButton = $("#login-button");
@@ -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"); %>
@@ -38,9 +38,9 @@
38
38
  setInterval(this.update, this.updateCooldown);
39
39
  }
40
40
 
41
- async change(itemID, amount) {
41
+ async change(itemName, amount) {
42
42
  let change = {
43
- item: itemID,
43
+ item: itemName,
44
44
  amount: amount
45
45
  }
46
46
 
@@ -149,6 +149,16 @@
149
149
  });
150
150
  }
151
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
+ }
152
162
  }
153
163
 
154
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
- }