notherbase-fs 1.3.1 → 1.3.4

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,9 +1,10 @@
1
+ const db = require("../models");
2
+ const path = require('path');
3
+ const fs = require("fs");
4
+
5
+ let router = require("express").Router();
6
+
1
7
  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
8
  router.post(`/:region/:area/:poi/:detail/serve/:script`, async function(req, res) {
8
9
  try {
9
10
  let currentAreaRoute = `${req.params.region}/${req.params.area}/${req.params.poi}`;
@@ -43,19 +44,30 @@ const explorer = async function explorer(worldPath, voidPath) {
43
44
  const foundInventory = await db.inventory.findOne({ user: req.session.currentUser }).populate("items.item");
44
45
 
45
46
  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
47
+
48
+ if (fs.existsSync(main + ".ejs")) {
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
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
+ });
56
70
  }
57
-
58
- await res.render(`explorer`, context);
59
71
  }
60
72
  catch(err) {
61
73
  console.log(err);
@@ -70,18 +82,29 @@ const explorer = async function explorer(worldPath, voidPath) {
70
82
 
71
83
  let main = `${worldPath}/${req.params.region}/${req.params.area}/${req.params.poi}/views/index`;
72
84
 
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
85
+ if (fs.existsSync(main + ".ejs")) {
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
+ });
82
107
  }
83
-
84
- await res.render(`explorer`, context);
85
108
  }
86
109
  catch(err) {
87
110
  console.log(err);
@@ -101,9 +124,7 @@ const explorer = async function explorer(worldPath, voidPath) {
101
124
  siteTitle: "NotherBase | The Void",
102
125
  user: null,
103
126
  inventory: null,
104
- main: `${voidPath}/index`,
105
- dir: dir,
106
- path: path
127
+ main: `${voidPath}/index`
107
128
  });
108
129
  });
109
130
 
@@ -51,18 +51,18 @@ router.post("/", async function(req, res) {
51
51
  await foundInventory.save();
52
52
 
53
53
  res.status(200).send({
54
- item: itemToEmpty,
54
+ item: {
55
+ _id: itemToEmpty
56
+ },
55
57
  amount: 0
56
58
  });
57
59
  }
58
60
  else {
59
61
  await foundInventory.save();
60
-
61
62
  res.status(200).send(foundInventory.items[j]);
62
63
  }
63
64
  }
64
65
  else {
65
- console.log("subtract from too few", req.change);
66
66
  res.status(304).send(
67
67
  `Unable to remove ${req.body.amount} ${req.body.item}
68
68
  from inventory because the inventory has only ${foundInventory.items[j].amount}.`
@@ -87,7 +87,6 @@ router.post("/", async function(req, res) {
87
87
  res.status(200).send(foundInventory.items[foundInventory.items.length - 1]);
88
88
  }
89
89
  else {
90
- console.log("subtract from none", req.body);
91
90
  res.status(304).send(
92
91
  `Unable to remove ${req.body.amount} ${req.body.item}
93
92
  from inventory because the inventory has none.`
@@ -96,12 +95,10 @@ router.post("/", async function(req, res) {
96
95
  };
97
96
  }
98
97
  else {
99
- console.log(`${req.body.item} doesn't exist!`);
100
98
  res.status(400).send(`${req.body.item} doesn't exist!`);
101
99
  }
102
100
  }
103
101
  else {
104
- console.log(`${req.body.item} ${req.body.amount} Check Input!`);
105
102
  res.status(400).send(`${req.body.item} ${req.body.amount} Check Input!`);
106
103
  }
107
104
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notherbase-fs",
3
- "version": "1.3.1",
3
+ "version": "1.3.4",
4
4
  "description": "Functions to help make developing for NotherBase easier.",
5
5
  "main": "notherbase-fs.js",
6
6
  "scripts": {
@@ -11,7 +11,7 @@
11
11
 
12
12
  <hr>
13
13
 
14
- <button onclick="tradeForDoll()">Trade 5g for a doll</button>
14
+ <button onclick="tradeForDoll()" id="trade">Trade 5g for a doll</button>
15
15
 
16
16
  <hr>
17
17
 
@@ -68,8 +68,22 @@
68
68
  </a>
69
69
 
70
70
  <script>
71
+ let bought = false;
72
+
71
73
  let tradeForDoll = async function tradeForDoll() {
72
- if (await playerInventory.change(itemIDs[0], -5)) await playerInventory.change(itemIDs[1], 1);
74
+ if (!bought) {
75
+ $("#trade").addClass("invisible");
76
+
77
+ let paid = await playerInventory.change("Gold Coin", -5);
78
+
79
+ if (paid) {
80
+ bought = true;
81
+ await playerInventory.change("Rag Doll", 1);
82
+ }
83
+ else {
84
+ $("#trade").removeClass("invisible");
85
+ }
86
+ }
73
87
  }
74
88
 
75
89
  let time = 0;
@@ -45,7 +45,18 @@
45
45
  }
46
46
 
47
47
  try {
48
- await $.post("/inventory", change, (data, status) => {
48
+ let data = null;
49
+ let status = null;
50
+
51
+ await $.post("/inventory", change, (d, s) => {
52
+ data = d;
53
+ status = s;
54
+ });
55
+
56
+ if (status === "notmodified") {
57
+ return false;
58
+ }
59
+ else {
49
60
  let holding = false;
50
61
 
51
62
  for (let i = 0; i < this.items.length; i++) {
@@ -53,7 +64,7 @@
53
64
  this.items[i].amount = data.amount;
54
65
  holding = true;
55
66
 
56
- if (this.items[i].amount === 0) this.items.splice(i, 1);
67
+ if (data.amount <= 0) this.items.splice(i, 1);
57
68
  }
58
69
  }
59
70
 
@@ -62,9 +73,8 @@
62
73
  }
63
74
 
64
75
  this.render();
65
- });
66
-
67
- return true;
76
+ return true;
77
+ }
68
78
  }
69
79
  catch(err) {
70
80
  console.log(err);
@@ -86,6 +96,7 @@
86
96
  }
87
97
 
88
98
  render() {
99
+ console.log(this.items);
89
100
  this.$list.empty();
90
101
 
91
102
  for (let i = 0; i < this.items.length; i++) {