home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 164 / MOBICLIC164.ISO / mac / MOBICLIC.app / Contents / Resources / movie.swf / scripts / com / milanpresse / capsule / GameEngineCapsule.as < prev    next >
Text File  |  2014-05-13  |  5KB  |  163 lines

  1. package com.milanpresse.capsule
  2. {
  3.    import com.milanpresse.engine.Context;
  4.    import com.milanpresse.engine.Engine;
  5.    import com.milanpresse.engine.HostContainer;
  6.    import com.milanpresse.engine.config.Config;
  7.    import com.milanpresse.engine.typeargument.ModuleCallerParameter;
  8.    import flash.display.Sprite;
  9.    import flash.system.Security;
  10.    
  11.    public class GameEngineCapsule extends Sprite implements ICapsule
  12.    {
  13.        
  14.       
  15.       private var _engine;
  16.       
  17.       protected var _host;
  18.       
  19.       public var isHost:Boolean = false;
  20.       
  21.       protected var _callback:Function = null;
  22.       
  23.       private var _config:ICapsuleConfig = null;
  24.       
  25.       private var _inHost:Boolean;
  26.       
  27.       private var _initParams:Object = null;
  28.       
  29.       private var _engineLib:LoadLib;
  30.       
  31.       private var _contextInitParams:Object = null;
  32.       
  33.       public function GameEngineCapsule()
  34.       {
  35.          super();
  36.          Security.allowDomain("*");
  37.          if(parent != null)
  38.          {
  39.             this._inHost = false;
  40.             this.init();
  41.          }
  42.          else
  43.          {
  44.             this._inHost = true;
  45.          }
  46.       }
  47.       
  48.       public function get config() : ICapsuleConfig
  49.       {
  50.          return this._config as Config;
  51.       }
  52.       
  53.       public function set config(param1:ICapsuleConfig) : void
  54.       {
  55.          this._config = param1;
  56.       }
  57.       
  58.       public function get host() : *
  59.       {
  60.          return this._host as HostContainer;
  61.       }
  62.       
  63.       public function get engine() : *
  64.       {
  65.          return this._engine as Engine;
  66.       }
  67.       
  68.       public function init(param1:Object = null) : void
  69.       {
  70.          trace(this,"init",param1);
  71.          this._initParams = param1 == null ? {} : param1;
  72.          this._contextInitParams = this._initParams.initParams == undefined ? {} : this._initParams.initParams;
  73.          this.loadEngine(this.engineLoaded);
  74.       }
  75.       
  76.       private function loadEngine(param1:Function) : void
  77.       {
  78.          var _loc2_:* = null;
  79.          if(this._inHost == false && this.isHost == false)
  80.          {
  81.             _loc2_ = "../../HOTE/gameEngine_as3/bin/GameEngine/library.swf";
  82.          }
  83.          else if(this._inHost == false && this.isHost == true)
  84.          {
  85.             _loc2_ = "DATA/HOTE/gameEngine_as3/bin/GameEngine/library.swf";
  86.          }
  87.          else
  88.          {
  89.             _loc2_ = this.getDirectoryPathOfFile(this._initParams.context.path) + "/DATA/HOTE/gameEngine_as3/bin/GameEngine/library.swf";
  90.          }
  91.          this._engineLib = new LoadLib("com.milanpresse.engine.Engine",_loc2_,this.engineLoaded,{"app":this});
  92.       }
  93.       
  94.       private function engineLoaded() : void
  95.       {
  96.          if(this._inHost == false)
  97.          {
  98.             this.initAsHost();
  99.          }
  100.          else
  101.          {
  102.             this.initAsChild();
  103.          }
  104.       }
  105.       
  106.       private function initAsHost() : void
  107.       {
  108.          var _loc1_:Context = new Context();
  109.          _loc1_.urlParameters = this.loaderInfo.parameters;
  110.          _loc1_.hostContext = _loc1_;
  111.          _loc1_.path = this.loaderInfo.url;
  112.          _loc1_.data = this;
  113.          this._contextInitParams.callerParameters = new ModuleCallerParameter();
  114.          _loc1_.initParams = this._contextInitParams;
  115.          this._host = new HostContainer(this);
  116.          this._engine = new Engine(this.start,_loc1_) as Engine;
  117.       }
  118.       
  119.       private function initAsChild(param1:* = null) : void
  120.       {
  121.          this._callback = this._initParams.callback;
  122.          var _loc2_:Context = this._initParams.context;
  123.          this._host = new HostContainer(_loc2_.data);
  124.          var _loc3_:Context = new Context();
  125.          _loc3_.hostContext = _loc2_;
  126.          _loc3_.path = this.loaderInfo.url;
  127.          _loc3_.data = this;
  128.          _loc3_.initParams = this._contextInitParams;
  129.          this._engine = new Engine(this.initEnd,_loc3_);
  130.       }
  131.       
  132.       private function initEnd(param1:* = null) : void
  133.       {
  134.          this._callback();
  135.       }
  136.       
  137.       private function getDirectoryPathOfFile(param1:String) : String
  138.       {
  139.          var _loc2_:Array = unescape(param1).replace(/\\/g,"/").split("/");
  140.          _loc2_.pop();
  141.          return _loc2_.join("/");
  142.       }
  143.       
  144.       public function start(param1:Object = null) : void
  145.       {
  146.       }
  147.       
  148.       public function destroy() : void
  149.       {
  150.          this._engine.destroy();
  151.          this._engineLib.destroy();
  152.       }
  153.       
  154.       public function sleep() : void
  155.       {
  156.       }
  157.       
  158.       public function wake() : void
  159.       {
  160.       }
  161.    }
  162. }
  163.