Skip to content

Commit

Permalink
DefaultTweenBuilder supports fromDelta param
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhengh committed Apr 13, 2016
1 parent f837a49 commit 8267da5
Showing 1 changed file with 64 additions and 24 deletions.
88 changes: 64 additions & 24 deletions src/starlingbuilder/engine/tween/DefaultTweenBuilder.as
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,9 @@ package starlingbuilder.engine.tween
return;
}

if (!data.hasOwnProperty("properties"))
{
trace("Missing tween param: properties");
return;
}

var initData:Object = saveInitData(obj, data.properties, data.delta);

setFrom(obj, data.from);
var initData:Object = saveInitData(obj, data.properties, data.delta, data.from, data.fromDelta);

var properties:Object = UIBuilder.cloneObject(data.properties);

setDelta(obj, data.delta, properties);
var properties:Object = createProperties(obj, data, initData);

var tween:Object = Starling.current.juggler.tween(obj, data.time, properties);

Expand Down Expand Up @@ -169,23 +159,57 @@ package starlingbuilder.engine.tween
delete _saveData[obj];
}

private function setFrom(obj:Object, from:Object):void
private function createProperties(obj:Object, data:Object, initData:Object):Object
{
for (var name:String in from)
var fromData:Object = {};
var name:String;

//set from
if (data.hasOwnProperty("from"))
{
if (obj.hasOwnProperty(name))
{
obj[name] = from[name];
}
var from:Object = data.from;
for (name in from)
if (obj.hasOwnProperty(name))
{
obj[name] = from[name];
fromData[name] = initData[name];
}
}
}

private function setDelta(obj:Object, delta:Object, properties:Object):void
{
for (var id:String in delta)
//set fromDelta
if (data.hasOwnProperty("fromDelta"))
{
var fromDelta:Object = data.fromDelta;
for (name in fromDelta)
if (obj.hasOwnProperty(name))
{
obj[name] += fromDelta[name];
fromData[name] = initData[name];
}
}

//clone properties
var properties:Object;
if (data.hasOwnProperty("properties"))
properties = UIBuilder.cloneObject(data.properties);
else
properties = {};

//set delta
if (data.hasOwnProperty("delta"))
{
properties[id] = obj[id] + delta[id];
var delta:Object = data.delta;
for (name in delta)
if (obj.hasOwnProperty(name))
properties[name] = obj[name] + delta[name];
}

//set init data for from and fromDelta (if not exist)
for (name in fromData)
if (!properties.hasOwnProperty(name))
properties[name] = fromData[name];

return properties;
}

private function recoverInitData(obj:Object, initData:Object):void
Expand All @@ -196,7 +220,7 @@ package starlingbuilder.engine.tween
}
}

private function saveInitData(obj:Object, properties:Object, delta:Object):Object
private function saveInitData(obj:Object, properties:Object, delta:Object, from:Object, fromDelta:Object):Object
{
var data:Object = {};
var name:String;
Expand All @@ -217,6 +241,22 @@ package starlingbuilder.engine.tween
}
}

for (name in from)
{
if (obj.hasOwnProperty(name))
{
data[name] = obj[name];
}
}

for (name in fromDelta)
{
if (obj.hasOwnProperty(name))
{
data[name] = obj[name];
}
}

return data;
}

Expand Down

0 comments on commit 8267da5

Please sign in to comment.