- for num in faders
- html_tiles[num].unbind('click').fadeOut fade_ms
- timeout fade_ms, ->
- top_tile = -1
- new_px = 0
- new_slide = 0
- for fader in faders
- cur_top = board_aboves[fader][0]
- if cur_top is undefined
- cur_top = fader
- if top_tile isnt cur_top
- new_px = board_top_px[fader] - tile_width
- new_slide = 1
- top_tile = cur_top
- html_tiles[fader].remove()
- dest = fader
- aboves = board_aboves[fader].clone().reverse()
+ update_selection_display()
+ neighbors = {}
+ nneighbors = {}
+ for i in faders
+ tiles[i].dom.unbind('click').fadeOut fade_ms
+ tiles[i].new_hp = tiles[i].hp
+ for n in board_neighbors[i]
+ neighbors[n] = tiles[n]
+ for nn in board_neighbors[n]
+ nneighbors[nn] = tiles[nn]
+ for i in faders
+ delete nneighbors[i]
+ delete neighbors[i]
+ for k, v of neighbors
+ delete nneighbors[k]
+ # convert to arrays so we can sort, etc
+ nneighbors = (v for k, v of nneighbors)
+ neighbors = (v for k, v of neighbors)
+ # TODO make this apply eavenly to neighbors
+ # TODO different range for different word lengths
+ for nei in [neighbors, nneighbors]
+ if unsink > 0
+ for i in nei
+ if i.hp is 0 and unsink >= 10
+ i.new_hp = 10
+ unsink -= 10
+ i.text = new_letter()
+ i.dom.html i.text
+ for nei in [neighbors, nneighbors]
+ if unsink > 0
+ for i in nei
+ if i.hp > 0 and unsink > 0
+ unsink -= 10 - i.hp
+ i.new_hp = 10
+ for i in tiles
+ i.new_hp ?= i.hp - 1
+ if i.new_hp < 0
+ i.new_hp = 0
+ else if i.new_hp > HP_MAX
+ i.new_hp = HP_MAX
+ if i.new_hp isnt i.hp
+ i.dom.removeClass "hp#{i.hp}"
+ i.dom.addClass "hp#{i.new_hp}"
+ i.hp = i.new_hp
+ delete i.new_hp
+ timeout fade_ms + 1, ->
+ # which tiles need to be slid down
+ sliders = (false for i in tiles)
+
+ prev_col_top = null
+ next_new_y = null
+ for deleted in faders
+ # find the tile number of the top tile in this column
+ if board_aboves[deleted].length is 0
+ col_top = deleted
+ else
+ col_top = board_aboves[deleted][0]
+
+ # reset location where new tiles appear when we change columns
+ if prev_col_top isnt col_top
+ next_new_y = -10 - tile_width
+ prev_col_top = col_top
+
+ tiles[deleted].dom.remove()
+
+ # For each each tile above the one we've deleted:
+ # 1. move it down one slot in the data scructures
+ # 2. mark it as needing to slide
+ dest = deleted
+ aboves = board_aboves[deleted].clone().reverse()