Dimka69

e_g.OS modified version

Feb 6th, 2023 (edited)
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if(!localStorage.os) localStorage.os = "{}";
  2. splitEmoji = (string) => [...new Intl.Segmenter().segment(string)].map(x => x.segment)
  3. filltoxy = function(x,y,sizex,sizey,char,color){
  4.     if(!sizex) sizex = 16
  5.     if(!sizey) sizey = 8
  6.     if(!char) char = '█'
  7.     if(!color) color = 0
  8.     for(let j = 0; j < sizey; j++){
  9.         for(let i = 0; i < sizex; i++){
  10.             writeCharToXY(char, color, i + x, j + y)
  11.         };
  12.     };
  13. };
  14.  
  15. fillrandomtoxy = function(x,y,sizex,sizey,char,color){
  16.     if(!sizex) sizex = 16
  17.     if(!sizey) sizey = 8
  18.     if(!char) char = '█'
  19.     if(!color) color = 0
  20.     for(let j = 0; j < sizey; j++){
  21.         for(let i = 0; i < sizex; i++){
  22.             writeCharToXY(char, Math.round(Math.random() * 16777216 / color) * color, i + x, j + y);
  23.         };
  24.     };
  25. };
  26.  
  27. texttoxy = function(x,y,typetext,color){
  28.     try{
  29.         typetext = typetext.split('\n');
  30.         for(let j = 0; j < typetext.length; j++){
  31.             for(let i = 0; i < typetext[j].length; i++){
  32.                 writeCharToXY(splitEmoji(typetext[j])[i], color, i + x, j + y);
  33.             };
  34.         }
  35.     }
  36.     catch(e){}
  37. };
  38.  
  39. linkfilltoxy = function(x,y,sizex,sizey,link){
  40.     if(!sizex) sizex = 16
  41.     if(!sizey) sizey = 8
  42.     if(!link) link = "https://ourworldoftext.com/"
  43.     for(let j = 0; j < sizey; j++){
  44.         for(let i = 0; i < sizex; i++){
  45.             network.link({
  46.                 tileX: Math.floor((x + i) / 16),
  47.                 tileY: Math.floor((y + j) / 8),
  48.                 charX: (((x + i) % 16) + 16) % 16,
  49.                 charY: (((y + j) % 8) + 8) % 8
  50.             }, 'url', {
  51.                 url: link
  52.             });
  53.         };
  54.     };
  55. };
  56.  
  57. repGetCharInfoXY = function(x,y,sizex,sizey){
  58.     result = ""
  59.     if(!sizex) sizex = 16
  60.     if(!sizey) sizey = 8
  61.     if(!x) x = 0
  62.     if(!y) y = 0
  63.     for(let j = 0; j < sizey; j++){
  64.         for(let i = 0; i < sizex; i++){
  65.             result += getCharInfoXY(x + i, y + j).char
  66.         };
  67.     result += "\n";
  68.     };
  69.     return result;
  70. };
  71.  
  72. repGetCharColorXY = function(x,y,sizex,sizey){
  73.     result = []
  74.     if(!sizex) sizex = 16
  75.     if(!sizey) sizey = 8
  76.     if(!x) x = 0
  77.     if(!y) y = 0
  78.     for(let j = 0; j < sizey; j++){
  79.         for(let i = 0; i < sizex; i++){
  80.             result.push(getCharInfoXY(x + i, y + j).color)
  81.         };
  82.     result.push("\n")
  83.     };
  84.     return result;
  85. };
  86.  
  87. repGetCharMoreXY = function(x,y,sizex,sizey){
  88.     result = []
  89.     if(!sizex) sizex = 16
  90.     if(!sizey) sizey = 8
  91.     if(!x) x = 0
  92.     if(!y) y = 0
  93.     for(let j = 0; j < sizey; j++){
  94.         for(let i = 0; i < sizex; i++){
  95.             result.push([getCharInfoXY(x + i, y + j).char, getCharInfoXY(x + i, y + j).color])
  96.         };
  97.     result.push("\n")
  98.     };
  99.     return result;
  100. };
  101.  
  102. restarting = 0;
  103. usedtoomuch = 0;
  104. defaultreason = 0;
  105. isHome = 0;
  106. isCreatingFile = 0;
  107. openlog = 0;
  108. overcontrol = 0;
  109. function read(){
  110.     notdead = 0;
  111.     isHome = 0;
  112.     isReading = 1;
  113.     filltoxy(x, -8, 32, 16, ' ');
  114.     if(selected.endsWith('.txt')){
  115.         texttoxy(x, -8, JSON.parse(localStorage.os)[selected]);
  116.         notdead = 1;
  117.     }
  118.     else if(selected.endsWith('.png') || selected.endsWith('.jpg') || selected.endsWith('.jpeg')){
  119.         for(i = 0; i < 16; i++){
  120.             for(j = 0; j < 32; j++){
  121.                 texttoxy(x+j, -8+i, '█', JSON.parse(localStorage.os)[selected][i*33+j]);
  122.             }
  123.         }
  124.         notdead = 1;
  125.     }
  126.     else if(selected.endsWith('.ran')){
  127.         texttoxy(x, -8, "#"+(random=Math.floor(Math.random()*16777216)).toString(16), random);
  128.     }
  129.     else{
  130.         filltoxy(x, -8, 32, 16, ' ');
  131.         texttoxy(x, -8, ':(\n\nCannot find file extension');
  132.     };
  133.     if(notdead){
  134.         texttoxy(x+28, 7, 'Save');
  135.         texttoxy(x, 7, 'Cancel');
  136.         flushWrites();
  137.         setTimeout(function(){
  138.             linkfilltoxy(x+28, 7, 4, 1, "comu:save");
  139.             linkfilltoxy(x, 7, 6, 1, "comu:home");
  140.         }, 250);
  141.     }
  142.     else{
  143.         texttoxy(x+13, 7, 'Cancel');
  144.         flushWrites();
  145.         setTimeout(function(){
  146.             linkfilltoxy(x+13, 7, 6, 1, "comu:home");
  147.         }, 250);
  148.     };
  149. }
  150. function gohome(){
  151.     isHome = 1;
  152.     filltoxy(x, -8, 32, 16, ' ');
  153.     texttoxy(x, -8, 'Previous');
  154.     texttoxy(x+Math.round(16-('Page ' + page).length/2), -8, 'Page ' + page);
  155.     texttoxy(x+28, -8, 'Next');
  156.     flushWrites();
  157.     setTimeout(function(){
  158.         linkfilltoxy(x, -8, 8, 1, "comu:page-");
  159.         linkfilltoxy(x+28, -8, 4, 1, "comu:page+");
  160.     }, 250);
  161.     for(i = 14 * (page - 1); i < Math.min(14 * page, Object.entries(JSON.parse(localStorage.os)).length); i++){
  162.         texttoxy(x, -7 + (i % 14), Object.entries(JSON.parse(localStorage.os))[i][0]);
  163.         flushWrites();
  164.         linkfilltoxy(x, -7 + (i % 14), 1, 1, "comu:select "+Object.entries(JSON.parse(localStorage.os))[i][0]);
  165.     };
  166.     texttoxy(x, 7, "Create new file");
  167.     texttoxy(x+16, 7, "e_g.OS (By e_g.)");
  168.     flushWrites();
  169.     linkfilltoxy(x, 7, 15, 1, "comu:createfilepop");
  170. };
  171. function createfilepop(){
  172.     filltoxy(x, -8, 32, 3, ' ');
  173.     filltoxy(x, -2, 32, 10, ' ');
  174.     isCreatingFile = 1;
  175.     texttoxy(x, -8, 'Create a new file.\n\nName:\n--------------------------------\n\n--------------------------------');
  176.     texttoxy(x+28, 7, 'Save');
  177.     texttoxy(x, 7, 'Cancel');
  178.     flushWrites();
  179.     setTimeout(function(){
  180.         linkfilltoxy(x+28, 7, 4, 1, "comu:createfile");
  181.         linkfilltoxy(x, 7, 6, 1, "comu:home");
  182.     }, 250);
  183. };
  184. function cmd(e){
  185.     if(usedtoomuch > 3) return;
  186.     if(!e.username || block_list.includes(e.username)) return;
  187.     if(isOpening) return;
  188.     usedtoomuch++;
  189.     isReading = 0;
  190.     isCreatingFile = 0;
  191.     if(e.data == "save"){
  192.         if(isHome) return;
  193.         os = JSON.parse(localStorage.os);
  194.         if(selected.endsWith('.txt')){
  195.             os[selected] = repGetCharInfoXY(x, -8, 32, 16);
  196.         }
  197.         else if(selected.endsWith('.png') || selected.endsWith('.jpg') || selected.endsWith('.jpeg')){
  198.             os[selected] = repGetCharColorXY(x, -8, 32, 16);
  199.         }
  200.         else if(selected.replace(/\n+$/g,'').replace(/\s+$/g,'').endsWith('.rtxt')){
  201.             os[selected] = repGetCharMoreXY(x, -8, 32, 16);
  202.         }
  203.         localStorage.os = JSON.stringify(os);
  204.         gohome();
  205.         if(openlog){
  206.             w.chat.send(e.username?e.username:e.id + ' ' + e.data);
  207.         }
  208.         else{
  209.             console.log(e.username?e.username:e.id, e.data);
  210.         };
  211.     };
  212.     if(e.data.startsWith("select")){
  213.         if(!JSON.parse(localStorage.os)[e.data.substring(e.data.indexOf(' ') + 1)]) return;
  214.         selected = e.data.substring(e.data.indexOf(' ') + 1);
  215.         read();
  216.         if(openlog){
  217.             w.chat.send(e.username + ' ' + e.data);
  218.         }
  219.         else{
  220.             console.log(e.username, e.data);
  221.         };
  222.     };
  223.     if(e.data.startsWith("home")){
  224.         gohome();
  225.         if(openlog){
  226.             w.chat.send(e.username + ' ' + e.data);
  227.         }
  228.         else{
  229.             console.log(e.username, e.data);
  230.         };
  231.     };
  232.     if(e.data.startsWith("createfilepop")){
  233.         isHome = 0;
  234.         filltoxy(x, -8, 32, 16, ' ');
  235.         createfilepop();
  236.         if(openlog){
  237.             w.chat.send(e.username + ' ' + e.data);
  238.         }
  239.         else{
  240.             console.log(e.username, e.data);
  241.         };
  242.     };
  243.     if(e.data == "createfile"){
  244.         if(isReading) return;
  245.         name = splitEmoji(repGetCharInfoXY(x, -4, 32, 1).replace(/^\s+/g, '').replace(/\n+$/g, '').replace(/\s+$/g, '')).slice(0,32).join('').toLowerCase();
  246.         if(!JSON.parse(localStorage.os)[name]){
  247.             os = JSON.parse(localStorage.os);
  248.             if(name.endsWith('.txt')){
  249.                 os[name] = "empty";
  250.             }
  251.             else if(name.endsWith('.png') || name.endsWith('.jpg') || name.endsWith('.jpeg')){
  252.                 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];
  253.             }
  254.             else {
  255.                 os[name] = 1;
  256.             }
  257.             localStorage.os = JSON.stringify(os)
  258.         }
  259.         gohome();
  260.         if(openlog){
  261.             w.chat.send(e.username + ' ' + e.data);
  262.         }
  263.         else{
  264.             console.log(e.username, e.data);
  265.         };
  266.     }
  267.     if(e.data == "page+"){
  268.         page++
  269.         if(Math.ceil(Object.keys(JSON.parse(localStorage.os)).length / 14) < page){
  270.             page = 1;
  271.         };
  272.         gohome();
  273.         if(openlog){
  274.             w.chat.send(e.username + ' ' + e.data);
  275.         }
  276.         else{
  277.             console.log(e.username, e.data);
  278.         };
  279.     }
  280.     if(e.data == "page-"){
  281.         page--
  282.         if(page < 1) page = Math.max(1,Math.ceil(Object.keys(JSON.parse(localStorage.os)).length / 14));
  283.         gohome();
  284.         if(openlog){
  285.             w.chat.send(e.username + ' ' + e.data);
  286.         }
  287.         else{
  288.             console.log(e.username, e.data);
  289.         };
  290.     };
  291. };
  292. w.broadcastReceive(true);
  293. w.setFlushInterval(1);
  294. function start(){
  295.     page = 1;
  296.     x = -48;
  297.     block_list = [];
  298.     w.on("cmd", cmd);
  299.     isOpening = 1;
  300.     fillrandomtoxy(x, -8, 32, 16, '█', restarting?1:1118481);
  301.     setTimeout(function(){
  302.         filltoxy(x, -8, 32, 16, ' ');
  303.     }, 1000)
  304.     setTimeout(function(){
  305.         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":""));
  306.     }, 1125)
  307.     setTimeout(function(){
  308.         filltoxy(x, -8, 32, 16, ' ');
  309.     }, 5875)
  310.     setTimeout(function(){
  311.         gohome();
  312.         isOpening = 0;
  313.     }, 6000);
  314. };
  315. function restart(reason){
  316.     isHome = 0;
  317.     isReading = 0;
  318.     isCreatingFile = 0;
  319.     defaultreason = 0;
  320.     if(reason == "defaultreason1") defaultreason = 1;
  321.     restarting = 1;
  322.     filltoxy(x, -8, 32, 16, ' ');
  323.     texttoxy(x, -8, 'Restarting...\nReason:\n\n' + reason, 0x00C000)
  324.     setTimeout(function(){
  325.         w.off("cmd", cmd);
  326.         start();
  327.     }, 3000);
  328. };
  329. start();
  330. function turnoff(reason){
  331.     isHome = 0;
  332.     isReading = 0;
  333.     isCreatingFile = 0;
  334.     defaultreason = 0;
  335.     restarting = 1;
  336.     filltoxy(x, -8, 32, 16, ' ');
  337.     texttoxy(x, -8, 'Turning off...\nReason:\n\n' + reason, 0xC00000)
  338.     w.off("cmd", cmd);
  339.     setTimeout(function(){
  340.         filltoxy(x, -8, 32, 16, '█', 0x000001);
  341.     }, 5000);
  342. };
  343. function defaultreason1(reason){
  344.     localStorage.os = "{}";
  345.     restart("defaultreason1:\n" + reason);
  346. }
  347. setInterval(function(){
  348.     usedtoomuch = 0;
  349. }, 1000);
  350. setInterval(function(){
  351.     if(isHome) gohome();
  352.     if(isCreatingFile) createfilepop();
  353. }, 5000);
  354. defaultreason1("New fresh start");
  355. w.chat.send("A new fresh start of e_g.OS")
Advertisement
Add Comment
Please, Sign In to add comment