rubysketch 0.9.4 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/release-gem.yml +10 -1
- data/.github/workflows/test.yml +9 -0
- data/ChangeLog.md +18 -0
- data/RubySketch.podspec +1 -1
- data/VERSION +1 -1
- data/bin/rubysketch +33 -0
- data/examples/constraint.rb +89 -0
- data/lib/rubysketch/all.rb +2 -0
- data/lib/rubysketch/constraint.rb +422 -0
- data/lib/rubysketch/context.rb +17 -9
- data/lib/rubysketch/extension.rb +1 -1
- data/lib/rubysketch/helper.rb +10 -0
- data/lib/rubysketch/pin.rb +108 -0
- data/lib/rubysketch/shape.rb +1 -1
- data/lib/rubysketch/sprite.rb +442 -48
- data/pod.rake +1 -1
- data/rubysketch.gemspec +8 -6
- data/test/helper.rb +23 -0
- data/test/test_constraint.rb +230 -0
- data/test/test_context.rb +55 -18
- data/test/test_sprite.rb +2 -8
- data/test/test_sprite_world.rb +66 -0
- metadata +38 -15
data/lib/rubysketch/extension.rb
CHANGED
data/lib/rubysketch/helper.rb
CHANGED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
module RubySketch
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# A pin fastened at a point on a sprite.
|
|
5
|
+
# Creating a constraint between sprites starts from a pin.
|
|
6
|
+
#
|
|
7
|
+
class Pin
|
|
8
|
+
|
|
9
|
+
# @private
|
|
10
|
+
def initialize(sprite, x = nil, y = nil, pin__: nil)
|
|
11
|
+
if pin__
|
|
12
|
+
@sprite__ = pin__.view&.sprite
|
|
13
|
+
@pin__ = pin__
|
|
14
|
+
else
|
|
15
|
+
@sprite__ = sprite
|
|
16
|
+
@pin__ = x ? sprite.getInternal__.pin(x, y) : sprite.getInternal__.pin
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Creates a constraint that makes the pin and the target point coincide.
|
|
21
|
+
#
|
|
22
|
+
# @param [Sprite, Pin, Vector, Array<Numeric>, nil] target
|
|
23
|
+
# the center of a sprite, a pin, or a point in the world.
|
|
24
|
+
# snaps to the world when target is omitted
|
|
25
|
+
#
|
|
26
|
+
# @return [SnapConstraint] a new constraint
|
|
27
|
+
#
|
|
28
|
+
def snap(*args, **options, &block)
|
|
29
|
+
create__ SnapConstraint, @pin__.snap(*unwrap__(args)), options, block
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Creates a constraint that keeps the distance to the target point.
|
|
33
|
+
#
|
|
34
|
+
# @param [Sprite, Pin, Vector, Array<Numeric>, nil] target
|
|
35
|
+
# the center of a sprite, a pin, or a point in the world.
|
|
36
|
+
# links to the world when target is omitted
|
|
37
|
+
#
|
|
38
|
+
# @return [LinkConstraint] a new constraint
|
|
39
|
+
#
|
|
40
|
+
def link(*args, **options, &block)
|
|
41
|
+
create__ LinkConstraint, @pin__.link(*unwrap__(args)), options, block
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Creates a constraint that makes the pin ride on the target like a
|
|
45
|
+
# wheel: it slides along an axis for the suspension and spins freely.
|
|
46
|
+
#
|
|
47
|
+
# @param [Sprite, Pin, Vector, Array<Numeric>, nil] target
|
|
48
|
+
# the center of a sprite, a pin, or a point in the world.
|
|
49
|
+
# rides on the world when target is omitted
|
|
50
|
+
#
|
|
51
|
+
# @return [WheelConstraint] a new constraint
|
|
52
|
+
#
|
|
53
|
+
def wheel(*args, **options, &block)
|
|
54
|
+
create__ WheelConstraint, @pin__.wheel(*unwrap__(args)), options, block
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Creates a constraint that moves the pin toward the target every frame.
|
|
58
|
+
#
|
|
59
|
+
# @param [Sprite, Pin, Vector, Array<Numeric>, nil] target
|
|
60
|
+
# the center of a sprite, a pin, or a point in the world.
|
|
61
|
+
# chases nothing when target is omitted
|
|
62
|
+
#
|
|
63
|
+
# @return [ChaseConstraint] a new constraint
|
|
64
|
+
#
|
|
65
|
+
def chase(*args, **options, &block)
|
|
66
|
+
create__ ChaseConstraint, @pin__.chase(*unwrap__(args)), options, block
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Returns the sprite the pin is fastened to.
|
|
70
|
+
#
|
|
71
|
+
# @return [Sprite, nil] nil for a pin in the world
|
|
72
|
+
#
|
|
73
|
+
def sprite()
|
|
74
|
+
@sprite__
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Returns the position of the pin.
|
|
78
|
+
#
|
|
79
|
+
# @return [Vector, nil] sprite-local position, or nil for the center
|
|
80
|
+
#
|
|
81
|
+
def position()
|
|
82
|
+
@pin__.position&.toVector
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
alias pos position
|
|
86
|
+
|
|
87
|
+
# @private
|
|
88
|
+
def getInternal__()
|
|
89
|
+
@pin__
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
private
|
|
93
|
+
|
|
94
|
+
def create__(klass, constraint, options, block)
|
|
95
|
+
klass.new(constraint).tap do |c|
|
|
96
|
+
c.set options unless options.empty?
|
|
97
|
+
Xot::BlockUtil.instance_eval_or_block_call c, &block if block
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def unwrap__(args)
|
|
102
|
+
args.map {|arg| RubySketch.unwrap__ arg}
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
end# Pin
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
end# RubySketch
|
data/lib/rubysketch/shape.rb
CHANGED
|
@@ -83,7 +83,7 @@ module RubySketch
|
|
|
83
83
|
|
|
84
84
|
# @deprecated Use {#contactEnd} instead.
|
|
85
85
|
def contact_end(&block)
|
|
86
|
-
warn "Shape#contact_end is deprecated, use #contactEnd instead", uniq: true
|
|
86
|
+
Xot.warn "Shape#contact_end is deprecated, use #contactEnd instead", uniq: true
|
|
87
87
|
contactEnd(&block)
|
|
88
88
|
end
|
|
89
89
|
|