dango_generator 0.4.3 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
data/dango_generator.rb CHANGED
@@ -7,6 +7,100 @@ class DangoGenerator < Rails::Generator::NamedBase
7
7
  # super
8
8
  # end
9
9
 
10
+ # 初期化の共通で使う部分
11
+ def common_init(m)
12
+ # 起動スクリプト
13
+ m.file "script/dango_server" , "script/dango_server", :collision => :force
14
+
15
+ # crossdomain.xml
16
+ m.file "public/crossdomain.xml" , "public/crossdomain.xml", :collision => :force
17
+
18
+ # vendorプラグイン
19
+ m.directory 'vendor/plugins/dango/lib'
20
+ m.file "lib/dango_monitor_client.rb" , "vendor/plugins/dango/lib/dango_monitor_client.rb", :collision => :force
21
+ m.file "lib/dango_controller_plugin.rb" , "vendor/plugins/dango/lib/dango_controller_plugin.rb", :collision => :force
22
+ m.directory 'vendor/plugins/dango/tasks'
23
+ m.file "tasks/dango.rake" , "vendor/plugins/dango/tasks/dango.rake", :collision => :force
24
+
25
+ # dangoフォルダ内
26
+ m.directory 'dango/server'
27
+ m.file "dango/server/99_dango_server.rb" , "dango/server/99_dango_server.rb", :collision => :skip
28
+
29
+ # dangoのclient_swf
30
+ m.directory 'dango/client_swf'
31
+ m.directory 'dango/client_swf/src'
32
+ m.file "dango/client_swf/src/DangoConfig.as" , "dango/client_swf/src/DangoConfig.as", :collision => :skip
33
+
34
+ # dangoコンフィグ
35
+ m.directory 'config/dango'
36
+ %w(
37
+ development.yml
38
+ test.yml
39
+ production.yml
40
+ system_message.yml
41
+ ).each do |as3_file|
42
+ m.file "config/dango/#{as3_file}", "config/dango/#{as3_file}", :collision => :skip
43
+ end
44
+
45
+ # dangoのas3ライブラリ
46
+ m.directory 'dango/client_swf/src/org/rubyforge/dango'
47
+ %w(
48
+ DangoAS3Mode.as
49
+ DangoAS3ModeReceiveEvent.as
50
+ DangoClientFramework.as
51
+ DangoError.as
52
+ DangoErrorCode.as
53
+ DangoErrorEvent.as
54
+ DangoReceiveEvent.as
55
+ DangoURLLoader.as
56
+ DangoURLLoaderEvent.as
57
+ DangoUtil.as
58
+ ).each do |as3_file|
59
+ m.file "as3/org/rubyforge/dango/#{as3_file}", "dango/client_swf/src/org/rubyforge/dango/#{as3_file}", :collision => :force
60
+ end
61
+
62
+ # http://code.google.com/p/as3corelib/のインポート
63
+ # as3corelib-readme.txt
64
+ # as3corelib-license.txt
65
+ %w(
66
+ com/adobe/crypto/MD5.as
67
+ com/adobe/crypto/SHA1.as
68
+ com/adobe/crypto/SHA224.as
69
+ com/adobe/crypto/SHA256.as
70
+ com/adobe/crypto/WSSEUsernameToken.as
71
+ com/adobe/errors/IllegalStateError.as
72
+ com/adobe/images/BitString.as
73
+ com/adobe/images/JPGEncoder.as
74
+ com/adobe/images/PNGEncoder.as
75
+ com/adobe/net/DynamicURLLoader.as
76
+ com/adobe/net/IURIResolver.as
77
+ com/adobe/net/URI.as
78
+ com/adobe/net/URIEncodingBitmap.as
79
+ com/adobe/net/proxies/RFC2817Socket.as
80
+ com/adobe/serialization/json/JSON.as
81
+ com/adobe/serialization/json/JSONDecoder.as
82
+ com/adobe/serialization/json/JSONEncoder.as
83
+ com/adobe/serialization/json/JSONParseError.as
84
+ com/adobe/serialization/json/JSONToken.as
85
+ com/adobe/serialization/json/JSONTokenizer.as
86
+ com/adobe/serialization/json/JSONTokenType.as
87
+ com/adobe/utils/ArrayUtil.as
88
+ com/adobe/utils/DateUtil.as
89
+ com/adobe/utils/DictionaryUtil.as
90
+ com/adobe/utils/IntUtil.as
91
+ com/adobe/utils/NumberFormatter.as
92
+ com/adobe/utils/StringUtil.as
93
+ com/adobe/utils/XMLUtil.as
94
+ com/adobe/webapis/ServiceBase.as
95
+ com/adobe/webapis/URLLoaderBase.as
96
+ com/adobe/webapis/events/ServiceEvent.as
97
+ ).each do |as3corelib_file|
98
+ m.directory File.dirname("dango/client_swf/src/#{as3corelib_file}")
99
+ m.file "as3/#{as3corelib_file}", "dango/client_swf/src/#{as3corelib_file}", :collision => :force
100
+ end
101
+ end
102
+
103
+
10
104
  def manifest
11
105
  record do |m|
12
106
 
@@ -16,97 +110,47 @@ class DangoGenerator < Rails::Generator::NamedBase
16
110
  # p class_name
17
111
 
18
112
  # dangoの初期設定
19
- # if class_name == "init"
20
-
21
- # 起動スクリプト
22
- m.template "script/dango_server" , "script/dango_server"
23
-
24
- # crossdomain.xml
25
- m.template "public/crossdomain.xml" , "public/crossdomain.xml"
26
-
27
- # vendorプラグイン
28
- m.directory 'vendor/plugins/dango/lib'
29
- m.template "lib/dango_monitor_client.rb" , "vendor/plugins/dango/lib/dango_monitor_client.rb"
30
- m.template "lib/dango_controller_plugin.rb" , "vendor/plugins/dango/lib/dango_controller_plugin.rb"
31
- m.directory 'vendor/plugins/dango/tasks'
32
- m.template "tasks/dango.rake" , "vendor/plugins/dango/tasks/dango.rake"
33
-
34
- # dangoフォルダ内
35
- m.directory 'dango/server'
36
- m.template "dango/server/99_dango_server.rb" , "dango/server/99_dango_server.rb"
37
-
38
- # dangoのclient_swf
39
- m.directory 'dango/client_swf'
40
- m.directory 'dango/client_swf/src'
41
- m.template "dango/client_swf/src/DangoConfig.as" , "dango/client_swf/src/DangoConfig.as"
113
+ common_init(m)
114
+
115
+
116
+ if name == "init_as3mode" # init_as3mode
117
+ m.file "sample_as3mode/dango/server/99_dango_server.rb" ,
118
+ "dango/server/99_dango_server.rb", :collision => :force
42
119
 
43
- # dangoコンフィグ
44
- m.directory 'config/dango'
120
+ m.directory "dango/client_swf/bin-debug"
45
121
  %w(
46
- development.yml
47
- test.yml
48
- production.yml
49
- system_message.yml
50
- ).each do |as3_file|
51
- m.template "config/dango/#{as3_file}", "config/dango/#{as3_file}"
122
+ sample_as3mode.swf
123
+ sample_as3mode.html
124
+ AC_OETags.js
125
+ playerProductInstall.swf
126
+ ).each do |file|
127
+ m.file "sample_as3mode/dango/client_swf/bin-debug/#{file}",
128
+ "dango/client_swf/bin-debug/#{file}", :collision => :force
52
129
  end
53
130
 
54
- # dangoのas3ライブラリ
55
- m.directory 'dango/client_swf/src/org/rubyforge/dango'
56
- %w(
57
- DangoClientFramework.as
58
- DangoError.as
59
- DangoErrorCode.as
60
- DangoErrorEvent.as
61
- DangoReceiveEvent.as
62
- DangoURLLoader.as
63
- DangoURLLoaderEvent.as
64
- DangoUtil.as
65
- ).each do |as3_file|
66
- m.template "as3/org/rubyforge/dango/#{as3_file}", "dango/client_swf/src/org/rubyforge/dango/#{as3_file}"
67
- end
131
+ m.file "sample_as3mode/dango/client_swf/src/sample_asmode.mxml" ,
132
+ "dango/client_swf/src/sample_as3mode.mxml", :collision => :force
68
133
 
69
- # http://code.google.com/p/as3corelib/のインポート
70
- # as3corelib-readme.txt
71
- # as3corelib-license.txt
134
+ elsif name == "sample_servermode_chat"
135
+ m.directory "dango/client_swf/bin-debug"
72
136
  %w(
73
- com/adobe/crypto/MD5.as
74
- com/adobe/crypto/SHA1.as
75
- com/adobe/crypto/SHA224.as
76
- com/adobe/crypto/SHA256.as
77
- com/adobe/crypto/WSSEUsernameToken.as
78
- com/adobe/errors/IllegalStateError.as
79
- com/adobe/images/BitString.as
80
- com/adobe/images/JPGEncoder.as
81
- com/adobe/images/PNGEncoder.as
82
- com/adobe/net/DynamicURLLoader.as
83
- com/adobe/net/IURIResolver.as
84
- com/adobe/net/URI.as
85
- com/adobe/net/URIEncodingBitmap.as
86
- com/adobe/net/proxies/RFC2817Socket.as
87
- com/adobe/serialization/json/JSON.as
88
- com/adobe/serialization/json/JSONDecoder.as
89
- com/adobe/serialization/json/JSONEncoder.as
90
- com/adobe/serialization/json/JSONParseError.as
91
- com/adobe/serialization/json/JSONToken.as
92
- com/adobe/serialization/json/JSONTokenizer.as
93
- com/adobe/serialization/json/JSONTokenType.as
94
- com/adobe/utils/ArrayUtil.as
95
- com/adobe/utils/DateUtil.as
96
- com/adobe/utils/DictionaryUtil.as
97
- com/adobe/utils/IntUtil.as
98
- com/adobe/utils/NumberFormatter.as
99
- com/adobe/utils/StringUtil.as
100
- com/adobe/utils/XMLUtil.as
101
- com/adobe/webapis/ServiceBase.as
102
- com/adobe/webapis/URLLoaderBase.as
103
- com/adobe/webapis/events/ServiceEvent.as
104
- ).each do |as3corelib_file|
105
- m.directory File.dirname("dango/client_swf/src/#{as3corelib_file}")
106
- m.template "as3/#{as3corelib_file}", "dango/client_swf/src/#{as3corelib_file}"
137
+ sample_servermode_chat.swf
138
+ sample_servermode_chat.html
139
+ AC_OETags.js
140
+ playerProductInstall.swf
141
+ ).each do |file|
142
+ m.file "sample_servermode_chat/dango/client_swf/bin-debug/#{file}",
143
+ "dango/client_swf/bin-debug/#{file}", :collision => :force
107
144
  end
108
145
 
109
- # end
146
+ m.file "sample_servermode_chat/dango/client_swf/src/sample_servermode_chat.mxml" ,
147
+ "dango/client_swf/src/sample_servermode_chat.mxml", :collision => :force
148
+
149
+ m.file "sample_servermode_chat/dango/server/99_dango_server.rb" ,
150
+ "dango/server/99_dango_server.rb", :collision => :force
151
+
152
+ end
153
+
110
154
  end
111
155
 
112
156
  # puts "completed to dango_generator"
@@ -0,0 +1,163 @@
1
+ 
2
+ package org.rubyforge.dango {
3
+ /**
4
+ * DangoのAS3Mode用のクラス
5
+ *
6
+ */
7
+
8
+ import org.rubyforge.dango.*;
9
+ import flash.events.*;
10
+
11
+ public class DangoAS3Mode implements IEventDispatcher {
12
+
13
+ private var dispatcher:EventDispatcher; // Event送出用
14
+
15
+ private var dango_client:DangoClientFramework;
16
+ public var all_sid_list:Array = []; //接続しているクライアントのsidの一覧
17
+
18
+ /**
19
+ * DangoAS3Mode
20
+ * コンストラクタ
21
+ *
22
+ * @param config:*
23
+ * @return void
24
+ */
25
+ public function DangoAS3Mode(config:*):void{
26
+ // Event送出用
27
+ dispatcher = new EventDispatcher(this);
28
+
29
+ // DangoClientFrameworkコネクション
30
+ try{
31
+ dango_client = new DangoClientFramework(config);
32
+ } catch(error:Error) {
33
+ trace(error.message);
34
+ }
35
+
36
+ // エラー時のイベントリスナー
37
+ dango_client.addEventListener("DangoError", connection_error);
38
+
39
+ // イベント
40
+ dango_client.addEventListener("dango__connect" , dango__connect);
41
+ dango_client.addEventListener("dango_notice_send_object" , dango_notice_send_object);
42
+ dango_client.addEventListener("dango_notice_current_sids", dango_notice_current_sids);
43
+ }
44
+
45
+ // 接続エラー
46
+ private function connection_error(evt:DangoErrorEvent):void {
47
+ this.dispatchEvent(new DangoErrorEvent("DangoError", evt.code, evt.message));
48
+ }
49
+
50
+ /**
51
+ * send_object
52
+ * クライアント同士のデータ送信
53
+ *
54
+ * @param object:Objcet
55
+ * @param sids:Array
56
+ * @return void
57
+ */
58
+ public function send_object(object:Object, sids:Array):void {
59
+ dango_client.send_action("send_object", {"object":object, "sids":sids}, true);
60
+ // dango_client.send_action("send_object", object, true);
61
+ }
62
+
63
+ /**
64
+ * dango__connect
65
+ * 接続しているクライアントのsidの一覧の記録
66
+ *
67
+ * @return Array
68
+ */
69
+ private function dango__connect(evt:DangoReceiveEvent):void {
70
+ this.dispatchEvent(new DangoAS3ModeReceiveEvent("dango__connect", {}));
71
+ }
72
+
73
+ /**
74
+ * dango_notice_send_object
75
+ * 接続しているクライアントのsidの一覧取得
76
+ *
77
+ * @return Array
78
+ */
79
+ private function dango_notice_send_object(evt:DangoReceiveEvent):void {
80
+ var recv_data:Object = evt.receive_data;
81
+
82
+ this.dispatchEvent(new DangoAS3ModeReceiveEvent("dango_as3mode_receive", recv_data));
83
+ }
84
+
85
+ /**
86
+ * dango_notice_current_sids
87
+ * 接続しているクライアントのsidの一覧の記録
88
+ *
89
+ * @return Array
90
+ */
91
+ private function dango_notice_current_sids(evt:DangoReceiveEvent):void {
92
+ var ret:Object = evt.receive_data;
93
+ all_sid_list = ret["sids"];
94
+ }
95
+
96
+
97
+ /**
98
+ * addEventListener
99
+ * Event送出用
100
+ *
101
+ * @param type:String
102
+ * @param listener:Function
103
+ * @param useCapture:Boolean = false
104
+ * @param priority:int = 0
105
+ * @param useWeakReference:Boolean = false
106
+ * @return void
107
+ */
108
+ public function addEventListener(type:String, listener:Function,
109
+ useCapture:Boolean = false,
110
+ priority:int = 0,
111
+ useWeakReference:Boolean = false):void{
112
+ dispatcher.addEventListener(type, listener, useCapture, priority);
113
+ }
114
+
115
+ /**
116
+ * dispatchEvent
117
+ * Event送出用
118
+ *
119
+ * @param evt:Event
120
+ * @return Boolean
121
+ */
122
+ public function dispatchEvent(evt:Event):Boolean{
123
+ return dispatcher.dispatchEvent(evt);
124
+ }
125
+
126
+ /**
127
+ * hasEventListener
128
+ * Event送出用
129
+ *
130
+ * @param type:String
131
+ * @return Boolean
132
+ */
133
+ public function hasEventListener(type:String):Boolean{
134
+ return dispatcher.hasEventListener(type);
135
+ }
136
+
137
+ /**
138
+ * removeEventListener
139
+ * Event送出用
140
+ *
141
+ * @param type:String
142
+ * @param listener:Function
143
+ * @param useCapture:Boolean = false
144
+ * @return void
145
+ */
146
+ public function removeEventListener(type:String, listener:Function,
147
+ useCapture:Boolean = false):void{
148
+ dispatcher.removeEventListener(type, listener, useCapture);
149
+ }
150
+
151
+ /**
152
+ * willTrigger
153
+ * Event送出用
154
+ *
155
+ * @param type:String
156
+ * @return Boolean
157
+ */
158
+ public function willTrigger(type:String):Boolean {
159
+ return dispatcher.willTrigger(type);
160
+ }
161
+
162
+ }
163
+ }
@@ -0,0 +1,23 @@
1
+
2
+ package org.rubyforge.dango {
3
+ import flash.events.*;
4
+
5
+ public class DangoAS3ModeReceiveEvent extends Event {
6
+ private var dango_type:String;
7
+ public var receive_data:Object;
8
+ public var receive_count_no:uint;
9
+
10
+ public function DangoAS3ModeReceiveEvent(type:String,
11
+ receive_data_orig:Object,
12
+ bubbles:Boolean = false,
13
+ cancelable:Boolean = false) {
14
+ dango_type = type;
15
+ receive_data = receive_data_orig;
16
+ super(type, bubbles, cancelable);
17
+ }
18
+
19
+ public override function clone():Event {
20
+ return(new DangoAS3ModeReceiveEvent(dango_type, receive_data));
21
+ }
22
+ }
23
+ }
@@ -11,7 +11,6 @@ package org.rubyforge.dango {
11
11
  import flash.utils.*;
12
12
  import flash.system.*;
13
13
  import flash.display.*;
14
- import mx.utils.ObjectUtil;
15
14
 
16
15
  import com.adobe.serialization.json.JSON;
17
16
 
@@ -76,7 +75,7 @@ package org.rubyforge.dango {
76
75
  */
77
76
  public function DangoClientFramework(config:*){
78
77
  trace("DangoClientFramework start...");
79
- trace("config=" + ObjectUtil.toString(config));
78
+ trace("config=" + config);
80
79
 
81
80
  // 設定ファイルの読み込み
82
81
  if(config.hasOwnProperty("server_host")){ server_host = config.server_host; }
@@ -365,7 +364,7 @@ package org.rubyforge.dango {
365
364
  // this.dispatchEvent(new DangoErrorEvent("DangoError", DangoErrorCode.IOError, "failed in DangoClientFramework:socket_read_push_cache:receive_cache_do_phase == 0"));
366
365
 
367
366
  // キャッシュに残っているデータを消して再度初めから受信できるようにする
368
- trace("DangoClientFramework:socket_read_push_cache:receive_cache_do_phase==0:err=" + ObjectUtil.toString(err));
367
+ trace("DangoClientFramework:socket_read_push_cache:receive_cache_do_phase==0:err=" + err);
369
368
  receive_cache_do_phase = 0; // 長さから取得する
370
369
  receive_cache_byta = new ByteArray; // キャッシュを空にする
371
370
  break;
@@ -416,7 +415,7 @@ package org.rubyforge.dango {
416
415
  // this.dispatchEvent(new DangoErrorEvent("DangoError", DangoErrorCode.IOError, "failed in DangoClientFramework:socket_read_push_cache:receive_cache_do_phase == 1"));
417
416
 
418
417
  // キャッシュに残っているデータを消して再度初めから受信できるようにする
419
- trace("DangoClientFramework:socket_read_push_cache:receive_cache_do_phase==1:err=" + ObjectUtil.toString(err));
418
+ trace("DangoClientFramework:socket_read_push_cache:receive_cache_do_phase==1:err=" + err);
420
419
  receive_cache_do_phase = 0; // 長さから取得する
421
420
  receive_cache_byta = new ByteArray; // キャッシュを空にする
422
421
  break;
@@ -451,6 +450,7 @@ package org.rubyforge.dango {
451
450
  this.sid = recv_data["_sid"];
452
451
  has_sid = true;
453
452
  if(is_debug){ trace("DangoClientFramework:this.sid=" + this.sid + " server_time=" + server_time); }
453
+ this.dispatchEvent(new DangoReceiveEvent("dango__connect", {}, count_no));
454
454
 
455
455
  } else { // 通常のデータならイベント発生
456
456
  if(is_debug){ trace("DangoClientFramework:dispatchEvent:dango_" + notice_name + " server_time=" + server_time); }
@@ -532,7 +532,7 @@ package org.rubyforge.dango {
532
532
  // if(!is_connect){ throw new DangoError("error:not connect"); } // 接続されていない場合はエラー
533
533
 
534
534
  // 送信データの作成
535
- var send_obj_dup:Object = ObjectUtil.copy(send_obj);
535
+ var send_obj_dup:Object = DangoUtil.deep_copy(send_obj);
536
536
  send_obj_dup["_action_name"] = action_name;
537
537
  send_obj_dup["_return_id"] = (new Date()).time;
538
538
 
@@ -557,8 +557,6 @@ package org.rubyforge.dango {
557
557
  * @return void
558
558
  */
559
559
  public function send_data_to_server( send_obj:Array ):void {
560
- // if(is_debug){ trace("DangoClientFramework:send_data_to_server:send_obj=" + ObjectUtil.toString(send_obj)); }
561
-
562
560
  var encode_type:uint = default_encode_type;
563
561
 
564
562
  // データが空ならJSONencodeしない
@@ -590,14 +588,36 @@ package org.rubyforge.dango {
590
588
  }
591
589
 
592
590
  /**
593
- * dango_before_filter の雛形
591
+ * dango__connect の雛形
594
592
  * すべてのdango通知の前処理用のメソッド
595
593
  * オーバーライドして使うもの
596
594
  *
597
595
  * @param evt:DangoReceiveEvent
598
596
  * @return void
597
+ protected function dango__connect(evt:Object):void {
598
+ }
599
599
  */
600
- protected function dango__before_filter(evt:Object):void {
600
+
601
+ /**
602
+ * dango__after_filter の雛形
603
+ * すべてのdango通知の前処理用のメソッド
604
+ * オーバーライドして使うもの
605
+ *
606
+ * @param evt:DangoReceiveEvent
607
+ * @return void
608
+ protected function dango__after_filter(evt:Object):void {
601
609
  }
610
+ */
611
+
612
+ /**
613
+ * dango__after_filter の雛形
614
+ * すべてのdango通知の前処理用のメソッド
615
+ * オーバーライドして使うもの
616
+ *
617
+ * @param evt:DangoReceiveEvent
618
+ * @return void
619
+ protected function dango__after_filter(evt:Object):void {
620
+ }
621
+ */
602
622
  }
603
623
  }