ObjectDeathAdapter.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6694 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2011 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://code.google.com/p/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.dobj {
|
||||
|
||||
/**
|
||||
* An object death listener that delegates to a callback function.
|
||||
*/
|
||||
public class ObjectDeathAdapter
|
||||
implements ObjectDeathListener
|
||||
{
|
||||
/**
|
||||
* Create a new adapter that delegates to the given callback function. The function should
|
||||
* match the signature of the ObjectDeathListener's objectDestroyed method:
|
||||
* <listing version="3.0">
|
||||
* function objectDestroyed (event :ObjectDestroyedEvent) :void;
|
||||
* </listing>
|
||||
*/
|
||||
public function ObjectDeathAdapter (callback :Function)
|
||||
{
|
||||
_callback = callback;
|
||||
}
|
||||
|
||||
public function objectDestroyed (event :ObjectDestroyedEvent) :void
|
||||
{
|
||||
_callback(event);
|
||||
}
|
||||
|
||||
protected var _callback :Function;
|
||||
}
|
||||
}
|
||||
@@ -22,13 +22,14 @@
|
||||
package com.threerings.presents.util {
|
||||
|
||||
import flash.utils.Dictionary;
|
||||
|
||||
import com.threerings.util.Log;
|
||||
|
||||
import com.threerings.presents.dobj.DObject;
|
||||
import com.threerings.presents.dobj.DObjectManager;
|
||||
import com.threerings.presents.dobj.ObjectAccessError;
|
||||
import com.threerings.presents.dobj.ObjectDeathListener;
|
||||
import com.threerings.presents.dobj.ObjectDeathAdapter;
|
||||
import com.threerings.presents.dobj.ObjectDestroyedEvent;
|
||||
import com.threerings.presents.dobj.SubscriberAdapter;
|
||||
import com.threerings.util.Log;
|
||||
|
||||
/**
|
||||
* Safely manages subscriptions and provides access to objects.
|
||||
@@ -208,14 +209,12 @@ public class SafeObjectManager
|
||||
protected var _log :Log;
|
||||
protected var _available :Function;
|
||||
protected var _failed :Function;
|
||||
protected var _odlist :ObjectDeathListenerAdapter = new ObjectDeathListenerAdapter(destroyed);
|
||||
protected var _odlist :ObjectDeathAdapter = new ObjectDeathAdapter(destroyed);
|
||||
protected var _entries :Dictionary = new Dictionary();
|
||||
}
|
||||
}
|
||||
|
||||
import com.threerings.presents.dobj.DObject;
|
||||
import com.threerings.presents.dobj.ObjectDeathListener;
|
||||
import com.threerings.presents.dobj.ObjectDestroyedEvent;
|
||||
import com.threerings.presents.util.SafeSubscriber;
|
||||
|
||||
class Entry
|
||||
@@ -232,19 +231,3 @@ class Entry
|
||||
sub = subscriber;
|
||||
}
|
||||
}
|
||||
|
||||
class ObjectDeathListenerAdapter
|
||||
implements ObjectDeathListener
|
||||
{
|
||||
public var callback :Function;
|
||||
|
||||
public function ObjectDeathListenerAdapter (callback :Function)
|
||||
{
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public function objectDestroyed (event :ObjectDestroyedEvent) :void
|
||||
{
|
||||
callback(event);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user