// -*- Mode: Javascript -*- // http://localhost:8080/wnov/majo/ //////////////////////////////////////////////////////////// // 定数 //////////////////////////////////////////////////////////// var WnovView_END = 0; var WnovView_CONTINUE = 1; var COLORFILEMAP = new Array(); COLORFILEMAP[BLACK] = "h99.jpg"; COLORFILEMAP[WHITE] = "h100.jpg"; COLORFILEMAP[RED] = "h101.jpg"; //////////////////////////////////////////////////////////// // コンストラクタ //////////////////////////////////////////////////////////// /** * 表示オブジェクトのコンストラクタ * @return なし */ function WnovView(){ this.textClear = function(){return WnovView_TextClear(this);} this.init = function(env){return WnovView_Init(this, env);} this.getEnv = function(){return WnovView_GetEnv(this);} this.update = function(cmd, fnComp){return WnovView_Update(this, cmd, fnComp);} this.playtitle = ""; this.fnComp = undefined; this.temp = new Sound; this.se = new Sound; this.bgm = new Sound; this.env = new Array(); this.textObj = document.getElementById( "DIVTEXT" ); this.bkImage = function(cmd){return WnovView_BkImage(this, cmd);} } //////////////////////////////////////////////////////////// // メンバメソッド //////////////////////////////////////////////////////////// /** * 文字の消去 * @return なし */ function WnovView_TextClear(it){ var Obj = document.getElementById( "DIVTEXT" ); Obj.innerHTML = ""; } /** * ビュー初期化 * @return なし */ function WnovView_Init(it, env){ WnovView_TextClear(it); // 背景画の初期化 if(undefined != env[HGRAPH] && "" != env[HGRAPH]){ var Obj = document.getElementById( "DIVBACKGROUND" ); Obj.innerHTML = ""; var fileName = COLORFILEMAP[env[HGRAPH][2]]; if(undefined == fileName){ fileName = env[HGRAPH][2]; } if("" != fileName){ divInsertImage("DIVBACKGROUND", "", "bkimage", "img/" + fileName); } it.env[HGRAPH] = env[HGRAPH]; } // 左キャラの初期化 if(undefined != env[LGRAPH] && "" != env[LGRAPH]){ imageSet("CHARA_L0", "img/"+env[LGRAPH][1], env[LGRAPH][2], env[LGRAPH][3]); divSetAlpha("CHARA_L0", 100); it.env[LGRAPH] = env[LGRAPH]; } // 右キャラの初期化 if(undefined != env[RGRAPH] && "" != env[RGRAPH]){ imageSet("CHARA_R0", "img/"+env[RGRAPH][1], 320, 0); divSetAlpha("CHARA_R0", 100) it.env[RGRAPH] = env[RGRAPH]; } // BGMの初期化 if(undefined != env[MUSIC] && "" != env[MUSIC]){ it.bgm.loadSound("se/" + env[MUSIC][1], true, true); it.playtitle = env[MUSIC][1]; it.env[MUSIC] = env[MUSIC]; } } /** * 背景画の処理 * @return なし */ function WnovView_BkImage(it, cmd) { if(undefined == cmd){ return; } if(NEXTPAGE == cmd[1]){ return; } imageSet("CHARA_L0", "img/default.gif", 0, 0); // 左キャラ消去 imageSet("CHARA_R0", "img/default.gif", 320, 0); // 右キャラ消去 var Obj = document.getElementById( "DIVBACKGROUND" ); Obj.innerHTML = ""; Wnov_log("test "+cmd[2]); Wnov_log("test "+COLORFILEMAP[cmd[2]]); var fileName = COLORFILEMAP[cmd[2]]; if(undefined == fileName){ fileName = cmd[2]; } if("" != fileName){ divInsertImage("DIVBACKGROUND", "", "bkimage", "img/" + fileName); } Wnov_log(cmd); Wnov_log(fileName); // 環境更新 it.env[LGRAPH] = [LGRAPH, "default.gif", 0, 0]; it.env[RGRAPH] = [RGRAPH, "default.gif"]; it.env[HGRAPH] = cmd; } /** * 現在の環境(背景画・左キャラ・右キャラ・BGM)を返す * @return 環境 */ function WnovView_GetEnv(it){ return it.env; } /** * 表示を更新 * @param it Viewのインスタンス * @param cmd コマンド * @param fnComp 終了通知コールバック * @return なし */ function WnovView_Update(it, cmd, fnComp){ divClearImage("idWAIT"); // ウェイトカーソル消去 var result = WnovView_EvalCommand(it, cmd);// コマンド評価 // 後処理 if(WnovView_END == result){ setTimeout(fnComp, 0); } if(WnovView_CONTINUE == result){ it.fnComp = fnComp; } return; } /** * コマンドを評価する * @param it WnovModelのインスタンス * @param cmd コマンド * @return なし */ function WnovView_EvalCommand(it, cmd){ if(undefined == cmd){ return WnovView_END; } // 評価関数取得 var func = WnovViewFUNCMAP[cmd[0]]; if(undefined == func){ return WnovView_END; } // コマンド評価 return func(it, cmd); } //////////////////////////////////////////////////////////// // コマンド評価関数 //////////////////////////////////////////////////////////// /** * コマンド評価関数の型 * @param it WnovViewのインスタンス * @param cmd コマンド * @retval WnovView_END 処理完了 * @retval WnovView_CONTINUE 処理継続 */ /// コマンド評価関数の連想配列 var WnovViewFUNCMAP = new Array(); /// [WAVE]の評価関数。効果音を鳴らす。 WnovViewFUNCMAP[WAVE] = function(it, cmd){ if("0.mp3" == cmd[1]){ it.se.stop(); } else { it.se.loadSound("se/" + cmd[1], true); } return WnovView_END; } /// [MUSIC]の評価関数。BGMを鳴らす。 WnovViewFUNCMAP[MUSIC] = function(it, cmd){ if(cmd[1] == it.playtitle){ return WnovView_END; } if("0.mp3" == cmd[1]){ it.bgm.stop(); } else { it.bgm.loadSound("se/" + cmd[1], true, true); } it.playtitle = cmd[1]; it.env[MUSIC] = cmd; return WnovView_END; } /// [T]の評価関数。文字を表示。 WnovViewFUNCMAP[T] = function(it, cmd){ it.textObj.appendChild( document.createTextNode(cmd[1]) ); return WnovView_END; } /// [NEWLINE]の評価関数。改行を行う。 WnovViewFUNCMAP[NEWLINE] = function(it, cmd){ it.textObj.innerHTML += "
"; return WnovView_END; } /// [NEXTPAGE]の評価関数。改ページを行う。 WnovViewFUNCMAP[NEXTPAGE] = function(it, cmd){ it.textObj.innerHTML = ""; divClearImage("idWAIT"); WnovView_BkImage(it, cmd); return WnovView_END; } /// [PSELECT]の評価関数。選択肢を表示する。 WnovViewFUNCMAP[PSELECT] = function(it, cmd){ InsertSelection("DIVTEXT", "WnovOnSelect", [cmd[4], cmd[6]]); return WnovView_END; } /// [LGRAPH]の評価関数。左キャラを表示する。 WnovViewFUNCMAP[LGRAPH] = function(it, cmd){ imageSet("CHARA_L0", "img/"+cmd[1], cmd[2], cmd[3]); divSetAlpha("CHARA_L0", 100); it.env[LGRAPH] = [LGRAPH, cmd[1], cmd[2], cmd[3]]; return WnovView_END; } /// [NLGRAPH]の評価関数。左キャラを表示する。 WnovViewFUNCMAP[NLGRAPH] = WnovViewFUNCMAP[LGRAPH]; /// [RGRAPH]の評価関数。右キャラを表示する。 WnovViewFUNCMAP[RGRAPH] = function(it, cmd){ imageSet("CHARA_R0", "img/"+cmd[1], 320, 0); divSetAlpha("CHARA_R0", 100); it.env[RGRAPH] = cmd; return WnovView_END; } /// [DGRAPH]の評価関数。左右キャラを表示する。 WnovViewFUNCMAP[DGRAPH] = function(it, cmd){ imageSet("CHARA_L0", "img/"+cmd[1], 0, 0); imageSet("CHARA_R0", "img/"+cmd[2], 320, 0); divSetAlpha("CHARA_R0", 100); divSetAlpha("CHARA_L0", 100); it.env[LGRAPH] = [LGRAPH, cmd[1], 0, 0]; it.env[RGRAPH] = [RGRAPH, cmd[2]]; return WnovView_END; } /// [WAIT]の評価関数。ウェイトカーソルを表示する。 WnovViewFUNCMAP[WAIT] = function(it, cmd){ if(0 == cmd[1]){ divInsertImage("idWAIT", "", "", "cursor/click.gif"); } else { divInsertImage("idWAIT", "", "", "cursor/page.gif"); } return WnovView_END; }