Advertisement
jargon

Roe2Js :: "canvasRenderPurse.js"

Jul 2nd, 2024 (edited)
760
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function canvasPurseTray ( ) {
  2.  
  3.     var purseSpanX = 5;
  4.     var purseSpanY = 6;
  5.  
  6.     var ent_stats = [];
  7.  
  8.     var [ px, py, pz ] = cursorState ( layers.critter );
  9.        
  10.     var xOffset = viewSpanX * tileW;
  11.    
  12.     drawRectangle(xOffset+gutterW*2, gutterH, purseSpanX * tileW, purseSpanY * tileH, 'black', 'black');
  13.        
  14.     var ss = [];
  15.    
  16.     logFeats({ full_map: left(full_map[px][py][pz]+`________`,4)});
  17.    
  18.     ent_stats.stats = full_entity_stats[px][py];
  19.  
  20.     ss.push(ent_stats.stats);
  21.     ss.card = {};
  22.     ss.card.namesake = `Placeholder`;
  23.     ss.card.actionRoster = [];
  24.    
  25.     switch(true){
  26.     case (oobMap([px,py]) !== true):
  27.        
  28.         ss.push(ent_stats.stats);
  29.         ss.card.namesake = `Out Of Bounds`;
  30.         ss.card.actionRoster = [];
  31.        
  32.         break;
  33.        
  34.     case (invalidName(full_map[px][py][layers.critter],2)):
  35.        
  36.         ss.push(ent_stats.stats);
  37.         ss.card.namesake = `Placeholder`;
  38.         ss.card.actionRoster = [];
  39.        
  40.         break;
  41.        
  42.     case (oobMap([px,py]) === true):
  43.        
  44.         ss.push(full_entity_stats[px][py][layers.critter].stats);
  45.         ss.card.namesake = ss.card.namesake;
  46.         ss.card.actionRoster = sections(ss.card.action,4);
  47.        
  48.         break;
  49.     }
  50.    
  51.     let buffer = [];
  52.    
  53.     for(let y = purseConstraints.viewMinY; y <= purseConstraints.viewMaxY; y++){
  54.         for(let x = purseConstraints.viewMinX; x <= purseConstraints.viewMaxX; x++){
  55.                        
  56.             buffer = [];
  57.            
  58.             if(y === 3){
  59.                 let z = x;
  60.                 if((z >= 0) && (z < layers.gui)){
  61.                     if(oobMap([px,py]) === true){
  62.                         buffer.push(
  63.                             full_map[px][py][z]
  64.                         );
  65.                     }
  66.                 }
  67.             }
  68.            
  69.             let x1 = 0;
  70.             let purseSpanX = 5;
  71.            
  72.             let y1 = 4;
  73.             let purseSpanY = 3;
  74.                
  75.             if((x >= x1) && (x < x1 + purseSpanX) && (y >= y1) && (y < y1 + purseSpanY)){
  76.                
  77.                 let i = (x - x1) + (y - y1) * purseSpanX;
  78.  
  79.                 if((i >= 0) && (i < ss.card.actionRoster.length)){
  80.                     buffer.push( ss.card.actionRoster[i] );
  81.                 }
  82.             }
  83.            
  84.             buffer.push(`sel2dots`);
  85.            
  86.             drawImageStack(buffer,xOffset+
  87.             gutterW * 2 + x * tileW,gutterH + y * tileH,tileW,tileH);
  88.         }
  89.     }
  90.    
  91.     ss.card.namesake = ucwords(ss.card.namesake);
  92.    
  93.     switch(true){
  94.     case (ucwords(ss.card.namesake) === "Placeholder"):
  95.     case (ucwords(ss.card.namesake) === "Out Of Bounds"):
  96.         break;
  97.     default:       
  98.        
  99.         renderStats(px,py,z);
  100.        
  101.         drawText(gutterW + 0 * tileW, gutterH + 8 + 12,'16px Impact','white','" ' + ss.card.namesake + ' "');
  102.        
  103.         break;
  104.     }
  105.    
  106.     return true;   
  107. }
  108.  
  109.     function renderStatBar(x,y,width,height,caption,font,fg,bg){
  110.        
  111.         drawRectangle( x, y, width, height, 'black', bg );
  112.  
  113.         drawText( x, y, `${height}px ${font}`, fg, caption );
  114.        
  115.     }
  116.  
  117.     function renderStats(px,py,z){
  118.            
  119.         // var [ px, py, pz ] = cursorState ( layers.critter );
  120.        
  121.         var xOffset = viewSpanX * tileW + gutterW * 3;
  122.        
  123.         z = z || pz;
  124.        
  125.         let s = [];
  126.         let pct = [];
  127.        
  128.         s['health'] = full_entity_stats[px][py][layers.critter].stats.health;
  129.        
  130.         s['stamina'] = full_entity_stats[px][py][layers.critter].stats.stamina;
  131.        
  132.         s['essence'] = full_entity_stats[px][py][layers.critter].stats.essence;
  133.        
  134.         renderStatusBar( s, 'health', tileW * viewSpanX + gutterW * 2, gutterH + gutterH * 2, tileW * purseSpanX, tileH / 2, 'black', 'red' );
  135.  
  136.         renderStatusBar( s, 'stamina', tileW * viewSpanX + gutterW * 2, gutterH + gutterH * 3, tileW * purseSpanX, tileH / 2, 'black', 'yellow' );
  137.  
  138.         renderStatusBar( s, 'essence', tileW * viewSpanX + gutterW * 2, gutterH + gutterH * 4, tileW * purseSpanX, tileH / 2, 'black', 'cyan' );
  139.     }
  140.    
  141. function renderStatusBar(stat, attrName, gutterW, gutterH, width, height, fg, bg ) {
  142.        
  143.     // var [ px, py, pz ] = cursorState ( );
  144.  
  145.     let s = stat[attrName];
  146.    
  147.     let pct = [];
  148.     let w = [];
  149.    
  150.     s.minimum = s.minimum || 0;
  151.     s.maximum = s.maximum || 1;
  152.     s.current = s.current || 0;
  153.     s.recovery = s.recovery || 0;
  154.            
  155.     pct['current'] = Math.round(100 * s.current / s.maximum);
  156.  
  157.     pct['minimum'] = Math.round(100 * s.minimum / s.maximum);
  158.  
  159.     pct['maximum'] = Math.round(100 * s.maximum / s.maximum);
  160.  
  161.     pct['recovery'] = Math.round(100 * (s.current + s.recovery) / s.maximum);
  162.    
  163.     let x = gutterW;
  164.     let y = gutterH + tileH;
  165.    
  166.     // s.current, s.recovery
  167.     // s.minimum, s.maximum
  168.  
  169.     let caption = `${attrName}: ${s.current} / ${s.maximum}`;
  170.    
  171.     let font = 'Small Fonts';
  172.    
  173.     // fg, bg
  174.  
  175.     w['current'] = width * curve(pct['current']) / 100;
  176.     w['recovery'] = width * curve(pct['recovery']) / 100;
  177.    
  178.     w['minimum'] = 0;
  179.     w['maximum'] = width * curve(1.0) / 100;
  180.  
  181.     drawRectangle( x, y, w['maximum'], height, 'black', 'gray' );
  182.    
  183.     drawRectangle( x, y + gutterH / 2, w['current'], height - gutterH / 2, 'black', bg );
  184.  
  185.     drawRectangle( x, y, w['recovery'], height - gutterH / 2, 'rgba(0,0,0,0.0)', 'rgba(255,255,255,0.7)' );
  186.  
  187.     drawRectangle( x, y, width, height, 'black', 'rgba(0,0,0,0.0)' );
  188.  
  189.     drawText( x, y + gutterH, `${height*0.8}px ${font}`, 'black', caption );
  190.  
  191. }
  192.  
  193. function curve( x = 0 ) {
  194.     var y = Math.sqrt(1 - x * x);
  195.     y = (x + y) / 2;
  196.     logFeats( { curve: y } );
  197.     return y;
  198. }
  199.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement