-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
144 lines (138 loc) · 6.76 KB
/
script.js
File metadata and controls
144 lines (138 loc) · 6.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const output = document.getElementById("out");
const input = document.getElementById("in");
const prompt = document.getElementById("prompt");
const bar = document.getElementById("input-line");
let ignoreInput = true;
const cmds = {
help: () => {
return "Available commands:" +
"\n \n - Help : Display list of console commands." +
"\n \n - Clr : Clear the display." +
"\n \n - Echo <text> : Print <text> to the display." +
"\n \n - Date : Display the current date and time." +
"\n \n - WhoAmI : Display information about me." +
"\n \n - Reload : Restart the console." +
"\n \n - PList : Display list of project names." +
"\n \n - PInfo <name> : Display information regarding the project <name>." +
"\n \n - Roll <n> : Roll an <n> sided die." +
"\n \n - Flip : Flip a coin."
},
clr: () => {
output.innerHTML = "";
return "";
},
echo: (msg) => {
if (msg && msg.length > 0) {
return msg.join(" ")
}
return " ";
},
date: () => {
const d = new Date();
return `${["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"][d.getDay()]}, ${["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "Novemeber", "December"][d.getMonth()]} ${d.getDate()}, ${d.getFullYear()} ${String(d.getHours() % 12 || 12).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}:${String(d.getSeconds()).padStart(2, "0")} ${d.getHours() < 12 ? "AM" : "PM"}.`;
},
whoami: () => {
return "I am an Undegraduate at Iowa State University, double majoring in Computer Science and Applied Mathematics." +
"\n \nContact me:" +
"\n \n - Email: <a href=mailto:[email protected]>[email protected]</a>" +
"\n \n - Linked In: <a href=https://www.linkedin.com/in/benjamin-coberly-948b63352/ target=_blank>linkedin.com/in/benjamin-coberly-948b63352/</a>" +
"\n \nExplore more:" +
"\n \n - GitHub: <a href=https://github.com/Arkhstar>github.com/Arkhstar</a>" +
"\n \n - YouTube: <a href=https://www.youtube.com/@arkhstar target=_blank>youtube.com/@arkhstar</a>";
},
reload: () => {
window.location.reload();
return "";
},
plist: () => {
return "Projects:\n \n - BoolForge\n \n - Sanguine";
},
pinfo: (args) => {
if (args && args.length > 0) {
switch(args[0]) {
case "boolforge":
return "BoolForge is a python package made to generate and analyze random Boolean functions and networks, with a focus on the concept of canalization. Developed under the mentorship of, and in collaboration with, Dr. Claus Kadelka of Iowa State University." +
"\n \n - Repository: <a href=https://github.com/ckadelka/BoolForge/ target=_blank>github.com/ckadelka/BoolForge/</a>." +
"\n \n - Documentation: <a href=https://ckadelka.github.io/BoolForge/ target=_blank>ckadelka.github.io/BoolForge/</a>.";
case "sanguine":
return "Sanguine Penitence is a dark fantasy adventure exploration game where you must wander cursed wilds, hunting fell beasts for coin. Hunt, sacrifice, and survive in a world where the gods who reign never sleep.\nDeveloped as a Capstone Project for F2025 HON 3210 - The Game Shapes You." +
"\n \n - More Information: <a href=https://arkhstar.github.io/SanguinePenitence/ target=_blank>arkhstar.github.io/SanguinePenitence/</a>." +
"\n \n - OST: <a href=https://www.youtube.com/playlist?list=PL-U76qja-eQRMND9OwjXtSdVvitpuOssW target=_blank>www.youtube.com/playlist?list=PL-U76qja-eQRMND9OwjXtSdVvitpuOssW</a>.";
}
return `Err: Invalid project name \'${args[0]}\'.`
}
return "Err: You must provide a project name.";
},
roll: (sides) => {
if (sides && sides.length > 0) {
if (sides[0] > 0) {
return `You rolled a ${Math.floor(Math.random() * sides + 1)}!`;
}
return "Err: You must provide a positive number of faces.";
}
return "Err: You must provide the number of faces of the die (e.g. 6).";
},
flip: () => {
return `You got ${Math.random() > 0.5 ? "Heads" : "Tails"}!`;
},
}
function writeLine(text, speed = 1) {
const line = document.createElement("div");
output.prepend(line);
if (speed > 0) {
return new Promise(resolve => {
let i = 0;
const interval = setInterval(() => {
line.innerHTML = text.slice(0, i + 1);
i++;
if (i >= text.length) {
clearInterval(interval);
resolve();
}
}, speed);
})
}
line.textContent = text
}
function readArguments(cmd) {
const args = cmd.toLowerCase().trim().split(" ");
if (cmds[args[0]]) {
return cmds[args[0]](args.slice(1));
}
return `Unknown command \'${args[0]}\'.`;
}
input.addEventListener("keydown", async (e) => {
if (ignoreInput) {
return;
}
if (e.key === "Enter") {
bar.style.opacity = 0;
ignoreInput = true;
const cmd = input.value;
input.value = "";
writeLine(`${prompt.textContent}${cmd}\n \n `, 0);
const result = readArguments(cmd);
if (result) {
await writeLine(`${result}\n \n \n `);
}
input.value = "";
bar.style.opacity = 1;
ignoreInput = false;
}
});
document.addEventListener("click", (e) => {
if (e.target != input) {
input.focus();
}
});
async function writeHeader() {
await writeLine(" Now Loading\n \n " +
"________ ________ _____\n___ __ )_________________(_)_____ _______ ______(_)______\n__ __ | _ \\_ __ \\____ /_ __ `/_ __ `__ \\_ /__ __ \\\n_ /_/ // __/ / / /___ / / /_/ /_ / / / / / / _ / / /\n/_____/ \\___//_/ /_/___ / \\__,_/ /_/ /_/ /_//_/ /_/ /_/\n /___/\n " +
" _________ ______ ______\n __ ____/________ /________________ /____ __\n _ / _ __ \\_ __ \\ _ \\_ ___/_ /__ / / /\n / /___ / /_/ / /_/ / __/ / _ / _ /_/ / 's\n \\____/ \\____//_.___/\\___//_/ /_/ _\\__, /\n /____/\n " +
"\n Portfolio\n\n" +
" :========================================================:\n \n \nType a command or type Help to get started!\n \n \n \n ");
input.value = "";
bar.style.opacity = 1;
ignoreInput = false;
};
writeHeader();