Skip to content

Commit 0667683

Browse files
Merge pull request #19 from roman-yagodin/master
Update website
2 parents 5f123de + 22e2803 commit 0667683

File tree

5 files changed

+97
-7
lines changed

5 files changed

+97
-7
lines changed

data/about/d4c1df21.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
author: Roman Yagodin
3+
colors: [ white ]
4+
---
5+
The Protogame project combines (in a strange way) a lot of things which is dear to me: WWW, programming, FLOSS, computer games, languages, philosophy, self-knowledge, humor, etc.
6+
7+
You can think of it as a blog, a collection of personal notes, a game of words - that you can play with, then make your own, and then develop further in a ways that you (and probably only you) would know, understand and love.
8+
9+
I'm trying to keep it simple, but hopefully not too stupid :)

data/marx/50935c17-ru.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
author: Karl Marx
3+
co-authors: [ Spinoza, Hegel ]
4+
lang: ru
5+
colors: [ white, blue ]
6+
---
7+
Необходимость слепа, пока не станет осознанной.
8+
Свобода - это сознание необходимости.

data/marx/50935c17y.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
author: Karl Marx
3+
co-authors: [ Spinoza, Hegel ]
4+
colors: [ white, blue ]
5+
link: https://www.socratic-method.com/quote-meanings-and-interpretations/karl-marx-necessity-is-blind-until-it-becomes-conscious-freedom-is-the-consciousness-of-necessity
6+
---
7+
Necessity is blind until it becomes conscious.
8+
Freedom is the consciousness of necessity.

js/app.js

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ const _3s = _1s * 3;
1616
const _4s = _1s * 4;
1717
const _5s = _1s * 5;
1818

19+
function sec(x) {
20+
return _1s * x;
21+
}
22+
1923
const styles = {
2024
default: "\x1b[0m",
2125
bold: "\x1b[1m",
@@ -277,7 +281,15 @@ function getKeyString(key) {
277281
return "Anykey";
278282
}
279283

280-
// TODO: Semi-infinite "....." prompt
284+
async function readAutoKey() {
285+
setStyle(styles.faint + styles.white);
286+
const key = await waitAutoKey(sec(5), randomInt(sec(8), sec(16)), "\r");
287+
await moveCursorHome();
288+
resetStyle();
289+
290+
return key;
291+
}
292+
281293
async function readKey(prompt = "..", echo = false) {
282294
while (true) {
283295

@@ -286,7 +298,6 @@ async function readKey(prompt = "..", echo = false) {
286298
await type(prompt);
287299
resetStyle();
288300

289-
// TODO: Add option to don't await input indefinitely - e.g. set timer and "run" CLS command from time to time.
290301
const key = await waitKey();
291302

292303
if (echo) {
@@ -389,11 +400,12 @@ async function puzzle1() {
389400
await command("CLS");
390401

391402
await typeln(`You ${randomMsg(["see a", "enter the", "step into the"])} small, dark room covered in old webs`);
403+
await wait(_hs);
392404
await typeln("with just table, chair and rusty terminal on it.");
393405
await typeln();
394406
await typeln("There is no doors or even windows!");
395407

396-
await readKey();
408+
await readAutoKey();
397409

398410
return true;
399411
}
@@ -444,7 +456,7 @@ async function scene2_greeting() {
444456
while (true) {
445457
const choice = await menu([
446458
{ text: "", choice: "showMenu" },
447-
{ text: "Continue protogame", choice: "continue" },
459+
{ text: `Continue ${randomMsg(["adventure", "your journey"])}`, choice: "continue" },
448460
{ text: "You have emails: (1)", choice: "email" },
449461
{ text: "New protogame (resets progress)", choice: "newGame" }
450462
], showMenu);
@@ -481,7 +493,7 @@ async function scene2_greeting() {
481493
await typeln(randomMsg(["Done.", "Done.", "Yes!", "Meow!", "Wow!", "Clap!", "Zzz...", "Shhh...", "Flip!", "Flop!", "Slap!", "Plop!", "Boom!", "Ding!"]));
482494
await typeln();
483495

484-
await readKey();
496+
await readAutoKey();
485497

486498
// to the world
487499
if (game.isNewGame()) {
@@ -604,7 +616,7 @@ async function scene4_world(note) {
604616
await typeNote(note, noteColor);
605617
showNote = false;
606618

607-
await readKey();
619+
await readAutoKey();
608620
}
609621

610622
// TODO: Positive/negative switch: "Don't follow"
@@ -813,6 +825,58 @@ async function scene4_world(note) {
813825
return false;
814826
}
815827

828+
/**
829+
* @param {*} silentTime Initial time to wait w/o typing anything
830+
* @param {*} maxWaitTime Max. time to wait for user input before simulating key press
831+
* @param {*} autoKey Key to pass as if user pressed it
832+
* @returns
833+
*/
834+
async function waitAutoKey(silentTime, maxWaitTime, autoKey) {
835+
t.focus();
836+
await type("..");
837+
838+
const pollInterval = 100;
839+
const typeDelay = 500;
840+
let totalWaitTime = 0;
841+
let typeWaitTime = 0;
842+
843+
// use it like a buffer
844+
game.lastKey = null;
845+
return new Promise((resolve) => {
846+
const interval = setInterval(() => {
847+
totalWaitTime += pollInterval;
848+
849+
if (totalWaitTime > silentTime) {
850+
typeWaitTime += pollInterval;
851+
if (typeWaitTime > typeDelay) {
852+
t.write(".");
853+
typeWaitTime = 0;
854+
}
855+
}
856+
857+
if (totalWaitTime > maxWaitTime) {
858+
game.lastKey = autoKey;
859+
}
860+
861+
const key = game.lastKey;
862+
if (key) {
863+
clearInterval(interval);
864+
console.log({key: game.lastKey});
865+
resolve(game.lastKey);
866+
}
867+
}, pollInterval);
868+
});
869+
}
870+
871+
/** CSI Ps G: Moves cursor to column #1, without cleanup */
872+
async function moveCursorHome() {
873+
await type("\x9B1G");
874+
}
875+
876+
async function test() {
877+
return true;
878+
}
879+
816880
export class App {
817881
init() {
818882
const t = new Terminal({
@@ -841,6 +905,7 @@ export class App {
841905
}
842906

843907
async main() {
908+
//await test();
844909
await scene1_puzzlebox();
845910
await command("CLS");
846911
setTheme(bowTheme);

0 commit comments

Comments
 (0)