game object
This commit is contained in:
parent
9110fc006a
commit
bd6602a061
41
src/Gamedisc.as
Normal file
41
src/Gamedisc.as
Normal file
|
@ -0,0 +1,41 @@
|
|||
package
|
||||
{
|
||||
import flash.events.EventDispatcher;
|
||||
/**
|
||||
* ...
|
||||
* @author jjp
|
||||
*/
|
||||
public class Gamedisc
|
||||
{
|
||||
public var urlVideo:String;
|
||||
public var rgqte:Array;
|
||||
public function Gamedisc(urlVideo:String)
|
||||
{
|
||||
this.urlVideo = urlVideo;
|
||||
this.rgqte = [];
|
||||
}
|
||||
public function AddQte(qte:Qte):void
|
||||
{
|
||||
rgqte.splice(Math.abs(Util.binarySearch(rgqte, qte, Qte.compare)), 0, qte);
|
||||
}
|
||||
public function ToJson():Object
|
||||
{
|
||||
var jsonRgqte:Array = [];
|
||||
for each (var qte:Qte in rgqte)
|
||||
jsonRgqte.push(qte.ToJson());
|
||||
return { urlVideo: urlVideo, rgqte: jsonRgqte };
|
||||
}
|
||||
public function FromJson(json:Object):void
|
||||
{
|
||||
rgqte = [];
|
||||
for each (var jsonQte:Object in json.rgqte)
|
||||
{
|
||||
var qte:Qte = new Qte();
|
||||
qte.FromJson(jsonQte);
|
||||
rgqte.push(qte);
|
||||
}
|
||||
urlVideo = json.urlVideo;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
42
src/Qte.as
Normal file
42
src/Qte.as
Normal file
|
@ -0,0 +1,42 @@
|
|||
package
|
||||
{
|
||||
import flash.geom.Point;
|
||||
/**
|
||||
* ...
|
||||
* @author jjp
|
||||
*/
|
||||
public class Qte
|
||||
{
|
||||
public var rgpoint:Array;
|
||||
public var secTrigger:Number;
|
||||
|
||||
public function Qte(rgpoint: Array = null, secTrigger:Number = -1)
|
||||
{
|
||||
this.rgpoint = rgpoint;
|
||||
this.secTrigger = secTrigger;
|
||||
}
|
||||
public static function compare(qte1:Qte, qte2:Qte):int
|
||||
{
|
||||
if (qte1.secTrigger == qte2.secTrigger)
|
||||
return 0;
|
||||
else if (qte1.secTrigger < qte2.secTrigger)
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
public function ToJson():Object
|
||||
{
|
||||
var jsonRgpoint:Array = [];
|
||||
for each(var point:Point in rgpoint)
|
||||
jsonRgpoint.push([point.x, point.y]);
|
||||
return { rgpoint: jsonRgpoint, secTrigger: secTrigger };
|
||||
}
|
||||
public function FromJson(json:Object):void
|
||||
{
|
||||
rgpoint = []
|
||||
for each(var jsonPoint:Array in json.rgpoint)
|
||||
rgpoint.push(new Point(jsonPoint[0], jsonPoint[1]));
|
||||
secTrigger = json.secTrigger;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
28
src/Util.as
Normal file
28
src/Util.as
Normal file
|
@ -0,0 +1,28 @@
|
|||
package
|
||||
{
|
||||
/**
|
||||
* ...
|
||||
* @author jjp
|
||||
*/
|
||||
public class Util
|
||||
{
|
||||
public static function binarySearch(rgo:Array, o:*, dgCompare:Function):int
|
||||
{
|
||||
var imin:int = 0;
|
||||
var imax:int = rgo.length - 1;
|
||||
while (imax >= imin)
|
||||
{
|
||||
var imid:int = Math.floor((imax + imin) / 2);
|
||||
var kcompare:int = dgCompare(rgo[imid], o);
|
||||
if (kcompare == 0)
|
||||
return imid;
|
||||
else if (kcompare < 0)
|
||||
imin = imid + 1;
|
||||
else
|
||||
imax = imid - 1;
|
||||
}
|
||||
return -imin;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue