Advertisement
jargon

Roe2Js :: "canvasRenderStats.js"

Jul 3rd, 2024
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     function renderStatBar(x,y,width,height,caption,font,fg,bg){
  2.        
  3.         drawRectangle( x, y, width, height, 'black', bg );
  4.  
  5.         drawText( x, y, `${height}px ${font}`, fg, caption );
  6.        
  7.     }
  8.  
  9.     function renderStats(px,py,z){
  10.            
  11.         // var [ px, py, pz ] = cursorState ( layers.critter );
  12.        
  13.         var xOffset = viewSpanX * tileW + gutterW * 3;
  14.         var yOffset = gutterH;
  15.        
  16.         z = z || pz;
  17.        
  18.         let s = [];
  19.         let pct = [];
  20.        
  21.         drawText(gutterW * 3 + viewSpanX * tileW, gutterH * 2 + tileH / 2,'16px Impact','white','" ' + ucwords(full_entity_stats[px][py][layers.critter].stats.card.namesake) + ' "');
  22.        
  23.         s['health'] = full_entity_stats[px][py][layers.critter].stats.health;
  24.        
  25.         s['stamina'] = full_entity_stats[px][py][layers.critter].stats.stamina;
  26.        
  27.         s['essence'] = full_entity_stats[px][py][layers.critter].stats.essence;
  28.        
  29.         var width = purseSpanX;
  30.         var height = gutterH * 2;
  31.         var font = 'Small Fonts';
  32.        
  33.         drawText(
  34.             gutterW * 3 + viewSpanX * tileW, gutterH + tileH * 3,
  35.             `${height*0.8}px ${font}`,
  36.             'white',
  37.             "health:  " + s['health'].current
  38.             +'/'+ s['health'].maximum
  39.             );
  40.         drawText(
  41.             gutterW * 3 + viewSpanX * tileW, gutterH + tileH * 3 + gutterH * 2,
  42.             `${height*0.8}px ${font}`,
  43.             'white',
  44.             "stam: " + s['stamina'].current
  45.             +'/'+ s['stamina'].maximum
  46.             );
  47.         drawText(
  48.             gutterW * 3 + viewSpanX * tileW, gutterH + tileH * 3 + gutterH * 4,
  49.             `${height*0.8}px ${font}`,
  50.             'white',
  51.             "ess:     " + s['essence'].current
  52.             +'/'+ s['essence'].maximum
  53.             );
  54.  
  55.         /*
  56.         renderStatusBar( s, 'health', tileW * viewSpanX + gutterW * 2, gutterH + gutterH * 2, tileW * purseSpanX, tileH / 2, 'black', 'red' );
  57.  
  58.         renderStatusBar( s, 'stamina', tileW * viewSpanX + gutterW * 2, gutterH + gutterH * 3, tileW * purseSpanX, tileH / 2, 'black', 'yellow' );
  59.  
  60.         renderStatusBar( s, 'essence', tileW * viewSpanX + gutterW * 2, gutterH + gutterH * 4, tileW * purseSpanX, tileH / 2, 'black', 'cyan' );
  61.         */
  62.     }
  63.    
  64. function renderStatusBar(stat, attrName, xOffset, yOffset, width, height, fg, bg ) {
  65.        
  66.     // var [ px, py, pz ] = cursorState ( );
  67.  
  68.     let s = stat[attrName];
  69.    
  70.     let pct = [];
  71.     let w = [];
  72.    
  73.     s.minimum = s.minimum || 0;
  74.     s.maximum = s.maximum || 1;
  75.     s.current = s.current || 0;
  76.     s.recovery = s.recovery || 0;
  77.            
  78.     pct['current'] = Math.floor(100 * s.current / s.maximum);
  79.  
  80.     pct['minimum'] = Math.floor(100 * s.minimum / s.maximum);
  81.  
  82.     pct['maximum'] = Math.floor(100 * s.maximum / s.maximum);
  83.  
  84.     pct['recovery'] = Math.floor(100 * (s.current + s.recovery) / s.maximum);
  85.    
  86.     let x = xOffset;
  87.     let y = yOffset + tileH;
  88.    
  89.     // s.current, s.recovery
  90.     // s.minimum, s.maximum
  91.  
  92.     let caption = `${attrName}: ${s.current} / ${s.maximum}`;
  93.    
  94.     let font = 'Small Fonts';
  95.    
  96.     // fg, bg
  97.  
  98.     w['current'] = width * curve(pct['current']) / 100;
  99.     w['recovery'] = width * curve(pct['recovery']) / 100;
  100.    
  101.     w['minimum'] = 0;
  102.     w['maximum'] = width * curve(1.0) / 100;
  103.  
  104.     drawRectangle( x, y, w['maximum'], height, 'black', 'gray' );
  105.    
  106.     drawRectangle( x, y + gutterH / 2, w['current'], height - gutterH / 2, 'black', bg );
  107.  
  108.     drawRectangle( x, y, w['recovery'], height - gutterH / 2, 'rgba(0,0,0,0.0)', 'rgba(255,255,255,0.7)' );
  109.  
  110.     drawRectangle( x, y, width, height, 'black', 'rgba(0,0,0,0.0)' );
  111.  
  112.     drawText( x, y + gutterH, `${height*0.8}px ${font}`, 'black', caption );
  113.  
  114. }
  115.  
  116. function curve( x = 0 ) {
  117.     var y = Math.sqrt(1 - x * x);
  118.     y = (x + y) / 2;
  119.     logFeats( { curve: y } );
  120.     return y;
  121. }
  122.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement