Class: Gamefic::Entity

Inherits:
Element show all
Includes:
Grammar::WordAdapter, Messaging, Node
Defined in:
lib/gamefic/entity.rb

Direct Known Subclasses

Actor

Constant Summary

Constants included from Matchable

Matchable::SPLIT_REGEXP

Instance Attribute Summary

Attributes included from Grammar::Plural

#plural

Attributes included from Grammar::Person

#person

Attributes included from Grammar::Gender

#gender

Attributes included from Describable

#definite_article, #indefinite_article, #name, #synonyms

Instance Method Summary collapse

Methods included from Grammar::WordAdapter

#contract, #pronoun, #verb

Methods included from Grammar::Plural

#plural?

Methods included from Messaging

#flush, #messages, #output, #stream, #tell

Methods included from Node

#accessible?, #children, #flatten, #parent

Methods inherited from Element

default_attributes, inherited, #initialize, #post_initialize, set_default

Methods included from Describable

default_description, default_description=, #definitely, #description, #description=, #has_description?, #indefinitely, #keywords, #proper_named=, #proper_named?, #to_s

Methods included from Matchable

#keywords, #match?

Constructor Details

This class inherits a constructor from Gamefic::Element

Instance Method Details

#[](key) ⇒ Object

Get a custom property.

Parameters:

  • key (Symbol)

    The property’s name

Returns:

  • The value of the property



43
44
45
# File 'lib/gamefic/entity.rb', line 43

def [](key)
  session[key]
end

#[]=(key, value) ⇒ Object

Set a custom property.

Parameters:

  • key (Symbol)

    The property’s name

  • value

    The value to set



51
52
53
# File 'lib/gamefic/entity.rb', line 51

def []=(key, value)
  session[key] = value
end

#parent=(node) ⇒ Object

Set the Entity’s parent.

Parameters:

  • node (Entity)

    The new parent.



22
23
24
25
26
27
# File 'lib/gamefic/entity.rb', line 22

def parent=(node)
  if node != nil and node.kind_of?(Entity) == false
    raise "Entity's parent must be an Entity"
  end
  super
end

#sessionHash

A freeform property dictionary. Authors can use the session hash to assign custom properties to the entity. It can also be referenced directly using [] without the method name, e.g., entity.session or entity.

Returns:

  • (Hash)


35
36
37
# File 'lib/gamefic/entity.rb', line 35

def session
  @session ||= {}
end

#updateObject

Execute the entity’s on_update blocks. This method is typically called by the Engine that manages game execution. The base method does nothing. Subclasses can override it.



16
17
# File 'lib/gamefic/entity.rb', line 16

def update
end