sottolio 0.1.4 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/example/scripts/chapter_1.rb +49 -47
- data/example/scripts/chapter_2.rb +1 -1
- data/lib/sottolio/version.rb +1 -1
- data/opal/sottolio/bootstrapper.rb +25 -13
- data/opal/sottolio/script.rb +6 -2
- data/opal/sottolio/utils.rb +29 -17
- data/opal/sottolio/wrapper/canvas/canvas_input.rb +17 -14
- data/opal/sottolio/wrapper/canvas/canvas_text.rb +11 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b73cfc781b858b0c57d0af83350cfe79a9cc3f5a
|
4
|
+
data.tar.gz: 6a73dbf6d587e0d75e828b1b5477a98980942d47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d067d963c9d6cce25a5acd680d6dc381bbc2b14ecc60b0af0d7d55a5ed5322b5d3f9fa37e6b730d144c5a7a773735f74f2e9eece22dd450599ca58c896eba23
|
7
|
+
data.tar.gz: 9cdcea0dcb220ff9b388649ea95bf62b26d302c43a919cecc30d92dffb24399c6577f42c0dea5dcbb19c0f6f39a0dce783cd8c3935768b28b710d548e6a69b7d
|
data/Gemfile.lock
CHANGED
@@ -1,64 +1,66 @@
|
|
1
1
|
(@scripts ||= []) << Proc.new do
|
2
|
-
background :id
|
3
|
-
:resource
|
2
|
+
background :id => 'city', # it's the placeholder for #remove
|
3
|
+
:resource => 'resources/backgrounds/city.jpg'
|
4
4
|
|
5
|
-
play_sound :id
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
play_sound :id => 'background_theme',
|
6
|
+
:resource => 'resources/sounds/Classmate.m4a',
|
7
|
+
:loop => true,
|
8
|
+
:volume => 0.5 # 0.0 - 1.0
|
9
9
|
|
10
|
-
character :id
|
11
|
-
:resource
|
12
|
-
:x
|
13
|
-
:y
|
10
|
+
character :id => 'Rosalinda',
|
11
|
+
:resource => 'resources/characters/rosalinda.png',
|
12
|
+
:x => 800,
|
13
|
+
:y => 120
|
14
14
|
|
15
|
-
character :id
|
16
|
-
:resource
|
17
|
-
:x
|
18
|
-
:y
|
15
|
+
character :id => 'Ambrogia',
|
16
|
+
:resource => 'resources/characters/ambrogia.png',
|
17
|
+
:x => 10,
|
18
|
+
:y => 120
|
19
19
|
|
20
|
-
dialogue :name
|
21
|
-
:text
|
20
|
+
dialogue :name => 'Ambrogia', # optional
|
21
|
+
:text => 'Hi!'
|
22
22
|
|
23
|
-
input :name
|
24
|
-
:text
|
25
|
-
:id
|
26
|
-
:
|
23
|
+
input :name => 'Ambrogia',
|
24
|
+
:text => 'My name is Ambrogia, and yours?',
|
25
|
+
:id => 'name', # the variable where the input will be saved
|
26
|
+
:placeholder => 'Your name:',
|
27
|
+
:constraint => '#name# =~ /^[a-zA-Z]{3,10}$/',
|
28
|
+
:on_fail => 'Your name has to be contained in 3-10 chars.' # printed if the input won't match the constraint
|
27
29
|
|
28
|
-
dialogue :name
|
29
|
-
:text
|
30
|
-
:if
|
30
|
+
dialogue :name => 'Ambrogia',
|
31
|
+
:text => 'Oh, hai #name#!',
|
32
|
+
:if => '#name# =~ /^[a-zA-Z]+$/'
|
31
33
|
|
32
|
-
dialogue :name
|
33
|
-
:text
|
34
|
-
:
|
34
|
+
dialogue :name => 'Ambrogia',
|
35
|
+
:text => 'Don\'t tease me >:(',
|
36
|
+
:unless => '#name# =~ /^[a-zA-Z]+$/'
|
35
37
|
|
36
|
-
choice :name
|
37
|
-
:text
|
38
|
-
:id
|
39
|
-
:options
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
choice :name => 'Ambrogia',
|
39
|
+
:text => 'How do you feel?',
|
40
|
+
:id => 'feel',
|
41
|
+
:options => [
|
42
|
+
{ id: 'good', text: 'Good' },
|
43
|
+
{ id: 'bad', text: 'Bad' }
|
44
|
+
]
|
43
45
|
|
44
|
-
dialogue :name
|
45
|
-
:text
|
46
|
-
:if
|
46
|
+
dialogue :name => 'Ambrogia',
|
47
|
+
:text => 'I\'m glad you feel good, my dear!',
|
48
|
+
:if => [ '#feel# == good', '#name# == Patrizio' ]
|
47
49
|
|
48
|
-
dialogue :name
|
49
|
-
:text
|
50
|
-
:if
|
50
|
+
dialogue :name => 'Ambrogia',
|
51
|
+
:text => 'I\'m glad you feel good!',
|
52
|
+
:if => [ '#feel# == good', '#name# != Patrizio' ]
|
51
53
|
|
52
|
-
dialogue :name
|
53
|
-
:text
|
54
|
-
:if
|
54
|
+
dialogue :name => 'Ambrogia',
|
55
|
+
:text => 'I\'m sorry you feel bad!',
|
56
|
+
:if => '#feel# == bad'
|
55
57
|
|
56
|
-
dialogue :name
|
57
|
-
:text
|
58
|
+
dialogue :name => 'Ambrogia',
|
59
|
+
:text => 'Ok, time to go, cya!'
|
58
60
|
|
59
|
-
remove :id
|
61
|
+
remove :id => 'Ambrogia'
|
60
62
|
|
61
|
-
remove :id
|
63
|
+
remove :id => 'Rosalinda'
|
62
64
|
|
63
|
-
stop_sound :id
|
65
|
+
stop_sound :id => 'background_theme'
|
64
66
|
end
|
data/lib/sottolio/version.rb
CHANGED
@@ -27,8 +27,9 @@ module Sottolio
|
|
27
27
|
go_next = Sottolio.get 'next'
|
28
28
|
canvas = Canvas.new canvas_id
|
29
29
|
|
30
|
-
database
|
31
|
-
scripts
|
30
|
+
database = Database.new
|
31
|
+
scripts = Script.new @scripts
|
32
|
+
Utils.database = database
|
32
33
|
|
33
34
|
config = {
|
34
35
|
canvas_id: 'game',
|
@@ -44,17 +45,26 @@ module Sottolio
|
|
44
45
|
image_manager = ImageManager.new
|
45
46
|
input = nil
|
46
47
|
|
48
|
+
previous_dialogue = nil
|
47
49
|
next_dialogue = -> {
|
48
50
|
if lock.free? && (!input || input.destroyed? || (input.present? && !input.empty?)) && scripts.any?
|
49
|
-
|
51
|
+
if input.is_a?(CanvasInput) && input.present?
|
52
|
+
input.save_and_destroy
|
53
|
+
|
54
|
+
if !input.valid? && !previous_dialogue.nil?
|
55
|
+
previous_dialogue[:input][:failed] = true
|
56
|
+
scripts << previous_dialogue
|
57
|
+
end
|
58
|
+
end
|
50
59
|
|
51
60
|
canvas.fill_style = '#fff'
|
52
61
|
|
53
|
-
script
|
54
|
-
|
62
|
+
script = scripts.pop
|
63
|
+
previous_dialogue = script
|
64
|
+
current_command = script.keys.first
|
55
65
|
case current_command
|
56
66
|
when :play_sound
|
57
|
-
if script[:play_sound]
|
67
|
+
if Utils.command_conditions_passes? script[:play_sound]
|
58
68
|
sound = Sound.new script[:play_sound][:resource], script[:play_sound][:loop], script[:play_sound][:volume]
|
59
69
|
sound_manager.add script[:play_sound][:id], sound
|
60
70
|
sound_manager.play script[:play_sound][:id]
|
@@ -62,13 +72,13 @@ module Sottolio
|
|
62
72
|
|
63
73
|
next_dialogue.call
|
64
74
|
when :stop_sound
|
65
|
-
if script[:stop_sound]
|
75
|
+
if Utils.command_conditions_passes? script[:stop_sound]
|
66
76
|
sound_manager.stop script[:stop_sound][:id]
|
67
77
|
end
|
68
78
|
|
69
79
|
next_dialogue.call
|
70
80
|
when :background
|
71
|
-
if script[:background]
|
81
|
+
if Utils.command_conditions_passes? script[:background]
|
72
82
|
background = Background.new canvas_id, script[:background][:resource], script[:background][:id]
|
73
83
|
image_manager.add background
|
74
84
|
image_manager.draw script[:background][:id]
|
@@ -76,7 +86,7 @@ module Sottolio
|
|
76
86
|
|
77
87
|
next_dialogue.call
|
78
88
|
when :character
|
79
|
-
if script[:character]
|
89
|
+
if Utils.command_conditions_passes? script[:character]
|
80
90
|
character = Character.new canvas_id, script[:character][:resource], script[:character][:id]
|
81
91
|
image_manager.add character
|
82
92
|
image_manager.draw script[:character][:id], script[:character][:x], script[:character][:y]
|
@@ -88,7 +98,7 @@ module Sottolio
|
|
88
98
|
|
89
99
|
next_dialogue.call
|
90
100
|
when :dialogue
|
91
|
-
if script[:dialogue]
|
101
|
+
if Utils.command_conditions_passes? script[:dialogue]
|
92
102
|
canvas.clear
|
93
103
|
|
94
104
|
if script[:dialogue].include? :name
|
@@ -100,7 +110,7 @@ module Sottolio
|
|
100
110
|
next_dialogue.call
|
101
111
|
end
|
102
112
|
when :input
|
103
|
-
if script[:input]
|
113
|
+
if Utils.command_conditions_passes? script[:input]
|
104
114
|
canvas.clear
|
105
115
|
|
106
116
|
if script[:input].include? :name
|
@@ -109,12 +119,14 @@ module Sottolio
|
|
109
119
|
canvas_text.write script[:input][:text].apply(database)
|
110
120
|
end
|
111
121
|
|
112
|
-
|
122
|
+
placeholder = (script[:input][:failed] == true ? script[:input][:on_fail] || 'Please check your input' : script[:input][:placeholder]).apply(database)
|
123
|
+
input = CanvasInput.new canvas_id, database, script[:input][:id], placeholder, script[:input][:constraint]
|
124
|
+
input.focus! if script[:input][:failed] != true
|
113
125
|
else
|
114
126
|
next_dialogue.call
|
115
127
|
end
|
116
128
|
when :choice
|
117
|
-
if script[:choice]
|
129
|
+
if Utils.command_conditions_passes? script[:choice]
|
118
130
|
canvas.clear
|
119
131
|
|
120
132
|
if script[:choice].include? :name
|
data/opal/sottolio/script.rb
CHANGED
data/opal/sottolio/utils.rb
CHANGED
@@ -35,23 +35,35 @@ class String
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
38
|
+
module Utils
|
39
|
+
class << self
|
40
|
+
def database=(database)
|
41
|
+
@@database = database
|
42
|
+
end
|
43
|
+
|
44
|
+
def command_conditions_passes?(command)
|
45
|
+
return true unless command.include?(:if) || command.include?(:unless)
|
46
|
+
|
47
|
+
sym = command.include?(:if) ? :if : :unless
|
48
|
+
res = acceptable_constraint? [command[sym]]
|
49
|
+
sym == :if ? res : !res
|
50
|
+
end
|
51
|
+
|
52
|
+
def acceptable_constraint?(constraint)
|
53
|
+
res = []
|
54
|
+
|
55
|
+
[constraint].flatten.each do |c| # i.e.: [ '#feel# == good', '#name# == Patrizio' ]
|
56
|
+
statement = c.apply(@@database).split(/(.+)(==|!=|=~)(.+)/).delete_if { |s| s.strip.empty? }.map(&:strip)
|
57
|
+
eval = case statement[1] # #send won't work with !=
|
58
|
+
when '==' then statement[0] == statement[2]
|
59
|
+
when '!=' then statement[0] != statement[2]
|
60
|
+
when '=~' then !!(statement[0] =~ statement[2].to_regex)
|
61
|
+
end
|
62
|
+
|
63
|
+
res << eval
|
51
64
|
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
return sym == :if ? res.last : !res.last
|
65
|
+
|
66
|
+
res.inject { |sum, x| sum && x }
|
67
|
+
end
|
56
68
|
end
|
57
69
|
end
|
@@ -18,26 +18,25 @@
|
|
18
18
|
#++
|
19
19
|
module Sottolio
|
20
20
|
class CanvasInput
|
21
|
-
def initialize(
|
22
|
-
@database
|
23
|
-
@key
|
24
|
-
@
|
21
|
+
def initialize(canvas_id, database, key, placeholder, constraint, x = 500, y = 800)
|
22
|
+
@database = database
|
23
|
+
@key = key
|
24
|
+
@constraint = constraint
|
25
|
+
@destroyed = false
|
25
26
|
|
26
27
|
%x{
|
27
|
-
#@canvas_input = new CanvasText(
|
28
|
-
x:
|
29
|
-
y:
|
30
|
-
|
31
|
-
width:
|
32
|
-
padding:
|
28
|
+
#@canvas_input = new CanvasText(canvas_id, {
|
29
|
+
x: x,
|
30
|
+
y: y,
|
31
|
+
placeholder: placeholder,
|
32
|
+
width: 300,
|
33
|
+
padding: 8
|
33
34
|
});
|
34
35
|
}
|
35
|
-
|
36
|
-
focus
|
37
36
|
end
|
38
37
|
|
39
|
-
def focus
|
40
|
-
`#@canvas_input.focus()
|
38
|
+
def focus!
|
39
|
+
`#@canvas_input.focus()`
|
41
40
|
end
|
42
41
|
|
43
42
|
def value
|
@@ -63,6 +62,10 @@ module Sottolio
|
|
63
62
|
}
|
64
63
|
end
|
65
64
|
|
65
|
+
def valid?
|
66
|
+
Utils.acceptable_constraint?(@constraint)
|
67
|
+
end
|
68
|
+
|
66
69
|
def present?
|
67
70
|
not destroyed?
|
68
71
|
end
|
@@ -21,11 +21,8 @@ module Sottolio
|
|
21
21
|
def initialize(element, hash = nil)
|
22
22
|
super element, '2d'
|
23
23
|
|
24
|
-
@canvas_id
|
25
|
-
|
26
|
-
%x{
|
27
|
-
#@canvas_text = new CanvasText;
|
28
|
-
}
|
24
|
+
@canvas_id = element
|
25
|
+
@canvas_text = `new CanvasText()`
|
29
26
|
|
30
27
|
config hash if hash
|
31
28
|
end
|
@@ -36,7 +33,8 @@ module Sottolio
|
|
36
33
|
canvasId: #{hash[:canvas_id]},
|
37
34
|
fontFamily: #{hash[:font_family]},
|
38
35
|
fontSize: #{hash[:font_size]},
|
39
|
-
fontColor: #{hash[:font_color]}
|
36
|
+
fontColor: #{hash[:font_color]},
|
37
|
+
lineHeight: 30
|
40
38
|
});
|
41
39
|
}
|
42
40
|
end
|
@@ -44,20 +42,19 @@ module Sottolio
|
|
44
42
|
def draw_text(hash)
|
45
43
|
%x{
|
46
44
|
#@canvas_text.drawText({
|
47
|
-
x:
|
48
|
-
y:
|
49
|
-
text:
|
50
|
-
boxWidth:
|
45
|
+
x: #{hash[:x]},
|
46
|
+
y: #{hash[:y]},
|
47
|
+
text: #{hash[:text]},
|
48
|
+
boxWidth: 1280
|
51
49
|
});
|
52
50
|
}
|
53
51
|
end
|
54
52
|
|
55
53
|
def write(what, keep = false)
|
56
54
|
draw_text({
|
57
|
-
:x
|
58
|
-
:y
|
59
|
-
:text
|
60
|
-
:box_width => '130px'
|
55
|
+
:x => 10,
|
56
|
+
:y => 760,
|
57
|
+
:text => what
|
61
58
|
})
|
62
59
|
end
|
63
60
|
end
|