123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- task default: %w(develop)
- STORY_DIR=File.join(ENV['USERPROFILE'], 'Documents\\Twine\\Stories')
- FILES = {
- 'intro' => 'Intro',
- 'transform' => 'Transform',
- 'custom_girl' => 'Custom Girl',
- 'beaches' => 'Beaches',
- 'money_game' => 'Money Games',
- }
- task develop: %w(bundle_install) do
- sh "bundle exec twee2 build main.tw2 develop.html"
- end
- task watch: %w(bundle_install) do
- sh 'start watch.html' # FIXME non-windows
- sh "bundle exec twee2 watch main.tw2 watch.html"
- end
- task release: %w(bundle_install) do
- sh "bundle exec twee2 build main.tw2 release.html"
- end
- desc 'export sub files to Twine 2'
- task export: %w(bundle_install) do
- FILES.each do |short_name, long_name|
- IO.write "#{short_name}_wrapper.tw2", <<~EOF
- ::StoryTitle
- Volleyball - #{long_name}
- ::Twee2Settings [twee2]
- @story_start_name = 'Start #{long_name}'
- Twee2::build_config.story_format = 'SugarCube2'
- ::StoryIncludes
- images.tw2
- stylesheet.tw2
- storyjs.tw2
- #{short_name}.tw2
- EOF
- sh "bundle exec twee2 export #{short_name}_wrapper.tw2 '#{File.join(STORY_DIR, "Volleyball - #{long_name}.html")}'"
- end
- sh "bundle exec twee2 export main.tw2 '#{File.join(STORY_DIR, "Volleyball - Full Game.html")}'"
- end
- desc 'import sub files from Twine 2'
- task import: %w(bundle_install) do
- FILES.each do |short_name, long_name|
- sh "bundle exec twee2 decompile '#{File.join(STORY_DIR, "Volleyball - #{long_name}.html")}' '#{short_name}.tw2' --exclude=StoryJS,StoryCSS,StoryTitle,Twee2Settings --exclude-from=storyjs.tw2,stylesheet.tw2,images.tw2"
- end
- end
- task :bundle_install do
- sh 'bundle install'
- end
- task :clean do
- # TODO
- end
- task :lint do
- FILES.each do |short_name, long_name|
- filename = "#{short_name}.tw2"
- twee_source = IO.read(filename)
- twee_source.lines.each_with_index do |line, lineno|
- lineno += 1
- line
- .scan(%r{\[\[([^\]]*)\]\]})
- .map { |x| x[0] }
- .each do |link|
- case link.scan('->').length
- when 0
- #puts("link contains no ->, probably not a problem")
- next
- when 1
- # no problem
- else
- puts("link contains multiple -> definitely a problem")
- next
- end
- text, dest = link.split('->')
- if text.start_with?('\'')
- if !text.end_with?('\'')
- puts("#{filename}:#{lineno} link text (#{text.inspect}) does not end with single quote despite starting with one")
- next
- end
- text = text[1..-2]
- text
- .to_enum(:scan, '\'')
- .map {Regexp.last_match.offset(0)[0]}
- .each do |offset|
- if text[offset - 1] != '\\'
- puts "#{filename}:#{lineno} link text (#{text.inspect}) contains unquoted single quote in body"
- end
- end
- elsif text.start_with?('"')
- if !text.end_with?('"')
- puts("#{filename}:#{lineno} link text (#{text.inspect}) does not end with double quote despite starting with one")
- next
- end
- text = text[1..-2]
- text
- .to_enum(:scan, '"')
- .map {Regexp.last_match.offset(0)[0]}
- .each do |offset|
- if text[offset - 1] != '\\'
- puts "#{filename}:#{lineno} link text (#{text.inspect}) contains unquoted double quote in body"
- end
- end
- elsif text =~ /\A[\[\]'"\\]*\Z/
- puts "#{filename}:#{lineno} link text (#{text.inspect}) contains special characters but is not quoted with single or double quotes"
- end
- #puts(dest)
- end
- end
- end
- end
|