notherbase-fs 4.0.22 → 4.0.23

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.
Files changed (54) hide show
  1. package/README.md +6 -6
  2. package/controllers/creation.js +147 -147
  3. package/controllers/spirit-world.js +174 -174
  4. package/controllers/user.js +240 -240
  5. package/controllers/util.js +64 -64
  6. package/models/index.js +33 -33
  7. package/models/send-mail.js +58 -58
  8. package/models/spirit.js +234 -234
  9. package/notherbase-fs.js +112 -112
  10. package/package.json +40 -40
  11. package/public/js/base.js +222 -227
  12. package/public/js/chat-box.js +120 -120
  13. package/test/coast/tall-beach/nono-cove/index.css +17 -17
  14. package/test/coast/tall-beach/nono-cove/index.ejs +29 -29
  15. package/test/coast/tall-beach/nono-cove/nono-og/add-gold.js +15 -15
  16. package/test/coast/tall-beach/nono-cove/nono-og/index.ejs +46 -46
  17. package/test/coast/tall-beach/nono-cove/nono-og/nono.css +88 -88
  18. package/test/coast/tall-beach/nono-cove/nono-og/nono.js +207 -207
  19. package/test/pages/test-page/emailTime.js +8 -8
  20. package/test/pages/test-page/index.ejs +104 -104
  21. package/test/pages/void/index.ejs +35 -35
  22. package/test/pages/void/void.css +2 -2
  23. package/test/public/styles/main.css +792 -792
  24. package/test/the-front/add-gold.js +13 -13
  25. package/test/the-front/check/check.css +2 -2
  26. package/test/the-front/check/emailTime.js +9 -9
  27. package/test/the-front/check/flip.js +9 -9
  28. package/test/the-front/check/index.ejs +54 -54
  29. package/test/the-front/check/save-input.js +7 -7
  30. package/test/the-front/index.ejs +116 -99
  31. package/test/the-front/keeper/clipboards.js +133 -133
  32. package/test/the-front/keeper/index.ejs +80 -80
  33. package/test/the-front/keeper/keeper.css +157 -157
  34. package/test/the-front/keeper/keeper.js +140 -140
  35. package/test-index.js +19 -19
  36. package/test2/pages/test-page/emailTime.js +8 -8
  37. package/test2/pages/test-page/index.ejs +104 -104
  38. package/test2/pages/void/index.ejs +35 -35
  39. package/test2/pages/void/void.css +2 -2
  40. package/test2/public/styles/main.css +792 -792
  41. package/test2/the-front/add-gold.js +13 -13
  42. package/test2/the-front/check/check.css +2 -2
  43. package/test2/the-front/check/emailTime.js +9 -9
  44. package/test2/the-front/check/flip.js +9 -9
  45. package/test2/the-front/check/index.ejs +54 -54
  46. package/test2/the-front/check/save-input.js +7 -7
  47. package/test2/the-front/index.ejs +99 -99
  48. package/test2/the-front/keeper/clipboards.js +133 -133
  49. package/test2/the-front/keeper/index.ejs +80 -80
  50. package/test2/the-front/keeper/keeper.css +157 -157
  51. package/test2/the-front/keeper/keeper.js +140 -140
  52. package/views/explorer.ejs +82 -82
  53. package/views/footer.ejs +9 -9
  54. package/views/head.ejs +17 -17
@@ -1,208 +1,208 @@
1
- let tileSize = 30;
2
-
3
- class NonoTile {
4
- constructor (game, $field, position, modifier) {
5
- this.$div = $field.append(`<div class="nono-tile" id="${position[0]},${position[1]}"></div>`).children().last();
6
- this.$div.css("width", tileSize);
7
- this.$div.css("height", tileSize);
8
- this.position = position;
9
- this.state = "blank";
10
- this.$div.addClass(this.state);
11
- this.correctState = this.getRandomState(modifier);
12
- this.solved = this.checkIfSolved();
13
- this.game = game;
14
-
15
- this.$div.on("click", this.clicked);
16
- }
17
-
18
- getRandomState(modifier) {
19
- let roll = Math.floor(Math.random() * (2 + modifier));
20
- if (roll < 1) return "blank";
21
- else return "punched";
22
- }
23
-
24
- checkIfSolved() {
25
- if ((this.state === "blank" || this.state === "marked") && this.correctState === "blank") return true;
26
- else if (this.state === "punched" && this.correctState === "punched") return true;
27
- else return false;
28
- }
29
-
30
- clicked = () => {
31
- this.$div.removeClass(this.state);
32
-
33
- if (this.state === "blank") this.state = "marked";
34
- else if (this.state === "marked") this.state = "punched";
35
- else if (this.state === "punched") this.state = "blank";
36
-
37
- this.$div.addClass(this.state);
38
-
39
- this.solved = this.checkIfSolved();
40
- this.game.tryFinishGame();
41
- }
42
- }
43
-
44
- class NonoGame {
45
- constructor () {
46
- this.difficulty = 0;
47
- this.level = 2;
48
- this.$board = $("#nono-board");
49
- this.$field = null;
50
- this.dimensions = [this.level, this.level];
51
- this.hints = [[], []];
52
- this.tiles = [];
53
- this.nonoSize = 100;
54
- this.maxNonoId = 4;
55
- this.goldItem = "Gold Coin";
56
-
57
- this.startNew();
58
- }
59
-
60
- startNew() {
61
- this.dimensions = [this.level, this.level];
62
-
63
- this.$board.empty();
64
- this.$board.css("width", this.dimensions[0] * (tileSize) + this.nonoSize + 5);
65
- this.$board.css("height", this.dimensions[1] * (tileSize) + this.nonoSize + 5);
66
-
67
- let $nono = this.$board.append(`<img class="nono" src="/img/logo.png">`).children().last();
68
- $nono.css("width", this.nonoSize);
69
- $nono.css("height", this.nonoSize);
70
-
71
- let $topHints = this.$board.append(`<div class="top hints"></div>`).children().last();
72
- $topHints.css("width", this.dimensions[0] * tileSize);
73
- $topHints.css("height", this.nonoSize);
74
-
75
- let $columns = [];
76
- for (let i = 0; i < this.dimensions[0]; i++) {
77
- let $newColumn = $topHints.append(`<div class="column"></div>`).children().last();
78
- $newColumn.css("width", tileSize);
79
- $columns.push($newColumn);
80
- }
81
-
82
- let $sideHints = this.$board.append(`<div class="side hints"></div>`).children().last();
83
- $sideHints.css("width", this.nonoSize);
84
- $sideHints.css("height", this.dimensions[1] * tileSize);
85
-
86
- let $rows = [];
87
- for (let i = 0; i < this.dimensions[1]; i++) {
88
- let $newRow = $sideHints.append(`<div class="row"></div>`).children().last();
89
- $newRow.css("height", tileSize);
90
- $rows.push($newRow);
91
- }
92
-
93
- this.$field = this.$board.append(`<div class="nono-field"></div>`).children().last();
94
- this.$field.css("width", this.dimensions[0] * tileSize);
95
- this.$field.css("height", this.dimensions[1] * tileSize);
96
-
97
- this.tiles = this.generateTiles();
98
- this.hints = this.generateHints();
99
-
100
- for (let i = 0; i < this.dimensions[0]; i++) {
101
- for (let j = 0; j < this.hints[0][i].length; j++) {
102
- $columns[i].append(`<p class="hint">${this.hints[0][i][j]}</p>`);
103
- }
104
- }
105
-
106
- for (let i = 0; i < this.dimensions[1]; i++) {
107
- for (let j = 0; j < this.hints[1][i].length; j++) {
108
- $rows[i].append(`<p class="hint">${this.hints[1][i][j]}</p>`);
109
- }
110
- }
111
-
112
- if (this.checkForSolve()) {
113
- console.log("Randomly generated nothing!");
114
- this.startNew();
115
- }
116
- }
117
-
118
- generateTiles() {
119
- let tiles = [];
120
-
121
- for (let i = 0; i < this.dimensions[0]; i++) {
122
- for (let j = 0; j < this.dimensions[1]; j++) {
123
- tiles.push(new NonoTile(
124
- this,
125
- this.$field,
126
- [i, j],
127
- 1 - (this.difficulty / 10)
128
- ));
129
- }
130
- }
131
-
132
- return tiles;
133
- }
134
-
135
- generateHints() {
136
- let hints = [[], []];
137
-
138
- for (let i = 0; i < this.dimensions[0]; i++) {
139
- let current = 0;
140
- hints[0].push([]);
141
-
142
- for (let j = 0; j < this.dimensions[1]; j++) {
143
- if (this.tiles[j * this.dimensions[0] + i].correctState === "punched") current++;
144
- else if (current > 0) {
145
- hints[0][i].push(current);
146
- current = 0;
147
- }
148
- }
149
-
150
- if (current > 0 || hints[0][i].length < 1) {
151
- hints[0][i].push(current);
152
- }
153
- }
154
-
155
- for (let i = 0; i < this.dimensions[1]; i++) {
156
- let current = 0;
157
- hints[1].push([]);
158
-
159
- for (let j = 0; j < this.dimensions[0]; j++) {
160
- if (this.tiles[i * this.dimensions[0] + j].correctState === "punched") current++;
161
- else if (current > 0) {
162
- hints[1][i].push(current);
163
- current = 0;
164
- }
165
- }
166
-
167
- if (current > 0 || hints[1][i].length < 1) hints[1][i].push(current);
168
- }
169
-
170
- return hints;
171
- }
172
-
173
- checkForSolve() {
174
- let solved = true;
175
-
176
- for (let i = 0; i < this.tiles.length; i++) {
177
- if (!this.tiles[i].solved) {
178
- solved = false;
179
- break;
180
- }
181
- }
182
-
183
- return solved;
184
- }
185
-
186
- tryFinishGame() {
187
- if (this.checkForSolve()) {
188
- base.do("add-gold");
189
-
190
- let $tiles = $(".nono-tile");
191
- $tiles.off("click");
192
- $tiles.addClass("borderless");
193
- $tiles = $(".nono-tile.marked");
194
- $tiles.addClass("blank");
195
- $tiles.removeClass("marked");
196
-
197
- this.level++;
198
- if (this.level > 10) {
199
- this.difficulty += this.level - 10;
200
- if (this.difficulty > 10) this.difficulty = 10;
201
- this.level -= 10;
202
- }
203
- setTimeout(() => {this.startNew();}, 2000);
204
- }
205
- }
206
- }
207
-
1
+ let tileSize = 30;
2
+
3
+ class NonoTile {
4
+ constructor (game, $field, position, modifier) {
5
+ this.$div = $field.append(`<div class="nono-tile" id="${position[0]},${position[1]}"></div>`).children().last();
6
+ this.$div.css("width", tileSize);
7
+ this.$div.css("height", tileSize);
8
+ this.position = position;
9
+ this.state = "blank";
10
+ this.$div.addClass(this.state);
11
+ this.correctState = this.getRandomState(modifier);
12
+ this.solved = this.checkIfSolved();
13
+ this.game = game;
14
+
15
+ this.$div.on("click", this.clicked);
16
+ }
17
+
18
+ getRandomState(modifier) {
19
+ let roll = Math.floor(Math.random() * (2 + modifier));
20
+ if (roll < 1) return "blank";
21
+ else return "punched";
22
+ }
23
+
24
+ checkIfSolved() {
25
+ if ((this.state === "blank" || this.state === "marked") && this.correctState === "blank") return true;
26
+ else if (this.state === "punched" && this.correctState === "punched") return true;
27
+ else return false;
28
+ }
29
+
30
+ clicked = () => {
31
+ this.$div.removeClass(this.state);
32
+
33
+ if (this.state === "blank") this.state = "marked";
34
+ else if (this.state === "marked") this.state = "punched";
35
+ else if (this.state === "punched") this.state = "blank";
36
+
37
+ this.$div.addClass(this.state);
38
+
39
+ this.solved = this.checkIfSolved();
40
+ this.game.tryFinishGame();
41
+ }
42
+ }
43
+
44
+ class NonoGame {
45
+ constructor () {
46
+ this.difficulty = 0;
47
+ this.level = 2;
48
+ this.$board = $("#nono-board");
49
+ this.$field = null;
50
+ this.dimensions = [this.level, this.level];
51
+ this.hints = [[], []];
52
+ this.tiles = [];
53
+ this.nonoSize = 100;
54
+ this.maxNonoId = 4;
55
+ this.goldItem = "Gold Coin";
56
+
57
+ this.startNew();
58
+ }
59
+
60
+ startNew() {
61
+ this.dimensions = [this.level, this.level];
62
+
63
+ this.$board.empty();
64
+ this.$board.css("width", this.dimensions[0] * (tileSize) + this.nonoSize + 5);
65
+ this.$board.css("height", this.dimensions[1] * (tileSize) + this.nonoSize + 5);
66
+
67
+ let $nono = this.$board.append(`<img class="nono" src="/img/logo.png">`).children().last();
68
+ $nono.css("width", this.nonoSize);
69
+ $nono.css("height", this.nonoSize);
70
+
71
+ let $topHints = this.$board.append(`<div class="top hints"></div>`).children().last();
72
+ $topHints.css("width", this.dimensions[0] * tileSize);
73
+ $topHints.css("height", this.nonoSize);
74
+
75
+ let $columns = [];
76
+ for (let i = 0; i < this.dimensions[0]; i++) {
77
+ let $newColumn = $topHints.append(`<div class="column"></div>`).children().last();
78
+ $newColumn.css("width", tileSize);
79
+ $columns.push($newColumn);
80
+ }
81
+
82
+ let $sideHints = this.$board.append(`<div class="side hints"></div>`).children().last();
83
+ $sideHints.css("width", this.nonoSize);
84
+ $sideHints.css("height", this.dimensions[1] * tileSize);
85
+
86
+ let $rows = [];
87
+ for (let i = 0; i < this.dimensions[1]; i++) {
88
+ let $newRow = $sideHints.append(`<div class="row"></div>`).children().last();
89
+ $newRow.css("height", tileSize);
90
+ $rows.push($newRow);
91
+ }
92
+
93
+ this.$field = this.$board.append(`<div class="nono-field"></div>`).children().last();
94
+ this.$field.css("width", this.dimensions[0] * tileSize);
95
+ this.$field.css("height", this.dimensions[1] * tileSize);
96
+
97
+ this.tiles = this.generateTiles();
98
+ this.hints = this.generateHints();
99
+
100
+ for (let i = 0; i < this.dimensions[0]; i++) {
101
+ for (let j = 0; j < this.hints[0][i].length; j++) {
102
+ $columns[i].append(`<p class="hint">${this.hints[0][i][j]}</p>`);
103
+ }
104
+ }
105
+
106
+ for (let i = 0; i < this.dimensions[1]; i++) {
107
+ for (let j = 0; j < this.hints[1][i].length; j++) {
108
+ $rows[i].append(`<p class="hint">${this.hints[1][i][j]}</p>`);
109
+ }
110
+ }
111
+
112
+ if (this.checkForSolve()) {
113
+ console.log("Randomly generated nothing!");
114
+ this.startNew();
115
+ }
116
+ }
117
+
118
+ generateTiles() {
119
+ let tiles = [];
120
+
121
+ for (let i = 0; i < this.dimensions[0]; i++) {
122
+ for (let j = 0; j < this.dimensions[1]; j++) {
123
+ tiles.push(new NonoTile(
124
+ this,
125
+ this.$field,
126
+ [i, j],
127
+ 1 - (this.difficulty / 10)
128
+ ));
129
+ }
130
+ }
131
+
132
+ return tiles;
133
+ }
134
+
135
+ generateHints() {
136
+ let hints = [[], []];
137
+
138
+ for (let i = 0; i < this.dimensions[0]; i++) {
139
+ let current = 0;
140
+ hints[0].push([]);
141
+
142
+ for (let j = 0; j < this.dimensions[1]; j++) {
143
+ if (this.tiles[j * this.dimensions[0] + i].correctState === "punched") current++;
144
+ else if (current > 0) {
145
+ hints[0][i].push(current);
146
+ current = 0;
147
+ }
148
+ }
149
+
150
+ if (current > 0 || hints[0][i].length < 1) {
151
+ hints[0][i].push(current);
152
+ }
153
+ }
154
+
155
+ for (let i = 0; i < this.dimensions[1]; i++) {
156
+ let current = 0;
157
+ hints[1].push([]);
158
+
159
+ for (let j = 0; j < this.dimensions[0]; j++) {
160
+ if (this.tiles[i * this.dimensions[0] + j].correctState === "punched") current++;
161
+ else if (current > 0) {
162
+ hints[1][i].push(current);
163
+ current = 0;
164
+ }
165
+ }
166
+
167
+ if (current > 0 || hints[1][i].length < 1) hints[1][i].push(current);
168
+ }
169
+
170
+ return hints;
171
+ }
172
+
173
+ checkForSolve() {
174
+ let solved = true;
175
+
176
+ for (let i = 0; i < this.tiles.length; i++) {
177
+ if (!this.tiles[i].solved) {
178
+ solved = false;
179
+ break;
180
+ }
181
+ }
182
+
183
+ return solved;
184
+ }
185
+
186
+ tryFinishGame() {
187
+ if (this.checkForSolve()) {
188
+ base.do("add-gold");
189
+
190
+ let $tiles = $(".nono-tile");
191
+ $tiles.off("click");
192
+ $tiles.addClass("borderless");
193
+ $tiles = $(".nono-tile.marked");
194
+ $tiles.addClass("blank");
195
+ $tiles.removeClass("marked");
196
+
197
+ this.level++;
198
+ if (this.level > 10) {
199
+ this.difficulty += this.level - 10;
200
+ if (this.difficulty > 10) this.difficulty = 10;
201
+ this.level -= 10;
202
+ }
203
+ setTimeout(() => {this.startNew();}, 2000);
204
+ }
205
+ }
206
+ }
207
+
208
208
  let nonoGame = new NonoGame();
@@ -1,9 +1,9 @@
1
- export default async function emailTime(req, user) {
2
- await req.db.SendMail.send(
3
- req.body.data.toEmail,
4
- req.body.data.subject,
5
- req.body.data.html
6
- );
7
-
8
- return "Sent";
1
+ export default async function emailTime(req, user) {
2
+ await req.db.SendMail.send(
3
+ req.body.data.toEmail,
4
+ req.body.data.subject,
5
+ req.body.data.html
6
+ );
7
+
8
+ return "Sent";
9
9
  }
@@ -1,105 +1,105 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Test</title>
6
- <meta name="viewport" content="width=device-width,initial-scale=1.0">
7
- <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
8
- <link rel="preconnect" href="https://fonts.googleapis.com">
9
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10
- <!-- font-family: 'Roboto' or 'Roboto Condensed', sans-serif; -->
11
- <link href="https://fonts.googleapis.com/css2?family=Roboto&family=Roboto+Condensed:wght@700&display=swap" rel="stylesheet">
12
- <!-- 'Redacted Script', cursive; -->
13
- <link href="https://fonts.googleapis.com/css2?family=Redacted+Script:wght@300&display=swap" rel="stylesheet">
14
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
15
- <link rel="stylesheet" href="/styles/main.css">
16
- <link rel="stylesheet" href="/styles/menu.css">
17
- <link rel="stylesheet" href="/styles/inventory.css">
18
- <link rel="stylesheet" href="/styles/player.css">
19
- <link rel="stylesheet" href="/styles/account.css">
20
- <link rel="stylesheet" href="/styles/more.css">
21
- <link rel="stylesheet" href="/styles/chat.css">
22
- <script src="/js/base.js"></script>
23
- </head>
24
- <script>
25
- const currentRoute = "<%- route %>";
26
- </script>
27
-
28
- <body>
29
- <main>
30
- <div class="chatter" id="adam"></div>
31
- <input type="text" id="adam">
32
- <button id="adam">Chat</button>
33
- </main>
34
- </body>
35
-
36
- <script>
37
- class Spirit {
38
- constructor(name) {
39
- this.name = name;
40
- this.children = {};
41
- }
42
-
43
- addChild(child, parent) {
44
- if (!this.children[child.name]) {
45
- this.children[child.name] = 1;
46
- }
47
-
48
- this.children[child.name]++;
49
- }
50
- }
51
-
52
- class Chatter {
53
- constructor(id) {
54
- this.name = id;
55
- this.brain = new Spirit("i");
56
- this.$div = $(`.chatter#${id}`);
57
- this.$input = $(`input#${id}`);
58
- this.$submit = $(`button#${id}`);
59
-
60
- this.$submit.click(() => {
61
- this.listen(this.$input.val());
62
- });
63
- }
64
-
65
- register = (word) => {
66
- if (!this.brain[word]) {
67
- this.brain[word] = new Spirit(word);
68
- }
69
-
70
- return this.brain[word];
71
- }
72
-
73
- think = () => {
74
-
75
- }
76
-
77
- listen = (message) => {
78
- message = message.toLowerCase();
79
- let words = message.split(" ");
80
-
81
- //add words to the dialogue tree
82
- this.register(words[0]);
83
- for (let i = 0; i < words.length; i++) {
84
- if (i < words.length - 1) {
85
- let child = this.register(words[i + 1]);
86
- if (i > 0) this.brain[words[i]].addChild(child, this.brain[words[i - 1]]);
87
- else this.brain[words[i]].addChild(child, null);
88
- }
89
- }
90
-
91
- //think
92
-
93
- this.respond(message);
94
- }
95
-
96
- respond(message) {
97
- this.$div.append(`<p>${this.name}: ${message}</p>`);
98
- }
99
- }
100
-
101
- const adam = new Chatter("adam");
102
- adam.listen(`In the beginning God created the heavens and the earth`);
103
- adam.listen("if i have the first two words in a three word relationship can the third word be guessed")
104
- </script>
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Test</title>
6
+ <meta name="viewport" content="width=device-width,initial-scale=1.0">
7
+ <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
8
+ <link rel="preconnect" href="https://fonts.googleapis.com">
9
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10
+ <!-- font-family: 'Roboto' or 'Roboto Condensed', sans-serif; -->
11
+ <link href="https://fonts.googleapis.com/css2?family=Roboto&family=Roboto+Condensed:wght@700&display=swap" rel="stylesheet">
12
+ <!-- 'Redacted Script', cursive; -->
13
+ <link href="https://fonts.googleapis.com/css2?family=Redacted+Script:wght@300&display=swap" rel="stylesheet">
14
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
15
+ <link rel="stylesheet" href="/styles/main.css">
16
+ <link rel="stylesheet" href="/styles/menu.css">
17
+ <link rel="stylesheet" href="/styles/inventory.css">
18
+ <link rel="stylesheet" href="/styles/player.css">
19
+ <link rel="stylesheet" href="/styles/account.css">
20
+ <link rel="stylesheet" href="/styles/more.css">
21
+ <link rel="stylesheet" href="/styles/chat.css">
22
+ <script src="/js/base.js"></script>
23
+ </head>
24
+ <script>
25
+ const currentRoute = "<%- route %>";
26
+ </script>
27
+
28
+ <body>
29
+ <main>
30
+ <div class="chatter" id="adam"></div>
31
+ <input type="text" id="adam">
32
+ <button id="adam">Chat</button>
33
+ </main>
34
+ </body>
35
+
36
+ <script>
37
+ class Spirit {
38
+ constructor(name) {
39
+ this.name = name;
40
+ this.children = {};
41
+ }
42
+
43
+ addChild(child, parent) {
44
+ if (!this.children[child.name]) {
45
+ this.children[child.name] = 1;
46
+ }
47
+
48
+ this.children[child.name]++;
49
+ }
50
+ }
51
+
52
+ class Chatter {
53
+ constructor(id) {
54
+ this.name = id;
55
+ this.brain = new Spirit("i");
56
+ this.$div = $(`.chatter#${id}`);
57
+ this.$input = $(`input#${id}`);
58
+ this.$submit = $(`button#${id}`);
59
+
60
+ this.$submit.click(() => {
61
+ this.listen(this.$input.val());
62
+ });
63
+ }
64
+
65
+ register = (word) => {
66
+ if (!this.brain[word]) {
67
+ this.brain[word] = new Spirit(word);
68
+ }
69
+
70
+ return this.brain[word];
71
+ }
72
+
73
+ think = () => {
74
+
75
+ }
76
+
77
+ listen = (message) => {
78
+ message = message.toLowerCase();
79
+ let words = message.split(" ");
80
+
81
+ //add words to the dialogue tree
82
+ this.register(words[0]);
83
+ for (let i = 0; i < words.length; i++) {
84
+ if (i < words.length - 1) {
85
+ let child = this.register(words[i + 1]);
86
+ if (i > 0) this.brain[words[i]].addChild(child, this.brain[words[i - 1]]);
87
+ else this.brain[words[i]].addChild(child, null);
88
+ }
89
+ }
90
+
91
+ //think
92
+
93
+ this.respond(message);
94
+ }
95
+
96
+ respond(message) {
97
+ this.$div.append(`<p>${this.name}: ${message}</p>`);
98
+ }
99
+ }
100
+
101
+ const adam = new Chatter("adam");
102
+ adam.listen(`In the beginning God created the heavens and the earth`);
103
+ adam.listen("if i have the first two words in a three word relationship can the third word be guessed")
104
+ </script>
105
105
  </html>