--- deliantra/server/lib/cf.pm 2006/08/29 14:49:28 1.54 +++ deliantra/server/lib/cf.pm 2006/08/29 17:32:19 1.55 @@ -107,6 +107,10 @@ ############################################################################# # "new" plug-in system +=head3 EVENTS AND OBJECT ATTACHMENTS + +=over 4 + =item $object->attach ($attachment, key => $value...) =item $object->detach ($attachment) @@ -125,6 +129,14 @@ Attach/detach a pre-registered attachment to a map. +=item $bool = $object->attached ($name) + +=item $bool = $player->attached ($name) + +=item $bool = $map->attached ($name) + +Checks wether the named attachment is currently attached to the object. + =item cf::attach_global ... Attach handlers for global events. @@ -185,6 +197,11 @@ Register an attachment by name through which objects can refer to this attachment. +=item cf:register_player_attachment $name, ... + +Register an attachment by name through which players can refer to this +attachment. + =item cf:register_map_attachment $name, ... Register an attachment by name through which maps can refer to this @@ -263,6 +280,8 @@ sub _attach_attachment { my ($obj, $name, %arg) = @_; + return if exists $obj->{_attachment}{$name}; + my $res; if (my $attach = $attachment{$name}) { @@ -290,7 +309,7 @@ my ($obj, $name, %arg) = @_; _attach_attachment $obj, $name, %arg; -} +}; # all those should be optimised *cf::object::detach = @@ -299,7 +318,15 @@ my ($obj, $name) = @_; delete $obj->{_attachment}{$name}; - reattach $obj; + reattach ($obj); +}; + +*cf::object::attached = +*cf::player::attached = +*cf::map::attached = sub { + my ($obj, $name) = @_; + + exists $obj->{_attachment}{$name} }; sub attach_global { @@ -331,6 +358,12 @@ $attachment{$name} = [[KLASS_OBJECT, @_]]; } +sub register_player_attachment { + my $name = shift; + + $attachment{$name} = [[KLASS_PLAYER, @_]]; +} + sub register_map_attachment { my $name = shift; @@ -368,6 +401,46 @@ 0 } +=item $bool = cf::invoke EVENT_GLOBAL_XXX, ... + +=item $bool = $object->invoke (EVENT_OBJECT_XXX, ...) + +=item $bool = $player->invoke (EVENT_PLAYER_XXX, ...) + +=item $bool = $map->invoke (EVENT_MAP_XXX, ...) + +Generate a global/object/player/map-specific event with the given arguments. + +This API is preliminary (most likely, the EVENT_KLASS_xxx prefix will be +removed in future versions), and there is no public API to access override +results (if you must, access C<@cf::invoke_results> directly). + +=back + +=head2 methods valid for all pointers + +=over 4 + +=item $object->valid + +=item $player->valid + +=item $map->valid + +Just because you have a perl object does not mean that the corresponding +C-level object still exists. If you try to access an object that has no +valid C counterpart anymore you get an exception at runtime. This method +can be used to test for existence of the C object part without causing an +exception. + +=back + +=cut + +*cf::object::valid = +*cf::player::valid = +*cf::map::valid = \&cf::_valid; + ############################################################################# # object support