engagementgamelab/CivicSeed

View on GitHub
client/code/game/game.render.js

Summary

Maintainability
F
1 wk
Test Coverage

File game.render.js has 691 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict'
/* global CivicSeed, $, $game */

var _ = require('underscore')

Severity: Major
Found in client/code/game/game.render.js - About 1 day to fix

    exports has 26 functions (exceeds 20 allowed). Consider refactoring.
    Open

    var $render = module.exports = {
    
      ready: false,
    
      colors: {
    Severity: Minor
    Found in client/code/game/game.render.js - About 3 hrs to fix

      Function createCanvasForPlayer has 72 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        createCanvasForPlayer: function (id, skinSuit, playerColor) {
          var context = _offscreenPlayersContext[id]
      
          // If player's canvas currently exists, clear it
          if (context) {
      Severity: Major
      Found in client/code/game/game.render.js - About 2 hrs to fix

        Function drawMapTile has 60 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          drawMapTile: function (tileData) {
            var srcX, srcY
        
            var tilesheetIndex = tileData.colored ? 1 : 0
            // background1, the ground texture
        Severity: Major
        Found in client/code/game/game.render.js - About 2 hrs to fix

          Function renderMouse has 50 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            renderMouse: function (mouse) {
              var mX = mouse.cX * $game.TILE_SIZE
              var mY = mouse.cY * $game.TILE_SIZE
              var state = $game.$map.getTileState({ x: mouse.cX, y: mouse.cY })
          
          
          Severity: Minor
          Found in client/code/game/game.render.js - About 2 hrs to fix

            Function loadTilesheets has 50 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              loadTilesheets: function (num) {
                var path = CivicSeed.CLOUD_PATH + '/img/game/'
                var ext = '.png'
            
                // load the images recursively until done
            Severity: Minor
            Found in client/code/game/game.render.js - About 2 hrs to fix

              Function onload has 43 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  _tilesheets[filename].onload = function () {
                    var next = num + 1
              
                    // If last image, go load skins?
                    if (num === _render.images.length - 1) {
              Severity: Minor
              Found in client/code/game/game.render.js - About 1 hr to fix

                Function renderBossTiles has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  renderBossTiles: function (tiles) {
                    for (var t = 0; t < tiles.length; t++) {
                      $render.clearMapTile(tiles[t])
                      _backgroundContext.fillStyle = tiles[t].color
                      _backgroundContext.fillRect(
                Severity: Minor
                Found in client/code/game/game.render.js - About 1 hr to fix

                  Function loadSkinSuitImages has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    loadSkinSuitImages: function (num) {
                      if (num === undefined) num = 0
                  
                      var next = num + 1
                      var skinsList = $game.$skins.getSetsList()
                  Severity: Minor
                  Found in client/code/game/game.render.js - About 1 hr to fix

                    Function drawForegroundTile has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      drawForegroundTile: function (tileData) {
                        var srcX, srcY
                    
                        var tilesheetIndex = tileData.colored ? 1 : 0
                        if (tileData.f1 > -1) {
                    Severity: Minor
                    Found in client/code/game/game.render.js - About 1 hr to fix

                      Function init has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        init: function (callback) {
                          // Optimize display for higher-pixel-density screens (e.g. Retina)
                          if (window.devicePixelRatio) {
                            $game.PIXEL_RATIO = window.devicePixelRatio
                          }
                      Severity: Minor
                      Found in client/code/game/game.render.js - About 1 hr to fix

                        Function createCanvasForPlayer has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                        Open

                          createCanvasForPlayer: function (id, skinSuit, playerColor) {
                            var context = _offscreenPlayersContext[id]
                        
                            // If player's canvas currently exists, clear it
                            if (context) {
                        Severity: Minor
                        Found in client/code/game/game.render.js - About 1 hr to fix

                        Cognitive Complexity

                        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                        A method's cognitive complexity is based on a few simple rules:

                        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                        • Code is considered more complex for each "break in the linear flow of the code"
                        • Code is considered more complex when "flow breaking structures are nested"

                        Further reading

                        Function renderTile has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          renderTile: function (i, j) {
                            // get the index (which refers to the location of the image)
                            // tilemap reference to images starts at 1 instead of 0
                            var curTile = $game.$map.currentTiles[i][j]
                            var backIndex1 = curTile.background - 1
                        Severity: Minor
                        Found in client/code/game/game.render.js - About 1 hr to fix

                          Function createCanvas has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                            createCanvas: function (elementId, width, height, onDOM, styles) {
                          Severity: Minor
                          Found in client/code/game/game.render.js - About 35 mins to fix

                            Function loadTilesheets has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                              loadTilesheets: function (num) {
                                var path = CivicSeed.CLOUD_PATH + '/img/game/'
                                var ext = '.png'
                            
                                // load the images recursively until done
                            Severity: Minor
                            Found in client/code/game/game.render.js - About 35 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Function renderFrame has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                              renderFrame: function () {
                                // $game.$others.clear();
                                // $game.$player.clear();
                                // $game.$npc.clear();
                                // $game.$botanist.clear();
                            Severity: Minor
                            Found in client/code/game/game.render.js - About 25 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Function loadSkinSuitImages has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                              loadSkinSuitImages: function (num) {
                                if (num === undefined) num = 0
                            
                                var next = num + 1
                                var skinsList = $game.$skins.getSetsList()
                            Severity: Minor
                            Found in client/code/game/game.render.js - About 25 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Similar blocks of code found in 3 locations. Consider refactoring.
                            Open

                                if (tileData.b3 > -1) {
                                  srcX = tileData.b3 % _tilesheetWidth
                                  srcY = Math.floor(tileData.b3 / _tilesheetWidth)
                                  // draw it to offscreen
                                  _backgroundContext.drawImage(
                            Severity: Major
                            Found in client/code/game/game.render.js and 2 other locations - About 5 hrs to fix
                            client/code/game/game.render.js on lines 456..472
                            client/code/game/game.render.js on lines 474..489

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 138.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 3 locations. Consider refactoring.
                            Open

                                if (tileData.b1 > -1) {
                                  srcX = tileData.b1 % _tilesheetWidth
                                  srcY = Math.floor(tileData.b1 / _tilesheetWidth)
                            
                                  // draw it to offscreen
                            Severity: Major
                            Found in client/code/game/game.render.js and 2 other locations - About 5 hrs to fix
                            client/code/game/game.render.js on lines 474..489
                            client/code/game/game.render.js on lines 491..506

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 138.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 3 locations. Consider refactoring.
                            Open

                                if (tileData.b2 > -1) {
                                  srcX = tileData.b2 % _tilesheetWidth
                                  srcY = Math.floor(tileData.b2 / _tilesheetWidth)
                                  // draw it to offscreen
                                  _backgroundContext.drawImage(
                            Severity: Major
                            Found in client/code/game/game.render.js and 2 other locations - About 5 hrs to fix
                            client/code/game/game.render.js on lines 456..472
                            client/code/game/game.render.js on lines 491..506

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 138.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                if (tileData.f2 > -1) {
                                  srcX = tileData.f2 % _tilesheetWidth
                                  srcY = Math.floor(tileData.f2 / _tilesheetWidth)
                                  _foregroundContext.drawImage(
                                    _tilesheetCanvas[tilesheetIndex],
                            Severity: Major
                            Found in client/code/game/game.render.js and 1 other location - About 4 hrs to fix
                            client/code/game/game.render.js on lines 514..528

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 134.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                if (tileData.f1 > -1) {
                                  srcX = tileData.f1 % _tilesheetWidth
                                  srcY = Math.floor(tileData.f1 / _tilesheetWidth)
                                  _foregroundContext.drawImage(
                                    _tilesheetCanvas[tilesheetIndex],
                            Severity: Major
                            Found in client/code/game/game.render.js and 1 other location - About 4 hrs to fix
                            client/code/game/game.render.js on lines 529..543

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 134.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                              clearRobot: function (info) {
                                _charactersContext.clearRect(
                                  info.prevX,
                                  info.prevY - $game.TILE_SIZE * 4,
                                  $game.TILE_SIZE * 6,
                            Severity: Major
                            Found in client/code/game/game.render.js and 1 other location - About 1 hr to fix
                            client/code/game/game.render.js on lines 776..783

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 63.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                              clearBotanist: function (info) {
                                _charactersContext.clearRect(
                                  info.prevX,
                                  info.prevY - $game.TILE_SIZE * 4,
                                  $game.TILE_SIZE * 6,
                            Severity: Major
                            Found in client/code/game/game.render.js and 1 other location - About 1 hr to fix
                            client/code/game/game.render.js on lines 786..793

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 63.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                      _tilesheetContext[0].drawImage(
                                        _tilesheets[filename],
                                        0,
                                        0,
                                        _tilesheets[filename].width,
                            Severity: Major
                            Found in client/code/game/game.render.js and 1 other location - About 1 hr to fix
                            client/code/game/game.render.js on lines 266..276

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 59.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Similar blocks of code found in 2 locations. Consider refactoring.
                            Open

                                      _tilesheetContext[1].drawImage(
                                        _tilesheets[filename],
                                        0,
                                        0,
                                        _tilesheets[filename].width,
                            Severity: Major
                            Found in client/code/game/game.render.js and 1 other location - About 1 hr to fix
                            client/code/game/game.render.js on lines 248..258

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 59.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            There are no issues that match your filters.

                            Category
                            Status