notherbase-fs 2.0.3 → 3.0.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/creation.js +57 -59
- package/controllers/spirit-world.js +55 -74
- package/controllers/spirits/contact.js +17 -10
- package/controllers/spirits/user.js +144 -112
- package/controllers/spirits/util.js +23 -31
- package/models/index.js +54 -117
- package/models/item.js +80 -0
- package/models/send-mail.js +2 -0
- package/models/spirit.js +77 -115
- package/models/user.js +189 -0
- package/notherbase-fs.js +1 -0
- package/package.json +1 -1
- package/public/styles/main.css +12 -3
- package/test/{explorer/coast/tall-beach/nono-cove/styles → coast/tall-beach/nono-cove}/index.css +0 -0
- package/test/coast/tall-beach/nono-cove/index.ejs +29 -0
- package/test/{explorer/coast/tall-beach/nono-cove/views/nono-og.ejs → coast/tall-beach/nono-cove/nono-og/index.ejs} +2 -2
- package/test/{explorer/coast/tall-beach/nono-cove/styles → coast/tall-beach/nono-cove/nono-og}/nono.css +0 -0
- package/test/{explorer/coast/tall-beach/nono-cove/local-scripts → coast/tall-beach/nono-cove/nono-og}/nono.js +1 -1
- package/test/{explorer/coast/tall-beach/nono-cove/server-scripts → test-page}/emailTime.js +0 -0
- package/test/{pages/test.ejs → test-page/index.ejs} +0 -0
- package/test/the-front/add-gold.js +35 -0
- package/test/the-front/check/add-more-gold.js +3 -0
- package/test/the-front/check/emailTime.js +11 -0
- package/test/the-front/check/index.ejs +13 -0
- package/test/the-front/check/subtract-gold.js +3 -0
- package/test/the-front/checks.js +11 -0
- package/test/the-front/incTranslation.js +9 -0
- package/test/the-front/index.ejs +107 -0
- package/test/void/index.ejs +4 -0
- package/test/void/void.css +3 -0
- package/views/explorer.ejs +32 -41
- package/views/menu/account.ejs +39 -0
- package/views/menu/inventory.ejs +8 -0
- package/views/menu/more.ejs +5 -0
- package/views/menu/player.ejs +3 -0
- package/views/menu.ejs +20 -62
- package/views/scripts/base.js +314 -0
- package/controllers/spirits/attribute.js +0 -47
- package/controllers/spirits/inventory.js +0 -71
- package/controllers/spirits/item.js +0 -41
- package/controllers/spirits/serve.js +0 -33
- package/public/js/commune.js +0 -22
- package/public/js/establishment.js +0 -44
- package/public/js/memories.js +0 -44
- package/test/explorer/coast/tall-beach/nono-cove/local-scripts/game.js +0 -7
- package/test/explorer/coast/tall-beach/nono-cove/local-scripts/items.js +0 -162
- package/test/explorer/coast/tall-beach/nono-cove/server-scripts/getTimer.js +0 -31
- package/test/explorer/coast/tall-beach/nono-cove/styles/items-floor.css +0 -92
- package/test/explorer/coast/tall-beach/nono-cove/views/index.ejs +0 -130
- package/test/pages/server-scripts/emailTime.js +0 -15
- package/test/the-front/server-scripts/emailTime.js +0 -15
- package/test/the-front/server-scripts/getTimer.js +0 -31
- package/test/the-front/views/check.ejs +0 -93
- package/test/the-front/views/index.ejs +0 -113
- package/test/void/styles/void.css +0 -0
- package/views/account.ejs +0 -122
- package/views/inventory.ejs +0 -117
- package/views/more.ejs +0 -16
- package/views/player.ejs +0 -60
package/views/menu.ejs
CHANGED
|
@@ -1,85 +1,43 @@
|
|
|
1
|
-
<div class="fade invisible">
|
|
1
|
+
<div class="fade invisible" onclick="base.closeMenu()">
|
|
2
2
|
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
<div class="menu invisible">
|
|
6
6
|
<div class="tabs">
|
|
7
|
-
<button id="inventory">
|
|
7
|
+
<button id="inventory" onclick="base.switchTab('inventory')">
|
|
8
8
|
Inventory
|
|
9
9
|
</button>
|
|
10
|
-
<button id="player">
|
|
10
|
+
<button id="player" onclick="base.switchTab('player')">
|
|
11
11
|
Player
|
|
12
12
|
</button>
|
|
13
|
-
<button id="account">
|
|
13
|
+
<button id="account" onclick="base.switchTab('account')">
|
|
14
14
|
Account
|
|
15
15
|
</button>
|
|
16
|
-
<button id="more">
|
|
16
|
+
<button id="more" onclick="base.switchTab('more')">
|
|
17
17
|
More
|
|
18
18
|
</button>
|
|
19
19
|
</div>
|
|
20
20
|
|
|
21
|
-
<button id="close">
|
|
21
|
+
<button id="close" onclick="base.closeMenu()">
|
|
22
22
|
X
|
|
23
23
|
</button>
|
|
24
24
|
|
|
25
25
|
<div id="content-window">
|
|
26
|
-
<%- include("./inventory.ejs"); %>
|
|
27
|
-
<%- include("./player.ejs"); %>
|
|
28
|
-
<%- include("./account.ejs", { user: user }); %>
|
|
29
|
-
<%- include("./more.ejs"); %>
|
|
26
|
+
<%- include("./menu/inventory.ejs"); %>
|
|
27
|
+
<%- include("./menu/player.ejs"); %>
|
|
28
|
+
<%- include("./menu/account.ejs", { user: user }); %>
|
|
29
|
+
<%- include("./menu/more.ejs"); %>
|
|
30
30
|
</div>
|
|
31
31
|
|
|
32
|
-
<button onclick="
|
|
33
|
-
</div>
|
|
34
|
-
|
|
35
|
-
<button id="menu"><i class="fas fa-cog"></i></button>
|
|
36
|
-
|
|
37
|
-
<script>
|
|
38
|
-
let $menu = $(".menu");
|
|
39
|
-
let $fade = $(".ui .fade");
|
|
40
|
-
let menuClosing = false;
|
|
41
|
-
|
|
42
|
-
let closeMenu = function closeMenu() {
|
|
43
|
-
menuClosing = true;
|
|
44
|
-
$fade.addClass("camo");
|
|
45
|
-
|
|
46
|
-
setTimeout(() => {
|
|
47
|
-
$menu.addClass("invisible");
|
|
48
|
-
$fade.addClass("invisible");
|
|
49
|
-
menuClosing = false;
|
|
50
|
-
}, 100);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
$("button#menu").on("click", function () {
|
|
54
|
-
$menu.toggleClass("invisible");
|
|
55
|
-
$fade.removeClass("camo");
|
|
56
|
-
$fade.removeClass("invisible");
|
|
57
|
-
});
|
|
32
|
+
<button onclick="logoutViaMenu()">Logout</button>
|
|
58
33
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
$(".menu .tabs button").on("click", function (e) {
|
|
68
|
-
switchTab(e.currentTarget.id);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
let switchTab = function switchTab(id) {
|
|
72
|
-
$("#content-window .content").addClass("invisible");
|
|
73
|
-
$(".menu .tabs button").removeClass("selected");
|
|
74
|
-
$(`#content-window #${id}`).removeClass("invisible");
|
|
75
|
-
$(`.menu .tabs #${id}`).addClass("selected");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
let logout = () => {
|
|
79
|
-
$.post("/s", JSON.stringify({
|
|
80
|
-
action: "logout"
|
|
81
|
-
}), () => {location.reload();});
|
|
82
|
-
}
|
|
34
|
+
<script>
|
|
35
|
+
const logoutViaMenu = async () => {
|
|
36
|
+
let response = await base.logout();
|
|
37
|
+
console.log(response);
|
|
38
|
+
location.reload();
|
|
39
|
+
}
|
|
40
|
+
</script>
|
|
41
|
+
</div>
|
|
83
42
|
|
|
84
|
-
|
|
85
|
-
</script>
|
|
43
|
+
<button id="menu" onclick="base.openMenu()"><i class="fas fa-cog"></i></button>
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
class Base {
|
|
2
|
+
static commune = async (route, data = null, options = null) => {
|
|
3
|
+
let body = { data, ...options };
|
|
4
|
+
|
|
5
|
+
let response = null;
|
|
6
|
+
|
|
7
|
+
await $.post(route, JSON.stringify(body), (res) => {
|
|
8
|
+
response = res;
|
|
9
|
+
if (res.status != "success") console.log(`${route} - ${res}`);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
return response;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
#Inventory = class Inventory {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.items = [];
|
|
18
|
+
this.lastUpdate = 0;
|
|
19
|
+
|
|
20
|
+
<% if (user) { %>
|
|
21
|
+
this.refresh();
|
|
22
|
+
<% } %>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async refresh() {
|
|
26
|
+
let $list = $(".inventory .item-list");
|
|
27
|
+
|
|
28
|
+
let response = await Base.commune("/s/user/getInventory", {}, { _lastUpdate: this.lastUpdate });
|
|
29
|
+
|
|
30
|
+
if (response.status === "success") {
|
|
31
|
+
this.items = response.data;
|
|
32
|
+
this.lastUpdate = response.lastUpdate;
|
|
33
|
+
$list.empty();
|
|
34
|
+
|
|
35
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
36
|
+
let $new = $list.append(
|
|
37
|
+
`<div class="item-card">
|
|
38
|
+
<h5>${this.items[i].name}</h5>
|
|
39
|
+
<button id="${i}">X</button>
|
|
40
|
+
<hr>
|
|
41
|
+
<p>${this.items[i].amount}</p>
|
|
42
|
+
</div>`
|
|
43
|
+
).children().last();
|
|
44
|
+
|
|
45
|
+
$new.find("button").on("click", this.reduceItem);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this.clearError();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
clearError() {
|
|
53
|
+
let $error = $("#inventory #error");
|
|
54
|
+
|
|
55
|
+
$error.addClass("invisible");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
setError(text) {
|
|
59
|
+
let $error = $("#inventory #error");
|
|
60
|
+
|
|
61
|
+
$error.text(text);
|
|
62
|
+
$error.removeClass("invisible");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
#PlayerAttributes = class PlayerAttributes {
|
|
67
|
+
constructor() {
|
|
68
|
+
this.attributes = [];
|
|
69
|
+
this.lastUpdate = 0;
|
|
70
|
+
|
|
71
|
+
<% if (user) { %>
|
|
72
|
+
this.refresh();
|
|
73
|
+
<% } %>
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async refresh() {
|
|
77
|
+
let response = await Base.commune("/s/user/getAttributes", {}, { _lastUpdate: this.lastUpdate });
|
|
78
|
+
if (response.status === "success") {
|
|
79
|
+
this.lastUpdate = response.lastUpdate;
|
|
80
|
+
this.attributes = response.data;
|
|
81
|
+
|
|
82
|
+
this.render();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
render() {
|
|
87
|
+
let $content = $(".menu .content#player");
|
|
88
|
+
|
|
89
|
+
$content.empty();
|
|
90
|
+
|
|
91
|
+
if (this.attributes) {
|
|
92
|
+
for (const [key, value] of Object.entries(this.attributes)) {
|
|
93
|
+
$content.append(`<h3 id="${key}">${key}: ${value}</h3>`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
#AccountServices = class AccountServices {
|
|
100
|
+
constructor() {
|
|
101
|
+
this.username = "";
|
|
102
|
+
this.email = "";
|
|
103
|
+
|
|
104
|
+
<% if (user) { %>
|
|
105
|
+
this.username = "<%= user.username %>";
|
|
106
|
+
this.email = "<%= user.email %>";
|
|
107
|
+
|
|
108
|
+
this.refresh();
|
|
109
|
+
<% } %>
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
refresh() {
|
|
113
|
+
let $email = $(".content#account .setting#email p");
|
|
114
|
+
let $emailInput = $(".content#account .edit#email input");
|
|
115
|
+
let $username = $(".content#account .setting#username p");
|
|
116
|
+
let $usernameInput = $(".content#account .edit#username input");
|
|
117
|
+
|
|
118
|
+
$email.text(this.email);
|
|
119
|
+
$emailInput.val(this.email);
|
|
120
|
+
$username.text(this.username);
|
|
121
|
+
$usernameInput.val(this.username);
|
|
122
|
+
|
|
123
|
+
$(".content#account .settings").removeClass("invisible");
|
|
124
|
+
$(".content#account #please-login").addClass("invisible");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
editEmail() {
|
|
128
|
+
let $emailSetting = $(".content#account .setting#email");
|
|
129
|
+
let $emailEdit = $(".content#account .edit#email");
|
|
130
|
+
|
|
131
|
+
$emailSetting.addClass("invisible");
|
|
132
|
+
$emailEdit.removeClass("invisible");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
cancelEmail() {
|
|
136
|
+
let $email = $(".content#account .setting#email p");
|
|
137
|
+
let $emailSetting = $(".content#account .setting#email");
|
|
138
|
+
let $emailEdit = $(".content#account .edit#email");
|
|
139
|
+
let $emailInput = $(".content#account .edit#email input");
|
|
140
|
+
|
|
141
|
+
$emailSetting.removeClass("invisible");
|
|
142
|
+
$emailEdit.addClass("invisible");
|
|
143
|
+
$emailInput.val($email.text());
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async updateEmail() {
|
|
147
|
+
let $info = $(".content#account #info");
|
|
148
|
+
let $email = $(".content#account .setting#email p");
|
|
149
|
+
let $emailInput = $(".content#account .edit#email input");
|
|
150
|
+
|
|
151
|
+
let response = await Base.commune("/s/user/changeEmail", { email: $emailInput.val() });
|
|
152
|
+
|
|
153
|
+
if (response.status === "success") {
|
|
154
|
+
$email.text($emailInput.val());
|
|
155
|
+
$info.text("Email Updated.");
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
$info.text("Email Not Updated!");
|
|
159
|
+
}
|
|
160
|
+
this.cancelEmail();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
editUsername() {
|
|
164
|
+
let $usernameSetting = $(".content#account .setting#username");
|
|
165
|
+
let $usernameEdit = $(".content#account .edit#username");
|
|
166
|
+
|
|
167
|
+
$usernameSetting.addClass("invisible");
|
|
168
|
+
$usernameEdit.removeClass("invisible");
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
cancelUsername() {
|
|
172
|
+
let $usernameSetting = $(".content#account .setting#username");
|
|
173
|
+
let $usernameEdit = $(".content#account .edit#username");
|
|
174
|
+
let $usernameInput = $(".content#account .edit#username input");
|
|
175
|
+
let $username = $(".content#account .setting#username p");
|
|
176
|
+
|
|
177
|
+
$usernameSetting.removeClass("invisible");
|
|
178
|
+
$usernameEdit.addClass("invisible");
|
|
179
|
+
$usernameInput.val($username.text());
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async updateUsername() {
|
|
183
|
+
let $info = $(".content#account #info");
|
|
184
|
+
let $username = $(".content#account .setting#username p");
|
|
185
|
+
let $usernameInput = $(".content#account .edit#username input");
|
|
186
|
+
|
|
187
|
+
let response = await Base.commune("/s/user/changeUsername", { username: $usernameInput.val() });
|
|
188
|
+
|
|
189
|
+
if (response.status === "success") {
|
|
190
|
+
$username.text($usernameInput.val());
|
|
191
|
+
$info.text("Username Updated.");
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
$info.text("Username Not Updated!");
|
|
195
|
+
}
|
|
196
|
+
this.cancelUsername();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
constructor() {
|
|
201
|
+
this.playerInventory = new this.#Inventory();
|
|
202
|
+
this.playerAttributes = new this.#PlayerAttributes();
|
|
203
|
+
this.playerAccount = new this.#AccountServices();
|
|
204
|
+
this.menuClosing = false;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
closeMenu = () => {
|
|
208
|
+
let $menu = $(".ui .menu");
|
|
209
|
+
let $fade = $(".ui .fade");
|
|
210
|
+
|
|
211
|
+
if (!this.menuClosing) {
|
|
212
|
+
this.menuClosing = true;
|
|
213
|
+
$fade.addClass("camo");
|
|
214
|
+
|
|
215
|
+
setTimeout(() => {
|
|
216
|
+
$menu.addClass("invisible");
|
|
217
|
+
$fade.addClass("invisible");
|
|
218
|
+
this.menuClosing = false;
|
|
219
|
+
}, 100);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
openMenu = () => {
|
|
224
|
+
let $menu = $(".ui .menu");
|
|
225
|
+
let $fade = $(".ui .fade");
|
|
226
|
+
|
|
227
|
+
$menu.removeClass("invisible");
|
|
228
|
+
$fade.removeClass("camo");
|
|
229
|
+
$fade.removeClass("invisible");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
switchTab = function switchTab(id) {
|
|
233
|
+
$("#content-window .content").addClass("invisible");
|
|
234
|
+
$(".menu .tabs button").removeClass("selected");
|
|
235
|
+
$(`#content-window #${id}`).removeClass("invisible");
|
|
236
|
+
$(`.menu .tabs #${id}`).addClass("selected");
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
logout = async () => {
|
|
240
|
+
let response = await Base.commune("/s/user/logout");
|
|
241
|
+
|
|
242
|
+
return response;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
sendMessageToNother = async () => {
|
|
246
|
+
await Base.commune("contactNother", {
|
|
247
|
+
content: $(".menu .content#more #content").val(),
|
|
248
|
+
route: currentRoute
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
$(".menu .content#more #content").val("");
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
attemptRegister = async (email, username, password) => {
|
|
255
|
+
let response = await Base.commune("/s/user/register", {
|
|
256
|
+
email, username, password
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
return response;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
attemptLogin = async (email, password) => {
|
|
263
|
+
let response = await Base.commune("/s/user/login", {
|
|
264
|
+
email: email,
|
|
265
|
+
password: password
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
if (response.status === "success") {
|
|
269
|
+
this.playerInventory.refresh();
|
|
270
|
+
this.playerAccount.username = response.data;
|
|
271
|
+
this.playerAccount.email = email;
|
|
272
|
+
this.playerAccount.refresh();
|
|
273
|
+
this.playerAttributes.refresh();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return response;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
resetPassword = async (email, test = false) => {
|
|
280
|
+
let response = await Base.commune("/s/user/sendPasswordReset", { email, test });
|
|
281
|
+
|
|
282
|
+
return response;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
changePassword = async (token, email, password, confirmation) => {
|
|
286
|
+
let response = await Base.commune("/s/user/changePassword", { token, email, password, confirmation });
|
|
287
|
+
|
|
288
|
+
return response;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
do = async (what, data = null, route = window.location.pathname) => {
|
|
292
|
+
let response = await Base.commune("/s/serve", {
|
|
293
|
+
script: what,
|
|
294
|
+
...data
|
|
295
|
+
}, {
|
|
296
|
+
route
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
this.playerInventory.refresh();
|
|
300
|
+
this.playerAttributes.refresh();
|
|
301
|
+
|
|
302
|
+
return response;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
load = async (service, scope = "local") => {
|
|
306
|
+
let response = await $.get("/s/load", { service, scope, route: window.location.pathname });
|
|
307
|
+
|
|
308
|
+
return response;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const base = new Base();
|
|
313
|
+
|
|
314
|
+
base.switchTab("inventory");
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import {loginCheck, check, findUser, fail, success} from "./util.js";
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
attributes: async (req) => {
|
|
5
|
-
loginCheck(req);
|
|
6
|
-
|
|
7
|
-
let user = await findUser(req);
|
|
8
|
-
|
|
9
|
-
return success("Got user attributes.", user.memory.data.attributes);
|
|
10
|
-
},
|
|
11
|
-
checkAttribute: async (req) => {
|
|
12
|
-
loginCheck(req);
|
|
13
|
-
|
|
14
|
-
let user = await findUser(req);
|
|
15
|
-
let att = user.memory.data.attributes;
|
|
16
|
-
|
|
17
|
-
if (att[req.body.data.check] >= req.body.data.against) {
|
|
18
|
-
return success("Passed check.")
|
|
19
|
-
}
|
|
20
|
-
else return fail("Failed check.");
|
|
21
|
-
},
|
|
22
|
-
setAttribute: async (req) => {
|
|
23
|
-
loginCheck(req);
|
|
24
|
-
|
|
25
|
-
let user = await findUser(req);
|
|
26
|
-
|
|
27
|
-
user.memory.data.attributes[req.body.data.change] = req.body.data.to;
|
|
28
|
-
await user.commit();
|
|
29
|
-
|
|
30
|
-
return success("Attributes set.", user.memory.data.attributes);
|
|
31
|
-
},
|
|
32
|
-
incrementAttribute: async (req) => {
|
|
33
|
-
loginCheck(req);
|
|
34
|
-
|
|
35
|
-
let user = await findUser(req);
|
|
36
|
-
let att = user.memory.data.attributes;
|
|
37
|
-
|
|
38
|
-
if (att[req.body.data.change] < req.body.data.max) {
|
|
39
|
-
att[req.body.data.change]++;
|
|
40
|
-
await user.commit();
|
|
41
|
-
|
|
42
|
-
return success("Attribute incremented.", att[req.body.data.change]);
|
|
43
|
-
}
|
|
44
|
-
else return fail("Attribute maxed.", att[req.body.data.change]);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { success, check, loginCheck, findUser } from "./util.js";
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
getUserInventory: async (req) => {
|
|
5
|
-
loginCheck(req);
|
|
6
|
-
let user = await findUser(req);
|
|
7
|
-
let inv = user.memory.data.inventory;
|
|
8
|
-
|
|
9
|
-
check(inv, "User inventory not found.");
|
|
10
|
-
|
|
11
|
-
return success("User inventory found.", inv);
|
|
12
|
-
},
|
|
13
|
-
updateItemInInventory: async (req) => {
|
|
14
|
-
check(req.body.data.name && req.body.data.amount, `${req.body.data.name} ${req.body.data.amount} Check Input!`);
|
|
15
|
-
|
|
16
|
-
let item = new req.db.Item(req.body.data.name);
|
|
17
|
-
let itemData = await item.recall();
|
|
18
|
-
|
|
19
|
-
check(itemData, "Item not found in database.");
|
|
20
|
-
|
|
21
|
-
let user = await findUser(req);
|
|
22
|
-
let inv = user.memory.data.inventory;
|
|
23
|
-
|
|
24
|
-
let holding = false;
|
|
25
|
-
|
|
26
|
-
for (let j = 0; j < inv.length; j++) {
|
|
27
|
-
if (inv[j].name === req.body.data.name) {
|
|
28
|
-
holding = true;
|
|
29
|
-
|
|
30
|
-
if (inv[j].amount >= -Math.floor(req.body.data.amount)) {
|
|
31
|
-
inv[j].amount += Math.floor(req.body.data.amount);
|
|
32
|
-
|
|
33
|
-
if (inv[j].amount === 0) {
|
|
34
|
-
let empty = inv[j];
|
|
35
|
-
|
|
36
|
-
inv.splice(j, 1);
|
|
37
|
-
await user.commit();
|
|
38
|
-
|
|
39
|
-
return success("Item emptied.", empty);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
await user.commit();
|
|
43
|
-
|
|
44
|
-
return success("Item offset.", inv[j]);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
return fail(`Unable to remove ${req.body.data.amount} ${req.body.data.name}
|
|
49
|
-
from inventory because the inventory has only ${inv[j].amount}.` );
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (!holding) {
|
|
55
|
-
if (req.body.data.amount > 0) {
|
|
56
|
-
inv.push({
|
|
57
|
-
name: req.body.data.name,
|
|
58
|
-
amount: req.body.data.amount
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
await user.commit();
|
|
62
|
-
|
|
63
|
-
return success("Item offset.", inv[inv.length - 1]);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
return fail(`Unable to remove ${req.body.data.amount} ${req.body.data.name}
|
|
67
|
-
from inventory because the inventory has none.`);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { success, check } from "./util.js";
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
getAllItems: async (req) => {
|
|
5
|
-
let items = new req.db.Item();
|
|
6
|
-
let all = await items.getAll();
|
|
7
|
-
|
|
8
|
-
check(all, "Items not found.");
|
|
9
|
-
|
|
10
|
-
return success("Found items.", all);
|
|
11
|
-
},
|
|
12
|
-
getItem: async (req) => {
|
|
13
|
-
let item = new req.db.Item(req.body.data.name);
|
|
14
|
-
|
|
15
|
-
let itemData = await item.recall();
|
|
16
|
-
|
|
17
|
-
check(itemData, `Item not found: ${req.body.data.name}`);
|
|
18
|
-
|
|
19
|
-
return success("Found item.", itemData);
|
|
20
|
-
},
|
|
21
|
-
setItem: async (req) => {
|
|
22
|
-
let item = new req.db.Item(req.body.data.name);
|
|
23
|
-
|
|
24
|
-
await item.commit(req.body.data);
|
|
25
|
-
|
|
26
|
-
return success();
|
|
27
|
-
},
|
|
28
|
-
newItem: async (req) => {
|
|
29
|
-
let item = new req.db.Item(req.body.data.name);
|
|
30
|
-
|
|
31
|
-
await item.create(req.body.data);
|
|
32
|
-
|
|
33
|
-
return success();
|
|
34
|
-
},
|
|
35
|
-
deleteItem: async (req) => {
|
|
36
|
-
let item = new req.db.Item(req.body.data.name);
|
|
37
|
-
item.delete();
|
|
38
|
-
|
|
39
|
-
return success("Item deleted.");
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { findUser, success, fail } from "./util.js";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
|
|
4
|
-
let serve = async (req, scriptPath) => {
|
|
5
|
-
let script, result = null;
|
|
6
|
-
|
|
7
|
-
if (fs.existsSync(scriptPath)) {
|
|
8
|
-
let user = await findUser(req);
|
|
9
|
-
|
|
10
|
-
script = await import(scriptPath);
|
|
11
|
-
result = await script.default(req, user);
|
|
12
|
-
return success("Served.", result);
|
|
13
|
-
}
|
|
14
|
-
else return fail(`Script not found: ${req.body.data.script} at ${scriptPath}`);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default {
|
|
18
|
-
serveExplorer: async (req) => {
|
|
19
|
-
let scriptPath = `${req.contentPath}/explorer${req.body.route}/server-scripts/${req.body.data.script}.js`;
|
|
20
|
-
|
|
21
|
-
return serve(req, scriptPath);
|
|
22
|
-
},
|
|
23
|
-
serveFront: async (req) => {
|
|
24
|
-
let scriptPath = `${req.contentPath}/the-front/server-scripts/${req.body.data.script}.js`;
|
|
25
|
-
|
|
26
|
-
return serve(req, scriptPath);
|
|
27
|
-
},
|
|
28
|
-
servePages: async (req) => {
|
|
29
|
-
let scriptPath = `${req.contentPath}/pages/server-scripts/${req.body.data.script}.js`;
|
|
30
|
-
|
|
31
|
-
return serve(req, scriptPath);
|
|
32
|
-
}
|
|
33
|
-
}
|
package/public/js/commune.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const commune = async (action, data = null, options) => {
|
|
2
|
-
try {
|
|
3
|
-
let body = {
|
|
4
|
-
action,
|
|
5
|
-
data,
|
|
6
|
-
...options
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
let response = null;
|
|
10
|
-
|
|
11
|
-
let onResponse = (res) => {
|
|
12
|
-
response = res;
|
|
13
|
-
if (res.status != "success") console.log(`${res.status}: ${res.message}`, res.data);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
await $.post("/s", JSON.stringify(body), onResponse);
|
|
17
|
-
|
|
18
|
-
return response;
|
|
19
|
-
} catch (error) {
|
|
20
|
-
return error;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
class Establishment {
|
|
2
|
-
constructor() {
|
|
3
|
-
this._lastUpdate = 0;
|
|
4
|
-
this.data = {};
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
load = async (service, route = currentRoute) => {
|
|
8
|
-
if (!this.data[service]) this.data[service] = { _lastUpdate: 0 };
|
|
9
|
-
|
|
10
|
-
let response = await commune("recall", {}, {
|
|
11
|
-
service: service,
|
|
12
|
-
_lastUpdate: this.data[service]._lastUpdate,
|
|
13
|
-
route: route,
|
|
14
|
-
scope: "global",
|
|
15
|
-
parent: null
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
if (!response.isUpToDate) {
|
|
19
|
-
this.data[service] = response.data;
|
|
20
|
-
this._lastUpdate = this.data[service]._lastUpdate;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return this.data[service];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
save = async (service, dataToSave, route = currentRoute) => {
|
|
27
|
-
this._lastUpdate = Date.now();
|
|
28
|
-
dataToSave._lastUpdate = this._lastUpdate;
|
|
29
|
-
|
|
30
|
-
let response = await commune("commit", dataToSave, {
|
|
31
|
-
service: service,
|
|
32
|
-
_lastUpdate: this._lastUpdate,
|
|
33
|
-
route: route,
|
|
34
|
-
scope: "global",
|
|
35
|
-
parent: null
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
this.data[service] = dataToSave;
|
|
39
|
-
|
|
40
|
-
return response;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const establishment = new Establishment();
|