Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Aethyr
Manage
Activity
Members
Labels
Plan
Issues
12
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Aethyr
Aethyr
Commits
342a7958
Commit
342a7958
authored
4 years ago
by
Jeffrey Phillips Freeman
Browse files
Options
Downloads
Patches
Plain Diff
Got defaults working but doesnt handle subclassing correctly yet.
parent
1a9b7572
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/aethyr/core/objects/game_object.rb
+9
-5
9 additions, 5 deletions
lib/aethyr/core/objects/game_object.rb
lib/aethyr/core/util/defaults.rb
+77
-3
77 additions, 3 deletions
lib/aethyr/core/util/defaults.rb
with
86 additions
and
8 deletions
lib/aethyr/core/objects/game_object.rb
+
9
−
5
View file @
342a7958
...
@@ -12,22 +12,23 @@ class GameObject < Publisher
...
@@ -12,22 +12,23 @@ class GameObject < Publisher
include
Lexicon
include
Lexicon
include
Defaults
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_accessor
:container
,
:show_in_look
,
:actions
,
:pose
,
:visible
,
:comment
,
:movable
,
:quantity
,
:info
attr_writer
:plural
attr_writer
:plural
alias
:room
:container
alias
:room
:container
alias
:can?
:respond_to?
alias
:can?
:respond_to?
alias
:goid
:game_object_id
alias
:goid
:game_object_id
Defaults
::
default
(
:gender
)
do
default
(
:gender
)
do
|
this
|
if
@
sex
==
'm'
if
this
.
sex
==
'm'
Lexicon
::
Gender
::
MASCULINE
Lexicon
::
Gender
::
MASCULINE
elsif
@
sex
==
'f'
elsif
this
.
sex
==
'f'
Lexicon
::
Gender
::
FEMININE
Lexicon
::
Gender
::
FEMININE
else
else
Lexicon
::
Gender
::
NEUTER
Lexicon
::
Gender
::
NEUTER
end
end
end
end
default
(
:visible
)
{
true
}
#Creates a new GameObject. Most of this long list of parameters is simply ignored at creation time,
#Creates a new GameObject. Most of this long list of parameters is simply ignored at creation time,
#because they can all be set later.
#because they can all be set later.
...
@@ -51,7 +52,6 @@ class GameObject < Publisher
...
@@ -51,7 +52,6 @@ class GameObject < Publisher
@sex
=
sex
@sex
=
sex
#The article of the object ('a','an',etc)
#The article of the object ('a','an',etc)
@article
=
article
@article
=
article
@visible
=
true
#This is tricky. If @show_in_look is something
#This is tricky. If @show_in_look is something
#other than false (or nil), then the object will
#other than false (or nil), then the object will
#not show up in the list of objects, but rather this
#not show up in the list of objects, but rather this
...
@@ -83,6 +83,10 @@ class GameObject < Publisher
...
@@ -83,6 +83,10 @@ class GameObject < Publisher
@admin
=
false
@admin
=
false
load_defaults
load_defaults
puts
"checking gender for
#{
@name
}
"
puts
@gender
puts
"and defaults"
puts
@@defaults
end
end
def
attributes
def
attributes
...
...
This diff is collapsed.
Click to expand it.
lib/aethyr/core/util/defaults.rb
+
77
−
3
View file @
342a7958
...
@@ -15,7 +15,7 @@ module Defaults
...
@@ -15,7 +15,7 @@ module Defaults
local_defaults
.
each
do
|
default
|
local_defaults
.
each
do
|
default
|
attribute
=
default
[
:attribute
]
attribute
=
default
[
:attribute
]
block
=
default
[
:block
]
block
=
default
[
:block
]
if
defined?
(
attribute
)
.
nil?
if
not
instance_variable_
defined?
(
attribute
)
self
.
set_default
(
attribute
,
&
block
)
self
.
set_default
(
attribute
,
&
block
)
end
end
end
end
...
@@ -24,7 +24,8 @@ module Defaults
...
@@ -24,7 +24,8 @@ module Defaults
private
private
def
set_default
(
attribute
)
def
set_default
(
attribute
)
self
.
set_instance_variable
(
attribute
,
yield
)
value
=
yield
self
self
.
instance_variable_set
(
attribute
,
value
)
end
end
module
ClassMethods
module
ClassMethods
...
@@ -42,13 +43,33 @@ end
...
@@ -42,13 +43,33 @@ end
class
Foo
class
Foo
include
Defaults
include
Defaults
attr_reader
:sex
default
(
:bar
)
{
"foobar"
}
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
def
initialize
@dummy_var
=
"this is just so something exists"
@sex
=
'm'
load_defaults
load_defaults
end
end
def
bar
def
local_failbar
@failbar
end
def
local_bar
@bar
@bar
end
end
...
@@ -59,4 +80,57 @@ class Foo
...
@@ -59,4 +80,57 @@ class Foo
def
local_df
def
local_df
@@defaults
@@defaults
end
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
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment