Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add ability to load namespaced classes #40

Merged
merged 3 commits into from

2 participants

@krzyzak

Hi,
I've noticed, that load_game_objects method doesn't support namespaced classes.
I've fixed this, plus changed reciever from Kernel to Object, which is top-level constant.

@ippa
Owner

Hey krzyzak. Sorry for taking ages to look at your patch! merging. Let me know if you need a new rc released soonish.

@ippa ippa merged commit 0bedf3a into ippa:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 21, 2011
  1. @krzyzak
Commits on Dec 4, 2011
  1. @krzyzak
  2. @krzyzak

    small bug fix

    krzyzak authored
This page is out of date. Refresh to see the latest.
View
7 lib/chingu/game_states/edit.rb
@@ -136,6 +136,10 @@ def initialize(options = {})
@hud_height = 140
@toolbar_icon_size = [32,32]
+ draw_toolbar_objects
+ end
+
+ def draw_toolbar_objects
x = 20
y = 60
@classes.each do |klass|
@@ -162,9 +166,8 @@ def initialize(options = {})
rescue
puts "Couldn't use #{klass} in editor: #{$!}"
end
- end
+ end
end
-
def display_help
text = <<END_OF_STRING
F1: This help screen
View
6 lib/chingu/helpers/game_object.rb
@@ -63,7 +63,11 @@ def load_game_objects(options = {})
objects.each do |object|
object.each_pair do |klassname, attributes|
begin
- klass = Kernel::const_get(klassname)
+ klass = Object
+ names = klassname.split('::')
+ names.each do |name|
+ klass = klass.const_defined?(name) ? klass.const_get(name) : klass.const_missing(name)
+ end
unless klass.class == "GameObject" && !except.include?(klass)
puts "Creating #{klassname.to_s}: #{attributes.to_s}" if debug
object = klass.create(attributes)
Something went wrong with that request. Please try again.