revolt 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -132,6 +132,11 @@ the track you want to find. For examples:
132
132
 
133
133
  rv_find_levels.rb temple
134
134
 
135
+ If you want to find a level by it's exact folder name, you can
136
+ prepend with ':' (or use the --id switch), for example:
137
+
138
+ rv_find_levels.rb :temple
139
+
135
140
  That would search for all levels whose name contains 'temple'
136
141
  (case insensitive). Another more complex example is to find
137
142
  all custom tracks that can be raced in reverse mode that
@@ -172,14 +177,15 @@ For more information and options:
172
177
 
173
178
 
174
179
  === rv_package_levels.rb
175
- Creates packages of levels. The parameters are the
176
- folder names of the levels to pack. From each level
177
- a separate package is created. Matching options can
178
- be used with -m as with rv_find_levels.rb
180
+ Creates packages of levels. The parameters are, as
181
+ in the above matching level names. Use the ':' in
182
+ front to pack using folder names of the levels. From
183
+ each level a separate package is created. Matching
184
+ options can be used with -m as with rv_find_levels.rb
179
185
 
180
186
  Example:
181
187
 
182
- rv_package_levels_level.rb rvt chilled
188
+ rv_package_levels_level.rb :rvt :chilled
183
189
 
184
190
  This would create rvt.zip and chilled.zip of corresponding
185
191
  levels.
@@ -48,6 +48,7 @@ class CmdArguments < Hash
48
48
 
49
49
  self[:base] = ReVolt::Info::path
50
50
  self[:force] = false
51
+ self[:default_match_with] = :name
51
52
 
52
53
  matchstrs = []
53
54
  opts = OptionParser.new do |opts|
@@ -70,6 +71,8 @@ class CmdArguments < Hash
70
71
  on_match(opts) do |value|
71
72
  matchstrs << value
72
73
  end
74
+ on_default_match_modifier(opts)
75
+
73
76
  opts.on('-d', '--debug',
74
77
  'Outputs debug information') do
75
78
  self[:debug] = true
@@ -93,8 +96,8 @@ class CmdArguments < Hash
93
96
 
94
97
  opts.parse!(cmd)
95
98
 
96
- cmd.each do |n|
97
- matchstrs << '%s=~%s' % ['name', n]
99
+ name_or_id_matches(cmd) do |m|
100
+ matchstrs << m
98
101
  end
99
102
 
100
103
  # If input file not specified, at least start date is required
@@ -27,6 +27,8 @@ class CmdArguments < Hash
27
27
  super()
28
28
 
29
29
  self[:base] = ReVolt::Info::path
30
+ self[:default_match_with] = :name
31
+
30
32
  matchstrs = []
31
33
  opts = OptionParser.new do |opts|
32
34
  opts.banner = "Usage: #$0 [options] [name_match ...]\n"
@@ -50,6 +52,7 @@ class CmdArguments < Hash
50
52
  on_match(opts) do |value|
51
53
  matchstrs << value
52
54
  end
55
+ on_default_match_modifier(opts)
53
56
 
54
57
  opts.on('-d', '--debug',
55
58
  'Outputs debug information') do
@@ -70,9 +73,20 @@ class CmdArguments < Hash
70
73
 
71
74
  opts.parse!(cmd)
72
75
 
76
+ name_or_id_matches(cmd) do |m|
77
+ matchstrs << m
78
+ end
79
+
80
+ =begin
81
+ ReVolt::Util::CommonCmdArgs
73
82
  cmd.each do |n|
74
- matchstrs << '%s=~%s' % ['name', n]
83
+ if n == ':all'
84
+ matchstrs << 'id=~.'
85
+ else
86
+ matchstrs << '%s=~%s' % ['name', n]
87
+ end
75
88
  end
89
+ =end
76
90
 
77
91
  # If input file not specified, at least start date is required
78
92
  if matchstrs.size == 0
@@ -47,6 +47,7 @@ class CmdArguments < Hash
47
47
 
48
48
  self[:base] = ReVolt::Info::path
49
49
  self[:all] = false
50
+ self[:default_match_with] = :name
50
51
 
51
52
  matchstrs = []
52
53
  opts = OptionParser.new do |opts|
@@ -67,6 +68,8 @@ class CmdArguments < Hash
67
68
  on_match(opts) do |value|
68
69
  matchstrs << value
69
70
  end
71
+ on_default_match_modifier(opts)
72
+
70
73
  opts.on('-d', '--debug',
71
74
  'Outputs debug information') do
72
75
  self[:debug] = true
@@ -90,8 +93,8 @@ class CmdArguments < Hash
90
93
 
91
94
  opts.parse!(cmd)
92
95
 
93
- cmd.each do |n|
94
- matchstrs << '%s=~%s' % ['name', n]
96
+ name_or_id_matches(cmd) do |m|
97
+ matchstrs << m
95
98
  end
96
99
 
97
100
  # If input file not specified, at least start date is required
@@ -42,7 +42,6 @@ class CmdArguments < Hash
42
42
 
43
43
  opts = OptionParser.new do |opts|
44
44
  opts.banner = "Usage: #$0 [options] package1 [package2 ...]\n"
45
- opts.separator "By default the URLs are read from standard console input"
46
45
 
47
46
  opts.separator ""
48
47
  opts.separator "Options:"
@@ -21,6 +21,15 @@ def main
21
21
  end
22
22
 
23
23
  if pkg_levs.size > 0
24
+ unless cmd[:force]
25
+ puts ""
26
+ print "Create packages of these levels? (y/N) "
27
+ answer = STDIN.gets.chomp
28
+ if answer.downcase != 'y'
29
+ puts "Packages not created"
30
+ exit(0)
31
+ end
32
+ end
24
33
  puts ''
25
34
  puts "Creating packages of #{pkg_levs.size} matching levels"
26
35
  pkg_levs.each do |l, match|
@@ -42,17 +51,20 @@ class CmdArguments < Hash
42
51
 
43
52
  self[:base] = ReVolt::Info::path
44
53
  self[:force] = false
54
+ self[:default_match_with] = :name
45
55
 
46
56
  matchstrs = []
47
57
  opts = OptionParser.new do |opts|
48
- opts.banner = "Usage: #$0 [options] [levelid ...]\n"
58
+ opts.banner = "Usage: #$0 [options] [name_match ...]\n"
49
59
  opts.separator ""
50
60
  opts.separator "Creates packages of levels. Each packaged level will be"
51
- opts.separator "named by its id"
61
+ opts.separator "named by its id. By default confirms before creating packages"
52
62
  opts.separator ""
53
63
  opts.separator "Examples:"
64
+ opts.separator " Package all levels whose name contains Chilled:"
65
+ opts.separator " #$0 Chilled"
54
66
  opts.separator " Package a level that is in RV levels sub-directory temple:"
55
- opts.separator " #$0 temple"
67
+ opts.separator " #$0 :temple"
56
68
  opts.separator " Packages all custom tracks that can be raced in reverse:"
57
69
  opts.separator " #$0 -m 'custom?,reverse?'"
58
70
 
@@ -65,10 +77,16 @@ class CmdArguments < Hash
65
77
  on_match(opts) do |value|
66
78
  matchstrs << value
67
79
  end
80
+ on_default_match_modifier(opts)
81
+
68
82
  opts.on('-d', '--debug',
69
83
  'Outputs debug information') do
70
84
  self[:debug] = true
71
85
  end
86
+ opts.on('-f', '--force',
87
+ 'Force packaging without confirmation') do
88
+ self[:force] = true
89
+ end
72
90
 
73
91
  on_base_path(opts) do |value|
74
92
  self[:base] = value
@@ -84,8 +102,8 @@ class CmdArguments < Hash
84
102
 
85
103
  opts.parse!(cmd)
86
104
 
87
- cmd.each do |pkgid|
88
- matchstrs << 'id=%s' % ['name', cmd[0]]
105
+ name_or_id_matches(cmd) do |m|
106
+ matchstrs << m
89
107
  end
90
108
 
91
109
  # If input file not specified, at least start date is required
@@ -0,0 +1,12 @@
1
+ require 'revolt'
2
+
3
+ levels = ReVolt::Levels.installed
4
+
5
+ pack_levels = []
6
+ levels.each_custom do |level|
7
+ if level.reverse?
8
+ pack_levels << level
9
+ end
10
+ end
11
+
12
+ levels.package('reverse_custom.zip', pack_levels)
data/lib/revolt/level.rb CHANGED
@@ -153,7 +153,7 @@ module ReVolt
153
153
  f = []
154
154
  # Level globs, and graphics globs
155
155
  globs = [path + '**/*',
156
- gfx_path + ReVolt::Util::caseinsensitiveglob(id.to_s + '.bm?')
156
+ gfx_dir + ReVolt::Util::caseinsensitiveglob(id.to_s + '.bm?')
157
157
  ]
158
158
  debug("Level gfx glob: #{globs[1]}")
159
159
 
@@ -194,10 +194,20 @@ module ReVolt
194
194
  inf_file
195
195
  end
196
196
 
197
- # Returns the path to the graphics files of the Level
197
+ # Returns the directory to the graphics files of the Level
198
+ def gfx_dir
199
+ ensure_parent
200
+ @parent.gfx_dir
201
+ end
202
+
203
+ # Returns the path to the graphics file of this level
204
+ # or nil if the graphics file does not exist
198
205
  def gfx_path
199
206
  ensure_parent
200
- @parent.gfx_path
207
+ gfxglob = gfx_dir + ReVolt::Util::caseinsensitiveglob(id.to_s + '.bmp')
208
+ gfx = Pathname.glob(gfxglob)
209
+ return nil if gfx.empty?
210
+ return gfx[0]
201
211
  end
202
212
 
203
213
  # Convenience function for moving this Level
data/lib/revolt/levels.rb CHANGED
@@ -38,7 +38,7 @@ module ReVolt
38
38
  include Enumerable
39
39
 
40
40
  # Pathname objects
41
- attr_accessor :path, :gfx_path, :base_path
41
+ attr_accessor :path, :gfx_dir, :base_path
42
42
 
43
43
  # Creates new Levels instance with given Re-Volt
44
44
  # base path. The actual levels directory
@@ -47,7 +47,7 @@ module ReVolt
47
47
  def initialize(base_rv_path, args = {})
48
48
  @base_path = Pathname.new(base_rv_path)
49
49
  @path = @base_path + "levels"
50
- @gfx_path = @base_path + "gfx"
50
+ @gfx_dir = @base_path + "gfx"
51
51
  @path_checked = false
52
52
 
53
53
  @levels = nil
@@ -132,7 +132,7 @@ module ReVolt
132
132
  def create_dir_structure
133
133
  @base_path.mkdir if !@base_path.exist?
134
134
  @path.mkdir if !@path.exist?
135
- @gfx_path.mkdir if !@gfx_path.exist?
135
+ @gfx_dir.mkdir if !@gfx_dir.exist?
136
136
 
137
137
  ensure_paths
138
138
  end
@@ -417,8 +417,8 @@ module ReVolt
417
417
  return if @path_checked
418
418
  raise IOError, "#{@path} does not exist" if !@path.exist?
419
419
  raise IOError, "#{@path} is not dir" if !@path.directory?
420
- raise IOError, "#{@gfx_path} does not exist" if !@gfx_path.exist?
421
- raise IOError, "#{@gfx_path} is not dir" if !@gfx_path.directory?
420
+ raise IOError, "#{@gfx_dir} does not exist" if !@gfx_dir.exist?
421
+ raise IOError, "#{@gfx_dir} is not dir" if !@gfx_dir.directory?
422
422
  @path_checked = true
423
423
  end
424
424
 
@@ -4,6 +4,9 @@ module ReVolt::Util
4
4
  # A mixin that can be included to utils that
5
5
  # need some of the common options
6
6
  module CommonCmdArgs
7
+ def initialize()
8
+ super[:default_match_with] = :id
9
+ end
7
10
 
8
11
  def on_base_path(opts, args = {}, &block)
9
12
  opts.on('-b', '--base [DIR]',
@@ -19,6 +22,35 @@ module ReVolt::Util
19
22
  end
20
23
  end
21
24
 
25
+ def on_default_match_modifier(opts, args = {})
26
+ opts.on('--id',
27
+ 'Uses id to match the command-line arguments') do
28
+ self[:default_match_with] = :id
29
+ yield if block_given?
30
+ end
31
+ opts.on('--name',
32
+ 'Uses name to match the command-line arguments') do
33
+ self[:default_match_with] = :name
34
+ yield if block_given?
35
+ end
36
+ end
37
+
38
+ def name_or_id_matches(strs, &block)
39
+ strs.each do |n|
40
+ mstr = case
41
+ when n == ':all'
42
+ 'id=~.'
43
+ when n =~ /^:(.*)/
44
+ '%s=%s' % ['id', $1]
45
+ when self[:default_match_with] == :name
46
+ '%s=~%s' % ['name', n]
47
+ else
48
+ '%s=%s' % ['id', n]
49
+ end
50
+ block.call(mstr)
51
+ end
52
+ end
53
+
22
54
  def match_help(opts)
23
55
  opts.separator "Match (-m, --match) general form:"
24
56
  opts.separator " key<op>match[,key2<op>match2[,...]]"
data/lib/revolt.rb CHANGED
@@ -10,5 +10,5 @@ require 'revolt/util/matcher'
10
10
  require 'revolt/args'
11
11
 
12
12
  module ReVolt
13
- VERSION = '0.8.0'
13
+ VERSION = '0.8.1'
14
14
  end
data/test/tc_level.rb CHANGED
@@ -93,6 +93,8 @@ class LevelTest < Test::Unit::TestCase
93
93
  strdowncase_and_order_structure(files))
94
94
  assert_equal(strdowncase_and_order_structure(dirs_expect),
95
95
  strdowncase_and_order_structure(dirs))
96
+ assert_equal('gfx/tEsT Level.bmp',
97
+ @level.gfx_path.relative_path_from(@levels.base_path).to_s)
96
98
  end
97
99
 
98
100
  def test_copy_level
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: revolt
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.8.0
7
- date: 2007-01-20 00:00:00 +02:00
6
+ version: 0.8.1
7
+ date: 2007-02-16 00:00:00 +02:00
8
8
  summary: Library for managing Re-Volt game, and some Commandline tools
9
9
  require_paths:
10
10
  - lib
@@ -37,6 +37,7 @@ files:
37
37
  - bin/rv_rename_level.rb
38
38
  - examples/find_rv_track.rb
39
39
  - examples/install_rv_track.rb
40
+ - examples/package_all_reverse_custom.rb
40
41
  - lib/revolt.rb
41
42
  - lib/revolt/args.rb
42
43
  - lib/revolt/config.rb