X-Git-Url: https://jasonwoof.com/gitweb/?p=hexbog.git;a=blobdiff_plain;f=main.coffee;h=147b76a2ff4680e47cd7b2881ea122ae5aac5db2;hp=c0524a09f97fb031dc4bf726b99e2271e316eeb2;hb=643696e68d5a23c907592334432796738fcc288c;hpb=ce432c1db2457df41346e82eba9838ab3708449e diff --git a/main.coffee b/main.coffee index c0524a0..147b76a 100644 --- a/main.coffee +++ b/main.coffee @@ -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 @@ -599,10 +603,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 @@ -625,9 +631,48 @@ show_definition = (word, type, definition, language) -> html += '
Definition ©wiktionary.org CC-BY-SA
' $definition_body.html html +connector_width = 11 +connector_radius = 5 +connector_slant = 12 +add_connector = (tile, horiz, vert) -> + style = {} + switch horiz + when 'left' + style.right = '100%' + when 'mid' + style.left = 21 - connector_radius + when 'right' + style.left = '100%' + switch vert + when 'top' + style.bottom = '100%' + when 'up' + style.top = 21 - connector_radius - connector_slant + when 'down' + style.top = 21 - connector_radius + connector_slant + when 'bot' + style.top = '100%' + 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) ->