Permalink
Browse files

Several bug fixes plus the support for weighted items.

  • Loading branch information...
1 parent 7a214f1 commit 2615e7ee8bef6a3743faed104a394154bc8c1f84 @darkmavis committed Mar 25, 2012
@@ -21,4 +21,3 @@
<buildCSSFiles/>
<flashCatalyst validateFlashCatalystCompatibility="false"/>
</actionScriptProperties>
-
View
@@ -94,6 +94,7 @@
<classEntry path="org.cyclopsframework.actions.animation.CFAnimateMovieClip"/>
<classEntry path="org.cyclopsframework.actions.animation.CFPlayMovieClip"/>
<classEntry path="org.cyclopsframework.core.CFSugar"/>
+ <classEntry path="org.cyclopsframework.utils.collections.CFWeightedItems"/>
</includeClasses>
<includeResources/>
<namespaceManifests/>
Binary file not shown.
@@ -397,7 +397,7 @@ package org.cyclopsframework.core
*/
public function send(receiverTag:String, messageName:String, ...data):CFAction
{
- return _parent.addf(function():void { _engine.send(receiverTag, messageName, data); });
+ return _parent.sugar.addf(function():void { _engine.send(receiverTag, messageName, data); });
}
/**
@@ -35,6 +35,7 @@ package org.cyclopsframework.game
import org.cyclopsframework.core.CFAction;
import org.cyclopsframework.core.CFEngine;
import org.cyclopsframework.core.CFMessage;
+ import org.cyclopsframework.core.CFTaggable;
import org.cyclopsframework.core.ICFDisposable;
import org.cyclopsframework.core.ICFMessageInterceptor;
import org.cyclopsframework.core.ICFPausable;
@@ -434,7 +435,8 @@ package org.cyclopsframework.game
{
child.dispose();
}
- engine.proxy(CFEngine.TAG_ALL)["stop"]();
+
+ (engine.proxy(CFEngine.TAG_ALL, function(o:Object):Boolean { return (o.hasOwnProperty("stop")); }) as Object).stop();
if (bg.parent != null)
{
@@ -49,6 +49,16 @@ package org.cyclopsframework.utils.collections
}
return result;
}
+
+ public static function arraysToKeyValuePairs(keys:Array, values:Array):Object
+ {
+ var result:Object = {};
+ for (var i:int = 0; i < keys.length; ++i)
+ {
+ result[keys[i]] = values[i];
+ }
+ return result;
+ }
}
}
@@ -0,0 +1,41 @@
+package org.cyclopsframework.utils.collections
+{
+ public class CFWeightedItems
+ {
+ private var _items:Array;
+ private var _probabilities:Array;
+ private var _sumOfProbabilities:Number = 0;
+
+ public function get random():Object
+ {
+ var target:Number = Math.random() * _sumOfProbabilities;
+
+ for (var i:int = 0; i < _probabilities.length; ++i)
+ {
+ if (target < _probabilities[i])
+ {
+ return _items[i];
+ }
+ }
+
+ throw(new Error("This line should never be reached."));
+
+ return null;
+
+ }
+
+ public function CFWeightedItems(items:Array, indexedProbabilities:Array)
+ {
+ _items = items;
+ _probabilities = new Array(indexedProbabilities.length);
+
+ for (var i:int = 0; i < indexedProbabilities.length; ++i)
+ {
+ _sumOfProbabilities += indexedProbabilities[i];
+ _probabilities[i] = _sumOfProbabilities;
+ }
+
+ }
+
+ }
+}
@@ -197,6 +197,17 @@ package org.cyclopsframework.utils.misc
throw new TypeError(name + " can't be a tag. Perhaps another class that supports grouping by tags would work better.");
}
}
+
+ public static function anyAreNull(...params):Boolean
+ {
+ for (var i:int = 0; i < params.length; ++i)
+ {
+ if (params[i] == null) return true;
+ }
+
+ return false;
+
+ }
}
}

0 comments on commit 2615e7e

Please sign in to comment.