notherbase-fs 1.0.38 → 1.0.42

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.
@@ -0,0 +1,134 @@
1
+ <% if (inventory.items) { %>
2
+ <div class="inventory invisible">
3
+ <% if (user.authLevels.length > 0) {
4
+ for (let i = 0; i < user.authLevels.length; i++) {
5
+ if (user.authLevels[i] === "Creator") { %>
6
+
7
+ <div class="item-spawner">
8
+ <input type="text" class="search">
9
+ <div class="search-results">
10
+
11
+ </div>
12
+ </div>
13
+
14
+ <% break;
15
+ }
16
+ }
17
+ } %>
18
+
19
+ <div class="item-list">
20
+ </div>
21
+ </div>
22
+
23
+ <button id="inventory-button">
24
+ <i class="fas fa-database"></i>
25
+ </button>
26
+ <% } else { %>
27
+ <button id="inventory-button">
28
+ ERR
29
+ </button>
30
+ <% } %>
31
+
32
+ <script>
33
+ class Inventory {
34
+ constructor() {
35
+ this.$div = $(".inventory");
36
+ this.$list = $(".item-list");
37
+ this.$search = $(".search");
38
+ this.$searchResults = $(".search-results");
39
+ this.searchResults = [];
40
+ this.$button = $("#inventory-button");
41
+ this.items = [];
42
+
43
+ this.$button.on("click", () => {
44
+ this.$div.toggleClass("invisible");
45
+ });
46
+
47
+ this.$search.on("keyup", () => {
48
+ let searchString = this.$search.val();
49
+
50
+ $.get(`/item`, { name: searchString }, (data) => {
51
+ this.renderSearchResults(data.foundItems);
52
+ });
53
+ });
54
+
55
+ $.get("/inventory", (data) => {
56
+ this.items = data.foundInventory.items;
57
+
58
+ this.render();
59
+ });
60
+
61
+ setInterval(this.update, this.updateCooldown);
62
+ }
63
+
64
+ change(change) {
65
+ $.post("/inventory", { change: change }, (data, status) => {
66
+ if (status === "success") {
67
+ let holding = false;
68
+
69
+ for (let i = 0; i < this.items.length; i++) {
70
+ if (this.items[i].item._id === data.item._id) {
71
+ this.items[i].amount = data.amount;
72
+ holding = true;
73
+
74
+ if (this.items[i].amount === 0) this.items.splice(i, 1);
75
+ }
76
+ }
77
+
78
+ if (!holding) {
79
+ this.items.push(data);
80
+ }
81
+
82
+ this.render();
83
+ }
84
+ else console.log(status);
85
+ });
86
+ }
87
+
88
+ render() {
89
+ this.$list.empty();
90
+
91
+ for (let i = 0; i < this.items.length; i++) {
92
+ let $new = this.$list.append(
93
+ `<div class="item-card">
94
+ <h5>${this.items[i].item.name}</h5>
95
+ <button id="${i}">X</button>
96
+ <hr>
97
+ <p>${this.items[i].amount}</p>
98
+ </div>`
99
+ ).children().last();
100
+
101
+ $new.find("button").on("click", (e) => {
102
+ let which = parseInt(e.currentTarget.id);
103
+
104
+ this.change({
105
+ item: this.items[which].item._id,
106
+ amount: -1
107
+ });
108
+ });
109
+ }
110
+ }
111
+
112
+ renderSearchResults(results) {
113
+ this.$searchResults.empty();
114
+ this.searchResults = results;
115
+
116
+ for (let i = 0; i < this.searchResults.length; i++) {
117
+ let $new = this.$searchResults.append(
118
+ `<p id="${i}">${this.searchResults[i].name}</p>`
119
+ ).children().last();
120
+
121
+ $new.on("click", (e) => {
122
+ let which = parseInt(e.currentTarget.id);
123
+
124
+ this.change({
125
+ item: this.searchResults[which]._id,
126
+ amount: 1
127
+ });
128
+ });
129
+ }
130
+ }
131
+ }
132
+
133
+ let playerInventory = new Inventory();
134
+ </script>
package/main.js DELETED
@@ -1,91 +0,0 @@
1
- const inventory = require(process.cwd() + "/models/inventory");
2
-
3
- let router;
4
- let dir;
5
-
6
- let explore = function explore(route, options) {
7
- options = {
8
- styles: [],
9
- externalStyles: [],
10
- scripts: [],
11
- needsKey: "",
12
- dropOff: "",
13
- ...options
14
- };
15
-
16
- options.styles = options.styles.map(style => {
17
- style = `${dir}/styles/${style}`;
18
- return style;
19
- });
20
-
21
- options.externalStyles = options.externalStyles.map(style => {
22
- style = `${dir}/${style}`;
23
- return style;
24
- });
25
-
26
- options.scripts = options.scripts.map(script => {
27
- script = `${dir}/local-scripts/${script}`;
28
- return script;
29
- });
30
-
31
- options.main = "index";
32
- if (route !== "") options.main = route;
33
- options.main = `${dir}/views/${options.main}`;
34
-
35
- router.get(`/${route}`, async function(req, res) {
36
- try {
37
- const foundInventory = await inventory.findOne({ user: req.session.currentUser }).populate("items.item");
38
-
39
- if (options.needsKey !== "" && foundInventory) {
40
- let hasKey = false;
41
-
42
- for (let i = 0; i < foundInventory.items.length; i++) {
43
- if (foundInventory.items[i].item.name === options.needsKey) hasKey = true;
44
- }
45
-
46
- if (!hasKey) res.redirect(options.dropOff);
47
- else res.render(`explorer`,
48
- {
49
- siteTitle: "NotherBase",
50
- user: req.session.currentUserFull,
51
- styles: options.styles,
52
- externalStyles: options.externalStyles,
53
- main: options.main,
54
- scripts: options.scripts,
55
- pov: req.query.pov,
56
- inventory: foundInventory,
57
- query: req.query
58
- });
59
- }
60
- else res.render(`explorer`,
61
- {
62
- siteTitle: "NotherBase",
63
- user: req.session.currentUserFull,
64
- styles: options.styles,
65
- externalStyles: options.externalStyles,
66
- main: options.main,
67
- scripts: options.scripts,
68
- pov: req.query.pov,
69
- inventory: foundInventory,
70
- query: req.query
71
- });
72
- }
73
- catch(err) {
74
- console.log(err);
75
- }
76
- });
77
- }
78
-
79
- let from = function from(currentDirectory) {
80
- dir = currentDirectory;
81
- router = require("express").Router();
82
-
83
- return {
84
- explore: explore,
85
- router: router
86
- };
87
- }
88
-
89
- module.exports = {
90
- from: from
91
- }