tyrano_dsl 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.travis.yml +3 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +290 -0
  8. data/Rakefile +10 -0
  9. data/bin/setup +8 -0
  10. data/bin/tyrano_dsl.rb +21 -0
  11. data/lib/tyrano_dsl/elements/background.rb +31 -0
  12. data/lib/tyrano_dsl/elements/character.rb +49 -0
  13. data/lib/tyrano_dsl/elements/elements_module.rb +7 -0
  14. data/lib/tyrano_dsl/elements/jump_target.rb +18 -0
  15. data/lib/tyrano_dsl/elements/label.rb +19 -0
  16. data/lib/tyrano_dsl/elements/scene.rb +21 -0
  17. data/lib/tyrano_dsl/elements/stance.rb +26 -0
  18. data/lib/tyrano_dsl/elements/title_screen.rb +16 -0
  19. data/lib/tyrano_dsl/elements/variable.rb +22 -0
  20. data/lib/tyrano_dsl/elements/world.rb +62 -0
  21. data/lib/tyrano_dsl/elements_writers/background_writer.rb +30 -0
  22. data/lib/tyrano_dsl/elements_writers/character_writer.rb +32 -0
  23. data/lib/tyrano_dsl/elements_writers/characters_writer.rb +43 -0
  24. data/lib/tyrano_dsl/elements_writers/elements_writers_module.rb +27 -0
  25. data/lib/tyrano_dsl/elements_writers/scene_writer.rb +30 -0
  26. data/lib/tyrano_dsl/elements_writers/title_screen_writer.rb +87 -0
  27. data/lib/tyrano_dsl/elements_writers/variables_writer.rb +30 -0
  28. data/lib/tyrano_dsl/file_actions/clear_directory.rb +34 -0
  29. data/lib/tyrano_dsl/file_actions/create_file.rb +33 -0
  30. data/lib/tyrano_dsl/file_actions/file_copy.rb +36 -0
  31. data/lib/tyrano_dsl/file_actions/files_actions_module.rb +28 -0
  32. data/lib/tyrano_dsl/file_actions/json_patch.rb +47 -0
  33. data/lib/tyrano_dsl/main.rb +18 -0
  34. data/lib/tyrano_dsl/parsed_word.rb +22 -0
  35. data/lib/tyrano_dsl/parser.rb +58 -0
  36. data/lib/tyrano_dsl/parsing_context.rb +18 -0
  37. data/lib/tyrano_dsl/parsing_words/ask_question.rb +32 -0
  38. data/lib/tyrano_dsl/parsing_words/conditional_jump.rb +42 -0
  39. data/lib/tyrano_dsl/parsing_words/declare_background.rb +32 -0
  40. data/lib/tyrano_dsl/parsing_words/declare_character.rb +38 -0
  41. data/lib/tyrano_dsl/parsing_words/declare_label.rb +20 -0
  42. data/lib/tyrano_dsl/parsing_words/declare_variable.rb +30 -0
  43. data/lib/tyrano_dsl/parsing_words/display_text.rb +22 -0
  44. data/lib/tyrano_dsl/parsing_words/hide_character.rb +20 -0
  45. data/lib/tyrano_dsl/parsing_words/hide_message_window.rb +16 -0
  46. data/lib/tyrano_dsl/parsing_words/include_file.rb +26 -0
  47. data/lib/tyrano_dsl/parsing_words/jump.rb +22 -0
  48. data/lib/tyrano_dsl/parsing_words/parsing_words_module.rb +72 -0
  49. data/lib/tyrano_dsl/parsing_words/set_background.rb +21 -0
  50. data/lib/tyrano_dsl/parsing_words/set_character_stance.rb +23 -0
  51. data/lib/tyrano_dsl/parsing_words/set_title_screen_background.rb +25 -0
  52. data/lib/tyrano_dsl/parsing_words/show_character.rb +26 -0
  53. data/lib/tyrano_dsl/parsing_words/show_message_window.rb +16 -0
  54. data/lib/tyrano_dsl/parsing_words/start_scene.rb +30 -0
  55. data/lib/tyrano_dsl/parsing_words/update_variable.rb +37 -0
  56. data/lib/tyrano_dsl/tyrano_dsl.rb +3 -0
  57. data/lib/tyrano_dsl/tyrano_exception.rb +6 -0
  58. data/lib/tyrano_dsl/vocabulary.rb +84 -0
  59. data/lib/tyrano_dsl/writer.rb +114 -0
  60. data/lib/tyrano_dsl/writing_context.rb +123 -0
  61. data/lib/tyrano_dsl/writing_words/ask_question.rb +28 -0
  62. data/lib/tyrano_dsl/writing_words/conditional_jump.rb +37 -0
  63. data/lib/tyrano_dsl/writing_words/declare_background.rb +5 -0
  64. data/lib/tyrano_dsl/writing_words/declare_character.rb +5 -0
  65. data/lib/tyrano_dsl/writing_words/declare_label.rb +18 -0
  66. data/lib/tyrano_dsl/writing_words/declare_variable.rb +5 -0
  67. data/lib/tyrano_dsl/writing_words/display_text.rb +16 -0
  68. data/lib/tyrano_dsl/writing_words/hide_character.rb +13 -0
  69. data/lib/tyrano_dsl/writing_words/hide_message_window.rb +12 -0
  70. data/lib/tyrano_dsl/writing_words/include_file.rb +5 -0
  71. data/lib/tyrano_dsl/writing_words/jump.rb +18 -0
  72. data/lib/tyrano_dsl/writing_words/nop.rb +8 -0
  73. data/lib/tyrano_dsl/writing_words/set_background.rb +18 -0
  74. data/lib/tyrano_dsl/writing_words/set_character_stance.rb +20 -0
  75. data/lib/tyrano_dsl/writing_words/set_title_screen_background.rb +4 -0
  76. data/lib/tyrano_dsl/writing_words/show_character.rb +31 -0
  77. data/lib/tyrano_dsl/writing_words/show_message_window.rb +12 -0
  78. data/lib/tyrano_dsl/writing_words/start_scene.rb +9 -0
  79. data/lib/tyrano_dsl/writing_words/update_variable.rb +28 -0
  80. data/lib/tyrano_dsl/writing_words/writing_words_module.rb +43 -0
  81. data/tyrano_dsl.gemspec +37 -0
  82. metadata +210 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 17d34d336f11f2f6009bb3984e5a01cf72c43cb0
4
+ data.tar.gz: 63f2ce47b179e1d620389051014fbbb0a7eb8db6
5
+ SHA512:
6
+ metadata.gz: ffe1a7e21309f9df76ebff536a5e5c9946c73199e44f4986e8cfb5aed0850e486476330c85134854f09a40e5ef005bc6d9253f5cb67dee94563f339c7b3e221c
7
+ data.tar.gz: 21bc3b5729e06fde892e7592153e89e49fa4fb1f86dfb4e5646729c80fe68c40334f25294ecb4aafa0fb3852890ccbe06ef96d37c64019cdc6181df06b0bf3e6
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
11
+
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at code@archiloque.net. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tyrano_dsl.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Julien Kirch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,290 @@
1
+ # TyranoDsl
2
+
3
+ [![Build Status](https://travis-ci.org/archiloque/tyrano_dsl.svg?branch=master)](https://travis-ci.org/archiloque/tyrano_dsl)
4
+
5
+ A DSL to write visual novels games in Ruby using [TyranoBuilder](http://tyranobuilder.com).
6
+
7
+ TyranoBuilder is a good tool has many features like native web export but I don't like to click-heavy interface to write.
8
+
9
+ The goal is to provide a simple syntax you can use directly or you can build upon.
10
+
11
+ You create your TyranoBuilder project with the specific options and the library is used to modify the content without touching the other things.
12
+
13
+ The project is a WIP: I add things as I need them, if you have any issue or need something please ask me.
14
+
15
+ If you use it for a published VN, please tell me: it would make me happy and I'll add a link to it in this page.
16
+
17
+ Example:
18
+
19
+ ```ruby
20
+ declare_character 'Shinji',
21
+ 'default' => 'default_stance.jpg',
22
+ 'angry' => 'angry.jpg'
23
+
24
+ declare_background 'School', 'background/school.jpg'
25
+
26
+ set_title_screen_background 'School'
27
+
28
+ start_scene 'First scene'
29
+ set_background 'School'
30
+ show_character 'Shinji', 'default', 434, 128
31
+ show_message_window
32
+ display_text 'Shinji', 'Hello!'
33
+ set_character_stance 'Shinji', 'angry'
34
+ display_text nil, 'Do you want to go in the eva ?'
35
+ ask_question [
36
+ {
37
+ 'text' => 'Yes!',
38
+ 'left' => 200,
39
+ 'top' => 200,
40
+ 'scene' => 'Second scene'
41
+ },
42
+ {
43
+ 'text' => 'No!',
44
+ 'left' => 200,
45
+ 'top' => 300,
46
+ 'scene' => 'Third scene',
47
+ 'label' => 'a label'
48
+ }
49
+ ]
50
+ start_scene 'Second scene'
51
+ ```
52
+
53
+ ## How to use it
54
+
55
+ - Install [TyranoBuilder](http://tyranobuilder.com)
56
+ - Create a project in it
57
+ - Install the gem
58
+ - Execute `tyrano-dsl PATH_TO_YOUR_TYRANO_PROJECT PATH_TO_YOUR_RUBY_CODE.rb` in your project directory.
59
+
60
+ `PATH_TO_YOUR_TYRANO_PROJECT` should look like `/Users/u/Library/Application\ Support/Steam/steamapps/common/TyranoBuilder/myproject/Test`
61
+
62
+ If everything is OK it should update the files in your TyranoBuilder project.
63
+
64
+ You can then reopen the project in TyranoBuilder and see the changes.
65
+
66
+ If there is an error it should be displayed and the message should help you to fix the problem.
67
+
68
+ ## Current vocabulary
69
+
70
+ ### Background
71
+
72
+ #### `declare_background` Declare a background
73
+
74
+ `declare_background(name, images_path)`
75
+ - `name` is a `String` representing the background's name
76
+ - `images_path` is a `String` indicating the path to the background images
77
+
78
+ ```ruby
79
+ declare_background 'School', 'background/school.jpg'
80
+ ```
81
+
82
+ #### `set_background` Set the background
83
+
84
+ `show_background(name)`
85
+ - `name` is a `String` representing the background's name
86
+
87
+ ```ruby
88
+ set_background 'School'
89
+ ```
90
+
91
+ ### Characters
92
+
93
+ #### `declare_character` Declare a character
94
+
95
+ `declare_character(name, stances)`
96
+ - `name` is a `String` representing the character's name
97
+ - `stances` is a `Hash{String => String}` providing a list of stances with the path to their corresponding images
98
+
99
+ ```ruby
100
+ declare_character 'Shinji',
101
+ 'default' => 'default_stance.jpg',
102
+ 'angry' => 'angry.jpg'
103
+ ```
104
+
105
+ #### `hide_character` Hide a character
106
+
107
+ `hide_character(name)`
108
+ - `name` is a `String` representing the character's name
109
+
110
+ ```ruby
111
+ hide_character 'Shinji'
112
+ ```
113
+
114
+ #### `set_character_stance` change the stance of a character
115
+
116
+ `set_character_stance(name, stance)`
117
+ - `name` is a `String` representing the character's name
118
+ - `stance` is a `String` defining the stance name
119
+
120
+ ```ruby
121
+ set_character_stance 'Shinji', 'angry'
122
+ ```
123
+
124
+ #### `show_character` show a character
125
+
126
+ `show_character(name, stance, left, top)`
127
+ - `name` is a `String` representing the character's name
128
+ - `stance` is a `String` defining the stance name
129
+ - `left` is an `Integer` defining the left position
130
+ - `top` is an `Integer` defining the top position
131
+
132
+ ```ruby
133
+ show_character 'Shinji', 'default', 434, 128
134
+ ```
135
+
136
+ ### Content
137
+
138
+ #### `ask_question` Ask a question
139
+
140
+ `ask_question(possible_answers)`
141
+ - `possible_answers` is a list of possible answers with the corresponding target
142
+ - `text` is a `String` representing the text of the answer
143
+ - `left` is an `Integer` defining the left position
144
+ - `top` is an `Integer` defining the top position
145
+ - `scene` is a `String` indicating the name of the scene to jump if the answer is selected
146
+ - `label` (optional) is a `String` indicating the name of the label in the scene to jump if the answer is selected
147
+
148
+
149
+ ```ruby
150
+ ask_question [
151
+ {
152
+ 'text' => 'Yes',
153
+ 'left' => 200,
154
+ 'top' => 200,
155
+ 'scene' => 'Second scene'
156
+ },
157
+ {
158
+ 'text' => 'No',
159
+ 'left' => 200,
160
+ 'top' => 300,
161
+ 'scene_name' => 'Third scene',
162
+ 'label_name' => 'a label'
163
+ }
164
+ ]
165
+ ```
166
+
167
+ ### Jump & Labels
168
+
169
+ #### `declare_label` Declare a label
170
+
171
+ `declare_label(name)`
172
+ - `name` is a `String` representing the label's name
173
+
174
+ ```ruby
175
+ declare_label 'my label'
176
+ ```
177
+
178
+ #### `conditional_jump` Jump to somewhere if a condition is met
179
+
180
+ `conditional_jump(variable, operator, value, scene, label)`
181
+ - `variable` is a `String` indicating the name of the variable to be tested
182
+ - `operator` is a `String` indicating the comparison operator to use: `<`, `==` (equal), `>`, `!=` (different)
183
+ - `value` is a `String` or a `Float` indicating the thing to compare the variable to, it can be a numerical value or the name of another variable
184
+ - `scene` is a `String` indicating the name of the scene to jump to
185
+ - `label` (optional) is a `String` indicating the name of the label in the scene to jump to
186
+
187
+ ```ruby
188
+ conditional_jump 'variable_1', '<', 10, 'Scene two'
189
+ conditional_jump 'variable_1', '=', 'variable_2', 'Scene two', 'Label three'
190
+ ```
191
+
192
+ #### `jump` Jump to somewhere
193
+
194
+ `jump(scene, label)`
195
+ - `scene` is a `String` indicating the name of the scene to jump to
196
+ - `label` (optional) is a `String` indicating the name of the label in the scene to jump to
197
+
198
+ ```ruby
199
+ jump 'Scene two'
200
+ jump 'Scene two', 'Label three'
201
+ ```
202
+
203
+ ### Variables
204
+
205
+ #### `declare_variable` Declare a variable
206
+
207
+ `declare_variable(variable_name, initial_value)`
208
+ - `variable_name` is a `String` representing the variable name
209
+ - `initial_value` is a `Float` representing the variable initial value
210
+
211
+ ```ruby
212
+ declare_variable 'happiness', 25
213
+ ```
214
+
215
+ #### `update_variable` Update a variable
216
+
217
+ `update_variable(variable_name, operation, value)`
218
+ - `variable_name` is a `String` representing the variable name
219
+ - `operator` is a `String` indicating the operation to apply
220
+ - `=` set the variable with the value
221
+ - `+=` add the value to the variable
222
+ - `-=` substract the value from the variable
223
+ - `*=` multiply the value with the variable
224
+ - `/=` divide the value with the variable
225
+ - `%=` set the variable with the reminder of the division with the value
226
+ - `value` is a `String` or a `Float` indicating the thing to use as a value, it can be a numerical value or the name of another variable
227
+
228
+ ```ruby
229
+ update_variable 'happiness', '=', 25
230
+ update_variable 'happiness', '+', 'calmness'
231
+ ```
232
+
233
+ ### Misc
234
+
235
+ #### `hide_message_window` Hide the message window
236
+
237
+ `hide_message_window`
238
+
239
+ ```ruby
240
+ hide_message_window
241
+ ```
242
+
243
+ #### `include_file` Include a file
244
+
245
+ `include_file(file_name)`
246
+ - `name` is a `file_name` representing the file to include
247
+
248
+ ```ruby
249
+ include_file('other_scene.rb')
250
+ ```
251
+
252
+ #### `show_message_window` Show the message window
253
+
254
+ `show_message_window`
255
+
256
+ ```ruby
257
+ show_message_window
258
+ ```
259
+
260
+ #### `start_scene` Start a new scene
261
+
262
+ `start_scene(name)`
263
+ - `name` is a `String` representing the scene's name
264
+
265
+ ```ruby
266
+ start_scene 'First scene'
267
+ ```
268
+
269
+ ## How the thing works
270
+
271
+ The tool works like a two passes compiler:
272
+ - the first pass validates the syntax, the entry point is in `parser.rb`
273
+ - the second generate the content, the entry point is in `writer.rb`
274
+ - the content is applied to disk
275
+
276
+ ## Links
277
+
278
+ - http://tyranobuilder.com/tyranoscript-tags-reference/ : the TyranoScript tags references
279
+
280
+ ## Contributing
281
+
282
+ Bug reports and pull requests are welcome on GitHub at https://github.com/archiloque/tyrano_dsl.
283
+
284
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
285
+
286
+
287
+ ## License
288
+
289
+ The code is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
290
+
@@ -0,0 +1,10 @@
1
+ require 'rake/testtask'
2
+ require 'bundler/gem_tasks'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/**/*_test.rb'
7
+ end
8
+
9
+ desc 'Run tests'
10
+ task :default => :test
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'json'
5
+ require 'tyrano_dsl/main'
6
+ require 'tyrano_dsl/tyrano_exception'
7
+ if ARGV.length != 2
8
+ raise 'You need two arguments : the path to the tyrano project and the path to your DSL file'
9
+ end
10
+ tyrano_project_path = ARGV[0]
11
+ dsl_file_path = ARGV[1]
12
+
13
+ builder_configuration_file = File.join(tyrano_project_path, 'builder_config.json')
14
+ unless File.exists? builder_configuration_file
15
+ raise "File not found [#{builder_configuration_file}]"
16
+ end
17
+
18
+ writing_context = TyranoDsl::Main.new.run(dsl_file_path)
19
+ writing_context.file_actions.each do |file_action|
20
+ file_action.run(tyrano_project_path)
21
+ end