notherbase-fs 1.2.14 → 1.3.0

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,162 @@
1
+ class ItemFloor {
2
+ constructor() {
3
+ this.items = [];
4
+ this.$itemList = $(".floor#items ul.items");
5
+ this.$items = $(".floor#items ul.items li");
6
+
7
+ this.$read = $(".floor#items .editor .read");
8
+ this.$readName = $(".floor#items .editor .read #name");
9
+ this.$readShort = $(".floor#items .editor .read #short");
10
+ this.$readFull = $(".floor#items .editor .read #full");
11
+
12
+ this.$edit = $(".floor#items .editor .edit");
13
+ this.$editName = $(".floor#items .editor .edit #name");
14
+ this.$editShort = $(".floor#items .editor .edit #short");
15
+ this.$editFull = $(".floor#items .editor .edit #full");
16
+
17
+ this.selected = -1;
18
+ this.state = "reading";
19
+
20
+ this.updateItems();
21
+ }
22
+
23
+ hasValidSelection() {
24
+ return (this.selected > -1 && this.selected < this.items.length);
25
+ }
26
+
27
+ async updateItems() {
28
+ try {
29
+ await $.get(`/item/all`, (data) => {
30
+ this.items = data.foundItems;
31
+ this.renderItemList();
32
+ });
33
+ }
34
+ catch(err) {
35
+ console.log(err);
36
+ }
37
+ };
38
+
39
+ renderItemList() {
40
+ this.$itemList.empty();
41
+
42
+ for (let i = 0; i < this.items.length; i++) {
43
+ $(".floor#items ul.items").append(`<li onClick="itemFloor.selectItem(${i})">${this.items[i].name}</li>`);
44
+ };
45
+
46
+ this.$items = $(".floor#items ul.items li");
47
+ this.selectItem(this.selected);
48
+ }
49
+
50
+ createNewItem() {
51
+ if (this.state === "reading") {
52
+ this.items.push({
53
+ _id: null,
54
+ name: "New Item",
55
+ shortDescription: "Short Description",
56
+ fullDescription: "Full Description"
57
+ });
58
+
59
+ this.renderItemList();
60
+ this.selectItem(this.items.length - 1);
61
+ this.editSelectedItem();
62
+ }
63
+ };
64
+
65
+ selectItem(index) {
66
+ this.$items.removeClass("selected");
67
+ this.selected = index;
68
+
69
+ if (index > -1) {
70
+ $(this.$items[index]).addClass("selected");
71
+ }
72
+
73
+ this.readSelectedItem();
74
+ }
75
+
76
+ readSelectedItem() {
77
+ this.cancelEdit();
78
+
79
+ if (this.hasValidSelection()) {
80
+ this.$readName.text(this.items[this.selected].name);
81
+ this.$readShort.text(this.items[this.selected].shortDescription);
82
+ this.$readFull.text(this.items[this.selected].fullDescription);
83
+ }
84
+ else {
85
+ this.$readName.text("Please select an item from the list.");
86
+ this.$readShort.text("");
87
+ this.$readFull.text("");
88
+ }
89
+ }
90
+
91
+ editSelectedItem() {
92
+ if (this.hasValidSelection()) {
93
+ if (this.state != "editing") {
94
+ this.$read.addClass("invisible");
95
+ }
96
+
97
+ this.state = "editing";
98
+ this.$edit.removeClass("invisible");
99
+
100
+ this.$editName.val(this.items[this.selected].name);
101
+ this.$editShort.val(this.items[this.selected].shortDescription);
102
+ this.$editFull.val(this.items[this.selected].fullDescription);
103
+ }
104
+ }
105
+
106
+ async saveSelectedItem() {
107
+ if (this.state === "editing") {
108
+ try {
109
+ await $.post("/item", {
110
+ id: this.items[this.selected]._id,
111
+ name: this.$editName.val(),
112
+ shortDescription: this.$editShort.val(),
113
+ fullDescription: this.$editFull.val(),
114
+ }, () => {
115
+ this.items[this.selected].name = this.$editName.val();
116
+ this.items[this.selected].shortDescription = this.$editShort.val();
117
+ this.items[this.selected].fullDescription = this.$editFull.val();
118
+ this.cancelEdit();
119
+ this.updateItems();
120
+ });
121
+ }
122
+ catch(err) {
123
+ console.log(err);
124
+ }
125
+ }
126
+ }
127
+
128
+ cancelEdit() {
129
+ if (this.state === "editing") {
130
+ this.$edit.addClass("invisible");
131
+ this.$read.removeClass("invisible");
132
+ this.state = "reading";
133
+ }
134
+ }
135
+
136
+ async deleteSelectedItem() {
137
+ if (this.state === "reading" && this.hasValidSelection()) {
138
+ try {
139
+ await $.post("/item/delete", {
140
+ id: this.items[this.selected]._id
141
+ }, () => {
142
+ this.selectItem(-1);
143
+ this.updateItems();
144
+ });
145
+ }
146
+ catch(err) {
147
+ console.log(err);
148
+ }
149
+ }
150
+ }
151
+ }
152
+
153
+ let itemFloor = new ItemFloor();
154
+
155
+
156
+
157
+
158
+
159
+
160
+ $(".floor button#toggle").on("click", function (e) {
161
+ $(e.target.parentElement).find(".content").toggleClass("invisible");
162
+ });
@@ -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,34 @@
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
+ console.log(poi.data);
8
+ if (!poi.data) poi.data = {
9
+ timer: 0,
10
+ lastTime: now
11
+ }
12
+ else {
13
+ if (!poi.data.lastTime) poi.data.lastTime = now;
14
+ if (!poi.data.timer) poi.data.timer = 0;
15
+ }
16
+ console.log(poi.data);
17
+
18
+ let difference = (now - poi.data.lastTime) / 1000;
19
+ poi.data.timer -= difference;
20
+ if (poi.data.timer < 0) poi.data.timer = 0;
21
+
22
+ console.log(poi.data);
23
+ poi.data.timer = poi.data.timer + 10;
24
+ poi.data.lastTime = Date.now();
25
+
26
+ poi.markModified("data");
27
+ await poi.save();
28
+ return poi.data.timer;
29
+ }
30
+ catch(err) {
31
+ console.log(err);
32
+ return false;
33
+ }
34
+ }
@@ -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
+ }
@@ -0,0 +1,92 @@
1
+ :root {
2
+ --bgColor: rgb(37, 37, 37);
3
+ --bgColorBright: rgb(66, 66, 66);
4
+ --shadowColor: rgb(26, 26, 26);
5
+ --textColor: rgb(185, 135, 69);
6
+ --textColorBright: rgb(221, 181, 130);
7
+ --standardBorder: 1px solid var(--textColor);
8
+ --standardRadius: 5px;
9
+ }
10
+
11
+ .floor#items ul.items {
12
+ width: 40%;
13
+ height: 800px;
14
+ border: var(--standardBorder);
15
+ padding: 5px;
16
+ margin: 0;
17
+ }
18
+
19
+ .floor#items ul.items li {
20
+ list-style: none;
21
+ cursor: pointer;
22
+ }
23
+
24
+ .floor#items ul.items li:hover {
25
+ background-color: var(--bgColorBright);
26
+ }
27
+
28
+ .floor#items ul.items li.selected {
29
+ background-color: var(--shadowColor);
30
+ }
31
+
32
+ .floor#items .editor {
33
+ width: 55%;
34
+ height: 800px;
35
+ border: var(--standardBorder);
36
+ padding: 10px;
37
+ }
38
+
39
+ .floor#items .read h5 {
40
+ margin: 10px;
41
+ }
42
+
43
+ .floor#items .read #name {
44
+ margin: 20px;
45
+ }
46
+
47
+ .floor#items .read #short {
48
+ width: 100%;
49
+ height: 100px;
50
+ border: var(--standardBorder);
51
+ padding: 2px;
52
+ }
53
+
54
+ .floor#items .read #full {
55
+ width: 100%;
56
+ height: 250px;
57
+ border: var(--standardBorder);
58
+ padding: 2px;
59
+ }
60
+
61
+ .floor#items .edit h5 {
62
+ margin: 10px;
63
+ }
64
+
65
+
66
+ .floor {
67
+ width: 100%;
68
+ min-height: 50px;
69
+ border: 1px solid var(--shadowColor);
70
+ background-color: var(--bgColor);
71
+ padding: 10px;
72
+ display: flex;
73
+ align-items: flex-start;
74
+ justify-content: center;
75
+ flex-wrap: wrap;
76
+ }
77
+
78
+ .floor h2 {
79
+ width: 90%;
80
+ }
81
+
82
+ .floor button {
83
+ margin: 0;
84
+ }
85
+
86
+ .floor .content {
87
+ width: 100%;
88
+ display: flex;
89
+ align-items: flex-start;
90
+ justify-content: center;
91
+ flex-wrap: wrap;
92
+ }
@@ -4,10 +4,58 @@
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
+
12
+ <hr>
13
+
14
+ <button onclick="tradeForDoll()">Trade 5g for a doll</button>
15
+
16
+ <hr>
17
+
18
+ <section class="floor" id="items">
19
+ <h2>Items</h2>
20
+ <button id="toggle">Toggle</button>
21
+
22
+ <div class="content invisible">
23
+ <ul class="items">
24
+
25
+ </ul>
26
+
27
+ <div class="editor">
28
+ <div class="edit invisible">
29
+ <h5>Item Name:</h5>
30
+ <input type="text" id="name">
31
+
32
+ <h5>Short Item Description:</h5>
33
+ <textarea id="short" name="short" cols="30" rows="3"></textarea>
34
+
35
+ <h5>Full Item Description:</h5>
36
+ <textarea id="full" name="full" cols="30" rows="10"></textarea>
37
+
38
+ <button id="cancel" onclick="itemFloor.cancelEdit()">Cancel</button>
39
+ <button id="save" onclick="itemFloor.saveSelectedItem()">Save</button>
40
+ </div>
41
+
42
+ <div class="read">
43
+ <h5 id="name">Item Name</h5>
44
+
45
+ <h5>Short Item Description:</h5>
46
+ <p id="short"></p>
47
+
48
+ <h5>Full Item Description:</h5>
49
+ <p id="full"></p>
50
+
51
+ <button id="new" onclick="itemFloor.createNewItem()">Create New</button>
52
+ <button id="edit" onclick="itemFloor.editSelectedItem()">Edit</button>
53
+ <button id="delete" onclick="itemFloor.deleteSelectedItem()">Delete</button>
54
+ <button id="refresh" onclick="itemFloor.updateItems()">Refresh List</button>
55
+ </div>
56
+ </div>
57
+ </div>
58
+ </section>
11
59
 
12
60
  <hr>
13
61
 
@@ -17,4 +65,44 @@
17
65
 
18
66
  <a href="/coast/tall-beach/nono-cove/nono-og" class="to">
19
67
  Go to Nono Cove
20
- </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>
@@ -1,66 +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"],
30
- serverScripts: ["game"]
31
- }
32
- },
33
- {
34
- name: "nono-og",
35
- options: {
36
- localScripts: ["nono"],
37
- styles: ["nono"],
38
- requiredItems: [
39
- "Gold Coin"
40
- ]
41
- }
42
- }
43
- ]
44
- }
45
- ]
46
- }
47
- ]
48
- }
49
- ]
50
- },
51
- theFront: {
52
- name: "the-front",
53
- dirname: __dirname,
54
- options: {},
55
- details: [
56
- {
57
- name: "",
58
- options: {
59
- requiredItems: ["Gold Coin"]
60
- }
61
- }
62
- ]
63
- }
64
- };
65
-
66
- 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,14 +38,14 @@
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
 
47
- await $.post("/inventory", change, (data, status) => {
48
- if (status === "success") {
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
- else console.log(status);
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() {
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
- }