Advertisement
JoshDreamland

CLion Extract Method Wut

Jul 12th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.81 KB | None | 0 0
  1.   SurfaceFormat::ColorGrid renderWorldByPurity(const World &world) {
  2.     return renderWorld(world, [](const Tile& t) {
  3.       if (t.hasTile) {
  4.         const Properties::TileProperty &tprop = t.getTileProperties();
  5.         if (tprop.givesItem == Properties::GivesItem::ALWAYS) {
  6.           return tprop.attributes.biome & (int) Properties::Biome::CRIMSON
  7.                  ? SurfaceFormat::RGBA(255, 0, 0, 255)
  8.                  : tprop.attributes.biome & (int) Properties::Biome::CORRUPTION
  9.                    ? SurfaceFormat::RGBA(128, 0, 255, 255)
  10.                    : tprop.attributes.biome & (int) Properties::Biome::HALLOW
  11.                      ? SurfaceFormat::RGBA(64, 128, 255, 255)
  12.                      : SurfaceFormat::RGBA(32, 200, 64, 255);
  13.         }
  14.       }
  15.       if (t.liquidAmount > 0 && t.liquidType != LiquidType::NONE) {
  16.         return t.liquidType == LiquidType::WATER
  17.                ? SurfaceFormat::RGBA(0, 0, 255, t.liquidAmount * 255 / 8)
  18.                : t.liquidType == LiquidType::HONEY
  19.                    ? SurfaceFormat::RGBA(255, 255, 0, t.liquidAmount * 255 / 8)
  20.                    : SurfaceFormat::RGBA(255, 0, 0, t.liquidAmount * 255 / 8);
  21.       }
  22.       return SurfaceFormat::RGBA(255, 255, 255, 255);
  23.     });
  24.   }
  25.  
  26. // ==============================================================================
  27. // Select lines 15-22, Refactor—→Extract method. Result:
  28. // ==============================================================================
  29.  
  30.   SurfaceFormat::RGBA getLiquidColor(const Tile &t);
  31.  
  32.   SurfaceFormat::ColorGrid renderWorldByPurity(const World &world) {
  33.     return renderWorld(world, [](const Tile& t) {
  34.       if (t.hasTile) {
  35.         const Properties::TileProperty &tprop = t.getTileProperties();
  36.         if (tprop.givesItem == Properties::GivesItem::ALWAYS) {
  37.           return tprop.attributes.biome & (int) Properties::Biome::CRIMSON
  38.                  ? SurfaceFormat::RGBA(255, 0, 0, 255)
  39.                  : tprop.attributes.biome & (int) Properties::Biome::CORRUPTION
  40.                    ? SurfaceFormat::RGBA(128, 0, 255, 255)
  41.                    : tprop.attributes.biome & (int) Properties::Biome::HALLOW
  42.                      ? SurfaceFormat::RGBA(64, 128, 255, 255)
  43.                      : SurfaceFormat::RGBA(32, 200, 64, 255);
  44.         }
  45.       }
  46.       return getLiquidColor(t);
  47.     });
  48.   }
  49.  
  50.   SurfaceFormat::ColorGrid getLiquidColor(const Tile &t) {
  51.     if (t.liquidAmount > 0 && t.liquidType != LiquidType::NONE) {
  52.         return t.liquidType == LiquidType::WATER
  53.                ? this->RGBA(0, 0, 255, t.liquidAmount * 255 / 8)
  54.                : t.liquidType == LiquidType::HONEY
  55.                    ? this->RGBA(255, 255, 0, t.liquidAmount * 255 / 8)
  56.                    : this->RGBA(255, 0, 0, t.liquidAmount * 255 / 8);
  57.       }
  58.     return this->RGBA(255, 255, 255, 255);
  59.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement