notherbase-fs 3.1.6 → 3.2.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.
@@ -8,6 +8,24 @@ import fs from 'fs';
8
8
  * The spirit world is the API of a base.
9
9
  */
10
10
  export default class SpiritWorld {
11
+ /**
12
+ * Sets up the spirit world.
13
+ * @param {Server} io
14
+ */
15
+ constructor(io) {
16
+ this.io = io;
17
+ this.rooms = {};
18
+
19
+ this.router = express.Router();
20
+ this.user = new User();
21
+
22
+ this.router.post("/load", this.load);
23
+ this.router.post("/serve", this.serve);
24
+ this.router.use("/user", this.user.router);
25
+
26
+ this.io.on('connection', this.#setupChat);
27
+ }
28
+
11
29
  /**
12
30
  * Sets up socket.io for instant messaging and etc.
13
31
  * @param {*} socket
@@ -22,8 +40,6 @@ export default class SpiritWorld {
22
40
  ]
23
41
  }
24
42
  }
25
-
26
- console.log(this.rooms[socket.handshake.query.room]);
27
43
 
28
44
  this.io.to(socket.handshake.query.room).emit("chat message", {
29
45
  name: "Server",
@@ -68,24 +84,6 @@ export default class SpiritWorld {
68
84
  });
69
85
  }
70
86
 
71
- /**
72
- * Sets up the spirit world.
73
- * @param {Server} io
74
- */
75
- constructor(io) {
76
- this.io = io;
77
- this.rooms = {};
78
-
79
- this.router = express.Router();
80
- this.user = new User();
81
-
82
- this.router.post("/load", this.load);
83
- this.router.post("/serve", this.serve);
84
- this.router.use("/user", this.user.router);
85
-
86
- this.io.on('connection', this.#setupChat);
87
- }
88
-
89
87
  /**
90
88
  * This API route requests a spirit from the database.
91
89
  * @param {Object} req
@@ -125,7 +123,7 @@ export default class SpiritWorld {
125
123
  let user = await req.db.User.recallOne(req.session.currentUser);
126
124
 
127
125
  script = await import(scriptPath);
128
- result = await script.default(req, user);
126
+ result = await script.default(req, user, this.io);
129
127
  success(res, "Served.", result);
130
128
  }
131
129
  else fail(res, `Script not found: ${req.body.script} at ${scriptPath}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notherbase-fs",
3
- "version": "3.1.6",
3
+ "version": "3.2.0",
4
4
  "description": "Functions to help make developing for NotherBase easier.",
5
5
  "exports": "./notherbase-fs.js",
6
6
  "scripts": {
@@ -72,7 +72,7 @@ class ChatBox {
72
72
  render() {
73
73
  this.$div.empty();
74
74
 
75
- this.$header = $(`<h4>Chatting with the name ${this.username}:`).appendTo(this.$div);
75
+ this.$header = $(`<h4>Chatting with the name ${this.username}:</h4>`).appendTo(this.$div);
76
76
  this.$chatLog = $(`<div class="chat-log"></div>`).appendTo(this.$div);
77
77
  this.$users = $(`<ul class="users"></ul>`).appendTo(this.$div);
78
78
  this.$entry = $(`<input autocomplete="off" type="text" class="chat-entry">`).appendTo(this.$div);
@@ -62,4 +62,5 @@
62
62
  width: 20%;
63
63
  height: 300px;
64
64
  border: var(--standardBorder);
65
+ margin: 0;
65
66
  }
@@ -0,0 +1,3 @@
1
+ .flipped {
2
+ background: black;
3
+ }
@@ -0,0 +1,10 @@
1
+ export default async (req, user, io) => {
2
+ let bigSwitch = await req.db.Spirit.recallOne("big-switch");
3
+
4
+ if (!bigSwitch.memory.data.flipped) await bigSwitch.commit({ flipped: true });
5
+ else await bigSwitch.commit({ flipped: false });
6
+ console.log(bigSwitch.memory.data);
7
+
8
+ io.to("big-switch").emit("big-switch", { flipped: bigSwitch.memory.data.flipped });
9
+ return "success";
10
+ }
@@ -1,3 +1,7 @@
1
+ <style>
2
+ <%- include("./check.css"); %>
3
+ </style>
4
+
1
5
  <h1>The Big Check</h1>
2
6
 
3
7
  <hr>
@@ -5,6 +9,7 @@
5
9
  <button onclick="base.do('add-more-gold')">+3</button>
6
10
  <button onclick="base.do('subtract-gold')">-30</button>
7
11
  <button onclick="base.do('emailTime')">email</button>
12
+ <button class="switch" onclick="base.do('flip')">Flip Me</button>
8
13
  <input type="text" id="test" placeholder="Loading...">
9
14
  <button onclick="saveInput()">Save</button>
10
15
 
@@ -27,4 +32,20 @@
27
32
 
28
33
  base.do("save-input", { text: inp });
29
34
  }
35
+
36
+ let switchSocket = io({
37
+ query: {
38
+ room: "big-switch",
39
+ name: "player"
40
+ }
41
+ });
42
+
43
+ switchSocket.on('big-switch', (update) => {
44
+ flipSwitch(update.flipped);
45
+ });
46
+
47
+ let flipSwitch = function flipSwitch(flipped) {
48
+ if (flipped) $(".switch").addClass("flipped");
49
+ else $(".switch").removeClass("flipped");
50
+ }
30
51
  </script>
@@ -1,7 +1,8 @@
1
- export default async (req, user) => {
1
+ export default async (req, user, io) => {
2
2
  let spirit = await req.db.Spirit.recallOne("test-save3", user.id);
3
+ console.log(req.body);
3
4
 
4
5
  await spirit.commit({
5
- text: req.body.data.text
6
+ text: req.body.text
6
7
  });
7
8
  }