Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(!localStorage.os) localStorage.os = "{}";
- splitEmoji = (string) => [...new Intl.Segmenter().segment(string)].map(x => x.segment)
- filltoxy = function(x,y,sizex,sizey,char,color){
- if(!sizex) sizex = 16
- if(!sizey) sizey = 8
- if(!char) char = '█'
- if(!color) color = 0
- for(let j = 0; j < sizey; j++){
- for(let i = 0; i < sizex; i++){
- writeCharToXY(char, color, i + x, j + y)
- };
- };
- };
- fillrandomtoxy = function(x,y,sizex,sizey,char,color){
- if(!sizex) sizex = 16
- if(!sizey) sizey = 8
- if(!char) char = '█'
- if(!color) color = 0
- for(let j = 0; j < sizey; j++){
- for(let i = 0; i < sizex; i++){
- writeCharToXY(char, Math.round(Math.random() * 16777216 / color) * color, i + x, j + y);
- };
- };
- };
- texttoxy = function(x,y,typetext,color){
- try{
- typetext = typetext.split('\n');
- for(let j = 0; j < typetext.length; j++){
- for(let i = 0; i < typetext[j].length; i++){
- writeCharToXY(splitEmoji(typetext[j])[i], color, i + x, j + y);
- };
- }
- }
- catch(e){}
- };
- linkfilltoxy = function(x,y,sizex,sizey,link){
- if(!sizex) sizex = 16
- if(!sizey) sizey = 8
- if(!link) link = "https://ourworldoftext.com/"
- for(let j = 0; j < sizey; j++){
- for(let i = 0; i < sizex; i++){
- network.link({
- tileX: Math.floor((x + i) / 16),
- tileY: Math.floor((y + j) / 8),
- charX: (((x + i) % 16) + 16) % 16,
- charY: (((y + j) % 8) + 8) % 8
- }, 'url', {
- url: link
- });
- };
- };
- };
- repGetCharInfoXY = function(x,y,sizex,sizey){
- result = ""
- if(!sizex) sizex = 16
- if(!sizey) sizey = 8
- if(!x) x = 0
- if(!y) y = 0
- for(let j = 0; j < sizey; j++){
- for(let i = 0; i < sizex; i++){
- result += getCharInfoXY(x + i, y + j).char
- };
- result += "\n";
- };
- return result;
- };
- repGetCharColorXY = function(x,y,sizex,sizey){
- result = []
- if(!sizex) sizex = 16
- if(!sizey) sizey = 8
- if(!x) x = 0
- if(!y) y = 0
- for(let j = 0; j < sizey; j++){
- for(let i = 0; i < sizex; i++){
- result.push(getCharInfoXY(x + i, y + j).color)
- };
- result.push("\n")
- };
- return result;
- };
- repGetCharMoreXY = function(x,y,sizex,sizey){
- result = []
- if(!sizex) sizex = 16
- if(!sizey) sizey = 8
- if(!x) x = 0
- if(!y) y = 0
- for(let j = 0; j < sizey; j++){
- for(let i = 0; i < sizex; i++){
- result.push([getCharInfoXY(x + i, y + j).char, getCharInfoXY(x + i, y + j).color])
- };
- result.push("\n")
- };
- return result;
- };
- restarting = 0;
- usedtoomuch = 0;
- defaultreason = 0;
- isHome = 0;
- isCreatingFile = 0;
- openlog = 0;
- overcontrol = 0;
- function read(){
- notdead = 0;
- isHome = 0;
- isReading = 1;
- filltoxy(x, -8, 32, 16, ' ');
- if(selected.endsWith('.txt')){
- texttoxy(x, -8, JSON.parse(localStorage.os)[selected]);
- notdead = 1;
- }
- else if(selected.endsWith('.png') || selected.endsWith('.jpg') || selected.endsWith('.jpeg')){
- for(i = 0; i < 16; i++){
- for(j = 0; j < 32; j++){
- texttoxy(x+j, -8+i, '█', JSON.parse(localStorage.os)[selected][i*33+j]);
- }
- }
- notdead = 1;
- }
- else if(selected.endsWith('.ran')){
- texttoxy(x, -8, "#"+(random=Math.floor(Math.random()*16777216)).toString(16), random);
- }
- else{
- filltoxy(x, -8, 32, 16, ' ');
- texttoxy(x, -8, ':(\n\nCannot find file extension');
- };
- if(notdead){
- texttoxy(x+28, 7, 'Save');
- texttoxy(x, 7, 'Cancel');
- flushWrites();
- setTimeout(function(){
- linkfilltoxy(x+28, 7, 4, 1, "comu:save");
- linkfilltoxy(x, 7, 6, 1, "comu:home");
- }, 250);
- }
- else{
- texttoxy(x+13, 7, 'Cancel');
- flushWrites();
- setTimeout(function(){
- linkfilltoxy(x+13, 7, 6, 1, "comu:home");
- }, 250);
- };
- }
- function gohome(){
- isHome = 1;
- filltoxy(x, -8, 32, 16, ' ');
- texttoxy(x, -8, 'Previous');
- texttoxy(x+Math.round(16-('Page ' + page).length/2), -8, 'Page ' + page);
- texttoxy(x+28, -8, 'Next');
- flushWrites();
- setTimeout(function(){
- linkfilltoxy(x, -8, 8, 1, "comu:page-");
- linkfilltoxy(x+28, -8, 4, 1, "comu:page+");
- }, 250);
- for(i = 14 * (page - 1); i < Math.min(14 * page, Object.entries(JSON.parse(localStorage.os)).length); i++){
- texttoxy(x, -7 + (i % 14), Object.entries(JSON.parse(localStorage.os))[i][0]);
- flushWrites();
- linkfilltoxy(x, -7 + (i % 14), 1, 1, "comu:select "+Object.entries(JSON.parse(localStorage.os))[i][0]);
- };
- texttoxy(x, 7, "Create new file");
- texttoxy(x+16, 7, "e_g.OS (By e_g.)");
- flushWrites();
- linkfilltoxy(x, 7, 15, 1, "comu:createfilepop");
- };
- function createfilepop(){
- filltoxy(x, -8, 32, 3, ' ');
- filltoxy(x, -2, 32, 10, ' ');
- isCreatingFile = 1;
- texttoxy(x, -8, 'Create a new file.\n\nName:\n--------------------------------\n\n--------------------------------');
- texttoxy(x+28, 7, 'Save');
- texttoxy(x, 7, 'Cancel');
- flushWrites();
- setTimeout(function(){
- linkfilltoxy(x+28, 7, 4, 1, "comu:createfile");
- linkfilltoxy(x, 7, 6, 1, "comu:home");
- }, 250);
- };
- function cmd(e){
- if(usedtoomuch > 3) return;
- if(!e.username || block_list.includes(e.username)) return;
- if(isOpening) return;
- usedtoomuch++;
- isReading = 0;
- isCreatingFile = 0;
- if(e.data == "save"){
- if(isHome) return;
- os = JSON.parse(localStorage.os);
- if(selected.endsWith('.txt')){
- os[selected] = repGetCharInfoXY(x, -8, 32, 16);
- }
- else if(selected.endsWith('.png') || selected.endsWith('.jpg') || selected.endsWith('.jpeg')){
- os[selected] = repGetCharColorXY(x, -8, 32, 16);
- }
- else if(selected.replace(/\n+$/g,'').replace(/\s+$/g,'').endsWith('.rtxt')){
- os[selected] = repGetCharMoreXY(x, -8, 32, 16);
- }
- localStorage.os = JSON.stringify(os);
- gohome();
- if(openlog){
- w.chat.send(e.username?e.username:e.id + ' ' + e.data);
- }
- else{
- console.log(e.username?e.username:e.id, e.data);
- };
- };
- if(e.data.startsWith("select")){
- if(!JSON.parse(localStorage.os)[e.data.substring(e.data.indexOf(' ') + 1)]) return;
- selected = e.data.substring(e.data.indexOf(' ') + 1);
- read();
- if(openlog){
- w.chat.send(e.username + ' ' + e.data);
- }
- else{
- console.log(e.username, e.data);
- };
- };
- if(e.data.startsWith("home")){
- gohome();
- if(openlog){
- w.chat.send(e.username + ' ' + e.data);
- }
- else{
- console.log(e.username, e.data);
- };
- };
- if(e.data.startsWith("createfilepop")){
- isHome = 0;
- filltoxy(x, -8, 32, 16, ' ');
- createfilepop();
- if(openlog){
- w.chat.send(e.username + ' ' + e.data);
- }
- else{
- console.log(e.username, e.data);
- };
- };
- if(e.data == "createfile"){
- if(isReading) return;
- name = splitEmoji(repGetCharInfoXY(x, -4, 32, 1).replace(/^\s+/g, '').replace(/\n+$/g, '').replace(/\s+$/g, '')).slice(0,32).join('').toLowerCase();
- if(!JSON.parse(localStorage.os)[name]){
- os = JSON.parse(localStorage.os);
- if(name.endsWith('.txt')){
- os[name] = "empty";
- }
- else if(name.endsWith('.png') || name.endsWith('.jpg') || name.endsWith('.jpeg')){
- os[name] = [8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128,128,120,112,104,96,88,80,72,64,56,48,40,32,24,16,8];
- }
- else {
- os[name] = 1;
- }
- localStorage.os = JSON.stringify(os)
- }
- gohome();
- if(openlog){
- w.chat.send(e.username + ' ' + e.data);
- }
- else{
- console.log(e.username, e.data);
- };
- }
- if(e.data == "page+"){
- page++
- if(Math.ceil(Object.keys(JSON.parse(localStorage.os)).length / 14) < page){
- page = 1;
- };
- gohome();
- if(openlog){
- w.chat.send(e.username + ' ' + e.data);
- }
- else{
- console.log(e.username, e.data);
- };
- }
- if(e.data == "page-"){
- page--
- if(page < 1) page = Math.max(1,Math.ceil(Object.keys(JSON.parse(localStorage.os)).length / 14));
- gohome();
- if(openlog){
- w.chat.send(e.username + ' ' + e.data);
- }
- else{
- console.log(e.username, e.data);
- };
- };
- };
- w.broadcastReceive(true);
- w.setFlushInterval(1);
- function start(){
- page = 1;
- x = -48;
- block_list = [];
- w.on("cmd", cmd);
- isOpening = 1;
- fillrandomtoxy(x, -8, 32, 16, '█', restarting?1:1118481);
- setTimeout(function(){
- filltoxy(x, -8, 32, 16, ' ');
- }, 1000)
- setTimeout(function(){
- texttoxy(x, -8, "\n\n\n\n Welcome to\n ████ ██\n ██ ██ ██\n ████ ████\n ██ ██\n ████ ████ ████\n 's OS\n !byeanons!\n an entire OS in OWOT" + (defaultreason?"\n\n defaultreason1":""));
- }, 1125)
- setTimeout(function(){
- filltoxy(x, -8, 32, 16, ' ');
- }, 5875)
- setTimeout(function(){
- gohome();
- isOpening = 0;
- }, 6000);
- };
- function restart(reason){
- isHome = 0;
- isReading = 0;
- isCreatingFile = 0;
- defaultreason = 0;
- if(reason == "defaultreason1") defaultreason = 1;
- restarting = 1;
- filltoxy(x, -8, 32, 16, ' ');
- texttoxy(x, -8, 'Restarting...\nReason:\n\n' + reason, 0x00C000)
- setTimeout(function(){
- w.off("cmd", cmd);
- start();
- }, 3000);
- };
- start();
- function turnoff(reason){
- isHome = 0;
- isReading = 0;
- isCreatingFile = 0;
- defaultreason = 0;
- restarting = 1;
- filltoxy(x, -8, 32, 16, ' ');
- texttoxy(x, -8, 'Turning off...\nReason:\n\n' + reason, 0xC00000)
- w.off("cmd", cmd);
- setTimeout(function(){
- filltoxy(x, -8, 32, 16, '█', 0x000001);
- }, 5000);
- };
- function defaultreason1(reason){
- localStorage.os = "{}";
- restart("defaultreason1:\n" + reason);
- }
- setInterval(function(){
- usedtoomuch = 0;
- }, 1000);
- setInterval(function(){
- if(isHome) gohome();
- if(isCreatingFile) createfilepop();
- }, 5000);
- defaultreason1("New fresh start");
- w.chat.send("A new fresh start of e_g.OS")
Advertisement
Add Comment
Please, Sign In to add comment