Sha256: 9b6ba70d1f9a61690e49ccc14cd189f613a270ef2abd02fdb2ce33e5ec8c5d5c
Contents?: true
Size: 1.7 KB
Versions: 2
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 { self.current_image = image(50, 80) {empty_playing_card(suit: suit)} self.model = game.foundation_piles[Model::PlayingCard::SUITS.index(suit)] } after_body { 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 } 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
glimmer-dsl-swt-4.20.13.9 | samples/elaborate/klondike_solitaire/view/foundation_pile.rb |
glimmer-dsl-swt-4.20.13.8 | samples/elaborate/klondike_solitaire/view/foundation_pile.rb |