… | |
… | |
107 | ############################################################################# |
107 | ############################################################################# |
108 | # "new" plug-in system |
108 | # "new" plug-in system |
109 | |
109 | |
110 | =item $object->attach ($attachment, key => $value...) |
110 | =item $object->attach ($attachment, key => $value...) |
111 | |
111 | |
|
|
112 | =item $object->detach ($attachment) |
|
|
113 | |
112 | Attach a pre-registered attachment to an object. |
114 | Attach/detach a pre-registered attachment to an object. |
113 | |
115 | |
114 | =item $player->attach ($attachment, key => $value...) |
116 | =item $player->attach ($attachment, key => $value...) |
115 | |
117 | |
|
|
118 | =item $player->detach ($attachment) |
|
|
119 | |
116 | Attach a pre-registered attachment to a player. |
120 | Attach/detach a pre-registered attachment to a player. |
117 | |
121 | |
118 | =item $map->attach ($attachment, key => $value...) # not yet persistent |
122 | =item $map->attach ($attachment, key => $value...) |
119 | |
123 | |
|
|
124 | =item $map->detach ($attachment) |
|
|
125 | |
120 | Attach a pre-registered attachment to a map. |
126 | Attach/detach a pre-registered attachment to a map. |
121 | |
127 | |
122 | =item cf::attach_global ... |
128 | =item cf::attach_global ... |
123 | |
129 | |
124 | Attach handlers for global events. |
130 | Attach handlers for global events. |
125 | |
131 | |
… | |
… | |
173 | =item cf::attach_to_maps ... |
179 | =item cf::attach_to_maps ... |
174 | |
180 | |
175 | Attach handlers to all maps. |
181 | Attach handlers to all maps. |
176 | |
182 | |
177 | =item cf:register_attachment $name, ... |
183 | =item cf:register_attachment $name, ... |
|
|
184 | |
|
|
185 | Register an attachment by name through which objects can refer to this |
|
|
186 | attachment. |
|
|
187 | |
|
|
188 | =item cf:register_map_attachment $name, ... |
|
|
189 | |
|
|
190 | Register an attachment by name through which maps can refer to this |
|
|
191 | attachment. |
178 | |
192 | |
179 | =cut |
193 | =cut |
180 | |
194 | |
181 | # the following variables are defined in .xs and must not be re-created |
195 | # the following variables are defined in .xs and must not be re-created |
182 | our @CB_GLOBAL = (); # registry for all global events |
196 | our @CB_GLOBAL = (); # registry for all global events |
… | |
… | |
277 | } |
291 | } |
278 | |
292 | |
279 | sub cf::player::attach { |
293 | sub cf::player::attach { |
280 | my ($obj, $name, %arg) = @_; |
294 | my ($obj, $name, %arg) = @_; |
281 | |
295 | |
282 | _attach_attachment KLASS_PLAYER, $obj, $name, %arg; |
296 | _attach_attachment $obj, $name, %arg; |
283 | } |
297 | } |
284 | |
298 | |
285 | sub cf::map::attach { |
299 | sub cf::map::attach { |
286 | my ($obj, $name, %arg) = @_; |
300 | my ($obj, $name, %arg) = @_; |
287 | |
301 | |
288 | _attach_attachment KLASS_MAP, $obj, $name, %arg; |
302 | _attach_attachment $obj, $name, %arg; |
|
|
303 | } |
|
|
304 | |
|
|
305 | sub cf::object::detach { |
|
|
306 | my ($obj, $name) = @_; |
|
|
307 | die;#d# |
|
|
308 | } |
|
|
309 | sub cf::player::detach { |
|
|
310 | my ($obj, $name) = @_; |
|
|
311 | die;#d# |
|
|
312 | } |
|
|
313 | sub cf::map::detach { |
|
|
314 | my ($obj, $name) = @_; |
|
|
315 | die;#d# |
289 | } |
316 | } |
290 | |
317 | |
291 | sub attach_global { |
318 | sub attach_global { |
292 | _attach @CB_GLOBAL, KLASS_GLOBAL, @_ |
319 | _attach @CB_GLOBAL, KLASS_GLOBAL, @_ |
293 | } |
320 | } |
… | |
… | |
313 | |
340 | |
314 | sub register_attachment { |
341 | sub register_attachment { |
315 | my $name = shift; |
342 | my $name = shift; |
316 | |
343 | |
317 | $attachment{$name} = [[KLASS_OBJECT, @_]]; |
344 | $attachment{$name} = [[KLASS_OBJECT, @_]]; |
|
|
345 | } |
|
|
346 | |
|
|
347 | sub register_map_attachment { |
|
|
348 | my $name = shift; |
|
|
349 | |
|
|
350 | $attachment{$name} = [[KLASS_MAP, @_]]; |
318 | } |
351 | } |
319 | |
352 | |
320 | our $override; |
353 | our $override; |
321 | our @invoke_results = (); # referenced from .xs code. TODO: play tricks with reify and mortals? |
354 | our @invoke_results = (); # referenced from .xs code. TODO: play tricks with reify and mortals? |
322 | |
355 | |
… | |
… | |
385 | } |
418 | } |
386 | |
419 | |
387 | sub object_freezer_save { |
420 | sub object_freezer_save { |
388 | my ($filename, $objs) = @_; |
421 | my ($filename, $objs) = @_; |
389 | |
422 | |
390 | $filename .= ".pst"; |
|
|
391 | |
|
|
392 | if (@$objs) { |
423 | if (@$objs) { |
393 | open my $fh, ">:raw", "$filename~"; |
424 | open my $fh, ">:raw", "$filename.pst~"; |
394 | chmod $fh, SAVE_MODE; |
|
|
395 | syswrite $fh, Storable::nfreeze { version => 1, objs => $objs }; |
425 | syswrite $fh, Storable::nfreeze { version => 1, objs => $objs }; |
396 | close $fh; |
426 | close $fh; |
|
|
427 | chmod SAVE_MODE, "$filename.pst~"; |
397 | rename "$filename~", $filename; |
428 | rename "$filename.pst~", "$filename.pst"; |
398 | } else { |
429 | } else { |
399 | unlink $filename; |
430 | unlink "$filename.pst"; |
400 | } |
431 | } |
|
|
432 | |
|
|
433 | chmod SAVE_MODE, "$filename~"; |
|
|
434 | rename "$filename~", $filename; |
401 | } |
435 | } |
402 | |
436 | |
403 | sub object_thawer_load { |
437 | sub object_thawer_load { |
404 | my ($filename) = @_; |
438 | my ($filename) = @_; |
405 | |
439 | |
… | |
… | |
667 | my ($map) = @_; |
701 | my ($map) = @_; |
668 | |
702 | |
669 | my $path = $map->tmpname; |
703 | my $path = $map->tmpname; |
670 | defined $path or return; |
704 | defined $path or return; |
671 | |
705 | |
672 | unlink "$path.cfperl"; |
|
|
673 | unlink "$path.pst"; |
706 | unlink "$path.pst"; |
674 | }; |
707 | }; |
675 | |
708 | |
|
|
709 | # old style persistent data, TODO: remove #d# |
676 | *cf::mapsupport::on_swapin = |
710 | *cf::mapsupport::on_swapin = |
677 | *cf::mapsupport::on_load = sub { |
711 | *cf::mapsupport::on_load = sub { |
678 | my ($map) = @_; |
712 | my ($map) = @_; |
679 | |
713 | |
680 | my $path = $map->tmpname; |
714 | my $path = $map->tmpname; |