🌳
- {pagenumber}.
+ {number}.
@@ -89,7 +87,7 @@ function Page({ editing, number }) {
}
{editing && (
@@ -101,7 +99,7 @@ function Page({ editing, number }) {
{!editing && !editid && (
)}
{loggedIn && (
diff --git a/server/interpreter.js b/server/interpreter.js
index c5f2faa6..69c64abf 100644
--- a/server/interpreter.js
+++ b/server/interpreter.js
@@ -3,31 +3,57 @@ const db = new sqlite('the_big_db.db', { verbose: console.log });
var sockets = new Map();
-function interpret(context, subject, command) {
- const words = command.split(' ');
+function interpret(context, player, command) {
+ // interpret and execute a command entered by a player.
+ //
+ // context: the location the player has entered the command in from.
+ // may be null if it's executing from a script?
+ // player: the id of the player object who typed in the command.
+ // may? be null if it's executing from a script? used for output.
+ // command: the full string typed in by the player
- const verbs = findVerbs(context, subject);
+ const socket = sockets.get(player)
+ const words = command.trim().split(' ');
+
+ socket?.send(`interpreting and executing the received command: ${command}`);
+
+ const verbs = findAvailableVerbs(context, player, command);
+ socket?.send(`found these verbs: ${Array.from(verbs.keys()).join(', ')}`)
+
// first word is either a subject or a verb. either way there must be a verb.
- // check if the first word is in the list of verbs.
const [first, second, third, ...rest] = words;
+
+ // if the second word is a verb, but the first word is also a verb, what do we do?
if (second in verbs) {
- executeVerb(verbs.get(second), first, third, ...rest);
+ // for now, assume that if the second word is a verb, it's the verb we want.
+ executeVerb(player, verbs.get(second), first, third, ...rest);
} else {
- executeVerb(verbs.get(first), subject, second, third, ...rest)
+ // if the second word is not a verb, then the first word is the verb, and the player is the implied subject.
+ executeVerb(player, verbs.get(first), player, second, third, ...rest)
}
}
-function findVerbs(location, actor) {
+function findAvailableVerbs(location, actor, command) {
// check for verbs on actor
// check for verbs on objects in location
// check for verbs on location
const out = new Map();
out.set("look", 29);
+ out.set("warp", 31);
return out;
}
-function executeVerb(verb, subject, object, ...rest) {
- lookUpObject(verb).fn(subject, object, ...rest)
+function executeVerb(outputObject, verbId, subject, object, ...rest) {
+ const fullVerb = lookUpObject(verbId);
+ if (!fullVerb) {
+ return sockets.get(outputObject)?.send(`verb not found`);
+ }
+ sockets.get(outputObject)?.send(`verb found as ${fullVerb.name}`);
+ const func = fullVerb.fn;
+ if (!func) {
+ return sockets.get(outputObject)?.send(`verb was found but didn't have a fn attribute`);
+ }
+ return fullVerb.fn(outputObject, subject, object, ...rest);
}
const objectQuery = db.prepare('select * from pages where id=?');
@@ -36,12 +62,22 @@ function lookUpObject(id) {
if (id == 30) return {name: "shoofle", contents: "this is a shoofle", location: 1};
if (id == 29) return {
name: "look",
+ verb: false,
contents: "send description of direct object to subject's socket",
- fn: (subject, object, ...rest) => {
- sockets.get(subject)?.send(`you looked around! subject: ${subject} object: ${object} args: ${rest}`);
- console.log(`${subject} looked at ${object} with args ${rest}`);
+ fn: (logReceiver, subject, object, ...rest) => {
+ sockets.get(logReceiver)?.send(`you looked around! subject ${subject} object: ${object} args: ${rest}`);
+ console.log(`${subject} looked at ${object} with args ${rest}, and output was directed to ${logReceiver}`);
+ }
+ }
+ if (id == 31) return {
+ name: "warp",
+ verb: true,
+ contents: "this built-in function changes the player's location, as well as telling their client to move",
+ fn: (logReceiver, subject, object, ...rest) => {
+ // TODO: change subject's location
+ sockets.get(logReceiver)?.send(`location change to: ${object}`);
}
- };
+ }
}
module.exports = { interpret, sockets, lookUpObject };
\ No newline at end of file
diff --git a/server/routes/sockets.js b/server/routes/sockets.js
index a2b722b2..78a852c7 100644
--- a/server/routes/sockets.js
+++ b/server/routes/sockets.js
@@ -9,17 +9,6 @@ const { loginRequired } = require('../authStuff.js');
const { interpret, sockets, lookUpObject } = require('../interpreter.js');
-const clockListeners = new Set();
-const clock = setInterval(() => {
- if (clockListeners.size == 0) return;
- console.log(`sending a ping to all ${clockListeners.size} connections`);
- clockListeners.forEach((x) => x());
-}, 5000);
-console.log(`set up the clock: ${clock}`);
-
-
-
-
app.ws('/embody', (ws, req) => {
@@ -38,5 +27,4 @@ app.ws('/embody', (ws, req) => {
-
module.exports = app;
\ No newline at end of file