commit
@@ -35,6 +35,7 @@ | ||
35 | 35 | [ |
36 | 36 | { type : "bg", image : "back_p0" }, |
37 | 37 | { type : "bgm", sound : "bgm" }, |
38 | + { type : "wait", frames : 30 }, | |
38 | 39 | { type : "message", |
39 | 40 | box : { x : 10, y : 260, w : 300, h : 110 }, |
40 | 41 | image : "face_p0", |
@@ -18,26 +18,36 @@ | ||
18 | 18 | { |
19 | 19 | map : |
20 | 20 | [ |
21 | - [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0], | |
22 | - [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0], | |
23 | - [ 0, 2, 3, 0, 0, 0, 0, 0, 10, 11, 12, 13, 0, 0, 0, 0, 0, 0, 0, 3], | |
24 | - [ 0, 3, 2, 0, 0, 0, 10, 11, 1, 1, 1, 1, 12, 13, 0, 0, 0, 0, 0, 0], | |
25 | - [ 0, 0, 0, 0, 10, 11, 1, 1, 1, 1, 1, 1, 1, 1, 12, 13, 0, 0, 0, 0], | |
26 | - [ 0, 0, 10, 11, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 12, 13, 0, 0], | |
27 | - [ 0, 0, 20, 21, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 22, 23, 0, 0], | |
28 | - [ 0, 0, 0, 0, 20, 21, 1, 1, 1, 1, 1, 1, 1, 1, 22, 23, 0, 0, 0, 0], | |
29 | - [ 0, 0, 0, 0, 0, 0, 20, 21, 1, 1, 1, 1, 22, 23, 0, 0, 0, 0, 0, 0], | |
30 | - [ 0, 0, 0, 3, 0, 0, 0, 0, 20, 21, 22, 23, 0, 0, 0, 0, 0, 0, 2, 0], | |
31 | - [ 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3], | |
32 | - [ 0, 0, 0, 0, 0, 0, 0, 0,1000,1100,1200,1300, 0, 0, 0, 0, 0, 0, 0, 0], | |
33 | - [ 0, 0, 0, 0, 0, 0,1000,1100,3200, 0, 0,3100,1200,1300, 0, 0, 0, 0, 3, 0], | |
34 | - [ 0, 0, 3, 0,1000,1100,3200, 0, 3, 0, 0, 0, 0,3100,1200,1300, 0, 2, 0, 0], | |
35 | - [ 0, 2, 2, 0,2000,2100, 0, 0, 0, 2, 3, 0, 0, 0,2200,2300, 0, 0, 0, 0], | |
36 | - [ 3, 0, 0, 0, 0,3100,1200,1300, 0, 0, 3, 0,1000,1100,3200, 0, 0, 0, 0, 0], | |
37 | - [ 0, 2, 0, 0, 0, 0, 0,3100,1200,1300,1000,1100,3200, 0, 0, 0, 0, 0, 0, 0], | |
38 | - [ 0, 0, 0, 0, 0, 0, 0, 0, 0,3100,3200, 0, 0, 0, 0, 0, 0, 0, 0, 0], | |
39 | - [ 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0], | |
40 | - [ 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0], | |
21 | + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
22 | + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
23 | + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0], | |
24 | + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0], | |
25 | + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
26 | + [0,0,0,0,0,0,4000,5000,6000,9000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
27 | + [0,0,0,0,4000,5000,14004,5,6,13007,6000,9000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
28 | + [0,0,4000,5000,14004,5,1,1,1,1,6,13007,6000,7000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
29 | + [0,0,8000,9000,8,9,1,1,1,1,10,11,10000,11000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
30 | + [0,0,0,13000,6000,9000,8,9,10,11,10000,5000,14000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
31 | + [0,0,0,0,0,13000,6000,9000,10000,5000,14000,0,16000,17000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
32 | + [0,0,0,0,0,0,0,13000,14000,0,0,0,20000,21000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
33 | + [0,0,0,0,0,0,0,0,0,0,0,0,24000,25000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
34 | + [2,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
35 | + [0,2,0,0,0,0,0,0,0,0,0,2,0,0,0,4,5,6,7,0,0,0,0,0,0,16000,17000,0,0,0], | |
36 | + [0,0,0,0,0,0,0,0,0,0,0,0,0,4,5,1,1,1,1,6,7,0,0,0,0,20000,21000,0,0,0], | |
37 | + [0,0,0,0,0,0,0,0,0,0,0,4,5,1,1,1,1,1,1,1,1,6,7,0,0,24000,25000,0,0,0], | |
38 | + [0,0,0,0,0,0,0,0,0,0,0,8,9,1,1,1,1,1,1,1,1,10,11,0,0,0,0,3,0,0], | |
39 | + [0,0,0,0,0,0,0,0,0,0,0,0,0,8,9,1,1,1,1,10,11,0,0,0,0,0,0,0,0,0], | |
40 | + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,9,10,11,0,0,0,0,0,2,0,0,0,0,0], | |
41 | + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0], | |
42 | + [0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
43 | + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
44 | + [0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,2,0,0,0,0,0,0,0], | |
45 | + [3,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,3,0,0], | |
46 | + [0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0], | |
47 | + [0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0], | |
48 | + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
49 | + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
50 | + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] | |
41 | 51 | ], |
42 | 52 | actors : |
43 | 53 | [ |
@@ -45,22 +55,31 @@ | ||
45 | 55 | type : 0, |
46 | 56 | name : "パンネロ", |
47 | 57 | status : 1, |
48 | - x : 4.5, y : 4.5, dir : 0, | |
58 | + x : 4.5, y : 4.5, z : 0, dir : 0, | |
59 | + hp : 0, mp : 0, | |
49 | 60 | event : { type : "none" } |
61 | + }, | |
62 | + { | |
63 | + type : 0, | |
64 | + name : "パンネロ", | |
65 | + status : 1, | |
66 | + x : 7.5, y : 4.5, z : 0, dir : 0, | |
67 | + hp : 0, mp : 0, | |
68 | + event : { type : "none" } | |
50 | 69 | } |
51 | 70 | ], |
52 | 71 | resource : |
53 | 72 | { |
54 | - image : | |
73 | + image : | |
55 | 74 | { |
56 | - mchip : { name : "mchip.png" }, | |
57 | - mchip_tr : { name : "mchip_tr.png" }, | |
58 | - actors : | |
75 | + mchip : { name : "mchip.png" }, | |
76 | + mchip_tr : { name : "mchip_tr.png" }, | |
77 | + actors : | |
59 | 78 | [ |
60 | 79 | { name : "actor_t0.png" } |
61 | 80 | ] |
62 | 81 | }, |
63 | - sound : | |
82 | + sound : | |
64 | 83 | { |
65 | 84 | } |
66 | 85 | }, |
@@ -68,8 +87,8 @@ | ||
68 | 87 | { |
69 | 88 | actorAction : |
70 | 89 | { |
71 | - frameCount : 9, fw : 40, fh : 36, | |
72 | - frames : { 0 : { x : 0, y : 0 }, 3 : { x : 1, y : 0 }, 6 : { x : 0, y : 0 } } | |
90 | + frameCount : 9, fw : 48, fh : 48, | |
91 | + frames : { 0 : { x : 0, y : 0 }, 3 : { x : 1, y : 0 }, 6 : { x : 2, y : 0 } } | |
73 | 92 | } |
74 | 93 | } |
75 | 94 | }); |
@@ -0,0 +1,165 @@ | ||
1 | +<!DOCTYPE html> | |
2 | +<html lang="ja"> | |
3 | +<head> | |
4 | + <meta charset="UTF-8" /> | |
5 | + <title>QV RPG Editor</title> | |
6 | + | |
7 | + <meta http-equiv="Content-Script-Type" content="text/javascript" /> | |
8 | + <meta http-equiv="Content-Style-Type" content="text/css" /> | |
9 | + | |
10 | + <style type="text/css"> | |
11 | + body | |
12 | + { | |
13 | + color: white; | |
14 | + background-color: black; | |
15 | + text-align: center; | |
16 | + } | |
17 | + #panel | |
18 | + { | |
19 | + position: relative; | |
20 | + text-align: center; | |
21 | + } | |
22 | + #screen | |
23 | + { | |
24 | + position: relative; | |
25 | + padding: 0px; | |
26 | + } | |
27 | + #dialog | |
28 | + { | |
29 | + margin: auto; | |
30 | + width: 650px; | |
31 | + position: relative; | |
32 | + background-color: steelblue; | |
33 | + border: 1px solid white | |
34 | + } | |
35 | + #dialog td | |
36 | + { | |
37 | + text-align: left; | |
38 | + margin: 5px; | |
39 | + border: 1px solid black | |
40 | + } | |
41 | + #usage | |
42 | + { | |
43 | + margin: auto; | |
44 | + width: 650px; | |
45 | + border: solid 1px white; | |
46 | + text-align: center; | |
47 | + font-size: small; | |
48 | + } | |
49 | + #help | |
50 | + { | |
51 | + margin: auto; | |
52 | + width: 640px; | |
53 | + border: solid 1px black; | |
54 | + text-align: left; | |
55 | + } | |
56 | + </style> | |
57 | + <script type="text/javascript" src="js/h5glib.js"></script> | |
58 | + <script type="text/javascript" src="js/editorScene.js"></script> | |
59 | + <script type="text/javascript" src="js/editorMain.js"></script> | |
60 | + <script type="text/javascript" src="stage0/stage.js"></script> | |
61 | + <script> | |
62 | + function handleEventTypeChange() | |
63 | + { | |
64 | + var lables = | |
65 | + [ | |
66 | + "", | |
67 | + "メッセージ", | |
68 | + "", | |
69 | + "データ URL" | |
70 | + ]; | |
71 | + var eventType = document.getElementById("eventType"); | |
72 | + var eventParamLabel = document.getElementById("eventParamLabel"); | |
73 | + eventParamLabel.textContent = lables[ eventType.selectedIndex ]; | |
74 | + } | |
75 | + </script> | |
76 | +</head> | |
77 | + | |
78 | +<body> | |
79 | + <header> | |
80 | + <h1>QV RPG Editor</h1> | |
81 | + </header> | |
82 | + | |
83 | + <article> | |
84 | + <section> | |
85 | + <div id="usage"></div> | |
86 | + <p></p> | |
87 | + <input id="data" type="button" value="Data"> | |
88 | + <p></p> | |
89 | + <div id="panel"> | |
90 | + <canvas id="screen" width="650" height="350"></canvas> | |
91 | + <div id="dialog"> | |
92 | + <caption>キャラクター編集</caption> | |
93 | + <table> | |
94 | + <tr> | |
95 | + <td>名前</td> | |
96 | + <td><input id="actorName" type="text" size="40" maxlength="40"></td> | |
97 | + </tr> | |
98 | + <tr> | |
99 | + <td>イベント</td> | |
100 | + <td> | |
101 | + <select id="eventType" onChange="handleEventTypeChange();"> | |
102 | + <option value="none" selected>なし</option> | |
103 | + <option value="text">メッセージ表示</option> | |
104 | + <option value="battle">戦闘</option> | |
105 | + <option value="warp">ステージ遷移</option> | |
106 | + </select> | |
107 | + </td> | |
108 | + </tr> | |
109 | + <tr> | |
110 | + <td id="eventParamLabel"></td> | |
111 | + <td><input id="eventParam" type="text" size="80" maxlength="80"></td> | |
112 | + </tr> | |
113 | + </table> | |
114 | + </div> | |
115 | + </div> | |
116 | + <div id="info"></div> | |
117 | + <p></p> | |
118 | + <p>help</p> | |
119 | + <div id="help"> | |
120 | + <ul> | |
121 | + <li>チップの選択<br> | |
122 | + 画面の右側にはマップチップ、透明マップチップ、キャラクターチップのチップ選択ボックスがあります。 | |
123 | + <ul> | |
124 | + <li>マップチップの選択<br> | |
125 | + マップチップを選択するとマップの床・壁を描画できます。<br> | |
126 | + マップチップを選択した状態で、マップ上のキャラクターをクリックするとキャラクターを選択できます。<br> | |
127 | + </li> | |
128 | + <li>キャラクターチップの選択<br> | |
129 | + キャラクターチップを選択すると、キャラクターの追加、削除ができます。<br> | |
130 | + </li> | |
131 | + </ul> | |
132 | + </li> | |
133 | + <br> | |
134 | + <li>キャラクターの編集<br> | |
135 | + マップチップを選択した状態で、マップ上のキャラクターをクリックしてキャラクターを選択します。<br> | |
136 | + ページ下部のキャラクター編集フォームで、選択したキャラクターの属性を編集できます。<br> | |
137 | + (編集を反映するには、編集中のキャラクターとは別のマップ上のセルをクリックします。)<br> | |
138 | + </li> | |
139 | + <li>キャラクターの移動<br> | |
140 | + マップチップを選択した状態で、マップ上のキャラクターをドラッグするとキャラクターを移動できます。<br> | |
141 | + </li> | |
142 | + <li>キャラクターの追加<br> | |
143 | + キャラクターチップの画像のあるチップ(上部の空白チップ以外)を選択します。<br> | |
144 | + マップをクリックするとキャラクターが追加されます。<br> | |
145 | + </li> | |
146 | + <li>キャラクターの削除<br> | |
147 | + キャラクターチップの上部の空白チップを選択します。<br> | |
148 | + マップをクリックするとキャラクターが削除されます。<br> | |
149 | + キャラクターの背景が薄緑色のものはプレーヤーのキャラクターなので削除できません。<br> | |
150 | + </li> | |
151 | + <br> | |
152 | + <li>ローカルでのデータの保存について<br> | |
153 | + [Data] ボタンをクリックすると、新しいウインドウが開いてゲームデータを表示します。<br> | |
154 | + 表示されたゲームデータの内容を「qvrpg/stage0/stage.js」に上書してゲームをリロードすると、編集した内容が反映されたゲームをプレイできます。<br> | |
155 | + </li> | |
156 | + </ul> | |
157 | + </div> | |
158 | + </section> | |
159 | + </article> | |
160 | + | |
161 | + <footer> | |
162 | + <p></p> | |
163 | + </footer> | |
164 | +</body> | |
165 | +</html> |
@@ -26,6 +26,14 @@ | ||
26 | 26 | ・キーボード |
27 | 27 | [↑]: 左上, [←]: 左下, [↓]: 右下, [→]: 右上 |
28 | 28 | |
29 | +・マップエディタの使い方 | |
30 | + アーカイブファイル解凍後に作成された「qvrpg/editor.html」をブラウザで開きます。 | |
31 | + ・マウス | |
32 | + マウスでチップを選択して、マップ画面をクリック・ドラッグします。 | |
33 | + スクロールバーのボタンをクリックするとスクロールします。 | |
34 | + ・ボタン | |
35 | + ・[Data] | |
36 | + 新しいウインドウが開いてゲームデータを表示します。 | |
29 | 37 | |
30 | 38 | |
31 | 39 | ・素材サイト |
@@ -0,0 +1,1703 @@ | ||
1 | +/* | |
2 | + * Copyright [yyyy] [name of copyright owner] | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | + | |
17 | + | |
18 | +// Anonymous function start | |
19 | +// | |
20 | +(function( window, undefined ) | |
21 | +{ | |
22 | + | |
23 | +// reference | |
24 | +var Config = window.h5glib.Config; | |
25 | +var Debug = window.h5glib.Debug; | |
26 | +var Command = window.h5glib.Command; | |
27 | +var Task = window.h5glib.Task; | |
28 | +var SoundTask = window.h5glib.SoundTask; | |
29 | +var ReadyTask = window.h5glib.ReadyTask; | |
30 | +var Message = window.h5glib.Message; | |
31 | +var MessageHandler = window.h5glib.MessageHandler; | |
32 | +var MessageManager = window.h5glib.MessageManager; | |
33 | +var SceneStatus = window.h5glib.SceneStatus; | |
34 | +var Scene = window.h5glib.Scene; | |
35 | + | |
36 | +var STAGE_RECT = { x : 10, y : 10, w : 256, h : 256 }; | |
37 | +var CHIP_RECT = { x : 290, y : 10, w : 128, h : 256 }; | |
38 | +var CHIP_TR_RECT = { x : 440, y : 10, w : 128, h : 256 }; | |
39 | +var ACTOR_RECT = { x : 590, y : 10, w : 32, h : 256 }; | |
40 | + | |
41 | +//...[透過チップ][チップ] | |
42 | +//...000 000 | |
43 | +//... actorid 要+1 | |
44 | + | |
45 | +/** | |
46 | + * RenderInfo | |
47 | + */ | |
48 | +var RenderInfo = | |
49 | +{ | |
50 | + mapGridPixels : 16, | |
51 | + chipGridPixels : 32, | |
52 | + chipPixels : 32, | |
53 | + actorFramesW : 3, | |
54 | + actorFramesH : 4 | |
55 | +}; | |
56 | + | |
57 | +/** | |
58 | + * MapInfo | |
59 | + */ | |
60 | +var MapInfo = | |
61 | +{ | |
62 | + maxValue : 1000, | |
63 | + chipLevel : 0, | |
64 | + chipTrLevel : 1, | |
65 | + actorLevel : 2 | |
66 | +}; | |
67 | + | |
68 | +/** | |
69 | + * Res | |
70 | + */ | |
71 | +var Res = | |
72 | +{ | |
73 | + String : | |
74 | + { | |
75 | + HTML_USAGE : "<p>" + | |
76 | + "マウスでチップを選択して、マップ画面をクリック・ドラッグします。<br>" + | |
77 | + "スクロールバーのボタンをクリックするとスクロールします。<br>" + | |
78 | + "(詳しい使い方はページ下の「help」を参照してください。)" + | |
79 | + "</p>", | |
80 | + ID_DATA : "data", | |
81 | + DEFAULT_NAME : "サンダー虎島" | |
82 | + }, | |
83 | + Color : | |
84 | + { | |
85 | + PANEL : "gainsboro", | |
86 | + BACKGROUND : "black", | |
87 | + BORDER : "gray", | |
88 | + BORDER_BUTTON_ON : "black", | |
89 | + BORDER_BUTTON_OFF : "gray", | |
90 | + GRIDLINE : "white", | |
91 | + SELECTED : "crimson", | |
92 | + ACTOR_0 : "springgreen" | |
93 | + }, | |
94 | + Font : | |
95 | + { | |
96 | + LARGE : "bold 18px 'MS Pゴシック'", | |
97 | + SMALL : "bold 14px 'MS Pゴシック'" | |
98 | + } | |
99 | +}; | |
100 | + | |
101 | +/** | |
102 | + * MessageType | |
103 | + */ | |
104 | +var MessageType = | |
105 | +{ | |
106 | + NONE : 0, | |
107 | + RET_PREV_SCENE : 1 | |
108 | +}; | |
109 | + | |
110 | +/** | |
111 | + * EventType | |
112 | + */ | |
113 | +var EventType = | |
114 | +{ | |
115 | + NONE : "none", | |
116 | + TEXT : "text", | |
117 | + BATTLE : "battle", | |
118 | + WARP : "warp" | |
119 | +}; | |
120 | + | |
121 | + | |
122 | +/** | |
123 | + * PanelTask | |
124 | + */ | |
125 | +var PanelTask = function( scene ) | |
126 | +{ | |
127 | + this.command = scene.command; // input | |
128 | +}; | |
129 | +PanelTask.prototype = new Task(); | |
130 | + | |
131 | +(function( pt ) | |
132 | +{ | |
133 | + /** | |
134 | + * 描画する。 | |
135 | + */ | |
136 | + pt.draw = function( scene ) | |
137 | + { | |
138 | + var context = scene.context; | |
139 | + var canvas = context.canvas; | |
140 | + | |
141 | + context.save(); | |
142 | + | |
143 | + context.fillStyle = Res.Color.PANEL; | |
144 | + context.fillRect( 0, 0, canvas.width, canvas.height ); | |
145 | + | |
146 | + context.restore(); | |
147 | + }; | |
148 | +})( PanelTask.prototype ); | |
149 | + | |
150 | +/** | |
151 | + * EditorTask | |
152 | + */ | |
153 | +var EditorTask = function() | |
154 | +{ | |
155 | + this.resource = null; | |
156 | + this.gridPixels = RenderInfo.mapGridPixels; | |
157 | + | |
158 | + this.rect = null; // ピクセル単位 ( x, y, w, h ), Canvas 基準 | |
159 | + this.scroll = null; // グリッド単位 ( x, y ) | |
160 | + this.selected = null; // グリッド単位 ( x, y ) | |
161 | + | |
162 | + this.getVisibleSize = null; // グリッド単位 ( w, h ) | |
163 | + this.getMaxScroll = null; // グリッド単位 ( w, h ) | |
164 | + this.getSelectedVal = null; // y * w + x | |
165 | +}; | |
166 | +EditorTask.prototype = new Task(); | |
167 | + | |
168 | +(function( pt ) | |
169 | +{ | |
170 | + /** | |
171 | + * | |
172 | + */ | |
173 | + pt.setScroll = function( sx, sy ) | |
174 | + { | |
175 | + var ms = this.getMaxScroll(); | |
176 | + if ( 0 <= sx && sx <= ms.w && | |
177 | + 0 <= sy && sy <= ms.h ) | |
178 | + { | |
179 | + this.scroll.x = sx; | |
180 | + this.scroll.y = sy; | |
181 | + } | |
182 | + }; | |
183 | + /** | |
184 | + * | |
185 | + */ | |
186 | + pt.drawBackground = function( context ) | |
187 | + { | |
188 | + context.fillStyle = Res.Color.BACKGROUND; | |
189 | + context.fillRect( this.rect.x, this.rect.y, this.rect.w, this.rect.h ); | |
190 | + }; | |
191 | + /** | |
192 | + * | |
193 | + */ | |
194 | + pt.drawGridLine = function( context ) | |
195 | + { | |
196 | + var vs = this.getVisibleSize(); | |
197 | + var lw = vs.w * this.gridPixels; | |
198 | + var lh = vs.h * this.gridPixels; | |
199 | + | |
200 | + context.strokeStyle = Res.Color.GRIDLINE; | |
201 | + for ( var i = 1; i <= vs.h; i++ ) | |
202 | + { | |
203 | + var y = this.rect.y + ( i * this.gridPixels ); | |
204 | + context.beginPath(); | |
205 | + context.moveTo( this.rect.x, y ); | |
206 | + context.lineTo( this.rect.x + lw, y ); | |
207 | + context.stroke(); | |
208 | + } | |
209 | + for ( var j = 1; j <= vs.w; j++ ) | |
210 | + { | |
211 | + var x = this.rect.x + ( j * this.gridPixels ); | |
212 | + context.beginPath(); | |
213 | + context.moveTo( x, this.rect.y ); | |
214 | + context.lineTo( x, this.rect.y + lh ); | |
215 | + context.stroke(); | |
216 | + } | |
217 | + }; | |
218 | + /** | |
219 | + * | |
220 | + */ | |
221 | + pt.drawSelected = function( context ) | |
222 | + { | |
223 | + // selected | |
224 | + context.strokeStyle = Res.Color.SELECTED; | |
225 | + context.beginPath(); | |
226 | + context.strokeRect( | |
227 | + this.rect.x + this.selected.x * this.gridPixels, | |
228 | + this.rect.y + this.selected.y * this.gridPixels, | |
229 | + this.gridPixels, | |
230 | + this.gridPixels | |
231 | + ); | |
232 | + context.beginPath(); | |
233 | + context.strokeRect( | |
234 | + this.rect.x + this.selected.x * this.gridPixels + 1, | |
235 | + this.rect.y + this.selected.y * this.gridPixels + 1, | |
236 | + this.gridPixels - 2, | |
237 | + this.gridPixels - 2 | |
238 | + ); | |
239 | + }; | |
240 | + /** | |
241 | + * | |
242 | + */ | |
243 | + pt.drawBorder = function( context ) | |
244 | + { | |
245 | + context.strokeStyle = Res.Color.BORDER; | |
246 | + context.beginPath(); | |
247 | + context.strokeRect( this.rect.x, this.rect.y, this.rect.w, this.rect.h ); | |
248 | + }; | |
249 | +})( EditorTask.prototype ); | |
250 | + | |
251 | +/** | |
252 | + * ScrollType | |
253 | + */ | |
254 | +var ScrollType = | |
255 | +{ | |
256 | + HORIZONTAL : 0, | |
257 | + VERTICAL : 1 | |
258 | +}; | |
259 | + | |
260 | +/** | |
261 | + * ScrollTask | |
262 | + */ | |
263 | +var ScrollTask = function( scene, type, target ) | |
264 | +{ | |
265 | + this.command = scene.command; // input | |
266 | + | |
267 | + this.type = type; | |
268 | + this.target = target; | |
269 | + this.rect = {}; // ピクセル単位 ( x, y, w, h ), Canvas 基準 | |
270 | + this.buttons = // ピクセル単位 ( x, y, w, h ), Canvas 基準 | |
271 | + [ | |
272 | + { value : -1, on : 0 }, | |
273 | + { value : 1, on : 0 } | |
274 | + ] | |
275 | + this.initRect(); | |
276 | + | |
277 | + // add mouse area | |
278 | + this.command.addMouseArea( new MouseArea( this, this.rect ) ); | |
279 | +}; | |
280 | +ScrollTask.prototype = new Task(); | |
281 | + | |
282 | +(function( pt ) | |
283 | +{ | |
284 | + pt.BAR_LEN = 18; | |
285 | + pt.BUTTON_LEN = 64; | |
286 | + | |
287 | + /** | |
288 | + * | |
289 | + */ | |
290 | + pt.initRect = function() | |
291 | + { | |
292 | + switch ( this.type ) | |
293 | + { | |
294 | + case ScrollType.HORIZONTAL : | |
295 | + // rect | |
296 | + this.rect.x = this.target.rect.x; | |
297 | + this.rect.y = this.target.rect.y + this.target.rect.h; | |
298 | + this.rect.w = this.target.rect.w; | |
299 | + this.rect.h = this.BAR_LEN; | |
300 | + // buttons | |
301 | + this.buttons[0].x = this.rect.x; | |
302 | + this.buttons[0].y = this.rect.y; | |
303 | + this.buttons[0].w = this.BUTTON_LEN; | |
304 | + this.buttons[0].h = this.rect.h; | |
305 | + this.buttons[1].x = this.rect.x + this.rect.w - this.BUTTON_LEN; | |
306 | + this.buttons[1].y = this.rect.y; | |
307 | + this.buttons[1].w = this.BUTTON_LEN; | |
308 | + this.buttons[1].h = this.rect.h; | |
309 | + break; | |
310 | + case ScrollType.VERTICAL : | |
311 | + this.rect.x = this.target.rect.x + this.target.rect.w; | |
312 | + this.rect.y = this.target.rect.y; | |
313 | + this.rect.w = this.BAR_LEN; | |
314 | + this.rect.h = this.target.rect.h; | |
315 | + // buttons | |
316 | + this.buttons[0].x = this.rect.x; | |
317 | + this.buttons[0].y = this.rect.y; | |
318 | + this.buttons[0].w = this.rect.w; | |
319 | + this.buttons[0].h = this.BUTTON_LEN; | |
320 | + this.buttons[1].x = this.rect.x; | |
321 | + this.buttons[1].y = this.rect.y + this.rect.h - this.BUTTON_LEN; | |
322 | + this.buttons[1].w = this.rect.w; | |
323 | + this.buttons[1].h = this.BUTTON_LEN; | |
324 | + break; | |
325 | + } | |
326 | + }; | |
327 | + /** | |
328 | + * | |
329 | + */ | |
330 | + pt.getSliderRect = function() | |
331 | + { | |
332 | + var vs = this.target.getVisibleSize(); | |
333 | + var ms = this.target.getMaxScroll(); | |
334 | + var scroll = this.target.scroll; | |
335 | + var sarea = {}; | |
336 | + var slider = {}; | |
337 | + | |
338 | + switch ( this.type ) | |
339 | + { | |
340 | + case ScrollType.HORIZONTAL : | |
341 | + // sarea | |
342 | + sarea.x = this.rect.x + this.BUTTON_LEN; | |
343 | + sarea.w = this.rect.w - ( this.BUTTON_LEN * 2 ); | |
344 | + // slider | |
345 | + slider.w = Math.floor( sarea.w * vs.w / ( vs.w + ms.w ) ); | |
346 | + slider.h = this.rect.h; | |
347 | + slider.x = ( ms.w > 0 ) ? ( sarea.x + ( sarea.w - slider.w ) * scroll.x / ms.w ) : sarea.x; | |
348 | + slider.y = this.rect.y; | |
349 | + break; | |
350 | + case ScrollType.VERTICAL : | |
351 | + // sarea | |
352 | + sarea.y = this.rect.y + this.BUTTON_LEN; | |
353 | + sarea.h = this.rect.h - ( this.BUTTON_LEN * 2 ); | |
354 | + // slider | |
355 | + slider.w = this.rect.w; | |
356 | + slider.h = Math.floor( sarea.h * vs.h / ( vs.h + ms.h ) ); | |
357 | + slider.x = this.rect.x; | |
358 | + slider.y = ( ms.h > 0 ) ? ( sarea.y + ( sarea.h - slider.h ) * scroll.y / ms.h ) : sarea.y; | |
359 | + break; | |
360 | + } | |
361 | + return slider; | |
362 | + }; | |
363 | + /** | |
364 | + * | |
365 | + */ | |
366 | + pt.addScroll = function( value ) | |
367 | + { | |
368 | + var scroll = this.target.scroll; | |
369 | + | |
370 | + switch ( this.type ) | |
371 | + { | |
372 | + case ScrollType.HORIZONTAL : | |
373 | + this.target.setScroll( scroll.x + value, scroll.y ); | |
374 | + break; | |
375 | + case ScrollType.VERTICAL : | |
376 | + this.target.setScroll( scroll.x, scroll.y + value ); | |
377 | + break; | |
378 | + } | |
379 | + }; | |
380 | + /** | |
381 | + * | |
382 | + */ | |
383 | + pt.update = function( scene ) | |
384 | + { | |
385 | + var upd = false; | |
386 | + | |
387 | + if ( this.command.mouse && this.command.mouseInfo.target == this ) | |
388 | + { | |
389 | + var mi = this.command.mouseInfo; | |
390 | + | |
391 | + // update button status | |
392 | + for ( var i = 0; i < this.buttons.length; i++ ) | |
393 | + { | |
394 | + var button = this.buttons[i]; | |
395 | + if ( button.x <= mi.x && mi.x <= button.x + button.w && | |
396 | + button.y <= mi.y && mi.y <= button.y + button.h ) | |
397 | + { | |
398 | + button.on = 1; | |
399 | + this.addScroll( button.value ); | |
400 | + upd = true; | |
401 | + break; | |
402 | + } | |
403 | + } | |
404 | + } | |
405 | + else | |
406 | + { | |
407 | + // set button off | |
408 | + for ( var i = 0; i < this.buttons.length; i++ ) | |
409 | + { | |
410 | + var button = this.buttons[i]; | |
411 | + if ( button.on ) { upd = true; } | |
412 | + button.on = 0; | |
413 | + } | |
414 | + } | |
415 | + return upd; | |
416 | + }; | |
417 | + | |
418 | + /** | |
419 | + * | |
420 | + */ | |
421 | + pt.draw = function( scene ) | |
422 | + { | |
423 | + var context = scene.context; | |
424 | + | |
425 | + context.save(); | |
426 | + | |
427 | + // background | |
428 | + context.fillStyle = Res.Color.BACKGROUND; | |
429 | + context.fillRect( this.rect.x + 2, this.rect.y + 2, this.rect.w - 4, this.rect.h - 4 ); | |
430 | + | |
431 | + // border | |
432 | + context.strokeStyle = Res.Color.BORDER; | |
433 | + context.beginPath(); | |
434 | + context.strokeRect( this.rect.x + 2, this.rect.y + 2, this.rect.w - 4, this.rect.h - 4 ); | |
435 | + | |
436 | + // slider | |
437 | + var slider = this.getSliderRect(); | |
438 | + context.fillStyle = Res.Color.PANEL; | |
439 | + context.fillRect( slider.x, slider.y, slider.w, slider.h ); | |
440 | + | |
441 | + context.strokeStyle = Res.Color.BORDER; | |
442 | + context.beginPath(); | |
443 | + context.strokeRect( slider.x, slider.y, slider.w, slider.h ); | |
444 | + | |
445 | + // button | |
446 | + for ( var i = 0; i < this.buttons.length; i++ ) | |
447 | + { | |
448 | + var button = this.buttons[i]; | |
449 | + context.fillStyle = Res.Color.PANEL; | |
450 | + context.fillRect( button.x, button.y, button.w, button.h ); | |
451 | + | |
452 | + context.strokeStyle = ( button.on ) ? Res.Color.BORDER_BUTTON_ON : Res.Color.BORDER_BUTTON_OFF; | |
453 | + context.beginPath(); | |
454 | + context.strokeRect( button.x, button.y, button.w, button.h ); | |
455 | + } | |
456 | + | |
457 | + context.restore(); | |
458 | + }; | |
459 | +})( ScrollTask.prototype ); | |
460 | + | |
461 | +/** | |
462 | + * StageTask | |
463 | + */ | |
464 | +var StageTask = function( scene ) | |
465 | +{ | |
466 | + this.command = scene.command; // input | |
467 | + this.gridPixels = RenderInfo.mapGridPixels; | |
468 | + this.rect = STAGE_RECT; | |
469 | + this.scroll = { x : 0, y : 0 }; | |
470 | + this.selected = { x : 0, y : 0 }; | |
471 | + this.currentTool = null; | |
472 | + | |
473 | + this.map = null; | |
474 | + this.getMapHeight = function() { return this.map.length; }; | |
475 | + this.getMapWidth = function() { return this.map[0].length; }; | |
476 | + this.actors = null; | |
477 | + | |
478 | + this.draggedValue = -1; | |
479 | + | |
480 | + // scroll task | |
481 | + this.hscrollTask = new ScrollTask( scene, ScrollType.HORIZONTAL, this ); | |
482 | + this.vscrollTask = new ScrollTask( scene, ScrollType.VERTICAL, this ); | |
483 | + // create list | |
484 | + this.child = this.hscrollTask; | |
485 | + this.child.append( this.vscrollTask ); | |
486 | + | |
487 | + // add mouse area | |
488 | + this.command.addMouseArea( new MouseArea( this, this.rect ) ); | |
489 | +}; | |
490 | +StageTask.prototype = new EditorTask(); | |
491 | + | |
492 | +(function( pt ) | |
493 | +{ | |
494 | + /** | |
495 | + * | |
496 | + */ | |
497 | + pt.setData = function( scene, map, actors, resource ) | |
498 | + { | |
499 | + this.map = map; | |
500 | + this.actors = actors; | |
501 | + this.resource = resource; | |
502 | + | |
503 | + // set actor value | |
504 | + this.putActors(); | |
505 | + // default pallete | |
506 | + this.currentTool = scene.chipTask; | |
507 | + }; | |
508 | + | |
509 | + /** | |
510 | + * | |
511 | + */ | |
512 | + pt.getVisibleSize = function() | |
513 | + { | |
514 | + var vw = this.rect.w / this.gridPixels; | |
515 | + var vh = this.rect.h / this.gridPixels; | |
516 | + var mw = this.getMapWidth(); | |
517 | + var mh = this.getMapHeight(); | |
518 | + if ( mw < vw ) | |
519 | + { | |
520 | + vw = mw; | |
521 | + } | |
522 | + if ( mh < vh ) | |
523 | + { | |
524 | + vh = mh; | |
525 | + } | |
526 | + return { w : vw, h : vh }; | |
527 | + }; | |
528 | + /** | |
529 | + * | |
530 | + */ | |
531 | + pt.getMaxScroll = function() | |
532 | + { | |
533 | + var mw = this.getMapWidth() - this.rect.w / this.gridPixels; | |
534 | + var mh = this.getMapHeight() - this.rect.h / this.gridPixels; | |
535 | + if ( mw < 0 ) | |
536 | + { | |
537 | + mw = 0; | |
538 | + } | |
539 | + if ( mh < 0 ) | |
540 | + { | |
541 | + mh = 0; | |
542 | + } | |
543 | + return { w : mw, h : mh }; | |
544 | + }; | |
545 | + /** | |
546 | + * | |
547 | + */ | |
548 | + pt.getSelectedVal = function() | |
549 | + { | |
550 | + var x = this.scroll.x + this.selected.x; | |
551 | + var y = this.scroll.y + this.selected.y; | |
552 | + var w = this.getMapWidth(); | |
553 | + return ( ( y * w ) + x ); | |
554 | + }; | |
555 | + | |
556 | + /** | |
557 | + * | |
558 | + */ | |
559 | + pt.setChipValue = function( x, y, level, value ) | |
560 | + { | |
561 | + var values = []; | |
562 | + for ( var i = 0; i < 3; i++ ) | |
563 | + { | |
564 | + values[i] = ( level == i ) ? value : this.getChipValue( x, y, i ); | |
565 | + for ( var n = 0; n < i; n++ ) | |
566 | + { | |
567 | + values[i] *= MapInfo.maxValue; | |
568 | + } | |
569 | + } | |
570 | + var retValue = 0; | |
571 | + for ( var i = 0; i < values.length; i++ ) | |
572 | + { | |
573 | + retValue += values[i]; | |
574 | + } | |
575 | + this.map[ y ][ x ] = retValue; | |
576 | + }; | |
577 | + /** | |
578 | + * | |
579 | + */ | |
580 | + pt.getChipValue = function( x, y, level ) | |
581 | + { | |
582 | + var val = this.map[ y ][ x ]; | |
583 | + for ( var i = 0; i < level; i++ ) | |
584 | + { | |
585 | + val /= MapInfo.maxValue; | |
586 | + } | |
587 | + return Math.floor( val ) % MapInfo.maxValue; | |
588 | + }; | |
589 | + | |
590 | + /** | |
591 | + * | |
592 | + */ | |
593 | + pt.setActorId = function( x, y, id ) | |
594 | + { | |
595 | + this.setChipValue( x, y, MapInfo.actorLevel, ( id + 1 ) ); | |
596 | + }; | |
597 | + /** | |
598 | + * | |
599 | + */ | |
600 | + pt.clearActorId = function( x, y ) | |
601 | + { | |
602 | + this.setChipValue( x, y, MapInfo.actorLevel, 0 ); | |
603 | + }; | |
604 | + /** | |
605 | + * | |
606 | + */ | |
607 | + pt.getActorId = function( x, y ) | |
608 | + { | |
609 | + var val = this.getChipValue( x, y, MapInfo.actorLevel ); | |
610 | + return ( val - 1 ); | |
611 | + }; | |
612 | + | |
613 | + /** | |
614 | + * | |
615 | + */ | |
616 | + pt.putActors = function() | |
617 | + { | |
618 | + for ( var i = 0; i < this.actors.length; i++ ) | |
619 | + { | |
620 | + var actor = this.actors[i]; | |
621 | + var x = Math.floor( actor.x ); | |
622 | + var y = Math.floor( actor.y ); | |
623 | + this.setActorId( x, y, i ); | |
624 | + } | |
625 | + }; | |
626 | + | |
627 | + /** | |
628 | + * | |
629 | + */ | |
630 | + pt.writeChip = function( mx, my, level, value ) | |
631 | + { | |
632 | + var upd = false; | |
633 | + | |
634 | + // drag actor | |
635 | + if ( this.draggedValue >= 0 ) | |
636 | + { | |
637 | + var actor = this.actors[ this.draggedValue ]; | |
638 | + var x = Math.floor( actor.x ); | |
639 | + var y = Math.floor( actor.y ); | |
640 | + if ( x != mx || y != my ) | |
641 | + { | |
642 | + // clear old | |
643 | + this.clearActorId( x, y ); | |
644 | + // update new | |
645 | + actor.x = mx + 0.5; | |
646 | + actor.y = my + 0.5; | |
647 | + this.setActorId( mx, my, this.draggedValue ); | |
648 | + | |
649 | + upd = true; | |
650 | + } | |
651 | + } | |
652 | + else | |
653 | + { | |
654 | + // チップの更新 | |
655 | + var curValue = this.getChipValue( mx, my, level ); | |
656 | + if ( curValue != value ) | |
657 | + { | |
658 | + this.setChipValue( mx, my, level, value ); | |
659 | + upd = true; | |
660 | + } | |
661 | + } | |
662 | + return upd; | |
663 | + }; | |
664 | + /** | |
665 | + * | |
666 | + */ | |
667 | + pt.writeActor = function( mx, my, value ) | |
668 | + { | |
669 | + var upd = false; | |
670 | + | |
671 | + var id = this.getActorId( mx, my ); | |
672 | + var type = value - 1; | |
673 | + | |
674 | + // no actor | |
675 | + if ( id < 0 ) | |
676 | + { | |
677 | + // not erase >> add | |
678 | + if ( value > 0 ) | |
679 | + { | |
680 | + // copy | |
681 | + var actorSrc = this.actors[0]; | |
682 | + var actorDst = {}; | |
683 | + for ( var key in actorSrc ) | |
684 | + { | |
685 | + actorDst[ key ] = actorSrc[ key ]; | |
686 | + } | |
687 | + // customize | |
688 | + actorDst.type = type; | |
689 | + actorDst.name = Res.String.DEFAULT_NAME; | |
690 | + actorDst.x = mx + 0.5; | |
691 | + actorDst.y = my + 0.5; | |
692 | + // add | |
693 | + this.actors.push( actorDst ); | |
694 | + this.putActors(); | |
695 | + | |
696 | + upd = true; | |
697 | + } | |
698 | + } | |
699 | + // actor exists | |
700 | + else | |
701 | + { | |
702 | + // erase | |
703 | + if ( value == 0 ) | |
704 | + { | |
705 | + // can not erase actors[0] | |
706 | + if ( id > 0 ) | |
707 | + { | |
708 | + this.clearActorId( mx, my ); | |
709 | + this.actors.splice( id, 1 ); | |
710 | + this.putActors(); | |
711 | + upd = true; | |
712 | + } | |
713 | + } | |
714 | + // replace | |
715 | + else | |
716 | + { | |
717 | + this.actors[ id ].type = type; | |
718 | + upd = true; | |
719 | + } | |
720 | + } | |
721 | + return upd; | |
722 | + }; | |
723 | + | |
724 | + /** | |
725 | + * | |
726 | + */ | |
727 | + pt.update = function( scene ) | |
728 | + { | |
729 | + var upd = false; | |
730 | + | |
731 | + if ( this.command.mouse && this.command.mouseInfo.target == this ) | |
732 | + { | |
733 | + var vs = this.getVisibleSize(); | |
734 | + var sx = Math.floor( this.command.mouseInfo.ox / this.gridPixels ); | |
735 | + var sy = Math.floor( this.command.mouseInfo.oy / this.gridPixels ); | |
736 | + | |
737 | + if ( sx < vs.w && sy < vs.h ) | |
738 | + { | |
739 | + // update selection | |
740 | + if ( ( sx != this.selected.x || sy != this.selected.y ) ) | |
741 | + { | |
742 | + this.selected.x = sx; | |
743 | + this.selected.y = sy; | |
744 | + upd = true; | |
745 | + } | |
746 | + | |
747 | + // update map | |
748 | + var value = this.currentTool.getSelectedVal(); | |
749 | + var mx = sx + this.scroll.x; | |
750 | + var my = sy + this.scroll.y; | |
751 | + if ( this.currentTool == scene.chipTask ) | |
752 | + { | |
753 | + if ( this.writeChip( mx, my, MapInfo.chipLevel, value ) ) { upd = true; } | |
754 | + } | |
755 | + else if ( this.currentTool == scene.chipTrTask ) | |
756 | + { | |
757 | + if ( this.writeChip( mx, my, MapInfo.chipTrLevel, value ) ) { upd = true; } | |
758 | + } | |
759 | + else | |
760 | + { | |
761 | + if ( this.writeActor( mx, my, value ) ) { upd = true; } | |
762 | + } | |
763 | + | |
764 | + // set drag param | |
765 | + if ( this.draggedValue == -1 ) | |
766 | + { | |
767 | + this.draggedValue = this.getActorId( mx, my ); | |
768 | + } | |
769 | + } | |
770 | + } | |
771 | + else | |
772 | + { | |
773 | + // clear drag param | |
774 | + if ( this.draggedValue != -1 ) | |
775 | + { | |
776 | + this.draggedValue = -1; | |
777 | + } | |
778 | + } | |
779 | + | |
780 | + // update scrollbar | |
781 | + if ( !upd ) | |
782 | + { | |
783 | + upd = this.updateChildren( scene ); | |
784 | + } | |
785 | + return upd; | |
786 | + }; | |
787 | + | |
788 | + /** | |
789 | + * 描画する。 | |
790 | + */ | |
791 | + pt.draw = function( scene ) | |
792 | + { | |
793 | + var context = scene.context; | |
794 | + var vs = this.getVisibleSize(); | |
795 | + | |
796 | + context.save(); | |
797 | + | |
798 | + // background | |
799 | + this.drawBackground( context ); | |
800 | + | |
801 | + // map | |
802 | + for ( var i = 0; i < vs.h; i++ ) | |
803 | + { | |
804 | + for ( var j = 0; j < vs.w; j++ ) | |
805 | + { | |
806 | + var mx = this.scroll.x + j; | |
807 | + var my = this.scroll.y + i; | |
808 | + | |
809 | + var value; | |
810 | + var image; | |
811 | + var sx, sy; | |
812 | + var sw = RenderInfo.chipPixels; | |
813 | + var sh = RenderInfo.chipPixels; | |
814 | + var dx = this.rect.x + ( j * this.gridPixels ); | |
815 | + var dy = this.rect.y + ( i * this.gridPixels ); | |
816 | + var dw = this.gridPixels; | |
817 | + var dh = this.gridPixels; | |
818 | + var cw; | |
819 | + | |
820 | + // draw chip | |
821 | + value = this.getChipValue( mx, my, MapInfo.chipLevel ); | |
822 | + image = this.resource.image.mchip.data; | |
823 | + cw = image.width / RenderInfo.chipPixels; | |
824 | + sx = ( value % cw ) * RenderInfo.chipPixels; | |
825 | + sy = Math.floor( value / cw ) * RenderInfo.chipPixels; | |
826 | + context.drawImage( image, sx, sy, sw, sh, dx, dy, dw, dh ); | |
827 | + // draw tr chip | |
828 | + value = this.getChipValue( mx, my, MapInfo.chipTrLevel ); | |
829 | + if ( value > 0 ) | |
830 | + { | |
831 | + image = this.resource.image.mchip_tr.data; | |
832 | + cw = image.width / RenderInfo.chipPixels; | |
833 | + sx = ( value % cw ) * RenderInfo.chipPixels; | |
834 | + sy = Math.floor( value / cw ) * RenderInfo.chipPixels; | |
835 | + context.drawImage( image, sx, sy, sw, sh, dx, dy, dw, dh ); | |
836 | + } | |
837 | + // draw actor | |
838 | + var id = this.getActorId( mx, my ); | |
839 | + if ( id >= 0 ) | |
840 | + { | |
841 | + image = this.resource.image.actors[ this.actors[ id ].type ].data; | |
842 | + sx = 0; | |
843 | + sy = 0; | |
844 | + sw = Math.floor( image.width / RenderInfo.actorFramesW ); | |
845 | + sh = Math.floor( image.height / RenderInfo.actorFramesH ); | |
846 | + if ( id == 0 ) | |
847 | + { | |
848 | + context.fillStyle = Res.Color.ACTOR_0; | |
849 | + context.fillRect( dx + 3, dy + 3, dw - 6, dh - 6 ); | |
850 | + } | |
851 | + context.drawImage( image, sx, sy, sw, sh, dx, dy, dw, dh ); | |
852 | + } | |
853 | + } | |
854 | + } | |
855 | + // grid line | |
856 | + this.drawGridLine( context ); | |
857 | + // selected | |
858 | + this.drawSelected( context ); | |
859 | + // border | |
860 | + this.drawBorder( context ); | |
861 | + | |
862 | + context.restore(); | |
863 | + | |
864 | + // draw scrollbar | |
865 | + this.drawChildren( scene ); | |
866 | + }; | |
867 | +})( StageTask.prototype ); | |
868 | + | |
869 | +/** | |
870 | + * ChipType | |
871 | + */ | |
872 | +var ChipType = | |
873 | +{ | |
874 | + NORMAL : 0, | |
875 | + TRANSPARENT : 1 | |
876 | +}; | |
877 | + | |
878 | +/** | |
879 | + * ChipTask | |
880 | + */ | |
881 | +var ChipTask = function( scene, type ) | |
882 | +{ | |
883 | + this.type = type; | |
884 | + this.image = null; | |
885 | + | |
886 | + this.command = scene.command; // input | |
887 | + this.gridPixels = RenderInfo.chipGridPixels; | |
888 | + this.rect = ( this.type == ChipType.NORMAL ) ? CHIP_RECT : CHIP_TR_RECT; | |
889 | + this.scroll = { x : 0, y : 0 }; | |
890 | + this.selected = { x : 0, y : 0 }; | |
891 | + | |
892 | + // scroll task | |
893 | + this.vscrollTask = new ScrollTask( scene, ScrollType.VERTICAL, this ); | |
894 | + this.vscrollTask = new ScrollTask( scene, ScrollType.VERTICAL, this ); | |
895 | + this.child = this.vscrollTask; | |
896 | + | |
897 | + | |
898 | + // add mouse area | |
899 | + this.command.addMouseArea( new MouseArea( this, this.rect ) ); | |
900 | +}; | |
901 | +ChipTask.prototype = new EditorTask(); | |
902 | + | |
903 | +(function( pt ) | |
904 | +{ | |
905 | + /** | |
906 | + * | |
907 | + */ | |
908 | + pt.setData = function( scene, resource ) | |
909 | + { | |
910 | + this.resource = resource; | |
911 | + | |
912 | + this.image = ( this.type == ChipType.NORMAL ) ? | |
913 | + resource.image.mchip.data : resource.image.mchip_tr.data; | |
914 | + }; | |
915 | + /** | |
916 | + * | |
917 | + */ | |
918 | + pt.getVisibleSize = function() | |
919 | + { | |
920 | + var vw = this.rect.w / this.gridPixels; | |
921 | + var iw = this.image.width / RenderInfo.chipPixels; | |
922 | + if ( iw < vw ) | |
923 | + { | |
924 | + vw = iw; | |
925 | + } | |
926 | + var vh = this.rect.h / this.gridPixels; | |
927 | + var ih = this.image.height / RenderInfo.chipPixels; | |
928 | + if ( ih < vh ) | |
929 | + { | |
930 | + vh = ih; | |
931 | + } | |
932 | + return { w : vw, h : vh }; | |
933 | + }; | |
934 | + /** | |
935 | + * | |
936 | + */ | |
937 | + pt.getMaxScroll = function() | |
938 | + { | |
939 | + var vw = this.rect.w / this.gridPixels; | |
940 | + var iw = this.image.width / RenderInfo.chipPixels; | |
941 | + var mw = iw - vw; | |
942 | + if ( mw < 0 ) | |
943 | + { | |
944 | + mw = 0; | |
945 | + } | |
946 | + var vh = this.rect.h / this.gridPixels; | |
947 | + var ih = this.image.height / RenderInfo.chipPixels; | |
948 | + var mh = ih - vh; | |
949 | + if ( mh < 0 ) | |
950 | + { | |
951 | + mh = 0; | |
952 | + } | |
953 | + return { w : mw, h : mh }; | |
954 | + }; | |
955 | + /** | |
956 | + * | |
957 | + */ | |
958 | + pt.getSelectedVal = function() | |
959 | + { | |
960 | + var x = this.scroll.x + this.selected.x; | |
961 | + var y = this.scroll.y + this.selected.y; | |
962 | + var w = this.image.width / RenderInfo.chipPixels; | |
963 | + return ( ( y * w ) + x ); | |
964 | + }; | |
965 | + /** | |
966 | + * | |
967 | + */ | |
968 | + pt.update = function( scene ) | |
969 | + { | |
970 | + var upd = false; | |
971 | + | |
972 | + if ( this.command.mouse && this.command.mouseInfo.target == this ) | |
973 | + { | |
974 | + var vs = this.getVisibleSize(); | |
975 | + var sx = Math.floor( this.command.mouseInfo.ox / this.gridPixels ); | |
976 | + var sy = Math.floor( this.command.mouseInfo.oy / this.gridPixels ); | |
977 | + if ( ( sx != this.selected.x || sy != this.selected.y || scene.stageTask.currentTool != this ) | |
978 | + && sx < vs.w && sy < vs.h ) | |
979 | + { | |
980 | + this.selected.x = sx; | |
981 | + this.selected.y = sy; | |
982 | + scene.stageTask.currentTool = this; | |
983 | + upd = true; | |
984 | + } | |
985 | + } | |
986 | + // update scrollbar | |
987 | + if ( !upd ) | |
988 | + { | |
989 | + upd = this.updateChildren( scene ); | |
990 | + } | |
991 | + return upd; | |
992 | + }; | |
993 | + | |
994 | + /** | |
995 | + * 描画する。 | |
996 | + */ | |
997 | + pt.draw = function( scene ) | |
998 | + { | |
999 | + var context = scene.context; | |
1000 | + var vs = this.getVisibleSize(); | |
1001 | + | |
1002 | + context.save(); | |
1003 | + | |
1004 | + // background | |
1005 | + this.drawBackground( context ); | |
1006 | + | |
1007 | + // chip | |
1008 | + context.drawImage( | |
1009 | + this.image, | |
1010 | + this.scroll.x * RenderInfo.chipPixels, // sx | |
1011 | + this.scroll.y * RenderInfo.chipPixels, // sy | |
1012 | + vs.w * RenderInfo.chipPixels, // sw | |
1013 | + vs.h * RenderInfo.chipPixels, // sh | |
1014 | + this.rect.x, // dx | |
1015 | + this.rect.y, // dy | |
1016 | + vs.w * this.gridPixels, // dw | |
1017 | + vs.h * this.gridPixels // dh | |
1018 | + ); | |
1019 | + // grid line | |
1020 | + this.drawGridLine( context ); | |
1021 | + // selected | |
1022 | + if ( scene.stageTask.currentTool == this ) | |
1023 | + { | |
1024 | + this.drawSelected( context ); | |
1025 | + } | |
1026 | + // border | |
1027 | + this.drawBorder( context ); | |
1028 | + | |
1029 | + context.restore(); | |
1030 | + | |
1031 | + // draw scrollbar | |
1032 | + this.drawChildren( scene ); | |
1033 | + }; | |
1034 | +})( ChipTask.prototype ); | |
1035 | + | |
1036 | +/** | |
1037 | + * ActorTask | |
1038 | + */ | |
1039 | +var ActorTask = function( scene ) | |
1040 | +{ | |
1041 | + this.command = scene.command; // input | |
1042 | + this.gridPixels = RenderInfo.chipGridPixels; | |
1043 | + this.rect = ACTOR_RECT; | |
1044 | + this.scroll = { x : 0, y : 0 }; | |
1045 | + this.selected = { x : 0, y : 0 }; | |
1046 | + | |
1047 | + // scroll task | |
1048 | + this.vscrollTask = new ScrollTask( scene, ScrollType.VERTICAL, this ); | |
1049 | + this.child = this.vscrollTask; | |
1050 | + | |
1051 | + // add mouse area | |
1052 | + this.command.addMouseArea( new MouseArea( this, this.rect ) ); | |
1053 | +}; | |
1054 | +ActorTask.prototype = new EditorTask(); | |
1055 | + | |
1056 | +(function( pt ) | |
1057 | +{ | |
1058 | + /** | |
1059 | + * | |
1060 | + */ | |
1061 | + pt.setData = function( scene, resource ) | |
1062 | + { | |
1063 | + this.resource = resource; | |
1064 | + }; | |
1065 | + /** | |
1066 | + * | |
1067 | + */ | |
1068 | + pt.getVisibleSize = function() | |
1069 | + { | |
1070 | + var vh = this.rect.h / this.gridPixels; | |
1071 | + var images = this.resource.image.actors.length + 1; // +空白セル | |
1072 | + if ( images < vh ) | |
1073 | + { | |
1074 | + vh = images; | |
1075 | + } | |
1076 | + return { w : 1, h : vh }; | |
1077 | + }; | |
1078 | + /** | |
1079 | + * | |
1080 | + */ | |
1081 | + pt.getMaxScroll = function() | |
1082 | + { | |
1083 | + var vh = this.rect.h / this.gridPixels; | |
1084 | + var images = this.resource.image.actors.length + 1; // +空白セル | |
1085 | + var mh = images - vh; | |
1086 | + if ( mh < 0 ) | |
1087 | + { | |
1088 | + mh = 0; | |
1089 | + } | |
1090 | + return { w : 0, h : mh }; | |
1091 | + }; | |
1092 | + /** | |
1093 | + * | |
1094 | + */ | |
1095 | + pt.getSelectedVal = function() | |
1096 | + { | |
1097 | + return this.scroll.y + this.selected.y; | |
1098 | + }; | |
1099 | + /** | |
1100 | + * | |
1101 | + */ | |
1102 | + pt.update = function( scene ) | |
1103 | + { | |
1104 | + var upd = false; | |
1105 | + if ( this.command.mouse && this.command.mouseInfo.target == this ) | |
1106 | + { | |
1107 | + var vs = this.getVisibleSize(); | |
1108 | + var sy = Math.floor( this.command.mouseInfo.oy / this.gridPixels ); | |
1109 | + if ( ( sy != this.selected.y || scene.stageTask.currentTool != this ) && sy < vs.h ) | |
1110 | + { | |
1111 | + this.selected.y = sy; | |
1112 | + scene.stageTask.currentTool = this; | |
1113 | + upd = true; | |
1114 | + } | |
1115 | + } | |
1116 | + // update scrollbar | |
1117 | + if ( !upd ) | |
1118 | + { | |
1119 | + upd = this.updateChildren( scene ); | |
1120 | + } | |
1121 | + return upd; | |
1122 | + }; | |
1123 | + | |
1124 | + /** | |
1125 | + * 描画する。 | |
1126 | + */ | |
1127 | + pt.draw = function( scene ) | |
1128 | + { | |
1129 | + var context = scene.context; | |
1130 | + var actors = scene.stageTask.actors; | |
1131 | + var vs = this.getVisibleSize(); | |
1132 | + | |
1133 | + context.save(); | |
1134 | + | |
1135 | + // background | |
1136 | + this.drawBackground( context ); | |
1137 | + | |
1138 | + // actor | |
1139 | + for ( var i = 1; i < vs.h; i++ ) // 空白セルはスキップ | |
1140 | + { | |
1141 | + var image = this.resource.image.actors[ i - 1 + this.scroll.y ].data; | |
1142 | + var sw = Math.floor( image.width / RenderInfo.actorFramesW ); | |
1143 | + var sh = Math.floor( image.height / RenderInfo.actorFramesH ); | |
1144 | + context.drawImage( | |
1145 | + image, | |
1146 | + 0, // sx | |
1147 | + 0, // sy | |
1148 | + sw, // sw | |
1149 | + sh, // sh | |
1150 | + this.rect.x, // dx | |
1151 | + this.rect.y + ( i * this.gridPixels ), // dy | |
1152 | + this.gridPixels, // dw | |
1153 | + this.gridPixels // dh | |
1154 | + ); | |
1155 | + } | |
1156 | + // grid line | |
1157 | + this.drawGridLine( context ); | |
1158 | + // selected | |
1159 | + if ( scene.stageTask.currentTool == this ) | |
1160 | + { | |
1161 | + this.drawSelected( context ); | |
1162 | + } | |
1163 | + // border | |
1164 | + this.drawBorder( context ); | |
1165 | + | |
1166 | + context.restore(); | |
1167 | + | |
1168 | + // draw scrollbar | |
1169 | + this.drawChildren( scene ); | |
1170 | + }; | |
1171 | +})( ActorTask.prototype ); | |
1172 | + | |
1173 | +/** | |
1174 | + * FormTask | |
1175 | + */ | |
1176 | +var FormTask = function( scene ) | |
1177 | +{ | |
1178 | + this.command = scene.command; // input | |
1179 | + this.currentValue = -1; | |
1180 | + this.currentActor = null; | |
1181 | +}; | |
1182 | +FormTask.prototype = new Task(); | |
1183 | + | |
1184 | +(function( pt ) | |
1185 | +{ | |
1186 | + pt.ID_ACTOR_NAME = "actorName"; | |
1187 | + pt.ID_EVENT_TYPE = "eventType"; | |
1188 | + pt.ID_EVENT_PARAM = "eventParam"; | |
1189 | + | |
1190 | + pt.eventNameId = {}; | |
1191 | + pt.eventNameId[ EventType.NONE ] = 0; | |
1192 | + pt.eventNameId[ EventType.TEXT ] = 1; | |
1193 | + pt.eventNameId[ EventType.BATTLE ] = 2; | |
1194 | + pt.eventNameId[ EventType.WARP ] = 3; | |
1195 | + pt.eventIdName = | |
1196 | + { | |
1197 | + 0 : EventType.NONE, | |
1198 | + 1 : EventType.TEXT, | |
1199 | + 2 : EventType.BATTLE, | |
1200 | + 3 : EventType.WARP | |
1201 | + }; | |
1202 | + | |
1203 | + /** | |
1204 | + * | |
1205 | + */ | |
1206 | + pt.formToActor = function( app, actor ) | |
1207 | + { | |
1208 | + var actorName = app.getDomElement( this.ID_ACTOR_NAME ); | |
1209 | + var eventType = app.getDomElement( this.ID_EVENT_TYPE ); | |
1210 | + var eventParam = app.getDomElement( this.ID_EVENT_PARAM ); | |
1211 | + if ( !actorName || !eventType || !eventParam ) | |
1212 | + { | |
1213 | + return; | |
1214 | + } | |
1215 | + // set actor | |
1216 | + actor.name = actorName.value; | |
1217 | + actor.event.type = this.eventIdName[ eventType.selectedIndex ]; | |
1218 | + if ( actor.event.type == EventType.TEXT ) | |
1219 | + { | |
1220 | + actor.event.text = eventParam.value; | |
1221 | + } | |
1222 | + else if ( actor.event.type == EventType.WARP ) | |
1223 | + { | |
1224 | + actor.event.baseUrl = eventParam.value; | |
1225 | + } | |
1226 | + }; | |
1227 | + /** | |
1228 | + * | |
1229 | + */ | |
1230 | + pt.actorToForm = function( app, actor ) | |
1231 | + { | |
1232 | + var actorName = app.getDomElement( this.ID_ACTOR_NAME ); | |
1233 | + var eventType = app.getDomElement( this.ID_EVENT_TYPE ); | |
1234 | + var eventParam = app.getDomElement( this.ID_EVENT_PARAM ); | |
1235 | + if ( !actorName || !eventType || !eventParam ) | |
1236 | + { | |
1237 | + return; | |
1238 | + } | |
1239 | + // set form | |
1240 | + actorName.value = actor.name; | |
1241 | + eventType.selectedIndex = this.eventNameId[ actor.event.type ]; | |
1242 | + eventParam.value = ""; | |
1243 | + if ( actor.event.type == EventType.TEXT ) | |
1244 | + { | |
1245 | + eventParam.value = actor.event.text; | |
1246 | + } | |
1247 | + else if ( actor.event.type == EventType.WARP ) | |
1248 | + { | |
1249 | + eventParam.value = actor.event.baseUrl; | |
1250 | + } | |
1251 | + }; | |
1252 | + /** | |
1253 | + * | |
1254 | + */ | |
1255 | + pt.clearForm = function( app ) | |
1256 | + { | |
1257 | + var actorName = app.getDomElement( this.ID_ACTOR_NAME ); | |
1258 | + var eventType = app.getDomElement( this.ID_EVENT_TYPE ); | |
1259 | + var eventParam = app.getDomElement( this.ID_EVENT_PARAM ); | |
1260 | + if ( !actorName || !eventType || !eventParam ) | |
1261 | + { | |
1262 | + return; | |
1263 | + } | |
1264 | + // clear | |
1265 | + actorName.value = ""; | |
1266 | + eventType.selectedIndex = 0; | |
1267 | + eventParam.value = ""; | |
1268 | + }; | |
1269 | + /** | |
1270 | + * | |
1271 | + */ | |
1272 | + pt.update = function( scene ) | |
1273 | + { | |
1274 | + var app = scene.app; | |
1275 | + var stage = scene.stageTask; | |
1276 | + var selectedVal = stage.getSelectedVal(); | |
1277 | + var id = stage.getActorId( | |
1278 | + stage.scroll.x + stage.selected.x, | |
1279 | + stage.scroll.y + stage.selected.y | |
1280 | + ); | |
1281 | + | |
1282 | + if ( this.currentValue != selectedVal ) | |
1283 | + { | |
1284 | + // if old is actor | |
1285 | + if ( this.currentActor != null ) | |
1286 | + { | |
1287 | + this.formToActor( app, this.currentActor ); | |
1288 | + } | |
1289 | + // if new is actor | |
1290 | + if ( id >= 0 ) | |
1291 | + { | |
1292 | + this.currentActor = stage.actors[ id ]; | |
1293 | + this.actorToForm( app, this.currentActor ); | |
1294 | + } | |
1295 | + else | |
1296 | + { | |
1297 | + this.currentActor = null; | |
1298 | + this.clearForm( app ); | |
1299 | + } | |
1300 | + // set current | |
1301 | + this.currentValue = selectedVal; | |
1302 | + } | |
1303 | + return false; | |
1304 | + }; | |
1305 | +})( FormTask.prototype ); | |
1306 | + | |
1307 | + | |
1308 | +/** | |
1309 | + * MouseArea | |
1310 | + */ | |
1311 | +var MouseArea = function( target, rect ) | |
1312 | +{ | |
1313 | + this.target = target; | |
1314 | + this.rect = rect; | |
1315 | +}; | |
1316 | + | |
1317 | +/** | |
1318 | + * InputCommand | |
1319 | + */ | |
1320 | +var InputCommand = function() | |
1321 | +{ | |
1322 | + this.tbl.escape = 0; | |
1323 | + this.tbl.mouse = 0; | |
1324 | + this.mouseInfo = | |
1325 | + { | |
1326 | + target : null, | |
1327 | + x : 0, | |
1328 | + y : 0, | |
1329 | + ox : 0, | |
1330 | + oy : 0 | |
1331 | + }; | |
1332 | + this.mouseAreas = []; | |
1333 | +}; | |
1334 | +InputCommand.prototype = new Command(); | |
1335 | + | |
1336 | +(function( pt ) | |
1337 | +{ | |
1338 | + /** | |
1339 | + * | |
1340 | + */ | |
1341 | + pt.handleSysEvent = function( event ) | |
1342 | + { | |
1343 | + var type = event.type.toLowerCase(); | |
1344 | + if ( type.substring( 0, 3 ) == "key" ) | |
1345 | + { | |
1346 | + var value = 0; | |
1347 | + if ( type == "keydown" ) { value = 1; } | |
1348 | + else if ( type == "keyup" ) { value = 0; } | |
1349 | + | |
1350 | + switch ( event.keyCode ) | |
1351 | + { | |
1352 | + case 27: this.tbl.escape = value; break; // ESC | |
1353 | + } | |
1354 | + } | |
1355 | + else if ( type == "mousedown" ) | |
1356 | + { | |
1357 | + if ( this.getMouseArea( event.layerX, event.layerY ) ) | |
1358 | + { | |
1359 | + this.mouse = 1; | |
1360 | + } | |
1361 | + else | |
1362 | + { | |
1363 | + this.mouse = 0; | |
1364 | + } | |
1365 | + } | |
1366 | + else if ( type == "mousemove" ) | |
1367 | + { | |
1368 | + if ( this.mouse ) | |
1369 | + { | |
1370 | + if ( !this.getMouseArea( event.layerX, event.layerY ) ) | |
1371 | + { | |
1372 | + this.mouse = 0; | |
1373 | + } | |
1374 | + } | |
1375 | + } | |
1376 | + else if ( type == "mouseup" || type == "mouseout" ) | |
1377 | + { | |
1378 | + this.mouse = 0; | |
1379 | + } | |
1380 | + }; | |
1381 | + /** | |
1382 | + * | |
1383 | + */ | |
1384 | + pt.getMouseArea = function( x, y ) | |
1385 | + { | |
1386 | + for ( var i = this.mouseAreas.length - 1; i >= 0; i-- ) | |
1387 | + { | |
1388 | + var area = this.mouseAreas[i]; | |
1389 | + if ( area.rect.x <= x && x <= area.rect.x + area.rect.w && | |
1390 | + area.rect.y <= y && y <= area.rect.y + area.rect.h ) | |
1391 | + { | |
1392 | + this.mouseInfo.target = area.target; | |
1393 | + this.mouseInfo.x = x; | |
1394 | + this.mouseInfo.y = y; | |
1395 | + this.mouseInfo.ox = x - area.rect.x; | |
1396 | + this.mouseInfo.oy = y - area.rect.y; | |
1397 | +//Debug.print( "x=" + x + ", y=" + y + ", ox=" + this.mouseInfo.ox + ", oy=" + this.mouseInfo.oy ); | |
1398 | + return area; | |
1399 | + } | |
1400 | + } | |
1401 | + return null; | |
1402 | + }; | |
1403 | + /** | |
1404 | + * | |
1405 | + */ | |
1406 | + pt.addMouseArea = function( area ) | |
1407 | + { | |
1408 | + this.mouseAreas.push( area ); | |
1409 | + }; | |
1410 | + /** | |
1411 | + * | |
1412 | + */ | |
1413 | + pt.removeMouseArea = function( area ) | |
1414 | + { | |
1415 | + for ( var i = 0; i < this.mouseAreas.length; i++ ) | |
1416 | + { | |
1417 | + if ( this.mouseAreas[i] == area ) | |
1418 | + { | |
1419 | + this.mouseAreas.splice( i, 1 ); | |
1420 | + break; | |
1421 | + } | |
1422 | + } | |
1423 | + }; | |
1424 | +})( InputCommand.prototype ); | |
1425 | + | |
1426 | +/** | |
1427 | + * EditorScene | |
1428 | + */ | |
1429 | +var EditorScene = function( app, name ) | |
1430 | +{ | |
1431 | + this.app = app; | |
1432 | + this.name = name; | |
1433 | + this.data = null; | |
1434 | + this.stageName = null; | |
1435 | + | |
1436 | + this.command = new InputCommand(); | |
1437 | + | |
1438 | + // create task | |
1439 | + this.panelTask = new PanelTask( this ); | |
1440 | + this.stageTask = new StageTask( this ); | |
1441 | + this.chipTask = new ChipTask( this, ChipType.NORMAL ); | |
1442 | + this.chipTrTask = new ChipTask( this, ChipType.TRANSPARENT ); | |
1443 | + this.actorTask = new ActorTask( this ); | |
1444 | + this.formTask = new FormTask( this ); | |
1445 | + // create list | |
1446 | + this.panelTask.append( this.stageTask ); | |
1447 | + this.panelTask.append( this.chipTask ); | |
1448 | + this.panelTask.append( this.chipTrTask ); | |
1449 | + this.panelTask.append( this.actorTask ); | |
1450 | + this.panelTask.append( this.formTask ); | |
1451 | + // head of task list | |
1452 | + this.child = this.panelTask; | |
1453 | + this.setStatus( SceneStatus.READY ); | |
1454 | + | |
1455 | + // message handler | |
1456 | + //this.msgManager = new MessageManager(); | |
1457 | +}; | |
1458 | +EditorScene.prototype = new Scene(); | |
1459 | + | |
1460 | +(function( pt ) | |
1461 | +{ | |
1462 | + /** | |
1463 | + * | |
1464 | + */ | |
1465 | + pt.init = function() | |
1466 | + { | |
1467 | + // window.onload のタイミング | |
1468 | + var self = this; | |
1469 | + var button; | |
1470 | + | |
1471 | + // data | |
1472 | + button = this.app.getDomElement( Res.String.ID_DATA ); | |
1473 | + if ( button ) | |
1474 | + { | |
1475 | + this.app.addSysEventHandler( button, "click", function() | |
1476 | + { | |
1477 | + try | |
1478 | + { | |
1479 | + if ( self.app.sceneManager.current == self ) | |
1480 | + { | |
1481 | + var str = self.serializeData( self.data ); | |
1482 | + var win = window.open( "", "_blank" ); | |
1483 | + win.document.write( "<pre>" + str + "</pre>" ); | |
1484 | + win.document.close(); | |
1485 | + } | |
1486 | + } | |
1487 | + catch ( e ) | |
1488 | + { | |
1489 | + self.app.kill(); | |
1490 | + Debug.alertError( e ); | |
1491 | + } | |
1492 | + }); | |
1493 | + } | |
1494 | + }; | |
1495 | + /** | |
1496 | + * | |
1497 | + */ | |
1498 | + pt.show = function() | |
1499 | + { | |
1500 | + this.setUsage( Res.String.HTML_USAGE ); | |
1501 | + | |
1502 | + this.command.clear(); | |
1503 | + this.holdContext(); | |
1504 | + this.draw( this ); | |
1505 | + }; | |
1506 | + | |
1507 | + /** | |
1508 | + * | |
1509 | + */ | |
1510 | + pt.setData = function( data ) | |
1511 | + { | |
1512 | + this.data = data; | |
1513 | + | |
1514 | + // set parameters | |
1515 | + this.stageTask.setData( this, data.map, data.actors, data.resource ); | |
1516 | + this.chipTask.setData( this, data.resource ); | |
1517 | + this.chipTrTask.setData( this, data.resource ); | |
1518 | + this.actorTask.setData( this, data.resource ); | |
1519 | + }; | |
1520 | + /** | |
1521 | + * | |
1522 | + */ | |
1523 | + pt.getData = function() | |
1524 | + { | |
1525 | + return this.data; | |
1526 | + }; | |
1527 | + /** | |
1528 | + * | |
1529 | + */ | |
1530 | + pt.serializeData = function( data ) | |
1531 | + { | |
1532 | + return "window.h5glib.loadDataCB(\n{\n" + this.serializeJson( data ) + "});"; | |
1533 | + } | |
1534 | + /** | |
1535 | + * | |
1536 | + */ | |
1537 | + pt.serializeJson = function( data ) | |
1538 | + { | |
1539 | + var stringify = function( obj ) | |
1540 | + { | |
1541 | + var arr = []; | |
1542 | + arr.push("{ "); | |
1543 | + var i = 0; | |
1544 | + for ( var key in obj ) | |
1545 | + { | |
1546 | + if ( i > 0 ) { arr.push(", "); } | |
1547 | + arr.push( pair( key, obj[ key ] ) ); | |
1548 | + i++; | |
1549 | + } | |
1550 | + arr.push(" }"); | |
1551 | + return arr.join(""); | |
1552 | + }; | |
1553 | + var pair = function( key, value ) | |
1554 | + { | |
1555 | + // object | |
1556 | + if ( typeof( value ) == "object" ) | |
1557 | + { | |
1558 | + return ( key + " : " + stringify( value ) ); | |
1559 | + } | |
1560 | + // string | |
1561 | + else if ( typeof( value ) == "string" ) | |
1562 | + { | |
1563 | + return ( key + " : \"" + value + "\"" ); | |
1564 | + } | |
1565 | + // primitive ? | |
1566 | + else | |
1567 | + { | |
1568 | + return ( key + " : " + value ); | |
1569 | + } | |
1570 | + }; | |
1571 | + | |
1572 | + var arr = []; | |
1573 | + | |
1574 | + // map | |
1575 | + arr.push("\tmap :\n\t["); | |
1576 | + for ( var i = 0; i < data.map.length; i++ ) | |
1577 | + { | |
1578 | + if ( i > 0 ) { arr.push(","); } | |
1579 | + | |
1580 | + arr.push("\n\t\t["); | |
1581 | + for ( var j = 0; j < data.map[i].length; j++ ) | |
1582 | + { | |
1583 | + if ( j > 0 ) { arr.push(","); } | |
1584 | + | |
1585 | + var val = Math.floor( data.map[i][j] ); | |
1586 | + arr.push( val ); | |
1587 | + } | |
1588 | + arr.push("]"); | |
1589 | + } | |
1590 | + arr.push("\n\t],\n"); | |
1591 | + | |
1592 | + // actors | |
1593 | + arr.push("\tactors :\n\t["); | |
1594 | + for ( var i = 0; i < data.actors.length; i++ ) | |
1595 | + { | |
1596 | + if ( i > 0 ) { arr.push(","); } | |
1597 | + | |
1598 | + var actor = data.actors[i]; | |
1599 | + arr.push("\n\t\t{\n"); | |
1600 | + | |
1601 | + arr.push("\t\t\t" + pair( "type", actor.type ) + ",\n"); | |
1602 | + arr.push("\t\t\t" + pair( "name", actor.name ) + ",\n"); | |
1603 | + arr.push("\t\t\t" + pair( "status", actor.status ) + ",\n"); | |
1604 | + arr.push("\t\t\t" + pair( "x", Math.floor( actor.x ) + 0.5 ) + ", " + pair( "y", Math.floor( actor.y ) + 0.5 ) +", " + | |
1605 | + pair( "z", actor.z ) + ", dir : " + actor.dir + ",\n" ); | |
1606 | + arr.push("\t\t\t" + pair( "hp", actor.hp ) + ", " + pair( "mp", actor.mp ) + ",\n" ); | |
1607 | + arr.push("\t\t\t" + pair( "event", actor.event )); | |
1608 | + | |
1609 | + arr.push("\n\t\t}"); | |
1610 | + } | |
1611 | + arr.push("\n\t],\n"); | |
1612 | + | |
1613 | + // resource | |
1614 | + arr.push("\tresource :\n\t{"); | |
1615 | + var resarr = | |
1616 | + [ | |
1617 | + { name : "image", obj : data.resource.image }, | |
1618 | + { name : "sound", obj : data.resource.sound } | |
1619 | + ]; | |
1620 | + for ( var k = 0; k < resarr.length; k++ ) | |
1621 | + { | |
1622 | + // image, sound | |
1623 | + if ( k > 0 ) { arr.push(","); } | |
1624 | + | |
1625 | + arr.push("\n\t\t" + resarr[k].name + " :\n\t\t{"); | |
1626 | + var obj = resarr[k].obj; | |
1627 | + i = 0; | |
1628 | + for ( var key in obj ) | |
1629 | + { | |
1630 | + if ( i > 0 ) { arr.push(","); } | |
1631 | + | |
1632 | + var prop = obj[ key ]; | |
1633 | + if ( prop instanceof Array ) | |
1634 | + { | |
1635 | + arr.push("\n\t\t\t" + key + " :\n\t\t\t["); | |
1636 | + for ( var n = 0; n < prop.length; n++ ) | |
1637 | + { | |
1638 | + if ( n > 0 ) { arr.push(","); } | |
1639 | + arr.push("\n\t\t\t\t{ " + pair( "name", prop[n].name ) + " }"); | |
1640 | + } | |
1641 | + arr.push("\n\t\t\t]"); | |
1642 | + } | |
1643 | + else | |
1644 | + { | |
1645 | + arr.push("\n\t\t\t" + key + " : { " + pair( "name", prop.name ) + " }"); | |
1646 | + } | |
1647 | + i++; | |
1648 | + } | |
1649 | + arr.push("\n\t\t}"); | |
1650 | + } | |
1651 | + arr.push("\n\t},\n"); | |
1652 | + | |
1653 | + // animation | |
1654 | + arr.push("\tanimation :\n\t{"); | |
1655 | + i = 0; | |
1656 | + for ( var key in data.animation ) | |
1657 | + { | |
1658 | + if ( i > 0 ) { arr.push(","); } | |
1659 | + | |
1660 | + var prop = data.animation[ key ]; | |
1661 | + arr.push("\n\t\t" + key + " :\n\t\t{"); | |
1662 | + arr.push("\n\t\t\t" + pair( "frameCount", prop.frameCount ) + ", " + pair( "fw", prop.fw ) + ", " + pair( "fh", prop.fh ) + ","); | |
1663 | + arr.push("\n\t\t\t" + pair( "frames", prop.frames ) ); | |
1664 | + arr.push("\n\t\t}"); | |
1665 | + | |
1666 | + i++; | |
1667 | + } | |
1668 | + arr.push("\n\t}\n"); | |
1669 | + | |
1670 | + return arr.join(""); | |
1671 | + }; | |
1672 | + /** | |
1673 | + * | |
1674 | + */ | |
1675 | + pt.loadData = function( data ) | |
1676 | + { | |
1677 | + try | |
1678 | + { | |
1679 | + // load resource | |
1680 | + this.app.loadResource( this.name, data.resource ); | |
1681 | + // set data | |
1682 | + this.setData( data ); | |
1683 | + // set status | |
1684 | + var self = this; | |
1685 | + window.setTimeout( function() { self.setStatus( SceneStatus.RUNNING ); self.show(); }, Config.loadInterval ); | |
1686 | + } | |
1687 | + catch ( e ) | |
1688 | + { | |
1689 | + this.app.kill(); | |
1690 | + Debug.alertError( e ); | |
1691 | + } | |
1692 | + }; | |
1693 | +})( EditorScene.prototype ); | |
1694 | + | |
1695 | + | |
1696 | +// Expose | |
1697 | +if ( !window.h5glib ) { window.h5glib = {}; } | |
1698 | +window.h5glib.EditorScene = EditorScene; | |
1699 | + | |
1700 | + | |
1701 | +// Anonymous function end | |
1702 | +// | |
1703 | +})( window ); |
@@ -0,0 +1,49 @@ | ||
1 | +/* | |
2 | + * Copyright [yyyy] [name of copyright owner] | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | + | |
17 | + | |
18 | +// Anonymous function | |
19 | +// | |
20 | +(function( window, undefined ) | |
21 | +{ | |
22 | + // initialize | |
23 | + var app = new h5glib.Application(); | |
24 | + | |
25 | + var scene = new h5glib.EditorScene( app, "stage0" ); | |
26 | + | |
27 | + app.sceneManager.add( scene ); | |
28 | + app.sceneManager.push( scene.name ); | |
29 | + | |
30 | + // window.onload のタイミング | |
31 | + app.addSysEventHandler( window, "load", function() | |
32 | + { | |
33 | + app.init(); | |
34 | + }); | |
35 | + | |
36 | + // Expose | |
37 | + if ( !window.h5glib ) { window.h5glib = {}; } | |
38 | + // for debug | |
39 | + if ( h5glib.Config.debug ) | |
40 | + { | |
41 | + window.h5glib.app = app; | |
42 | + } | |
43 | + // JSONP callback func | |
44 | + window.h5glib.loadDataCB = function( json ) | |
45 | + { | |
46 | + app.sceneManager.current.loadData( json ); | |
47 | + }; | |
48 | + | |
49 | +})( window ); |
@@ -43,6 +43,17 @@ | ||
43 | 43 | }; |
44 | 44 | |
45 | 45 | /** |
46 | + * MapInfo | |
47 | + */ | |
48 | +var MapInfo = | |
49 | +{ | |
50 | + maxValue : 1000, | |
51 | + chipLevel : 0, | |
52 | + chipTrLevel : 1, | |
53 | + actorLevel : 2 | |
54 | +}; | |
55 | + | |
56 | +/** | |
46 | 57 | * Res |
47 | 58 | */ |
48 | 59 | var Res = |
@@ -112,6 +123,63 @@ | ||
112 | 123 | /** |
113 | 124 | * |
114 | 125 | */ |
126 | + pt.setChipValue = function( x, y, level, value ) | |
127 | + { | |
128 | + var values = []; | |
129 | + for ( var i = 0; i < 3; i++ ) | |
130 | + { | |
131 | + values[i] = ( level == i ) ? value : this.getChipValue( x, y, i ); | |
132 | + for ( var n = 0; n < i; n++ ) | |
133 | + { | |
134 | + values[i] *= MapInfo.maxValue; | |
135 | + } | |
136 | + } | |
137 | + var retValue = 0; | |
138 | + for ( var i = 0; i < values.length; i++ ) | |
139 | + { | |
140 | + retValue += values[i]; | |
141 | + } | |
142 | + this.map[ y ][ x ] = retValue; | |
143 | + }; | |
144 | + /** | |
145 | + * | |
146 | + */ | |
147 | + pt.getChipValue = function( x, y, level ) | |
148 | + { | |
149 | + var val = this.map[ y ][ x ]; | |
150 | + for ( var i = 0; i < level; i++ ) | |
151 | + { | |
152 | + val /= MapInfo.maxValue; | |
153 | + } | |
154 | + return Math.floor( val ) % MapInfo.maxValue; | |
155 | + }; | |
156 | + | |
157 | + /** | |
158 | + * | |
159 | + */ | |
160 | + pt.setActorId = function( x, y, id ) | |
161 | + { | |
162 | + this.setChipValue( x, y, MapInfo.actorLevel, ( id + 1 ) ); | |
163 | + }; | |
164 | + /** | |
165 | + * | |
166 | + */ | |
167 | + pt.clearActorId = function( x, y ) | |
168 | + { | |
169 | + this.setChipValue( x, y, MapInfo.actorLevel, 0 ); | |
170 | + }; | |
171 | + /** | |
172 | + * | |
173 | + */ | |
174 | + pt.getActorId = function( x, y ) | |
175 | + { | |
176 | + var val = this.getChipValue( x, y, MapInfo.actorLevel ); | |
177 | + return ( val - 1 ); | |
178 | + }; | |
179 | + | |
180 | + /** | |
181 | + * | |
182 | + */ | |
115 | 183 | pt.update = function( scene ) |
116 | 184 | { |
117 | 185 | var upd = false; |
@@ -168,7 +236,7 @@ | ||
168 | 236 | var context = scene.context; |
169 | 237 | var canvas = context.canvas; |
170 | 238 | var resource = scene.data.resource; |
171 | - var viewPoint = scene.viewPoint; | |
239 | + var actorList = scene.actorListTask; | |
172 | 240 | |
173 | 241 | context.save(); |
174 | 242 | //context.clearRect( 0, 0, canvas.width, canvas.height ); |
@@ -184,8 +252,7 @@ | ||
184 | 252 | var offset_x = Math.floor( ( this.scroll.x % 1 ) * RenderInfo.chipPixels ); |
185 | 253 | var offset_y = Math.floor( ( this.scroll.y % 1 ) * RenderInfo.chipPixels ); |
186 | 254 | |
187 | - var image = resource.image.mchip.data; | |
188 | - var image_tr= resource.image.mchip_tr.data; | |
255 | + // チップを描画 | |
189 | 256 | for ( var i = 0; i <= cells_h; i++ ) |
190 | 257 | { |
191 | 258 | for ( var j = 0; j <= cells_w; j++ ) |
@@ -193,32 +260,64 @@ | ||
193 | 260 | if ( i == cells_h && offset_y == 0 ) { break; } |
194 | 261 | if ( j == cells_w && offset_x == 0 ) { continue; } |
195 | 262 | |
196 | - // チップを描画 | |
197 | - var mv = this.map[ scroll_y + i ][ scroll_x + j ]; | |
198 | - var mx = mv % 10; | |
199 | - var my = Math.floor( ( mv % 100 ) / 10 ); | |
200 | - this.drawChip( context, image, i, j, offset_x, offset_y, mx, my ); | |
263 | + var mx = scroll_x + j; | |
264 | + var my = scroll_y + i; | |
201 | 265 | |
202 | - // 透明チップを描画 | |
203 | - var mx_tr = Math.floor( ( mv % 1000 ) / 100 ); | |
204 | - var my_tr = Math.floor( ( mv % 10000 ) / 1000 ); | |
205 | - if ( mx_tr != 0 || my_tr != 0 ) | |
266 | + var image = resource.image.mchip.data; | |
267 | + var value = this.getChipValue( mx, my, MapInfo.chipLevel ); | |
268 | + var cw = image.width / RenderInfo.chipPixels; | |
269 | + var cx = value % cw; | |
270 | + var cy = Math.floor( value / cw ); | |
271 | + this.drawChip( context, image, i, j, offset_x, offset_y, cx, cy ); | |
272 | + } | |
273 | + } | |
274 | + // 透明チップ、アクターを描画 | |
275 | + for ( var i = 0; i <= cells_h; i++ ) | |
276 | + { | |
277 | + for ( var j = 0; j <= cells_w; j++ ) | |
278 | + { | |
279 | + if ( i == cells_h && offset_y == 0 ) { break; } | |
280 | + if ( j == cells_w && offset_x == 0 ) { continue; } | |
281 | + | |
282 | + var mx = scroll_x + j; | |
283 | + var my = scroll_y + i; | |
284 | + | |
285 | + // draw chip | |
286 | + var image = resource.image.mchip_tr.data; | |
287 | + var value = this.getChipValue( mx, my, MapInfo.chipTrLevel ); | |
288 | + if ( value > 0 ) | |
206 | 289 | { |
207 | - this.drawChip( context, image_tr, i, j, offset_x, offset_y, mx_tr, my_tr ); | |
290 | + var cw = image.width / RenderInfo.chipPixels; | |
291 | + var cx = value % cw; | |
292 | + var cy = Math.floor( value / cw ); | |
293 | + this.drawChip( context, image, i, j, offset_x, offset_y, cx, cy ); | |
208 | 294 | } |
295 | + // draw actor | |
296 | + var id = this.getActorId( mx, my ); | |
297 | + if ( id >= 0 ) | |
298 | + { | |
299 | + var actor = actorList.getActor( id ); | |
300 | + if ( actor ) | |
301 | + { | |
302 | + actor.draw( scene ); | |
303 | + actor.drawFlag = true; | |
304 | + } | |
305 | + } | |
209 | 306 | } |
210 | 307 | } |
211 | 308 | context.restore(); |
309 | + | |
310 | +if ( !scene.viewPoint.drawFlag ) { Debug.print("drawFlag=" + scene.viewPoint.drawFlag); } | |
212 | 311 | }; |
213 | 312 | /** |
214 | 313 | * |
215 | 314 | */ |
216 | - pt.drawChip = function( context, image, i, j, offset_x, offset_y, mx, my ) | |
315 | + pt.drawChip = function( context, image, i, j, offset_x, offset_y, cx, cy ) | |
217 | 316 | { |
218 | 317 | var canvas = context.canvas; |
219 | 318 | |
220 | - var sx = mx * RenderInfo.chipPixels; | |
221 | - var sy = my * RenderInfo.chipPixels; | |
319 | + var sx = cx * RenderInfo.chipPixels; | |
320 | + var sy = cy * RenderInfo.chipPixels; | |
222 | 321 | var dx = j * RenderInfo.chipPixels; |
223 | 322 | var dy = i * RenderInfo.chipPixels; |
224 | 323 | var fw = RenderInfo.chipPixels; |
@@ -259,7 +358,6 @@ | ||
259 | 358 | var ActorListTask = function( scene ) |
260 | 359 | { |
261 | 360 | this.command = scene.command; // input |
262 | - this.visible = []; | |
263 | 361 | }; |
264 | 362 | ActorListTask.prototype = new Task(); |
265 | 363 |
@@ -288,84 +386,40 @@ | ||
288 | 386 | } |
289 | 387 | } |
290 | 388 | }; |
291 | - | |
292 | 389 | /** |
293 | 390 | * |
294 | 391 | */ |
295 | - pt.processAction = function( scene ) | |
392 | + pt.getActor = function( id ) | |
296 | 393 | { |
297 | 394 | for ( var actor = this.child; actor != null; actor = actor.next ) |
298 | 395 | { |
299 | - actor.processAction( scene ); | |
396 | + if ( actor.id == id ) | |
397 | + { | |
398 | + return actor; | |
399 | + } | |
300 | 400 | } |
401 | + return null; | |
301 | 402 | }; |
302 | 403 | /** |
303 | 404 | * |
304 | 405 | */ |
305 | - pt.update = function( scene ) | |
406 | + pt.processAction = function( scene ) | |
306 | 407 | { |
307 | - this.processAction( scene ); | |
308 | - | |
309 | - return this.updateChildren( scene ); | |
310 | - }; | |
311 | - /** | |
312 | - * | |
313 | - */ | |
314 | - pt.draw = function( scene ) | |
315 | - { | |
316 | - this.pickVisible( scene ); | |
317 | - | |
318 | - var context = scene.context; | |
319 | - var canvas = context.canvas; | |
320 | - var stage = scene.stageTask; | |
321 | - | |
322 | - context.save(); | |
323 | - | |
324 | - for ( var i = 0; i < this.visible.length; i++ ) | |
408 | + for ( var actor = this.child; actor != null; actor = actor.next ) | |
325 | 409 | { |
326 | - var actor = this.visible[i]; | |
327 | - var image = actor.animator.image; | |
328 | - | |
329 | - var x = Math.floor( ( actor.ad.x - stage.scroll.x ) * RenderInfo.chipPixels ); | |
330 | - var y = Math.floor( ( actor.ad.y - stage.scroll.y ) * RenderInfo.chipPixels ); | |
331 | - | |
332 | - var sy = actor.DIR2SY[ actor.ad.dir ] * actor.animator.fh; | |
333 | - | |
334 | - context.drawImage( | |
335 | - image, | |
336 | - actor.animator.fx, // sx | |
337 | - sy, // sy | |
338 | - actor.animator.fw, // sw | |
339 | - actor.animator.fh, // sh | |
340 | - x - actor.animator.fw / 2, // dx | |
341 | - y - actor.animator.fh / 2, // dy | |
342 | - actor.animator.fw, // dw | |
343 | - actor.animator.fh // dh | |
344 | - ); | |
410 | + actor.processAction( scene ); | |
411 | + // clear draw flag | |
412 | + actor.drawFlag = false; | |
345 | 413 | } |
346 | - context.restore(); | |
347 | 414 | }; |
348 | 415 | /** |
349 | 416 | * |
350 | 417 | */ |
351 | - pt.pickVisible = function( scene ) | |
418 | + pt.update = function( scene ) | |
352 | 419 | { |
353 | - var context = scene.context; | |
354 | - var canvas = context.canvas; | |
355 | - var stage = scene.stageTask; | |
420 | + this.processAction( scene ); | |
356 | 421 | |
357 | - var sw = canvas.width / RenderInfo.chipPixels; | |
358 | - var sh = canvas.height / RenderInfo.chipPixels; | |
359 | - | |
360 | - this.visible.length = 0; | |
361 | - for ( var actor = this.child; actor != null; actor = actor.next ) | |
362 | - { | |
363 | - if ( stage.scroll.x <= actor.ad.x && actor.ad.x <= stage.scroll.x + sw && | |
364 | - stage.scroll.y <= actor.ad.y && actor.ad.y <= stage.scroll.y + sh ) | |
365 | - { | |
366 | - this.visible.push( actor ); | |
367 | - } | |
368 | - } | |
422 | + return this.updateChildren( scene ); | |
369 | 423 | }; |
370 | 424 | })( ActorListTask.prototype ); |
371 | 425 |
@@ -395,6 +449,8 @@ | ||
395 | 449 | count : 0, |
396 | 450 | locked : false |
397 | 451 | } |
452 | + | |
453 | + this.drawFlag = false; | |
398 | 454 | }; |
399 | 455 | ActorTask.prototype = new Task(); |
400 | 456 |
@@ -443,8 +499,10 @@ | ||
443 | 499 | */ |
444 | 500 | pt.moveTo = function( stage, x, y ) |
445 | 501 | { |
502 | + stage.clearActorId( Math.floor( this.ad.x ), Math.floor( this.ad.y ) ); | |
446 | 503 | this.ad.x = x; |
447 | 504 | this.ad.y = y; |
505 | + stage.setActorId( Math.floor( this.ad.x ), Math.floor( this.ad.y ), this.id ); | |
448 | 506 | }; |
449 | 507 | /** |
450 | 508 | * |
@@ -573,6 +631,32 @@ | ||
573 | 631 | } |
574 | 632 | return upd; |
575 | 633 | }; |
634 | + /** | |
635 | + * | |
636 | + */ | |
637 | + pt.draw = function( scene ) | |
638 | + { | |
639 | + var context = scene.context; | |
640 | + var canvas = context.canvas; | |
641 | + var stage = scene.stageTask; | |
642 | + | |
643 | + var image = this.animator.image; | |
644 | + var x = Math.floor( ( this.ad.x - stage.scroll.x ) * RenderInfo.chipPixels ); | |
645 | + var y = Math.floor( ( this.ad.y - stage.scroll.y ) * RenderInfo.chipPixels ); | |
646 | + var sy = this.DIR2SY[ this.ad.dir ] * this.animator.fh; | |
647 | + | |
648 | + context.drawImage( | |
649 | + image, | |
650 | + this.animator.fx, // sx | |
651 | + sy, // sy | |
652 | + this.animator.fw, // sw | |
653 | + this.animator.fh, // sh | |
654 | + x - this.animator.fw / 2, // dx | |
655 | + y - this.animator.fh / 2, // dy | |
656 | + this.animator.fw, // dw | |
657 | + this.animator.fh // dh | |
658 | + ); | |
659 | + }; | |
576 | 660 | })( ActorTask.prototype ); |
577 | 661 | |
578 | 662 | /** |
@@ -113,7 +113,7 @@ | ||
113 | 113 | shoot : { name : "shoot.ogg" }, |
114 | 114 | notice : { name : "notice.ogg" }, |
115 | 115 | battle : { name : "battle.ogg" }, |
116 | - warp : { name : "warp.ogg" }, | |
116 | + warp : { name : "warp.ogg" } | |
117 | 117 | } |
118 | 118 | }, |
119 | 119 | animation : |
@@ -22,10 +22,10 @@ | ||
22 | 22 | // initialize |
23 | 23 | var app = new h5glib.Application(); |
24 | 24 | |
25 | - var editorScene = new h5glib.EditorScene( app, "stage0" ); | |
25 | + var scene = new h5glib.EditorScene( app, "stage0" ); | |
26 | 26 | |
27 | - app.sceneManager.add( editorScene ); | |
28 | - app.sceneManager.push( editorScene.name ); | |
27 | + app.sceneManager.add( scene ); | |
28 | + app.sceneManager.push( scene.name ); | |
29 | 29 | |
30 | 30 | // window.onload のタイミング |
31 | 31 | app.addSysEventHandler( window, "load", function() |