All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.threerings.presents.tools.streamable_as.tmpl Maven / Gradle / Ivy

The newest version!
{{header}}// GENERATED PREAMBLE START
package {{package}} {

{{#importGroups}}
{{#this}}
import {{this}};
{{/this}}

{{/importGroups}}
// GENERATED PREAMBLE END

// GENERATED CLASSDECL START
public class {{classname}} {{^extends.isEmpty}}extends {{extends}}
{{/extends.isEmpty}}
{{^implements.isEmpty}}{{^extends.isEmpty}}    {{/extends.isEmpty}}implements {{implements}}
{{/implements.isEmpty}}
{
// GENERATED CLASSDECL END

// GENERATED STREAMING START
{{#pubFields}}
    public var {{name}} :{{simpleType}};{{#hasTypeParameters}} /* of */ {{parameterTypes}};{{/hasTypeParameters}}

{{/pubFields}}
{{#dobject}}
{{#pubFields}}
    public var {{name}}Changed :Signal = new Signal({{simpleType}}, {{simpleType}});
{{#dset}}
    public var {{name}}EntryAdded :Signal = new Signal({{parameterTypes}});
    public var {{name}}EntryRemoved :Signal = new Signal({{parameterTypes}});
    public var {{name}}EntryUpdated :Signal = new Signal({{parameterTypes}}, {{parameterTypes}});
{{/dset}}
{{#array}}
    public var {{name}}ElementUpdated :Signal = new Signal(int, Object, Object);
{{/array}}
{{#oidList}}
    public var {{name}}ObjectAdded :Signal = new Signal(int);
    public var {{name}}ObjectRemoved :Signal = new Signal(int);
{{/oidList}}
{{/pubFields}}

{{#pubFields}}
    public static const {{dobjectField}} :String = "{{name}}";
{{/pubFields}}

{{/dobject}}
    {{#superclassStreamable}}override {{/superclassStreamable}}public function readObject (ins :ObjectInputStream) :void
    {
{{#superclassStreamable}}
        super.readObject(ins);
{{/superclassStreamable}}
{{#pubFields}}
        {{name}} = ins.{{reader}};
{{/pubFields}}
{{#protFields}}
        {{name}} = ins.{{reader}};
{{/protFields}}
    }
{{^dobject}}

    {{#superclassStreamable}}override {{/superclassStreamable}}public function writeObject (out :ObjectOutputStream) :void
    {
{{#superclassStreamable}}
        super.writeObject(out);
{{/superclassStreamable}}
{{#pubFields}}
        out.{{writer}};
{{/pubFields}}
{{#protFields}}
        out.{{writer}};
{{/protFields}}
    }
{{/dobject}}

{{#dobject}}
    public function {{classname}} ()
    {
        new Signaller(this);
    }
{{/dobject}}
{{#protFields}}
    protected var {{name}} :{{simpleType}};
{{/protFields}}
// GENERATED STREAMING END

// GENERATED CLASSFINISH START
}
}
// GENERATED CLASSFINISH END

{{#dobject}}
// GENERATED SIGNALLER START
import org.osflash.signals.Signal;

import com.threerings.presents.dobj.AttributeChangeListener;
import com.threerings.presents.dobj.AttributeChangedEvent;
import com.threerings.presents.dobj.ElementUpdateListener;
import com.threerings.presents.dobj.ElementUpdatedEvent;
import com.threerings.presents.dobj.EntryAddedEvent;
import com.threerings.presents.dobj.EntryRemovedEvent;
import com.threerings.presents.dobj.EntryUpdatedEvent;
import com.threerings.presents.dobj.MessageEvent;
import com.threerings.presents.dobj.MessageListener;
import com.threerings.presents.dobj.ObjectAddedEvent;
import com.threerings.presents.dobj.ObjectDeathListener;
import com.threerings.presents.dobj.ObjectDestroyedEvent;
import com.threerings.presents.dobj.ObjectRemovedEvent;
import com.threerings.presents.dobj.OidListListener;
import com.threerings.presents.dobj.SetListener;

import {{package}}.{{classname}};

class Signaller
    implements AttributeChangeListener, SetListener, ElementUpdateListener, OidListListener
{
    public function Signaller (obj :{{classname}})
    {
        _obj = obj;
        _obj.addListener(this);
    }

    public function attributeChanged (event :AttributeChangedEvent) :void
    {
        var signal :Signal;
        switch (event.getName()) {
{{#pubFields}}
            case "{{name}}":
                signal = _obj.{{name}}Changed;
                break;
{{/pubFields}}
            default:
                return;
        }
        signal.dispatch(event.getValue(), event.getOldValue());
    }

    public function entryAdded (event :EntryAddedEvent) :void
    {
        var signal :Signal;
        switch (event.getName()) {
{{#pubFields}}
{{#dset}}
            case "{{name}}":
                signal = _obj.{{name}}EntryAdded;
                break;
{{/dset}}
{{/pubFields}}
            default:
                return;
        }
        signal.dispatch(event.getEntry());
    }

    public function entryRemoved (event :EntryRemovedEvent) :void
    {
        var signal :Signal;
        switch (event.getName()) {
{{#pubFields}}
{{#dset}}
            case "{{name}}":
                signal = _obj.{{name}}EntryRemoved;
                break;
{{/dset}}
{{/pubFields}}
            default:
                return;
        }
        signal.dispatch(event.getOldEntry());
    }

    public function entryUpdated (event :EntryUpdatedEvent) :void
    {
        var signal :Signal;
        switch (event.getName()) {
{{#pubFields}}
{{#dset}}
            case "{{name}}":
                signal = _obj.{{name}}EntryUpdated;
                break;
{{/dset}}
{{/pubFields}}
            default:
                return;
        }
        signal.dispatch(event.getEntry(), event.getOldEntry());
    }

    public function elementUpdated (event :ElementUpdatedEvent) :void
    {
        var signal :Signal;
        switch (event.getName()) {
{{#pubFields}}
{{#array}}
            case "{{name}}":
                signal = _obj.{{name}}ElementUpdated;
                break;
{{/array}}
{{/pubFields}}
            default:
                return;
        }
        signal.dispatch(event.getIndex(), event.getValue(), event.getOldValue());
    }

    public function objectAdded (event :ObjectAddedEvent) :void
    {
        var signal :Signal;
        switch (event.getName()) {
{{#pubFields}}
{{#oidList}}
            case "{{name}}":
                signal = _obj.{{name}}ObjectAdded;
                break;
{{/oidList}}
{{/pubFields}}
            default:
                return;
        }
        signal.dispatch(event.getOid());
    }

    public function objectRemoved (event :ObjectRemovedEvent) :void
    {
        var signal :Signal;
        switch (event.getName()) {
{{#pubFields}}
{{#oidList}}
            case "{{name}}":
                signal = _obj.{{name}}ObjectRemoved;
                break;
{{/oidList}}
{{/pubFields}}
            default:
                return;
        }
        signal.dispatch(event.getOid());
    }

    protected var _obj :{{classname}};
}
// GENERATED SIGNALLER END
{{/dobject}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy