X-Git-Url: https://jasonwoof.com/gitweb/?p=hexbog.git;a=blobdiff_plain;f=main.coffee;h=7daeab54a6959b286437143e11b199ec96de85a9;hp=900295d3b9d4e6646d1e0014060947b7e47adf85;hb=HEAD;hpb=fff2ed1a0a156da47c7fa1e9760c8546b9af44fe diff --git a/main.coffee b/main.coffee index 900295d..7daeab5 100644 --- a/main.coffee +++ b/main.coffee @@ -225,7 +225,7 @@ init_board_layout = () -> unless is_top_tile and fw_other is -1 push i + columns[col_num].height + fw_other # will be dereferenced later - space.neighbors = neighbors.clone() # FIXME ?remove ``.clone()`` + space.neighbors = neighbors col_offset += column.height # convert all space.neighbors arrays from containing space ids to referencing the space for s in spaces @@ -306,7 +306,7 @@ update_selection_display = -> else last = '' $little_tip.html "Click the #{last}\"#{word.substr(word.length - 1)}\" for #{score_for word} points" - $big_tip.html "#{word}" + $big_tip.html "#{word}" $big_tip.addClass('good') else $big_tip.html word @@ -332,9 +332,13 @@ unselect_tile = -> update_selection_display() _unselect_tile = -> - html_tile = selected.pop().dom - html_tile.removeClass 'selected_word' - html_tile.removeClass 'selected' + tile = selected.pop() + dom = tile.dom + if tile.connector? + tile.connector.remove() + delete tile.connector + dom.removeClass 'selected_word' + dom.removeClass 'selected' unselect_all = -> while selected.length @@ -544,7 +548,11 @@ blip_selection = -> force = effects.force.last() if force > 0 for tile in area.up - tile.new_hp = tile.hp + force + if tile.new_hp + # for overlap of board and [n]neigbors + tile.new_hp += force + else + tile.new_hp = tile.hp + force for s in spaces s.tile.new_hp ?= s.tile.hp - 1 if s.tile.new_hp < 0 @@ -599,10 +607,12 @@ score_for = (word) -> Math.round(Math.pow(1.7, word.length)) activate_selection = -> word = selected_word() if word.length < 3 + # should only happen when trying to blip a word with the keyboard # FIXME make this a hint log "Too short: \"#{word}\"" return unless is_word word + # should only happen when trying to blip a word with the keyboard # FIXME make this automatically part of the selection display log "Not on word list: \"#{word}\"" return @@ -616,18 +626,57 @@ activate_selection = -> show_definition = (word, type, definition, language) -> - html = "" + html = "" html += "#{word.substr(0, 1).toUpperCase() + word.substr(1)}, #{type}" if language isnt 'English' html += " (#{language})" html += ': ' html += definition - html += '
Definition ©wiktionary.org CC-BY-SA
' + html += '
Definition ©wiktionary.org CC-BY-SA
' $definition_body.html html +connector_width = 11 +connector_radius = 4 +connector_slant = 12 +add_connector = (tile, horiz, vert) -> + style = {} + switch horiz + when 'left' + style.left = -9 + when 'mid' + style.left = 21 - connector_radius + when 'right' + style.right = -9 + switch vert + when 'top' + style.top = -9 + when 'up' + style.top = 21 - connector_radius - connector_slant + when 'down' + style.top = 21 - connector_radius + connector_slant + when 'bot' + style.bottom = -9 + tile.connector = $("
").css style + tile.dom.append tile.connector select_tile = (tile) -> selected.push tile + if selected.length > 1 + prev = selected[selected.length - 2] + if prev.space.top_px < tile.space.top_px + if prev.space.left_px < tile.space.left_px + add_connector tile, 'left', 'up' + else if prev.space.left_px is tile.space.left_px + add_connector tile, 'mid', 'top' + else + add_connector tile, 'right', 'up' + else + if prev.space.left_px < tile.space.left_px + add_connector tile, 'left', 'down' + else if prev.space.left_px is tile.space.left_px + add_connector tile, 'mid', 'bot' + else + add_connector tile, 'right', 'down' update_selection_display() new_tile = (space, y) -> @@ -649,7 +698,7 @@ new_tile = (space, y) -> space.tile = tile html_tile.click -> - return if tile.hp < 1 + return unselect_all() if tile.hp < 1 word = selected_word() if tile in selected if selected_word().length > 2 and is_word(word) and tile is selected.last() @@ -779,7 +828,7 @@ extract_wiktionary_definiton = (html) -> look_up_definition = (word) -> $definition_body.html "Looking up definition for \"#{word}\"..." $.ajax({ - url: "http://en.wiktionary.org/w/api.php?action=parse&format=json&page=#{word}" + url: "https://en.wiktionary.org/w/api.php?action=parse&format=json&page=#{word}" jsonpCallback: "lud_#{word}" # always use the same callback for the same word so it's cacheable dataType: 'jsonp' cache: true