pario 0.3.4 → 0.4.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.
data/.gitignore CHANGED
@@ -1 +1,4 @@
1
1
  *.gem
2
+ .DS_Store
3
+ TODO.rdoc
4
+ b.rb
@@ -9,6 +9,10 @@ Pario is a Gosu Game framework that helps to give you structure and a start for
9
9
  * Windows users: gem install pario
10
10
  * ALSO: Gosu will automatically be installed when you install pario
11
11
 
12
+ Other Requirements
13
+ * sudo gem update --system
14
+ * ruby patchlevel 330, you may experience issues. Working on instructions to upgrade ruby on a system.
15
+
12
16
  == Getting Started
13
17
 
14
18
  1. At the command prompt, create a new Pario application:
@@ -21,6 +25,10 @@ Pario is a Gosu Game framework that helps to give you structure and a start for
21
25
 
22
26
  pario play
23
27
 
28
+ 3. Add more classes to the game:
29
+
30
+ pario add my_class
31
+
24
32
  == Learning Ruby
25
33
 
26
34
  * Ruby4kids: [link:http://www.ruby4kids.com] - links to game examples and videos.
data/bin/pario CHANGED
@@ -1,5 +1,8 @@
1
- #!/user/bin/evn ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
- pario_path = File.expand_path('../lib', __FILE__)
3
+ pario_path = File.expand_path('../../lib', __FILE__)
4
4
  $LOAD_PATH.unshift(pario_path) unless $LOAD_PATH.include?(pario_path)
5
- require 'pario'
5
+
6
+ require 'pario/cli'
7
+
8
+ Pario::Cli.new(ARGV, STDIN).run
@@ -1,210 +1,6 @@
1
- require 'optparse'
2
- require 'rdoc/usage'
3
- require 'ostruct'
4
1
  require 'erb'
2
+ require 'pario/inflector'
5
3
 
6
- class Pario
7
- Version = '0.3.4'
8
- Directories = %w{game lib media config}
9
-
10
- attr_reader :options, :command, :game_name, :arguments
11
-
12
- def initialize(arguments, stdin)
13
- @command = arguments[0]
14
- @arguments = arguments
15
- @stdin = stdin
16
-
17
- # Set defaults
18
- @options = OpenStruct.new
19
- @options.verbose = false
20
- @options.quiet = false
21
- end
22
-
23
- # Parse options, check arguments, then process the command
24
- def run
25
- if (parsed_options? && arguments_valid?) && !valid_pario_command?
26
- #TODO
27
- elsif valid_pario_command?
28
-
29
- @command = arguments.delete_at(0)
30
- process_command
31
- else
32
- output_usage
33
- end
34
-
35
- end
36
-
37
- protected
38
-
39
- def parsed_options?
40
- # Specify options
41
- opts = OptionParser.new
42
- opts.on('-v', '--version') { output_version ; exit 0 }
43
- opts.on('-h', '--help') { output_help }
44
- opts.on('-V', '--verbose') { @options.verbose = true }
45
-
46
- opts.parse!(@arguments) rescue return false
47
-
48
- process_options
49
- true
50
- end
51
-
52
- # Performs post-parse processing on options
53
- def process_options
54
- @options.verbose = false if @options.quiet
55
- end
56
-
57
- def output_options
58
- puts "Options:\
59
- "
60
-
61
- @options.marshal_dump.each do |name, val|
62
- puts " #{name} = #{val}"
63
- end
64
- end
65
-
66
- # True if required arguments were provided
67
- def arguments_valid?
68
- # TO DO - implement your real logic here
69
- true if @arguments.length == 1
70
- end
71
-
72
- # Setup the arguments
73
- def process_arguments
74
- #TODO
75
- end
76
-
77
- def output_help
78
- output_version
79
- RDoc::usage() #exits app
80
- end
81
-
82
- def output_usage
83
- RDoc::usage('usage') # gets usage from comments above
84
- end
85
-
86
- def output_version
87
- puts "#{File.basename(__FILE__)} version #{Version}"
88
- end
89
-
90
- def valid_pario_command?
91
- %w{create add play}.include? @command
92
- end
93
-
94
- def process_command
95
- send @command
96
- #process_standard_input # [Optional]
97
- end
98
-
99
- # Create a game
100
- def create
101
- create_directories
102
- create_base_files
103
- copy_files
104
- end
105
-
106
- def copy_files
107
- # TODO copy over README, LICENSE and pario_background
108
- end
109
-
110
- # This will take ""
111
- def game_name
112
- @game_name ||= @arguments[0]
113
- end
114
-
115
- def game_name_downcase
116
- game_name.split(/(?=[A-Z]+_)/).join('_').downcase
117
- end
118
-
119
- def game_name_upcase
120
- #TODO: need to handle camelcase
121
- game_name.to_s.gsub(/\b\w/){$&.upcase}
122
- end
123
-
124
- def create_base_files
125
- build_main
126
- # build_game_config
127
- build_game_class
128
- end
129
-
130
- def build_game_class
131
- Dir.chdir("game")
132
- game_file = File.open(game_name_downcase + ".rb", "w+")
133
- game_file.puts game_class
134
- end
135
-
136
- def build_main
137
- # "do you want to overwrite main.rb? Y/n" if File.exist?("main.rb")
138
- main_file = File.open("main.rb", "w+")
139
- main_file.puts main_class
140
- end
141
-
142
- def main_class
143
- main_template = ERB.new <<-EOF
144
- require 'rubygems'
145
- require 'gosu'
146
-
147
- Dir.glob(File.join("game", "*.rb")).each {|file| require file }
148
-
149
-
150
- game = #{game_name_upcase}.new(800, 600)
151
- game.show
152
- EOF
153
- main_template.result(binding)
154
- end
155
-
156
- def game_class
157
- game_template = ERB.new <<-EOF
158
- class #{game_name_upcase} < Gosu::Window
159
- def initialize(window_width, window_height)
160
- super(window_width,window_height,0)
161
- end
162
-
163
- def update
164
- # Code to your object around goes here
165
- # TODO: Need more details
166
- end
167
-
168
- def draw
169
- # Code to draw what you see goes here
170
- # TODO: Need more details
171
- end
172
- end
173
- EOF
174
- game_template.result(binding)
175
- end
176
-
177
- def create_directories
178
- Dir.mkdir(game_name_downcase) unless File.directory?(game_name_downcase)
179
- Dir.chdir(game_name_downcase)
180
- Directories.each do |sub_folder|
181
- Dir.mkdir sub_folder unless File.directory?(sub_folder)
182
- end
183
- end
184
-
185
- def add
186
- puts "Feature to come soon, I'm working on it!"
187
- end
188
-
189
- def play
190
- %x{ruby main.rb}
191
- end
192
-
193
- def process_standard_input
194
- input = @stdin.read
195
- # TO DO - process input
196
-
197
- # [Optional]
198
- # @stdin.each do |line|
199
- # # TO DO - process each line
200
- #end
201
- end
202
- end
203
-
204
-
205
- # TO DO - Add your Modules, Classes, etc
206
-
207
-
208
- # Create and run the application
209
- app = Pario.new(ARGV, STDIN)
210
- app.run
4
+ module Pario
5
+ autoload :Version, 'pario/version'
6
+ end
@@ -0,0 +1,145 @@
1
+ require 'pario'
2
+ require 'optparse'
3
+ require 'erb'
4
+
5
+ module Pario
6
+ class Cli
7
+
8
+ Directories = %w{game lib media config}
9
+
10
+ attr_reader :options, :command, :game_name, :arguments
11
+
12
+ def initialize(arguments, stdin)
13
+ @command = arguments[0]
14
+ @arguments = arguments
15
+ end
16
+
17
+ # Parse options, check arguments, then process the command
18
+ def run
19
+ if valid_pario_command?
20
+ @command = arguments.delete_at(0)
21
+ process_command
22
+ else
23
+ puts "Command not recognized."
24
+ end
25
+ end
26
+
27
+ protected
28
+
29
+ def output_version
30
+ puts "pario version #{Version::STRING}"
31
+ end
32
+
33
+ def valid_pario_command?
34
+ %w{create add play -v}.include? @command
35
+ end
36
+
37
+ def process_command
38
+ @command = "output_version" if command == "-v"
39
+ send @command
40
+ end
41
+
42
+ # Create a game
43
+ def create
44
+ create_directories
45
+ create_base_files
46
+ copy_files
47
+ end
48
+
49
+ def copy_files
50
+ # TODO copy over README, LICENSE and pario_background
51
+ end
52
+
53
+ # Set game name
54
+ def game_name
55
+ @game_name ||= @arguments.delete_at(0)
56
+ end
57
+
58
+ def create_base_files
59
+ build_main
60
+ build_extra_classes unless @arguments.empty?
61
+ # build_game_config
62
+ build_game_class
63
+ end
64
+
65
+ def build_game_class
66
+ game_file = File.open("#{game_name.camelize}.rb", "w+")
67
+ game_file.puts game_class
68
+ end
69
+
70
+ def build_main
71
+ # "do you want to overwrite main.rb? Y/n" if File.exist?("main.rb")
72
+ main_file = File.open("main.rb", "w+")
73
+ main_file.puts main_class
74
+ end
75
+
76
+ def build_extra_classes
77
+ Dir.chdir("game") unless Dir.getwd.split("/").last == "game"
78
+ @arguments.each do |new_class|
79
+ class_file = File.open("#{new_class.camelize}.rb", "w+")
80
+ class_file.puts class_template(new_class)
81
+ end
82
+ end
83
+
84
+ def class_template(name)
85
+ template = ERB.new <<-EOF
86
+ class #{name.capitalize}
87
+ def initialize
88
+ end
89
+ end
90
+ EOF
91
+ template.result(binding)
92
+ end
93
+
94
+ def main_class
95
+ main_template = ERB.new <<-EOF
96
+ require 'rubygems'
97
+ require 'gosu'
98
+
99
+ Dir.glob(File.join("game", "*.rb")).each {|file| require file }
100
+
101
+
102
+ game = #{game_name.capitalize}.new(800, 600)
103
+ game.show
104
+ EOF
105
+ main_template.result(binding)
106
+ end
107
+
108
+ def game_class
109
+ game_template = ERB.new <<-EOF
110
+ class #{game_name.capitalize} < Gosu::Window
111
+ def initialize(window_width, window_height)
112
+ super(window_width,window_height,0)
113
+ end
114
+
115
+ def update
116
+ # Code to your object around goes here
117
+ # TODO: Need more details
118
+ end
119
+
120
+ def draw
121
+ # Code to draw what you see goes here
122
+ # TODO: Need more details
123
+ end
124
+ end
125
+ EOF
126
+ game_template.result(binding)
127
+ end
128
+
129
+ def create_directories
130
+ Dir.mkdir(game_name.downcase) unless File.directory?(game_name.downcase)
131
+ Dir.chdir(game_name.downcase)
132
+ Directories.each do |sub_folder|
133
+ Dir.mkdir sub_folder unless File.directory?(sub_folder)
134
+ end
135
+ end
136
+
137
+ def add
138
+ build_extra_classes unless @arguments.empty?
139
+ end
140
+
141
+ def play
142
+ %x{ruby main.rb}
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,16 @@
1
+ module Inflector
2
+ module String
3
+ def camelize
4
+ gsub!(/(.)([A-Z])/,'\1_\2')
5
+ self.downcase
6
+ end
7
+
8
+ def capitalize
9
+ to_s.gsub(/\b\w/){$&.upcase}
10
+ end
11
+ end
12
+ end
13
+
14
+ class String
15
+ include Inflector::String
16
+ end
@@ -1,3 +1,9 @@
1
1
  module Pario #:nodoc:
2
- VERSION = "0.3.4"
2
+ module Version
3
+ MAJOR = '0'
4
+ MINOR = '4'
5
+ MICRO = '0'
6
+
7
+ STRING = [MAJOR, MINOR, MICRO].compact.join('.')
8
+ end
3
9
  end
@@ -0,0 +1,40 @@
1
+ module Util
2
+
3
+ # module Font
4
+ # def initialize(window, size, obj=nil, name=nil)
5
+ # super window, Gosu::default_font_name, size.to_i
6
+ # end
7
+ # def draw(text, color)
8
+ # super text, 0, 0, 99, 1, 1, color
9
+ # # @font.draw("Score: 0", 10, 10, 0, 1.0, 1.0, 0xffffff00)
10
+ # end
11
+ # end
12
+
13
+ def background_image(pic)
14
+ Gosu::Image.new(self, pic, true)
15
+ end
16
+
17
+ #########################
18
+ # There are more key hooks than the ones below, this is just a start
19
+ # TODO: link here to a key map of all of the possiblities
20
+ # EXAMPLE:
21
+ # if key_pressed? :left
22
+ # ...
23
+ # end
24
+ #
25
+ # UP - :up
26
+ # Down - :down
27
+ # Left - :left
28
+ # Right - :right
29
+ # Space Bar :space
30
+ # #########################
31
+ def key_pressed?(key)
32
+ key_const = Gosu.const_get(:"Kb#{key.to_s.gsub(/\b\w/){$&.upcase}}")
33
+ button_down?(key_const)
34
+ end
35
+
36
+ # positioning layers within a game
37
+ # module ZOrder
38
+ # Background, UI = *0..3
39
+ # end
40
+ end
@@ -6,7 +6,7 @@ require 'pario/version'
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = 'pario'
9
- s.version = '0.3.4'
9
+ s.version = Pario::Version::STRING
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.authors = ['Bill Davenport', 'Anthony Burns']
12
12
  s.email = ['bill@infoether.com', 'anthony@infoether.com']
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pario
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
8
  - 4
10
- version: 0.3.4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bill Davenport
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-02-18 00:00:00 -05:00
19
+ date: 2011-02-22 00:00:00 -05:00
20
20
  default_executable: pario
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -52,7 +52,11 @@ files:
52
52
  - lib/docs/LICENSE
53
53
  - lib/docs/README
54
54
  - lib/pario.rb
55
+ - lib/pario/cli.rb
56
+ - lib/pario/inflector.rb
57
+ - lib/pario/media/pario_background.png
55
58
  - lib/pario/version.rb
59
+ - lib/util.rb
56
60
  - pario.gemspec
57
61
  has_rdoc: true
58
62
  homepage: http://github.com/ruby4kids/pario