glimmer-dsl-swt 4.20.13.5 → 4.20.13.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +5 -5
- data/VERSION +1 -1
- data/docs/reference/GLIMMER_SAMPLES.md +13 -0
- data/glimmer-dsl-swt.gemspec +0 -0
- data/lib/glimmer/swt/custom/shape.rb +4 -4
- data/lib/glimmer/swt/image_proxy.rb +1 -1
- data/lib/glimmer/ui/custom_shape.rb +13 -0
- data/samples/elaborate/klondike_solitaire.rb +112 -0
- data/samples/elaborate/klondike_solitaire/model/column_pile.rb +60 -0
- data/samples/elaborate/klondike_solitaire/model/dealing_pile.rb +33 -0
- data/samples/elaborate/klondike_solitaire/model/dealt_pile.rb +25 -0
- data/samples/elaborate/klondike_solitaire/model/foundation_pile.rb +40 -0
- data/samples/elaborate/klondike_solitaire/model/game.rb +37 -0
- data/samples/elaborate/klondike_solitaire/model/playing_card.rb +86 -0
- data/samples/elaborate/klondike_solitaire/view/action_panel.rb +30 -0
- data/samples/elaborate/klondike_solitaire/view/column_pile.rb +66 -0
- data/samples/elaborate/klondike_solitaire/view/dealing_pile.rb +36 -0
- data/samples/elaborate/klondike_solitaire/view/dealt_pile.rb +38 -0
- data/samples/elaborate/klondike_solitaire/view/empty_playing_card.rb +28 -0
- data/samples/elaborate/klondike_solitaire/view/foundation_pile.rb +59 -0
- data/samples/elaborate/klondike_solitaire/view/hidden_playing_card.rb +19 -0
- data/samples/elaborate/klondike_solitaire/view/playing_card.rb +35 -0
- data/samples/elaborate/klondike_solitaire/view/tableau.rb +41 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7f34d2baa127f20cc05b387d51afed496456ee236e5a206594c1b5bd672aa56
|
4
|
+
data.tar.gz: e19feae85a8f5b29fee1c40eb259618b95b235ce7b41e847e8277a124e5ae362
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8fa48e0b887ed4a772eda18f997ed91f5ad2005d3aeae9aa1e1fccd2baffbdeb3e9578a56c2ca51b04eda425dc7b1ef420bf9bb6ab1b2fe28bde0aefc820dd2
|
7
|
+
data.tar.gz: 89a9947c73556344f300e7db6fe8d43913f1d089c041d5416b9c0b69367549764978c990737da74c157d573118d81c0a771ff06025676b5b3ba781f30e095853
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
### 4.20.13.8
|
4
|
+
|
5
|
+
- Glimmer Klondike Solitaire elaborate sample
|
6
|
+
|
7
|
+
### 4.20.13.7
|
8
|
+
|
9
|
+
- Support accepting ImageProxy objects in Canvas Shape DSL (not just image paths)
|
10
|
+
- Fix issue in ImageProxy not flattening args before selecting file path
|
11
|
+
|
12
|
+
### 4.20.13.6
|
13
|
+
|
14
|
+
- Ensure a dragged shape can be dropped back into a parent it originally belonged to without it counting as a drop into itself.
|
15
|
+
- Add set_data and get_data to Glimmer::UI::CustomShape, which proxies calls to body_root
|
16
|
+
|
3
17
|
### 4.20.13.5
|
4
18
|
|
5
19
|
- Fix issue occurring with shape drag & drop when the dragged shape is a drop target too, thus getting dropped back to itself.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 4.20.13.
|
1
|
+
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 4.20.13.9
|
2
2
|
## JRuby Desktop Development GUI Framework
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
|
4
4
|
[![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
|
@@ -15,7 +15,7 @@
|
|
15
15
|
[<img src="https://covers.oreillystatic.com/images/9780596519650/lrg.jpg" width=105 /><br />
|
16
16
|
Featured in JRuby Cookbook](http://shop.oreilly.com/product/9780596519650.do) and [Chalmers/Gothenburg University Software Engineering Master's Lecture Material](http://www.cse.chalmers.se/~bergert/slides/guest_lecture_DSLs.pdf)
|
17
17
|
|
18
|
-
[Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.13.
|
18
|
+
[Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.13.9 includes [SWT 4.20](https://download.eclipse.org/eclipse/downloads/drops4/R-4.20-202106111600/), which was released on June 11, 2021. Gem version numbers are in sync with the SWT library versions. The first two digits represent the SWT version number. The last two digits represent the minor and patch versions of Glimmer DSL for SWT. Note that SWT now supports AARCH64 on Mac and Linux, but it is not fully tested in Glimmer DSL for SWT yet, so deem its support experimental for the time being without guarantees for functionality until declared otherwise (report any issues you may encounter).
|
19
19
|
|
20
20
|
**Starting in version 4.20.0.0, [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) comes with the new [***Shine***](/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#shine) syntax** for highly intuitive and visually expressive View/Model Attribute Mapping, relying on `<=>` for bidirectional (two-way) data-binding and `<=` for unidirectional (one-way) data-binding, providing an alternative to the `bind` keyword (keep in mind that it is still a beta, so default back to `bind` whenever needed).
|
21
21
|
|
@@ -326,7 +326,7 @@ jgem install glimmer-dsl-swt
|
|
326
326
|
|
327
327
|
Or this command if you want a specific version:
|
328
328
|
```
|
329
|
-
jgem install glimmer-dsl-swt -v 4.20.13.
|
329
|
+
jgem install glimmer-dsl-swt -v 4.20.13.9
|
330
330
|
```
|
331
331
|
|
332
332
|
`jgem` is JRuby's version of `gem` command.
|
@@ -354,7 +354,7 @@ Note: if you're using activerecord or activesupport, keep in mind that Glimmer u
|
|
354
354
|
|
355
355
|
Add the following to `Gemfile`:
|
356
356
|
```
|
357
|
-
gem 'glimmer-dsl-swt', '~> 4.20.13.
|
357
|
+
gem 'glimmer-dsl-swt', '~> 4.20.13.9'
|
358
358
|
```
|
359
359
|
|
360
360
|
And, then run:
|
@@ -375,7 +375,7 @@ glimmer
|
|
375
375
|
```
|
376
376
|
|
377
377
|
```
|
378
|
-
Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.13.
|
378
|
+
Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.13.9
|
379
379
|
|
380
380
|
Usage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
|
381
381
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.20.13.
|
1
|
+
4.20.13.9
|
@@ -62,6 +62,7 @@
|
|
62
62
|
- [Tic Tac Toe](#tic-tac-toe)
|
63
63
|
- [Contact Manager](#contact-manager)
|
64
64
|
- [Glimmer Tetris](#glimmer-tetris)
|
65
|
+
- [Klondike Solitaire](#klondike-solitaire)
|
65
66
|
- [Mandelbrot Fractal](#mandelbrot-fractal)
|
66
67
|
- [Stock Ticker](#stock-ticker)
|
67
68
|
- [Metronome](#metronome)
|
@@ -1098,6 +1099,18 @@ Code:
|
|
1098
1099
|
|
1099
1100
|
![Tetris Help Menu](/images/glimmer-tetris-help-menu.png)
|
1100
1101
|
|
1102
|
+
#### Klondike Solitaire
|
1103
|
+
|
1104
|
+
This sample demonstrates how to build an interactive card game with MVC architecture, custom-shell/custom-widgets, data-binding, observers, and drag & drop.
|
1105
|
+
|
1106
|
+
Code:
|
1107
|
+
|
1108
|
+
[samples/elaborate/klondike_solitaire.rb](/samples/elaborate/klondike_solitaire.rb)
|
1109
|
+
|
1110
|
+
![Tetris](/images/glimmer-klondike-solitaire.png)
|
1111
|
+
|
1112
|
+
![Tetris](/images/glimmer-klondike-solitaire-played.png)
|
1113
|
+
|
1101
1114
|
#### Mandelbrot Fractal
|
1102
1115
|
|
1103
1116
|
This sample demonstrates how to render canvas graphics with multi-threaded processing taking advantage of all CPU cores and doing background processing of images.
|
data/glimmer-dsl-swt.gemspec
CHANGED
Binary file
|
@@ -228,9 +228,9 @@ module Glimmer
|
|
228
228
|
contain?(x, y)
|
229
229
|
end
|
230
230
|
|
231
|
-
def include_with_children?(x, y)
|
231
|
+
def include_with_children?(x, y, except_child: nil)
|
232
232
|
included = include?(x, y)
|
233
|
-
included ||= expanded_shapes.detect { |shape| shape.include?(x, y) }
|
233
|
+
included ||= expanded_shapes.reject {|shape| shape == except_child}.detect { |shape| shape.include?(x, y) }
|
234
234
|
end
|
235
235
|
|
236
236
|
# Indicates if a shape's x, y, width, height differ from its bounds calculation (e.g. arc / polygon)
|
@@ -405,7 +405,7 @@ module Glimmer
|
|
405
405
|
end
|
406
406
|
if @name == 'image'
|
407
407
|
if @args.first.is_a?(::String)
|
408
|
-
@args[0] = ImageProxy.
|
408
|
+
@args[0] = ImageProxy.create(@args[0])
|
409
409
|
end
|
410
410
|
if @args.first.is_a?(ImageProxy)
|
411
411
|
@image = @args[0] = @args[0].swt_image
|
@@ -592,7 +592,7 @@ module Glimmer
|
|
592
592
|
if observation_request == 'on_drop'
|
593
593
|
Shape.drop_shapes << self
|
594
594
|
handle_observation_request('on_mouse_up') do |event|
|
595
|
-
if Shape.dragging &&
|
595
|
+
if Shape.dragging && include_with_children?(event.x, event.y, except_child: Shape.dragged_shape)
|
596
596
|
drop_event = DropEvent.new(
|
597
597
|
doit: true,
|
598
598
|
dragged_shape: Shape.dragged_shape,
|
@@ -74,8 +74,8 @@ module Glimmer
|
|
74
74
|
end
|
75
75
|
options = @args.last.is_a?(Hash) ? @args.delete_at(-1) : {}
|
76
76
|
options[:swt_image] = @args.first if @args.size == 1 && @args.first.is_a?(Image)
|
77
|
-
@file_path = @args.first if @args.first.is_a?(String)
|
78
77
|
@args = @args.first if @args.size == 1 && @args.first.is_a?(Array)
|
78
|
+
@file_path = @args.first if @args.first.is_a?(String)
|
79
79
|
if options&.keys&.include?(:swt_image)
|
80
80
|
@swt_image = options[:swt_image]
|
81
81
|
@original_image_data = @image_data = @swt_image.image_data
|
@@ -264,6 +264,19 @@ module Glimmer
|
|
264
264
|
body_root.handle_observation_request(observation_request, &block)
|
265
265
|
end
|
266
266
|
|
267
|
+
# Sets data just like SWT widgets
|
268
|
+
def set_data(key=nil, value)
|
269
|
+
body_root.set_data(key, value)
|
270
|
+
end
|
271
|
+
alias setData set_data # for compatibility with SWT APIs
|
272
|
+
|
273
|
+
# Gets data just like SWT widgets
|
274
|
+
def get_data(key=nil)
|
275
|
+
body_root.get_data(key)
|
276
|
+
end
|
277
|
+
alias getData get_data # for compatibility with SWT APIs
|
278
|
+
alias data get_data # for compatibility with SWT APIs
|
279
|
+
|
267
280
|
def method_missing(method, *args, &block)
|
268
281
|
# TODO Consider supporting a glimmer error silencing option for methods defined here
|
269
282
|
# but fail the glimmer DSL for the right reason to avoid seeing noise in the log output
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'glimmer-dsl-swt'
|
2
|
+
|
3
|
+
require_relative 'klondike_solitaire/model/game'
|
4
|
+
|
5
|
+
require_relative 'klondike_solitaire/view/action_panel'
|
6
|
+
require_relative 'klondike_solitaire/view/tableau'
|
7
|
+
|
8
|
+
class KlondikeSolitaire
|
9
|
+
include Glimmer::UI::CustomShell
|
10
|
+
|
11
|
+
PLAYING_CARD_WIDTH = 50
|
12
|
+
PLAYING_CARD_HEIGHT = 80
|
13
|
+
PLAYING_CARD_SPACING = 5
|
14
|
+
MARGIN = 15
|
15
|
+
TABLEAU_WIDTH = 2*MARGIN + 7*(PLAYING_CARD_WIDTH + PLAYING_CARD_SPACING)
|
16
|
+
TABLEAU_HEIGHT = 400
|
17
|
+
|
18
|
+
|
19
|
+
## Add options like the following to configure CustomShell by outside consumers
|
20
|
+
#
|
21
|
+
# options :title, :background_color
|
22
|
+
# option :width, default: 320
|
23
|
+
# option :height, default: 240
|
24
|
+
|
25
|
+
## Use before_body block to pre-initialize variables to use in body
|
26
|
+
#
|
27
|
+
#
|
28
|
+
before_body {
|
29
|
+
@game = Model::Game.new
|
30
|
+
Display.app_name = 'Glimmer Klondike Solitaire'
|
31
|
+
@display = display {
|
32
|
+
on_about {
|
33
|
+
display_about_dialog
|
34
|
+
}
|
35
|
+
on_preferences {
|
36
|
+
display_about_dialog
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
## Use after_body block to setup observers for widgets in body
|
42
|
+
#
|
43
|
+
# after_body {
|
44
|
+
#
|
45
|
+
# }
|
46
|
+
|
47
|
+
## Add widget content inside custom shell body
|
48
|
+
## Top-most widget must be a shell or another custom shell
|
49
|
+
#
|
50
|
+
body {
|
51
|
+
shell(:no_resize) {
|
52
|
+
row_layout(:vertical) {
|
53
|
+
fill true
|
54
|
+
center true
|
55
|
+
margin_width 0
|
56
|
+
margin_height 0
|
57
|
+
margin_top 15
|
58
|
+
}
|
59
|
+
minimum_size TABLEAU_WIDTH, TABLEAU_HEIGHT
|
60
|
+
text "Glimmer Klondike Solitaire"
|
61
|
+
background :dark_green
|
62
|
+
|
63
|
+
action_panel(game: @game)
|
64
|
+
tableau(game: @game) {
|
65
|
+
layout_data {
|
66
|
+
width TABLEAU_WIDTH
|
67
|
+
height TABLEAU_HEIGHT
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
menu_bar {
|
72
|
+
menu {
|
73
|
+
text '&Game'
|
74
|
+
menu_item {
|
75
|
+
text '&Restart'
|
76
|
+
accelerator (OS.mac? ? :command : :ctrl), :r
|
77
|
+
|
78
|
+
on_widget_selected {
|
79
|
+
@game.restart!
|
80
|
+
}
|
81
|
+
}
|
82
|
+
menu_item {
|
83
|
+
text 'E&xit'
|
84
|
+
accelerator :alt, :f4
|
85
|
+
|
86
|
+
on_widget_selected {
|
87
|
+
body_root.close
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
91
|
+
menu {
|
92
|
+
text '&Help'
|
93
|
+
menu_item {
|
94
|
+
text '&About...'
|
95
|
+
on_widget_selected {
|
96
|
+
display_about_dialog
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
def display_about_dialog
|
105
|
+
message_box(body_root) {
|
106
|
+
text 'About'
|
107
|
+
message "Glimmer Klondike Solitaire\nGlimmer DSL for SWT Elaborate Sample"
|
108
|
+
}.open
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
KlondikeSolitaire.launch
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class KlondikeSolitaire
|
2
|
+
module Model
|
3
|
+
class ColumnPile
|
4
|
+
include Glimmer::DataBinding::ObservableModel
|
5
|
+
attr_reader :count
|
6
|
+
|
7
|
+
def initialize(game, count)
|
8
|
+
@game = game
|
9
|
+
@count = count
|
10
|
+
reset!
|
11
|
+
end
|
12
|
+
|
13
|
+
def reset!
|
14
|
+
playing_cards.clear
|
15
|
+
populate!(count.times.map { @game.deck.pop })
|
16
|
+
notify_observers(:playing_cards)
|
17
|
+
end
|
18
|
+
|
19
|
+
# this method does not validate
|
20
|
+
def populate!(new_playing_cards)
|
21
|
+
new_playing_cards.each_with_index do |playing_card, index|
|
22
|
+
playing_card.hidden = true if index < (new_playing_cards.size - 1)
|
23
|
+
playing_cards.push(playing_card)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# this method validates that playing card fits at the bottom of the column (opposite color and one number smaller)
|
28
|
+
# throws an error if it does not fit
|
29
|
+
def add!(new_playing_card)
|
30
|
+
bottom_card = playing_cards.last
|
31
|
+
if (playing_cards.empty? && new_playing_card.rank == 13) ||
|
32
|
+
(new_playing_card.color != bottom_card.color && new_playing_card.rank == (bottom_card.rank - 1))
|
33
|
+
playing_cards.push(new_playing_card)
|
34
|
+
else
|
35
|
+
raise "Cannot add #{new_playing_card} to #{self}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def remove!(card)
|
40
|
+
remove_cards_starting_at(playing_cards.index(card)).tap do |result|
|
41
|
+
playing_cards.last&.hidden = false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def remove_cards_starting_at(index)
|
46
|
+
removed_cards = playing_cards[index...playing_cards.size]
|
47
|
+
playing_cards[index...playing_cards.size] = []
|
48
|
+
removed_cards
|
49
|
+
end
|
50
|
+
|
51
|
+
def playing_cards
|
52
|
+
@playing_cards ||= []
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_s
|
56
|
+
"Column Pile #{count} (#{playing_cards.map {|card| "#{card.rank}#{card.suit.to_s[0].upcase}"}.join(" | ")})"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class KlondikeSolitaire
|
2
|
+
module Model
|
3
|
+
class DealingPile
|
4
|
+
DEALING_INITIAL_COUNT = 24
|
5
|
+
|
6
|
+
def initialize(game)
|
7
|
+
@game = game
|
8
|
+
reset!
|
9
|
+
end
|
10
|
+
|
11
|
+
def reset!
|
12
|
+
playing_cards.clear
|
13
|
+
DEALING_INITIAL_COUNT.times { playing_cards << @game.deck.pop }
|
14
|
+
end
|
15
|
+
|
16
|
+
def deal!
|
17
|
+
playing_card = playing_cards.shift
|
18
|
+
if playing_card.nil?
|
19
|
+
@game.dealt_pile.playing_cards.each do |a_playing_card|
|
20
|
+
playing_cards << a_playing_card
|
21
|
+
end
|
22
|
+
@game.dealt_pile.playing_cards.clear
|
23
|
+
else
|
24
|
+
@game.dealt_pile.push!(playing_card)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def playing_cards
|
29
|
+
@playing_cards ||= []
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class KlondikeSolitaire
|
2
|
+
module Model
|
3
|
+
class DealtPile
|
4
|
+
def initialize(game)
|
5
|
+
@game = game
|
6
|
+
end
|
7
|
+
|
8
|
+
def reset!
|
9
|
+
playing_cards.clear
|
10
|
+
end
|
11
|
+
|
12
|
+
def push!(playing_card)
|
13
|
+
playing_cards.push(playing_card)
|
14
|
+
end
|
15
|
+
|
16
|
+
def remove!(card)
|
17
|
+
playing_cards.delete(card)
|
18
|
+
end
|
19
|
+
|
20
|
+
def playing_cards
|
21
|
+
@playing_cards ||= []
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class KlondikeSolitaire
|
2
|
+
module Model
|
3
|
+
class FoundationPile
|
4
|
+
attr_reader :suit
|
5
|
+
|
6
|
+
def initialize(game, suit)
|
7
|
+
@game = game
|
8
|
+
@suit = suit
|
9
|
+
reset!
|
10
|
+
end
|
11
|
+
|
12
|
+
def reset!
|
13
|
+
playing_cards.clear
|
14
|
+
end
|
15
|
+
|
16
|
+
# adds a card
|
17
|
+
# validates if it is a card that belongs to the suit
|
18
|
+
def add!(playing_card)
|
19
|
+
if playing_card.suit == suit &&
|
20
|
+
(
|
21
|
+
(playing_cards.empty? && playing_card.rank == 1) ||
|
22
|
+
playing_card.rank == (playing_cards.last.rank + 1)
|
23
|
+
)
|
24
|
+
playing_cards.push(playing_card)
|
25
|
+
else
|
26
|
+
raise "Cannot add #{playing_card} to #{self}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def playing_cards
|
31
|
+
@playing_cards ||= []
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
"Foundation Pile #{suit} (#{playing_cards.map {|card| "#{card.rank}#{card.suit.to_s[0].upcase}"}.join(" | ")})"
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative 'playing_card'
|
2
|
+
require_relative 'dealt_pile'
|
3
|
+
require_relative 'dealing_pile'
|
4
|
+
require_relative 'column_pile'
|
5
|
+
require_relative 'foundation_pile'
|
6
|
+
|
7
|
+
class KlondikeSolitaire
|
8
|
+
module Model
|
9
|
+
class Game
|
10
|
+
COLUMN_PILE_COUNT = 7
|
11
|
+
|
12
|
+
attr_reader :deck, :dealing_pile, :dealt_pile, :column_piles, :foundation_piles
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@deck = new_deck
|
16
|
+
@dealt_pile = DealtPile.new(self)
|
17
|
+
@dealing_pile = DealingPile.new(self)
|
18
|
+
@column_piles = COLUMN_PILE_COUNT.times.map {|n| ColumnPile.new(self, n + 1)}
|
19
|
+
@foundation_piles = PlayingCard::SUITS.map {|suit| FoundationPile.new(self, suit)}
|
20
|
+
end
|
21
|
+
|
22
|
+
def restart!
|
23
|
+
@deck = new_deck
|
24
|
+
@dealt_pile.reset!
|
25
|
+
@dealing_pile.reset!
|
26
|
+
@column_piles.each(&:reset!)
|
27
|
+
@foundation_piles.each(&:reset!)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def new_deck
|
33
|
+
PlayingCard.deck.shuffle
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
class KlondikeSolitaire
|
2
|
+
module Model
|
3
|
+
class PlayingCard
|
4
|
+
SUITS = [:spades, :hearts, :clubs, :diamonds]
|
5
|
+
BLACK_SUITS = [:spades, :clubs]
|
6
|
+
RED_SUITS = [:hearts, :diamonds]
|
7
|
+
RANK_COUNT = 13
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def deck
|
11
|
+
suit_decks.flatten
|
12
|
+
end
|
13
|
+
|
14
|
+
def suit_decks
|
15
|
+
SUITS.map do |suit|
|
16
|
+
suit_deck(suit)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def suit_deck(suit)
|
21
|
+
1.upto(RANK_COUNT).map do |rank|
|
22
|
+
new(rank, suit)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def rank_text(rank)
|
27
|
+
case rank
|
28
|
+
when 1
|
29
|
+
'A'
|
30
|
+
when 11
|
31
|
+
'J'
|
32
|
+
when 12
|
33
|
+
'Q'
|
34
|
+
when 13
|
35
|
+
'K'
|
36
|
+
else
|
37
|
+
rank
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def suit_text(suit)
|
42
|
+
case suit
|
43
|
+
when :spades
|
44
|
+
"♠"
|
45
|
+
when :hearts
|
46
|
+
"♥"
|
47
|
+
when :clubs
|
48
|
+
"♣"
|
49
|
+
when :diamonds
|
50
|
+
"♦"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
attr_reader :rank, :suit
|
56
|
+
attr_accessor :hidden
|
57
|
+
alias hidden? hidden
|
58
|
+
|
59
|
+
def initialize(rank, suit, hidden = false)
|
60
|
+
@rank = rank
|
61
|
+
@suit = suit
|
62
|
+
@hidden = hidden
|
63
|
+
end
|
64
|
+
|
65
|
+
def color
|
66
|
+
if BLACK_SUITS.include?(suit)
|
67
|
+
:black
|
68
|
+
elsif RED_SUITS.include?(suit)
|
69
|
+
:red
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_s
|
74
|
+
"Playing Card #{rank}#{suit.to_s[0].upcase}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def suit_text
|
78
|
+
self.class.suit_text(suit)
|
79
|
+
end
|
80
|
+
|
81
|
+
def rank_text
|
82
|
+
self.class.rank_text(rank)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class KlondikeSolitaire
|
2
|
+
module View
|
3
|
+
class ActionPanel
|
4
|
+
include Glimmer::UI::CustomWidget
|
5
|
+
|
6
|
+
option :game
|
7
|
+
|
8
|
+
body {
|
9
|
+
composite {
|
10
|
+
grid_layout(1, false) {
|
11
|
+
margin_width 0
|
12
|
+
margin_height 0
|
13
|
+
}
|
14
|
+
|
15
|
+
background :dark_green
|
16
|
+
|
17
|
+
button {
|
18
|
+
layout_data :center, :center, true, false
|
19
|
+
|
20
|
+
text 'Restart Game'
|
21
|
+
|
22
|
+
on_widget_selected {
|
23
|
+
game.restart!
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require_relative '../model/column_pile'
|
2
|
+
|
3
|
+
require_relative 'playing_card'
|
4
|
+
|
5
|
+
class KlondikeSolitaire
|
6
|
+
module View
|
7
|
+
class ColumnPile
|
8
|
+
include Glimmer::UI::CustomShape
|
9
|
+
|
10
|
+
IMAGE_EMPTY = image(50, 80) {
|
11
|
+
rectangle(0, 0, 50, 80) {
|
12
|
+
background :dark_green
|
13
|
+
|
14
|
+
rectangle(0, 0, 49, 79, 15, 15) {
|
15
|
+
foreground :gray
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
options :pile_x, :pile_y, :model
|
21
|
+
|
22
|
+
after_body {
|
23
|
+
observe(model, 'playing_cards.last.hidden') do
|
24
|
+
build_column_pile(model.playing_cards)
|
25
|
+
end
|
26
|
+
build_column_pile(model.playing_cards)
|
27
|
+
}
|
28
|
+
|
29
|
+
body {
|
30
|
+
shape(pile_x, pile_y) {
|
31
|
+
on_drop do |drop_event|
|
32
|
+
begin
|
33
|
+
card_shape = drop_event.dragged_shape.get_data('custom_shape')
|
34
|
+
card = card_shape.model
|
35
|
+
model.add!(card)
|
36
|
+
card_parent_pile = card_shape.parent_pile
|
37
|
+
card_source_model = card_parent_pile.model
|
38
|
+
cards = card_source_model.remove!(card)
|
39
|
+
if cards.is_a?(Array) # if it is a column pile
|
40
|
+
cards[1..-1].each do |card|
|
41
|
+
model.add!(card)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
drop_event.dragged_shape.dispose
|
45
|
+
rescue => e
|
46
|
+
# pd e
|
47
|
+
drop_event.doit = false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
def build_column_pile(playing_cards)
|
54
|
+
body_root.shapes.to_a.each(&:dispose)
|
55
|
+
current_parent = body_root
|
56
|
+
playing_cards.each_with_index do |card, i|
|
57
|
+
current_parent.content {
|
58
|
+
current_parent = playing_card(card_x: 0, card_y: 20, model: card, parent_pile: self) {
|
59
|
+
drag_source true unless card.hidden?
|
60
|
+
}.body_root
|
61
|
+
}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative '../model/dealing_pile'
|
2
|
+
|
3
|
+
require_relative 'empty_playing_card'
|
4
|
+
require_relative 'hidden_playing_card'
|
5
|
+
|
6
|
+
class KlondikeSolitaire
|
7
|
+
module View
|
8
|
+
class DealingPile
|
9
|
+
include Glimmer::UI::CustomShape
|
10
|
+
|
11
|
+
options :pile_x, :pile_y, :model
|
12
|
+
|
13
|
+
after_body {
|
14
|
+
observe(model, 'playing_cards.empty?') do |empty_value|
|
15
|
+
body_root.shapes.to_a.each(&:dispose)
|
16
|
+
if empty_value
|
17
|
+
body_root.content {
|
18
|
+
empty_playing_card
|
19
|
+
}
|
20
|
+
else
|
21
|
+
body_root.content {
|
22
|
+
hidden_playing_card
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
}
|
27
|
+
|
28
|
+
body {
|
29
|
+
shape(pile_x, pile_y) {
|
30
|
+
hidden_playing_card
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative '../model/dealt_pile'
|
2
|
+
|
3
|
+
require_relative 'empty_playing_card'
|
4
|
+
require_relative 'playing_card'
|
5
|
+
|
6
|
+
class KlondikeSolitaire
|
7
|
+
module View
|
8
|
+
class DealtPile
|
9
|
+
include Glimmer::UI::CustomShape
|
10
|
+
|
11
|
+
options :pile_x, :pile_y, :model
|
12
|
+
|
13
|
+
after_body do
|
14
|
+
observe(model, 'playing_cards.empty?') do |empty_value|
|
15
|
+
if empty_value
|
16
|
+
body_root.shapes.to_a.dup.each(&:dispose)
|
17
|
+
body_root.content {
|
18
|
+
empty_playing_card
|
19
|
+
}
|
20
|
+
else
|
21
|
+
body_root.content {
|
22
|
+
playing_card(model: model.playing_cards.last, parent_pile: self) {
|
23
|
+
drag_source true
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
body {
|
31
|
+
shape(pile_x, pile_y) {
|
32
|
+
empty_playing_card
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative '../model/playing_card'
|
2
|
+
|
3
|
+
class KlondikeSolitaire
|
4
|
+
module View
|
5
|
+
class EmptyPlayingCard
|
6
|
+
include Glimmer::UI::CustomShape
|
7
|
+
|
8
|
+
option :suit
|
9
|
+
|
10
|
+
body {
|
11
|
+
rectangle(0, 0, 49, 79, 15, 15) {
|
12
|
+
foreground :gray
|
13
|
+
|
14
|
+
if suit
|
15
|
+
text {
|
16
|
+
string Model::PlayingCard.suit_text(suit)
|
17
|
+
x :default
|
18
|
+
y :default
|
19
|
+
is_transparent true
|
20
|
+
foreground Model::PlayingCard::BLACK_SUITS.include?(suit) ? :black : :red
|
21
|
+
}
|
22
|
+
end
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative '../model/playing_card'
|
2
|
+
require_relative '../model/foundation_pile'
|
3
|
+
|
4
|
+
class KlondikeSolitaire
|
5
|
+
module View
|
6
|
+
class FoundationPile
|
7
|
+
include Glimmer::UI::CustomShape
|
8
|
+
|
9
|
+
options :pile_x, :pile_y, :game, :suit
|
10
|
+
|
11
|
+
attr_accessor :current_image, :model
|
12
|
+
|
13
|
+
before_body {
|
14
|
+
self.current_image = image(50, 80) {empty_playing_card(suit: suit)}
|
15
|
+
self.model = game.foundation_piles[Model::PlayingCard::SUITS.index(suit)]
|
16
|
+
}
|
17
|
+
|
18
|
+
after_body {
|
19
|
+
observe(model, 'playing_cards.last') do |last_card|
|
20
|
+
if last_card
|
21
|
+
body_root.content {
|
22
|
+
playing_card(model: last_card)
|
23
|
+
}
|
24
|
+
else
|
25
|
+
body_root.clear_shapes
|
26
|
+
body_root.content {
|
27
|
+
empty_playing_card(suit: suit)
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
}
|
32
|
+
|
33
|
+
body {
|
34
|
+
shape(pile_x, pile_y) {
|
35
|
+
empty_playing_card(suit: suit)
|
36
|
+
|
37
|
+
on_drop do |drop_event|
|
38
|
+
begin
|
39
|
+
# TODO make sure one cannot drag a column pile of cards here
|
40
|
+
card_shape = drop_event.dragged_shape.get_data('custom_shape')
|
41
|
+
card = card_shape.model
|
42
|
+
card_parent_pile = card_shape.parent_pile
|
43
|
+
card_source_model = card_parent_pile.model
|
44
|
+
raise 'Cannot accept multiple cards' if card_source_model.playing_cards.index(card) != (card_source_model.playing_cards.size - 1)
|
45
|
+
model.add!(card)
|
46
|
+
card_source_model.remove!(card)
|
47
|
+
drop_event.dragged_shape.dispose
|
48
|
+
rescue => e
|
49
|
+
# pd e
|
50
|
+
drop_event.doit = false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
}
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class KlondikeSolitaire
|
2
|
+
module View
|
3
|
+
class HiddenPlayingCard
|
4
|
+
include Glimmer::UI::CustomShape
|
5
|
+
|
6
|
+
body {
|
7
|
+
rectangle(0, 0, 49, 79, 15, 15) {
|
8
|
+
background :red
|
9
|
+
|
10
|
+
# border
|
11
|
+
rectangle(0, 0, 49, 79, 15, 15) {
|
12
|
+
foreground :black
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class KlondikeSolitaire
|
2
|
+
module View
|
3
|
+
class PlayingCard
|
4
|
+
include Glimmer::UI::CustomShape
|
5
|
+
|
6
|
+
options :card_x, :card_y, :model, :parent_pile
|
7
|
+
|
8
|
+
before_body {
|
9
|
+
self.card_x ||= 0
|
10
|
+
self.card_y ||= 0
|
11
|
+
}
|
12
|
+
|
13
|
+
body {
|
14
|
+
rectangle(card_x, card_y, 49, 79, 15, 15) {
|
15
|
+
background model.hidden ? :red : :white
|
16
|
+
|
17
|
+
# border
|
18
|
+
rectangle(0, 0, 49, 79, 15, 15) {
|
19
|
+
foreground :black
|
20
|
+
}
|
21
|
+
|
22
|
+
unless model.hidden?
|
23
|
+
text {
|
24
|
+
string model ? "#{model.rank_text}#{model.suit_text}" : ""
|
25
|
+
x 5
|
26
|
+
y 5
|
27
|
+
foreground model ? model.color : :transparent
|
28
|
+
}
|
29
|
+
end
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative 'dealing_pile'
|
2
|
+
require_relative 'dealt_pile'
|
3
|
+
require_relative 'column_pile'
|
4
|
+
require_relative 'foundation_pile'
|
5
|
+
|
6
|
+
require_relative '../model/game'
|
7
|
+
|
8
|
+
class KlondikeSolitaire
|
9
|
+
module View
|
10
|
+
class Tableau
|
11
|
+
include Glimmer::UI::CustomWidget
|
12
|
+
|
13
|
+
option :game
|
14
|
+
|
15
|
+
body {
|
16
|
+
canvas {
|
17
|
+
background :dark_green
|
18
|
+
|
19
|
+
# row 1
|
20
|
+
@foundation_piles = Model::PlayingCard::SUITS.each_with_index.map do |suit, i|
|
21
|
+
foundation_pile(pile_x: MARGIN + i*(PLAYING_CARD_WIDTH + PLAYING_CARD_SPACING), pile_y: 0, game: game, suit: suit)
|
22
|
+
end
|
23
|
+
@dealt_pile = dealt_pile(pile_x: MARGIN + 5*(PLAYING_CARD_WIDTH + PLAYING_CARD_SPACING), pile_y: 0, model: game.dealt_pile)
|
24
|
+
@dealing_pile = dealing_pile(pile_x: MARGIN + 6*(PLAYING_CARD_WIDTH + PLAYING_CARD_SPACING), pile_y: 0, model: game.dealing_pile)
|
25
|
+
|
26
|
+
# row 2
|
27
|
+
@column_piles = 7.times.map do |n|
|
28
|
+
column_pile(pile_x: MARGIN + n*(PLAYING_CARD_WIDTH + PLAYING_CARD_SPACING), pile_y: PLAYING_CARD_HEIGHT + PLAYING_CARD_SPACING, model: game.column_piles[n])
|
29
|
+
end
|
30
|
+
|
31
|
+
on_mouse_up do |event|
|
32
|
+
if @dealing_pile.body_root.include?(event.x, event.y)
|
33
|
+
game.dealing_pile.deal!
|
34
|
+
end
|
35
|
+
end
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-swt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.20.13.
|
4
|
+
version: 4.20.13.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -545,6 +545,22 @@ files:
|
|
545
545
|
- samples/elaborate/contact_manager/contact.rb
|
546
546
|
- samples/elaborate/contact_manager/contact_manager_presenter.rb
|
547
547
|
- samples/elaborate/contact_manager/contact_repository.rb
|
548
|
+
- samples/elaborate/klondike_solitaire.rb
|
549
|
+
- samples/elaborate/klondike_solitaire/model/column_pile.rb
|
550
|
+
- samples/elaborate/klondike_solitaire/model/dealing_pile.rb
|
551
|
+
- samples/elaborate/klondike_solitaire/model/dealt_pile.rb
|
552
|
+
- samples/elaborate/klondike_solitaire/model/foundation_pile.rb
|
553
|
+
- samples/elaborate/klondike_solitaire/model/game.rb
|
554
|
+
- samples/elaborate/klondike_solitaire/model/playing_card.rb
|
555
|
+
- samples/elaborate/klondike_solitaire/view/action_panel.rb
|
556
|
+
- samples/elaborate/klondike_solitaire/view/column_pile.rb
|
557
|
+
- samples/elaborate/klondike_solitaire/view/dealing_pile.rb
|
558
|
+
- samples/elaborate/klondike_solitaire/view/dealt_pile.rb
|
559
|
+
- samples/elaborate/klondike_solitaire/view/empty_playing_card.rb
|
560
|
+
- samples/elaborate/klondike_solitaire/view/foundation_pile.rb
|
561
|
+
- samples/elaborate/klondike_solitaire/view/hidden_playing_card.rb
|
562
|
+
- samples/elaborate/klondike_solitaire/view/playing_card.rb
|
563
|
+
- samples/elaborate/klondike_solitaire/view/tableau.rb
|
548
564
|
- samples/elaborate/login.rb
|
549
565
|
- samples/elaborate/mandelbrot_fractal.rb
|
550
566
|
- samples/elaborate/meta_sample.rb
|