Sha256: 886d56dc349b080ddc79ab6aea74d1d4870ff766e1bc8988168894bd8fa5fcd3
Contents?: true
Size: 1.7 KB
Versions: 5
Compression:
Stored size: 1.7 KB
Contents
require_relative '../model/playing_card' require_relative '../model/foundation_pile' class KlondikeSolitaire module View class FoundationPile include Glimmer::UI::CustomShape options :pile_x, :pile_y, :game, :suit attr_accessor :current_image, :model before_body do self.current_image = image(50, 80) {empty_playing_card(suit: suit)} self.model = game.foundation_piles[Model::PlayingCard::SUITS.index(suit)] end after_body do observe(model, 'playing_cards.last') do |last_card| if last_card body_root.content { playing_card(model: last_card) } else body_root.clear_shapes body_root.content { empty_playing_card(suit: suit) } end end end body { shape(pile_x, pile_y) { empty_playing_card(suit: suit) on_drop do |drop_event| begin # TODO make sure one cannot drag a column pile of cards here card_shape = drop_event.dragged_shape.get_data('custom_shape') card = card_shape.model card_parent_pile = card_shape.parent_pile card_source_model = card_parent_pile.model raise 'Cannot accept multiple cards' if card_source_model.playing_cards.index(card) != (card_source_model.playing_cards.size - 1) model.add!(card) card_source_model.remove!(card) drop_event.dragged_shape.dispose rescue => e # pd e drop_event.doit = false end end } } end end end
Version data entries
5 entries across 5 versions & 1 rubygems