src/js/view-logic.es6
/**
 * @param   board      2D array of game cells
 * @return  string     html snippet for the game board
 */
@param   board      2D array of game cells
@return  string     html snippet for the game board
@param board 2D array of game cells @return string html snippet for the game board
function generateBoardHtml(gamestate) {
  let board = gamestate.board
  let htmlString = ``
  htmlString += `<table id='game-board'>`
  for(let i=0; i<board[0].length; i++) {
    htmlString += `<tr id='row-${i}'>`
    board.forEach(column => {
      let cell = column[i]
      let backgroundImageId = `${cell.x}-${cell.y}-background-image`
      let imageId = `${cell.x}-${cell.y}-image`
      htmlString += `<td id='${cell.x}-${cell.y}' data-x='${cell.x}' data-y='${cell.y}' class='cell'>`
      htmlString += `<img id='${backgroundImageId}' src='${cell.backgroundImage}' class='cell-background-image'>`
      if(cell.occupiedBy) {
        let unit = cell.occupiedBy
        if(unit.current.hp === 0) {
          htmlString += `<img id='${imageId}' src='${unit.images.dead}' class='cell-image'>`
        } else {
          htmlString += `<img id='${imageId}' src='${unit.images.default}' class='cell-image'>`
        }
      }
      if(cell.unitMovingThrough) {
        let unit = cell.unitMovingThrough
        if(unit.current.hp === 0) {
          htmlString += `<img id='${imageId}' src='${unit.images.dead}' class='cell-image'>`
        } else {
          htmlString += `<img id='${imageId}' src='${unit.images.default}' class='cell-image'>`
        }
      }
      if(cell.indicator) {
        htmlString += `<span class='indicator' style='animation: ${cell.indicator} 1.1s infinite; animation-direction: alternate;'></span>`
      }
      if(cellIsSelected(gamestate, cell)) {
        htmlString += `<span class='selector default-selector'></span>`
      }
      if(cellIsSelectedSecondary(gamestate, cell)) {
        if(gamestate.currentMode === 'attack') {
          htmlString += `<span class='selector attack-selector'></span>`
        }
        if(gamestate.currentMode === 'magic') {
          htmlString += `<span class='selector magic-selector'></span>`
        }
      }
      htmlString += `</td>`
    })
    htmlString += `</tr>`
  }
  htmlString += `</table>`
  return htmlString
}
function generateBoardHtml ( gamestate ) { let board = gamestate . board let htmlString = ` ` htmlString += ` ` for ( let i = 0 ; i < board [ 0 ] . length ; i ++ ) { htmlString += ` ${ i } ` board . forEach ( column => { let cell = column [ i ] let backgroundImageId = ` ${ cell . x } ${ cell . y } ` let imageId = ` ${ cell . x } ${ cell . y } ` htmlString += ` ${ cell . x } ${ cell . y } ${ cell . x } ${ cell . y } ` htmlString += ` ${ backgroundImageId } ${ cell . backgroundImage } ` if ( cell . occupiedBy ) { let unit = cell . occupiedBy if ( unit . current . hp === 0 ) { htmlString += ` ${ imageId } ${ unit . images . dead } ` } else { htmlString += ` ${ imageId } ${ unit . images . default } ` } } if ( cell . unitMovingThrough ) { let unit = cell . unitMovingThrough if ( unit . current . hp === 0 ) { htmlString += ` ${ imageId } ${ unit . images . dead } ` } else { htmlString += ` ${ imageId } ${ unit . images . default } ` } } if ( cell . indicator ) { htmlString += ` ${ cell . indicator } ` } if ( cellIsSelected ( gamestate , cell ) ) { htmlString += ` ` } if ( cellIsSelectedSecondary ( gamestate , cell ) ) { if ( gamestate . currentMode === 'attack' ) { htmlString += ` ` } if ( gamestate . currentMode === 'magic' ) { htmlString += ` ` } } htmlString += ` ` } ) htmlString += ` ` } htmlString += ` ` return htmlString }
@param   board      2D array of game cells
 @return  string     html snippet for the game board
@param board 2D array of game cells @return string html snippet for the game board
// number of rows // let image = cell.image ? cell.image : cell.backgroundImage // if there's something in the cell, add it's image on top of the cell image(assuming transparent images for units, items, etc.) // to allow movement over allies and corpses // primary selector // context sensitive selector, for attacking, moving, etc.