diff --git a/lib/aethyr/core/objects/game_object.rb b/lib/aethyr/core/objects/game_object.rb index cb1ec4e6f2fdc627c957b312c9adedb369f05fc2..873fe8c64e8edaab48254fb51123c768021deff6 100644 --- a/lib/aethyr/core/objects/game_object.rb +++ b/lib/aethyr/core/objects/game_object.rb @@ -12,22 +12,23 @@ class GameObject < Publisher include Lexicon include Defaults - attr_reader :short_desc, :game_object_id, :alt_names, :generic, :article, :sex, :show_in_look, :actions, :balance, :admin, :manager + attr_reader :short_desc, :game_object_id, :alt_names, :generic, :article, :sex, :gender, :show_in_look, :actions, :balance, :admin, :manager attr_accessor :container, :show_in_look, :actions, :pose, :visible, :comment, :movable, :quantity, :info attr_writer :plural alias :room :container alias :can? :respond_to? alias :goid :game_object_id - Defaults::default(:gender) do - if @sex == 'm' + default(:gender) do |this| + if this.sex == 'm' Lexicon::Gender::MASCULINE - elsif @sex == 'f' + elsif this.sex == 'f' Lexicon::Gender::FEMININE else Lexicon::Gender::NEUTER end end + default(:visible) { true } #Creates a new GameObject. Most of this long list of parameters is simply ignored at creation time, #because they can all be set later. @@ -51,7 +52,6 @@ class GameObject < Publisher @sex = sex #The article of the object ('a','an',etc) @article = article - @visible = true #This is tricky. If @show_in_look is something #other than false (or nil), then the object will #not show up in the list of objects, but rather this @@ -83,6 +83,10 @@ class GameObject < Publisher @admin = false load_defaults + puts "checking gender for #{@name}" + puts @gender + puts "and defaults" + puts @@defaults end def attributes diff --git a/lib/aethyr/core/util/defaults.rb b/lib/aethyr/core/util/defaults.rb index 11dff6136e69f7464a1b49af4586d74cd4e8a047..5c120cb577080d32e534833720b67075c8f68f88 100644 --- a/lib/aethyr/core/util/defaults.rb +++ b/lib/aethyr/core/util/defaults.rb @@ -15,7 +15,7 @@ module Defaults local_defaults.each do |default| attribute = default[:attribute] block = default[:block] - if defined?(attribute).nil? + if not instance_variable_defined?(attribute) self.set_default(attribute, &block) end end @@ -24,7 +24,8 @@ module Defaults private def set_default(attribute) - self.set_instance_variable(attribute, yield) + value = yield self + self.instance_variable_set(attribute, value) end module ClassMethods @@ -42,13 +43,33 @@ end class Foo include Defaults + + attr_reader :sex + default(:bar) {"foobar"} + default(:baz) { |this| this.instance_variable_get(:@bar).concat(" and baz") } + #default(:sex) {"m"} + default(:gender) do |this| + if this.sex == 'm' + "Lexicon::Gender::MASCULINE" + elsif this.sex == 'f' + "Lexicon::Gender::FEMININE" + else + "Lexicon::Gender::NEUTER" + end + end def initialize + @dummy_var = "this is just so something exists" + @sex = 'm' load_defaults end - def bar + def local_failbar + @failbar + end + + def local_bar @bar end @@ -59,4 +80,57 @@ class Foo def local_df @@defaults end + + def class_vars_proxy + self.class.instance_variables + end + + def local_baz + @baz + end + + def local_sex + @sex + end + + def local_gender + @gender + end end + +puts "check_df" +puts Foo.check_df + +puts "local_df" +foo = Foo.new +puts foo.local_df + +puts "Defaults::defaults" +puts Defaults::defaults + +#puts "foo.defaults" +#puts foo.defaults + +puts "local_bar" +puts foo.local_bar + +puts "local_failbar" +puts foo.local_failbar + +puts "instance vars" +puts foo.instance_variables + +puts "class vars" +puts Foo.instance_variables + +puts "class vars proxy" +puts foo.class_vars_proxy + +puts "local_baz" +puts foo.local_baz + +puts "local_sex" +puts foo.local_sex + +puts "local_gender" +puts foo.local_gender