diff --git a/src/Gamedisc.as b/src/Gamedisc.as new file mode 100644 index 0000000..3e29c4d --- /dev/null +++ b/src/Gamedisc.as @@ -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; + } + } + +} \ No newline at end of file diff --git a/src/Qte.as b/src/Qte.as new file mode 100644 index 0000000..50377fb --- /dev/null +++ b/src/Qte.as @@ -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; + } + } + +} \ No newline at end of file diff --git a/src/Util.as b/src/Util.as new file mode 100644 index 0000000..14fb105 --- /dev/null +++ b/src/Util.as @@ -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; + } + } + +} \ No newline at end of file