Advertisement
AJPlayz7

tree?

Mar 28th, 2025
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let tiles,
  2.     branches,
  3.     tankTree,
  4.  
  5.  
  6. function generateTankTree(indexes) {
  7.     tiles = [];
  8.     branches = [];
  9.     tankTree = { width: 0, height: 0 };
  10.     let rightmostSoFar = 0;
  11.     if (!Array.isArray(indexes)) indexes = [indexes];
  12.     for (let index of indexes) {
  13.         rightmostSoFar += 3 + measureSize(rightmostSoFar, 0, 0, { index }).width;
  14.     }
  15.     for (let { x, y } of tiles) {
  16.         tankTree.width = Math.max(tankTree.width, x);
  17.         tankTree.height = Math.max(tankTree.height, y);
  18.     }
  19. } // (...drawFloor)
  20.  
  21.  
  22. global.showTree = false;
  23. global.scrollX = global.scrollY = global.fixedScrollX = global.fixedScrollY = -1;
  24. global.scrollVelocityY = global.scrollVelocityX = 0;
  25. let lastGuiType = null;
  26. function drawUpgradeTree(spacing, alcoveSize) {
  27.     /*if (global.died) {
  28.         global.showTree = false;
  29.         global.scrollX = global.scrollY = global.fixedScrollX = global.fixedScrollY = global.scrollVelocityY = global.scrollVelocityX = 0;
  30.         global.treeScale = 1;
  31.         return;
  32.     }*/ // Hide the tree on death
  33.  
  34.     if (lastGuiType != gui.type) {
  35.         let m = util.getEntityImageFromMockup(gui.type), // The mockup that corresponds to the player's tank
  36.             rootName = m.rerootUpgradeTree, // The upgrade tree root of the player's tank
  37.             rootIndex = [];
  38.         for (let name of rootName) {
  39.             let ind = name == undefined ? -1 : global.mockups.find(i => i.className == name).index;
  40.             rootIndex.push(ind); // The index of the mockup that corresponds to the root tank (-1 for no root)
  41.         }
  42.         if (!rootIndex.includes(-1)) {
  43.             generateTankTree(rootIndex);
  44.         }
  45.         lastGuiType = gui.type;
  46.     }
  47.  
  48.     if (!tankTree) {
  49.         console.log('No tank tree rendered yet.');
  50.         return;
  51.     }
  52.  
  53.     let tileSize = alcoveSize / 2,
  54.         size = tileSize - 4, // TODO: figure out where this 4 comes from
  55.         spaceBetween = 10,
  56.         screenDivisor = (spaceBetween + tileSize) * 2 * global.treeScale,
  57.         padding = tileSize / screenDivisor,
  58.         dividedWidth = global.screenWidth / screenDivisor,
  59.         dividedHeight = global.screenHeight / screenDivisor,
  60.         treeFactor = 1 + spaceBetween / tileSize;
  61.  
  62.     global.fixedScrollX = Math.max(
  63.         dividedWidth - padding,
  64.         Math.min(
  65.             tankTree.width * treeFactor + padding - dividedWidth,
  66.             global.fixedScrollX + global.scrollVelocityX
  67.         )
  68.     );
  69.     global.fixedScrollY = Math.max(
  70.         dividedHeight - padding,
  71.         Math.min(
  72.             tankTree.height * treeFactor + padding - dividedHeight,
  73.             global.fixedScrollY + global.scrollVelocityY
  74.         )
  75.     );
  76.     global.scrollX = util.lerp(global.scrollX, global.fixedScrollX, 0.1);
  77.     global.scrollY = util.lerp(global.scrollY, global.fixedScrollY, 0.1);
  78.  
  79.     for (let [start, end] of branches) {
  80.         let sx = ((start.x - global.scrollX) * (tileSize + spaceBetween) + 1 + 0.5 * size) * global.treeScale + global.screenWidth / 2,
  81.             sy = ((start.y - global.scrollY) * (tileSize + spaceBetween) + 1 + 0.5 * size) * global.treeScale + global.screenHeight / 2,
  82.             ex = ((end.x - global.scrollX) * (tileSize + spaceBetween) + 1 + 0.5 * size) * global.treeScale + global.screenWidth / 2,
  83.             ey = ((end.y - global.scrollY) * (tileSize + spaceBetween) + 1 + 0.5 * size) * global.treeScale + global.screenHeight / 2;
  84.         if (ex < 0 || sx > global.screenWidth || ey < 0 || sy > global.screenHeight) continue;
  85.         ctx.strokeStyle = color.black;
  86.         ctx.lineWidth = 2 * global.treeScale;
  87.         drawGuiLine(sx, sy, ex, ey);
  88.     }
  89.     ctx.globalAlpha = 0.5;
  90.     ctx.fillStyle = color.guiwhite;
  91.     ctx.fillRect(0, 0, innerWidth, innerHeight);
  92.     ctx.globalAlpha = 1;
  93.  
  94.     //draw the various tank icons
  95.     let angle = -Math.PI / 4;
  96.     for (let { x, y, colorIndex, index } of tiles) {
  97.         let ax = (x - global.scrollX) * (tileSize + spaceBetween) * global.treeScale + global.screenWidth / 2,
  98.             ay = (y - global.scrollY) * (tileSize + spaceBetween) * global.treeScale + global.screenHeight / 2;
  99.         if (ax < -tileSize || ax > global.screenWidth + tileSize || ay < -tileSize || ay > global.screenHeight + tileSize) continue;
  100.         drawEntityIcon(index.toString(), ax, ay, tileSize * global.treeScale, tileSize * global.treeScale, global.treeScale, angle, 1, colorIndex);
  101.     }
  102.  
  103.     let text = "Arrow keys to navigate the class tree. Shift to navigate faster. Scroll wheel (or +/- keys) to zoom in/out.";
  104.     let w = measureText(text, 18);
  105.     ctx.globalAlpha = 1;
  106.     ctx.lineWidth = 1;
  107.     ctx.fillStyle = color.dgrey;
  108.     ctx.strokeStyle = color.black;
  109.     ctx.fillText(text, global.screenWidth / 2 - w / 2, innerHeight * 0.04);
  110.     ctx.strokeText(text, global.screenWidth / 2 - w / 2, innerHeight * 0.04);
  111. } // (...drawMessages)
  112.  
  113.  
  114.     global.canSkill = !!gui.points && !global.showTree;
  115.     global.fps = global.metrics.rendertime;
  116.     if (global.showTree) {
  117.         drawUpgradeTree(spacing, alcoveSize);
  118.     } else {
  119.         if (global.mobile) { // MOBILE UI
  120.             drawMobileJoysticks();
  121.             drawMobileButtons(spacing, alcoveSize);
  122.         } // (mobile ui)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement