In an effort to make DObject updates easier to react to in actionscript, gendobj now generates
signals for each field that can be listened to individually.
From the old:
barrel.addListener(new AttributeChangeAdapter(function (event :AttributeChangedEvent) :void {
if (event.getName() == BarrelObject.MONKEY_COUNT) {
// ... cast event.getValue() and use it
}
}));
to the new:
barrel.onMonkeyCountChanged.add(function (newValue :int, oldValue :int) :void {
// ...
});
Only AttributeChangedEvent have been signalified, but I'm planning to continue with the other
ChangeListeners shortly.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6328 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
+10
@@ -17,6 +17,10 @@
|
|||||||
<id>as3corelib-repo</id>
|
<id>as3corelib-repo</id>
|
||||||
<url>https://github.com/samskivert/as3corelib/raw/master/repository</url>
|
<url>https://github.com/samskivert/as3corelib/raw/master/repository</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>as3-signals-repo</id>
|
||||||
|
<url>https://github.com/groves/as3-signals/raw/master/repository</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -34,5 +38,11 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
<type>swc</type>
|
<type>swc</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.osflash</groupId>
|
||||||
|
<artifactId>signals</artifactId>
|
||||||
|
<version>0.8</version>
|
||||||
|
<type>swc</type>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -82,6 +82,11 @@ public class GenActionScriptStreamableTask extends GenTask
|
|||||||
ActionScriptUtils.addImportAndGetShortType(sclass.getSuperclass(), false, imports);
|
ActionScriptUtils.addImportAndGetShortType(sclass.getSuperclass(), false, imports);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isDObject = DObject.class.isAssignableFrom(sclass);
|
||||||
|
if (isDObject) {
|
||||||
|
imports.add("org.osflash.signals.Signal");
|
||||||
|
}
|
||||||
|
|
||||||
Set<String> implemented = Sets.newLinkedHashSet();
|
Set<String> implemented = Sets.newLinkedHashSet();
|
||||||
for (Class<?> iface : sclass.getInterfaces()) {
|
for (Class<?> iface : sclass.getInterfaces()) {
|
||||||
implemented.add(ActionScriptUtils.addImportAndGetShortType(iface, false, imports));
|
implemented.add(ActionScriptUtils.addImportAndGetShortType(iface, false, imports));
|
||||||
@@ -99,7 +104,7 @@ public class GenActionScriptStreamableTask extends GenTask
|
|||||||
"implements", Joiner.on(", ").join(implemented),
|
"implements", Joiner.on(", ").join(implemented),
|
||||||
"superclassStreamable", reqs.superclassStreamable,
|
"superclassStreamable", reqs.superclassStreamable,
|
||||||
"fields", fields,
|
"fields", fields,
|
||||||
"dobject", DObject.class.isAssignableFrom(sclass));
|
"dobject", isDObject);
|
||||||
|
|
||||||
File outputLocation = ActionScriptUtils.createActionScriptPath(_asroot, sclass);
|
File outputLocation = ActionScriptUtils.createActionScriptPath(_asroot, sclass);
|
||||||
if (outputLocation.exists()) {
|
if (outputLocation.exists()) {
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ public class {{classname}} {{^extends.isEmpty}}extends {{extends}}
|
|||||||
|
|
||||||
{{/fields}}
|
{{/fields}}
|
||||||
{{#dobject}}
|
{{#dobject}}
|
||||||
|
{{#fields}}
|
||||||
|
public var {{name}}Changed :Signal = new Signal({{simpleType}}, {{simpleType}});
|
||||||
|
{{/fields}}
|
||||||
|
|
||||||
{{#fields}}
|
{{#fields}}
|
||||||
public static const {{dobjectField}} :String = "{{name}}";
|
public static const {{dobjectField}} :String = "{{name}}";
|
||||||
|
|
||||||
@@ -47,7 +51,52 @@ public class {{classname}} {{^extends.isEmpty}}extends {{extends}}
|
|||||||
{{/fields}}
|
{{/fields}}
|
||||||
}
|
}
|
||||||
{{/dobject}}
|
{{/dobject}}
|
||||||
|
|
||||||
|
{{#dobject}}
|
||||||
|
public function {{classname}} ()
|
||||||
|
{
|
||||||
|
new Signaller(this);
|
||||||
|
}
|
||||||
|
{{/dobject}}
|
||||||
// GENERATED STREAMING END
|
// GENERATED STREAMING END
|
||||||
|
|
||||||
|
// GENERATED CLASSFINISH START
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// GENERATED CLASSFINISH END
|
||||||
|
|
||||||
|
{{#dobject}}
|
||||||
|
// GENERATED SIGNALLER START
|
||||||
|
import org.osflash.signals.Signal;
|
||||||
|
|
||||||
|
import com.threerings.presents.dobj.AttributeChangedEvent;
|
||||||
|
import com.threerings.presents.dobj.AttributeChangeListener;
|
||||||
|
|
||||||
|
import {{package}}.{{classname}};
|
||||||
|
|
||||||
|
class Signaller
|
||||||
|
implements AttributeChangeListener
|
||||||
|
{
|
||||||
|
public function Signaller (obj :{{classname}})
|
||||||
|
{
|
||||||
|
_obj = obj;
|
||||||
|
_obj.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attributeChanged (event :AttributeChangedEvent) :void
|
||||||
|
{
|
||||||
|
var signal :Signal;
|
||||||
|
switch (event.getName()) {
|
||||||
|
{{#fields}}
|
||||||
|
case "{{name}}":
|
||||||
|
signal = _obj.{{name}}Changed;
|
||||||
|
break;
|
||||||
|
{{/fields}}
|
||||||
|
}
|
||||||
|
signal.dispatch(event.getValue(), event.getOldValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected var _obj :{{classname}};
|
||||||
|
}
|
||||||
|
// GENERATED SIGNALLER END
|
||||||
|
{{/dobject}}
|
||||||
|
|||||||
Reference in New Issue
Block a user