shattered_ruby 0.5.0.2

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.
Files changed (60) hide show
  1. data/bin/console +4 -0
  2. data/bin/destroy +9 -0
  3. data/bin/generate +7 -0
  4. data/bin/runner +9 -0
  5. data/bin/shatter +22 -0
  6. data/lib/commands/console.rb +23 -0
  7. data/lib/game_loader.rb +118 -0
  8. data/lib/rails_generator/base.rb +203 -0
  9. data/lib/rails_generator/commands.rb +519 -0
  10. data/lib/rails_generator/generators/applications/shattered_app/USAGE +10 -0
  11. data/lib/rails_generator/generators/applications/shattered_app/shattered_app_generator.rb +103 -0
  12. data/lib/rails_generator/generators/components/actor/actor_generator.rb +22 -0
  13. data/lib/rails_generator/generators/components/actor/templates/actor.rb +0 -0
  14. data/lib/rails_generator/generators/components/model/USAGE +17 -0
  15. data/lib/rails_generator/generators/components/model/model_generator.rb +22 -0
  16. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +5 -0
  17. data/lib/rails_generator/generators/components/model/templates/model.rb +2 -0
  18. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +11 -0
  19. data/lib/rails_generator/generators/components/state/USAGE +30 -0
  20. data/lib/rails_generator/generators/components/state/state_generator.rb +19 -0
  21. data/lib/rails_generator/generators/components/state/templates/state.rb +31 -0
  22. data/lib/rails_generator/generators/components/view/USAGE +30 -0
  23. data/lib/rails_generator/generators/components/view/templates/material +4 -0
  24. data/lib/rails_generator/generators/components/view/templates/view.rb +9 -0
  25. data/lib/rails_generator/generators/components/view/view_generator.rb +28 -0
  26. data/lib/rails_generator/lookup.rb +209 -0
  27. data/lib/rails_generator/manifest.rb +53 -0
  28. data/lib/rails_generator/options.rb +143 -0
  29. data/lib/rails_generator/scripts/destroy.rb +7 -0
  30. data/lib/rails_generator/scripts/generate.rb +7 -0
  31. data/lib/rails_generator/scripts/update.rb +12 -0
  32. data/lib/rails_generator/scripts.rb +83 -0
  33. data/lib/rails_generator/simple_logger.rb +46 -0
  34. data/lib/rails_generator/spec.rb +44 -0
  35. data/lib/rails_generator.rb +43 -0
  36. data/lib/shatter.rb +7 -0
  37. data/lib/tasks/documentation.rake +46 -0
  38. data/lib/tasks/framework.rake +80 -0
  39. data/lib/tasks/log.rake +9 -0
  40. data/lib/tasks/misc.rake +4 -0
  41. data/lib/tasks/pre_namespace_aliases.rake +28 -0
  42. data/lib/tasks/shattered.rb +6 -0
  43. data/lib/tasks/statistics.rake +17 -0
  44. data/lib/tasks/testing.rake +102 -0
  45. data/lib/templates/MIT-LICENSE +20 -0
  46. data/lib/templates/README +35 -0
  47. data/lib/templates/Rakefile +11 -0
  48. data/lib/templates/configs/boot.rb +35 -0
  49. data/lib/templates/configs/empty.log +0 -0
  50. data/lib/templates/configs/ogre.cfg +4 -0
  51. data/lib/templates/configs/ogre_plugins.windows.cfg +14 -0
  52. data/lib/templates/configs/runner.rb +5 -0
  53. data/lib/templates/doc/README_FOR_APP +2 -0
  54. data/lib/templates/environments/environment.rb +10 -0
  55. data/lib/templates/media/basic.rmaterial +18 -0
  56. data/lib/templates/media/default.mesh +0 -0
  57. data/lib/templates/media/default.png +0 -0
  58. data/lib/templates/media/offset_map.rmaterial +117 -0
  59. data/lib/templates/test/test_helper.rb +5 -0
  60. metadata +153 -0
data/bin/console ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "#{File.dirname(__FILE__)}/../config/boot"
4
+ require "commands/console"
data/bin/destroy ADDED
@@ -0,0 +1,9 @@
1
+ #!/opt/local/bin/ruby
2
+
3
+ require File.dirname(__FILE__) + '/../config/boot'
4
+ require File.dirname(__FILE__) + '/../config/environment'
5
+ require 'rails_generator'
6
+ require 'rails_generator/scripts/destroy'
7
+
8
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
9
+ Rails::Generator::Scripts::Destroy.new.run(ARGV)
data/bin/generate ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby18
2
+ require File.dirname(__FILE__)+"/../config/boot"
3
+ require 'rails_generator'
4
+ require 'rails_generator/scripts/generate'
5
+
6
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
7
+ Rails::Generator::Scripts::Generate.new.run(ARGV)
data/bin/runner ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ if PLATFORM =~ /powerpc-darwin/
4
+ path = File.dirname(__FILE__) + "/../config/Mac/"
5
+ puts `(cd #{path}shattered.app; ./Contents/MacOS/shattered_mac)`
6
+ else
7
+ require File.dirname(__FILE__)+'/runner'
8
+ start_game
9
+ end
data/bin/shatter ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ #This file is adapted from the rails command.
3
+
4
+ min_release = "1.8.2 (2004-12-25)"
5
+ ruby_release = "#{RUBY_VERSION} (#{RUBY_RELEASE_DATE})"
6
+
7
+ if ruby_release < min_release
8
+ abort <<-end_message
9
+
10
+ Shattered requires Ruby version #{min_release} or later.
11
+ You're running #{ruby_release}; please upgrade to continue.
12
+
13
+ end_message
14
+ end
15
+
16
+ Signal.trap("INT") { puts; exit }
17
+
18
+
19
+ require File.dirname(__FILE__) + '/../lib/rails_generator'
20
+ require 'rails_generator/scripts/generate'
21
+ Rails::Generator::Base.use_application_sources!
22
+ Rails::Generator::Scripts::Generate.new.run(ARGV, :generator => 'shattered_app')
@@ -0,0 +1,23 @@
1
+ irb = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb'
2
+
3
+ require 'optparse'
4
+ options = { :sandbox => false, :irb => irb }
5
+ OptionParser.new do |opt|
6
+ opt.banner = "Usage: console [environment] [options]"
7
+ opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |options[:sandbox]| }
8
+ opt.on("--irb=[#{irb}]", 'Invoke a different irb.') { |options[:irb]| }
9
+ opt.parse!(ARGV)
10
+ end
11
+
12
+ libs = " -r irb/completion"
13
+ libs << " -r #{SHATTERED_ROOT}/config/environment"
14
+ libs << " -r console_sandbox" if options[:sandbox]
15
+
16
+ ENV['SHATTERED_ENV'] = ARGV.first || ENV['SHATTERED_ENV'] || 'development'
17
+ if options[:sandbox]
18
+ puts "Loading #{ENV['SHATTER_ENV']} environment in sandbox."
19
+ puts "Any modifications you make will be rolled back on exit."
20
+ else
21
+ puts "Loading #{ENV['SHATTER_ENV']} environment."
22
+ end
23
+ exec "#{options[:irb]} #{libs} --simple-prompt"
@@ -0,0 +1,118 @@
1
+ require 'singleton'
2
+
3
+ include ShatteredState
4
+ include ShatteredView
5
+ include ShatteredModel
6
+
7
+ module Shatter #:nodoc:all
8
+ #This class is loads the view, controller, and model. It then loads
9
+ #and starts the game based on these.
10
+ class GameLoader
11
+ include Singleton
12
+ attr_writer :environment
13
+ attr_reader :media_paths, :render_window, :input_manager, :key_manager, :key_converter
14
+ attr_accessor :current_state
15
+
16
+ # This will recourse into the app/** directories and load all ruby files
17
+ # inside those directories.
18
+ def load_all_sources(shattered_root)
19
+ File.find_by_extension(shattered_root+"/app", "rb").each do |file|
20
+ require(file)
21
+ end
22
+ end
23
+
24
+ # start the game
25
+ def run
26
+ load_all_sources(SHATTERED_ROOT)
27
+ load_environment
28
+
29
+ # Create our initial state, as defined by the environment.
30
+ create_state(@environment[:start_state])
31
+
32
+ start_game
33
+ end
34
+
35
+ # Create a state from the given name
36
+ # :sample creates a new SampleState object
37
+ def create_state(state_name)
38
+ state_class = eval("#{state_name.to_s.camelize}State")
39
+ raise Error, "#{state_class} is not a class" unless state_class.is_a? Class
40
+ state = state_class.new
41
+ unless state.is_a? ShatteredState::Base
42
+ raise Error, "#{state_class} is an invalid State object (not of ShatteredState::Base)"
43
+ end
44
+ return state
45
+ end
46
+
47
+ def load_environment
48
+ #Setup Ogre and the scene for the state
49
+ raise Error, "Ogre failed to initialize" if !setup_ogre
50
+ setup_input
51
+
52
+ load_resources(@environment[:media])
53
+ end
54
+
55
+ # Given ['app/media', 'media'], searches those directories, recursively, for OGRE media
56
+ def load_resources(paths)
57
+ @media_paths = paths
58
+ # setup our resource paths specified in environment.rb
59
+ Resources.instance.add_resource_paths(*paths)
60
+ Resources.instance.setup
61
+ end
62
+
63
+ #Load the root, setup the render window
64
+ #TODO: allow for the user to specify whether the window dialogue pops up
65
+ #further TODO: allow the user to skin the render window dialogue
66
+ def setup_ogre
67
+ # TODO: create platform loader for other platforms
68
+ plugins = SHATTERED_ROOT + "/config/ogre_plugins.windows.cfg"
69
+ config_save=SHATTERED_ROOT + "/config/ogrerb_defaults.save"
70
+ log=SHATTERED_ROOT + "/log/ogrerb.log"
71
+ @root = ShatteredOgre.create_root(plugins, config_save, log)
72
+ return false if !@root.show_config_dialog
73
+ # TODO: allow application name to be set.
74
+ @render_window = @root.initialise(true)
75
+
76
+ return true
77
+ end
78
+
79
+ #Every time this exits, a game dies.
80
+ def start_game
81
+ each_frame do |time_elapsed|
82
+ current_state.update_timers(time_elapsed)
83
+ @keyboard.capture
84
+ #@@environment[:input].flush
85
+ end
86
+ end
87
+
88
+ # Main game loop
89
+ def each_frame
90
+ timer = Ogre::Timer.new
91
+ while !@environment[:quit] && Ogre::Root::instance.render_one_frame
92
+ seconds = timer.get_microseconds / 1000000.0
93
+ yield seconds
94
+ timer.reset
95
+ end
96
+ end
97
+
98
+ # Leave the game
99
+ def quit!
100
+ @environment[:quit]=true
101
+ end
102
+
103
+ # load the input manager, the key manager, etc
104
+ # TODO: Consider how to make input non-exclusive, as well as mouse, etc.
105
+ # TODO: Investigate any use cases for non-buffered input
106
+ def setup_input
107
+ windowHnd = render_window.get_custom_attribute_unsigned_long("WINDOW")
108
+ @input_manager = OIS::InputManager.create_input_system(
109
+ { "WINDOW" => "#{windowHnd}",
110
+ "w32_mouse" => ["DISCL_FOREGROUND", "DISCL_NONEXCLUSIVE"],
111
+ "w32_keyboard" => ["DISCL_FOREGROUND", "DISCL_NONEXCLUSIVE"]
112
+ })
113
+ @keyboard = @input_manager.create_input_object(OIS::OISKeyboard, true)
114
+ @key_manager = OIS::KeyManager.new(@keyboard)
115
+ @key_converter = ShatteredPack::KeyConverter.new(@key_manager)
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,203 @@
1
+ require File.dirname(__FILE__) + '/options'
2
+ require File.dirname(__FILE__) + '/manifest'
3
+ require File.dirname(__FILE__) + '/spec'
4
+
5
+ # Rails::Generator is a code generation platform tailored for the Rails
6
+ # web application framework. Generators are easily invoked within Rails
7
+ # applications to add and remove components such as models and controllers.
8
+ # New generators are easy to create and may be distributed as RubyGems or
9
+ # tarballs for inclusion system-wide, per-user, or per-application.
10
+ #
11
+ # Generators may subclass other generators to provide variations that
12
+ # require little or no new logic but replace the template files.
13
+ # The postback generator is an example: it subclasses the scaffold
14
+ # generator and just replaces the code templates with its own.
15
+ #
16
+ # Now go forth and multiply^Wgenerate.
17
+ module Rails
18
+ module Generator
19
+ class GeneratorError < StandardError; end
20
+ class UsageError < GeneratorError; end
21
+
22
+
23
+ # The base code generator is bare-bones. It sets up the source and
24
+ # destination paths and tells the logger whether to keep its trap shut.
25
+ # You're probably looking for NamedBase, a subclass meant for generating
26
+ # "named" components such as models, controllers, and mailers.
27
+ #
28
+ # Generators create a manifest of the actions they perform then hand
29
+ # the manifest to a command which replay the actions to do the heavy
30
+ # lifting. Create, destroy, and list commands are included. Since a
31
+ # single manifest may be used by any command, creating new generators is
32
+ # as simple as writing some code templates and declaring what you'd like
33
+ # to do with them.
34
+ #
35
+ # The manifest method must be implemented by subclasses, returning a
36
+ # Rails::Generator::Manifest. The record method is provided as a
37
+ # convenience for manifest creation. Example:
38
+ # class EliteGenerator < Rails::Generator::Base
39
+ # def manifest
40
+ # record do |m|
41
+ # m.do(some)
42
+ # m.things(in) { here }
43
+ # end
44
+ # end
45
+ # end
46
+ class Base
47
+ include Options
48
+
49
+ # Declare default options for the generator. These options
50
+ # are inherited to subclasses.
51
+ default_options :collision => :ask, :quiet => false
52
+
53
+ # A logger instance available everywhere in the generator.
54
+ cattr_accessor :logger
55
+
56
+ # Every generator that is dynamically looked up is tagged with a
57
+ # Spec describing where it was found.
58
+ class_inheritable_accessor :spec
59
+
60
+ attr_reader :source_root, :destination_root, :args
61
+
62
+ def initialize(runtime_args, runtime_options = {})
63
+ @args = runtime_args
64
+ parse!(@args, runtime_options)
65
+
66
+ # Derive source and destination paths.
67
+ @source_root = options[:source] || File.join(spec.path, 'templates')
68
+ if options[:destination]
69
+ @destination_root = options[:destination]
70
+ elsif defined? ::SHATTERED_ROOT
71
+ @destination_root = ::SHATTERED_ROOT
72
+ end
73
+
74
+ # Silence the logger if requested.
75
+ logger.quiet = options[:quiet]
76
+
77
+ # Raise usage error if help is requested.
78
+ usage if options[:help]
79
+ end
80
+
81
+ # Generators must provide a manifest. Use the record method to create
82
+ # a new manifest and record your generator's actions.
83
+ def manifest
84
+ raise NotImplementedError, "No manifest for '#{spec.name}' generator."
85
+ end
86
+
87
+ # Return the full path from the source root for the given path.
88
+ # Example for source_root = '/source':
89
+ # source_path('some/path.rb') == '/source/some/path.rb'
90
+ #
91
+ # The given path may include a colon ':' character to indicate that
92
+ # the file belongs to another generator. This notation allows any
93
+ # generator to borrow files from another. Example:
94
+ # source_path('model:fixture.yml') = '/model/source/path/fixture.yml'
95
+ def source_path(relative_source)
96
+ # Check whether we're referring to another generator's file.
97
+ name, path = relative_source.split(':', 2)
98
+
99
+ # If not, return the full path to our source file.
100
+ if path.nil?
101
+ File.join(source_root, name)
102
+
103
+ # Otherwise, ask our referral for the file.
104
+ else
105
+ # FIXME: this is broken, though almost always true. Others'
106
+ # source_root are not necessarily the templates dir.
107
+ File.join(self.class.lookup(name).path, 'templates', path)
108
+ end
109
+ end
110
+
111
+ # Return the full path from the destination root for the given path.
112
+ # Example for destination_root = '/dest':
113
+ # destination_path('some/path.rb') == '/dest/some/path.rb'
114
+ def destination_path(relative_destination)
115
+ File.join(destination_root, relative_destination)
116
+ end
117
+
118
+ protected
119
+ # Convenience method for generator subclasses to record a manifest.
120
+ def record
121
+ Rails::Generator::Manifest.new(self) { |m| yield m }
122
+ end
123
+
124
+ # Override with your own usage banner.
125
+ def banner
126
+ "Usage: #{$0} #{spec.name} [options]"
127
+ end
128
+
129
+ # Read USAGE from file in generator base path.
130
+ def usage_message
131
+ File.read(File.join(spec.path, 'USAGE')) rescue ''
132
+ end
133
+ end
134
+
135
+
136
+ # The base generator for named components: models, controllers, mailers,
137
+ # etc. The target name is taken as the first argument and inflected to
138
+ # singular, plural, class, file, and table forms for your convenience.
139
+ # The remaining arguments are aliased to actions for controller and
140
+ # mailer convenience.
141
+ #
142
+ # If no name is provided, the generator raises a usage error with content
143
+ # optionally read from the USAGE file in the generator's base path.
144
+ #
145
+ # See Rails::Generator::Base for a discussion of Manifests and Commands.
146
+ class NamedBase < Base
147
+ attr_reader :name, :class_name, :singular_name, :plural_name, :table_name
148
+ attr_reader :class_path, :file_path, :class_nesting, :class_nesting_depth
149
+ alias_method :file_name, :singular_name
150
+ alias_method :actions, :args
151
+
152
+ def initialize(runtime_args, runtime_options = {})
153
+ super
154
+
155
+ # Name argument is required.
156
+ usage if runtime_args.empty?
157
+
158
+ @args = runtime_args.dup
159
+ base_name = @args.shift
160
+ assign_names!(base_name)
161
+ end
162
+
163
+ protected
164
+ # Override with your own usage banner.
165
+ def banner
166
+ "Usage: #{$0} #{spec.name} #{spec.name.camelize}Name [options]"
167
+ end
168
+
169
+ private
170
+ def assign_names!(name)
171
+ @name = name
172
+ base_name, @class_path, @file_path, @class_nesting, @class_nesting_depth = extract_modules(@name)
173
+ @class_name_without_nesting, @singular_name, @plural_name = inflect_names(base_name)
174
+ @table_name = singular_name
175
+ if @class_nesting.empty?
176
+ @class_name = @class_name_without_nesting
177
+ else
178
+ @class_name = "#{@class_nesting}::#{@class_name_without_nesting}"
179
+ end
180
+ end
181
+
182
+ # Extract modules from filesystem-style or ruby-style path:
183
+ # good/fun/stuff
184
+ # Good::Fun::Stuff
185
+ # produce the same results.
186
+ def extract_modules(name)
187
+ modules = name.include?('/') ? name.split('/') : name.split('::')
188
+ name = modules.pop
189
+ path = modules.map { |m| m.underscore }
190
+ file_path = (path + [name.underscore]).join('/')
191
+ nesting = modules.map { |m| m.camelize }.join('::')
192
+ [name, path, file_path, nesting, modules.size]
193
+ end
194
+
195
+ def inflect_names(name)
196
+ camel = name.camelize
197
+ under = camel.underscore
198
+ plural = under.pluralize
199
+ [camel, under, plural]
200
+ end
201
+ end
202
+ end
203
+ end