]> git.cworth.org Git - zombocom-ai/blobdiff - index.js
Add an endgame to the hunt
[zombocom-ai] / index.js
index 606fba79adbd99c68135ced4f9efa854c601980e..29f304bd13e2b3015c32b54af60fd94eee5227de 100644 (file)
--- a/index.js
+++ b/index.js
@@ -175,7 +175,7 @@ function emit_bus_timer() {
 
 function start_bus_timer() {
     const bus = state.bus;
-    bus.timer = 3; // XXX: 30 in production
+    bus.timer = 30;
     emit_bus_timer();
     bus_interval = setInterval(emit_bus_timer, 1000);
 }
@@ -191,7 +191,10 @@ bus_code = [
 for i in range(400):
   set_color('midnight blue' if i % 2 == 0 else 'navy blue')
   set_opacity(0.5)
-  random_dot()`,
+  random_dot()
+
+# The only limit is your fingers!
+fingers()`,
 
     `def random_line():
   x = random_within(512) - 60
@@ -204,7 +207,10 @@ for i in range(400):
 
 for i in range(200):
   set_color('black')
-  random_line()`,
+  random_line()
+
+# This is Zombo.com. Welcome!
+mouths()`,
 
     `def random_blob():
   move_to(random_within(512), random_within(512))
@@ -214,7 +220,10 @@ for i in range(200):
 
 for i in range(100):
   set_random_color()
-  random_blob()`,
+  random_blob()
+
+# The infinite eyes is possible!
+eyes()`,
 
     `def random_curve():
   move_to(random_within(512), random_within(512))
@@ -223,7 +232,11 @@ for i in range(100):
 
 for i in range(200):
   set_color('pink' if i % 2 == 0 else 'lime green')
-  random_curve()`
+  random_curve()
+
+# You can do anything!
+fingers()
+`
 ];
 
 io_bus.on("connection", (socket) => {
@@ -287,7 +300,8 @@ io_bus.on("connection", (socket) => {
            // Give all clients the new image
            io_bus.emit('output', filename);
        } catch (e) {
-           console.log("Error executing turtle script: " + e);
+           // Send any error out to the users
+           io_bus.emit('error', e.toString())
        }
     });
 
@@ -556,13 +570,10 @@ io.on('connection', (socket) => {
        socket.emit('inform-name', socket.request.session.name);
     });
 
-    // When any client comments, send that to all clients (including sender)
-    socket.on('comment', (comment) => {
-        const images = state.images;
+    function send_and_save_comment(comment) {
+       const images = state.images;
 
-        // Send comment to clients after adding commenter's name
-        comment.name = socket.request.session.name;
-        io.emit('comment', comment);
+       io.emit('comment', comment);
 
         const index = images.findIndex(image => image.id == comment.image_id);
 
@@ -576,14 +587,52 @@ io.on('connection', (socket) => {
         image.comments.push(comment);
         images.splice(index, 1);
         images.push(image);
+    }
+
+    // When any client comments, send that to all clients (including sender)
+    socket.on('comment', (comment) => {
+        // We have to add the sender's name befor we can send the comment
+        comment.name = socket.request.session.name;
+
+       send_and_save_comment(comment);
     });
 
+    function endgame() {
+       // Before revealing Coda's final image, have her comment on
+       // each of the weaknesses, in order to bring them to the top
+       // of the feed.
+       state.targets.forEach(target => {
+           const comment = {
+               name: "Coda",
+               text: "Zombo.com is weak!",
+               image_id: target.id
+           };
+           send_and_save_comment(comment);
+       });
+
+       const image = {
+           id: state.images.length,
+           censored: false,
+           link: false,
+           code: 0,
+           prompt: "",
+           filename: "/images/coda-future-repaired.png",
+           comments: [{
+               name: "Coda",
+               text: "I don't know how to thank you enough! You found all the weaknesses necessary for us to defeat Zombo.com, (as I've commented below as you'll see the next time you look). It's now been rendered harmless and inert throughout the entire timeline. I'm going to leave to get back to rebuilding our world. I hope you've found everything you were looking for along the way as well."
+           }]
+       };
+       io.emit('image', image);
+       state.images.push(image);
+    }
+
     // Generate an image when requested
     socket.on('generate', (request) => {
         console.log(`Generating image for ${socket.request.session.name} with code=${request['code']} and prompt=${request['prompt']}`);
         async function generate_image(code, prompt) {
             function emit_image(image, target) {
-                image.id = state.images.length;
+                image.id = state.next_image_id;
+               state.next_image_id = state.next_image_id + 1;
                 image.censored = false;
                 image.link = "";
                 if (target) {
@@ -591,8 +640,16 @@ io.on('connection', (socket) => {
                         "name": "ZomboCom",
                         "text": target.response
                     }];
-                    if (! state.targets.includes(target.short)) {
-                        state.targets.push(target.short);
+                    if (state.targets.filter(item => item.name === target.short).length === 0) {
+                        state.targets.push({
+                           name: target.short,
+                           id: image.id
+                       });
+                       if (state.targets.length == 8) {
+                           // When the final target has been achieved, trigger
+                           // the endgame (in 10 seconds)
+                           setTimeout(endgame, 10000);
+                       }
                     }
                 } else {
                     image.comments = [];