lib/demiurge.rb
def instantiate_new_item(name, parent, extra_state = {})
      parent = item_by_name(parent) unless parent.is_a?(StateItem)
      ss = parent.get_structure

      # The new instantiated item is different from the parent because
      # it has its own name, and because it can get named actions from
      # the parent as well as itself. The latter is important because
      # we can't easily make new action procs without an associated
      # World File of some kind.
      ss[1] = name
      ss[2] = deepcopy(ss[2])
      ss[2].merge!(extra_state)
      ss[2]["parent"] = parent.name

      child = register_state_item(StateItem.from_name_type(self, *ss))
      if @finished_init && child.respond_to?(:finished_init)
        child.finished_init
      end
      if child.get_action("new")
        child.run_action("new")
      end
      child
    end
# This method creates a new StateItem based on an existing parent
# StateItem, and will retain some level of linkage to that parent
# StateItem afterward as well. This provides a simple form of
# action inheritance and data inheritance.
#
# The new child item will begin with a copy of the parent's state
# which can then be overridden. There will not be a longer-term
# link to the parent's state, and any later state changes in the
# parent or child will not affect each other.
#
# There *will* be a longer-term link to the parent's actions, and
# any action not overridden in the child item will fall back to
# the parent's action of the same name.
#
# If the parent item has an action named "new", it will be called
# on the newly-copied child item after the copy is complete.
#
# @param name [String] The new item name to register with the engine
# @param parent [Demiurge::StateItem] The parent StateItem
# @param extra_state [Hash] Additional state data for the child
# @return [Demiurge::StateItem] The newly-created StateItem which has been registered with the engine
# @since 0.0.1
This method creates a new StateItem based on an existing parent
StateItem, and will retain some level of linkage to that parent
StateItem afterward as well. This provides a simple form of
action inheritance and data inheritance.

The new child item will begin with a copy of the parent's state
which can then be overridden. There will not be a longer-term
link to the parent's state, and any later state changes in the
parent or child will not affect each other.

There *will* be a longer-term link to the parent's actions, and
any action not overridden in the child item will fall back to
the parent's action of the same name.

If the parent item has an action named "new", it will be called
on the newly-copied child item after the copy is complete.
This method creates a new StateItem based on an existing parent StateItem and will retain some level of linkage to that parent StateItem afterward as well . This provides a simple form of action inheritance and data inheritance . The new child item will begin with a copy of the parent ' s state which can then be overridden . There will not be a longer - term link to the parent ' s state and any later state changes in the parent or child will not affect each other . There * will * be a longer - term link to the parent ' s actions and any action not overridden in the child item will fall back to the parent ' s action of the same name . If the parent item has an action named " new " it will be called on the newly - copied child item after the copy is complete .
def instantiate_new_item(name, parent, extra_state = {})
      parent = item_by_name(parent) unless parent.is_a?(StateItem)
      ss = parent.get_structure
      ss[1] = name
      ss[2] = deepcopy(ss[2])
      ss[2].merge!(extra_state)
      ss[2]["parent"] = parent.name
      child = register_state_item(StateItem.from_name_type(self, *ss))
      if @finished_init && child.respond_to?(:finished_init)
        child.finished_init
      end
      if child.get_action("new")
        child.run_action("new")
      end
      child
    end
def instantiate_new_item ( name , parent , extra_state = { } ) parent = item_by_name ( parent ) unless parent . is_a? ( StateItem ) ss = parent . get_structure ss [ 1 ] = name ss [ 2 ] = deepcopy ( ss [ 2 ] ) ss [ 2 ] . merge! ( extra_state ) ss [ 2 ] [ "parent" ] = parent . name child = register_state_item ( StateItem . from_name_type ( self , * ss ) ) if @finished_init && child . respond_to? ( :finished_init ) child . finished_init end if child . get_action ( "new" ) child . run_action ( "new" ) end child end
This method creates a new StateItem based on an existing parent
StateItem, and will retain some level of linkage to that parent
StateItem afterward as well.
This method creates a new StateItem based on an existing parent StateItem and will retain some level of linkage to that parent StateItem afterward as well .
# The new instantiated item is different from the parent because # it has its own name, and because it can get named actions from # the parent as well as itself. The latter is important because # we can't easily make new action procs without an associated # World File of some kind.
The newly-created StateItem which has been registered with the engine
The newly - created StateItem which has been registered with the engine
Demiurge::StateItem
name
The new item name to register with the engine
The new item name to register with the engine
parent
The parent StateItem
The parent StateItem
extra_state
Additional state data for the child
Additional state data for the child
since
None