// JavaScript file js_adv.js v0.2 last modified 10/04/19
if (typeof jsGame == "undefined") var jsGame = {};
jsGame.Base = Class.create({
initialize: function(element) {
this.path = {
image: '../image/',
smJS: '../js/soundmanager2.js',
smSWF: '../swf/',
BGM: '../bgm/',
snd: '../snd/'
};
this.disp = $(element);
this.GData = jsGame.dataBase;
this.dispOffset = this.disp.cumulativeOffset();
this.MData = {
gameVars: {},
systemVars: {
SE: {
onContinue: null,
onSelectChoice: null,
onTimeup: null
}
},
template: []
};
this.flag = [];
this.story = 1;
this.fixedId = {
dialogForm: 'form_' + element,
dialogText: 'text_' + element
};
this.effectScope = 'scope_' + element;
this.currentTextId = 1;
this.currentFlagNum = 1;
//BGM、効果音
this.mute = true;
this.playingNumber = '';
this.flash = false;
this.trackList = [];
this.bgmTracks = new Element('DIV', ({ className: 'track' }));
this.soundTracks = new Element('DIV', ({ className: 'track' }));
this.disp.insert(this.bgmTracks);
this.disp.insert(this.soundTracks);
if (navigator.plugins && navigator.mimeTypes['application/x-shockwave-flash']) {
var plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin,
flashplayer_ver = parseInt(plugin.description.match(/\d+\.\d+/));
if (plugin)
this.loadForFlash();
}
else if (Prototype.Browser.IE) {
if (new ActiveXObject("ShockwaveFlash.ShockwaveFlash"))
this.loadForFlash();
}
//モーダル風ウィンドウ
this.modal = new Element('DIV', { className: 'modal' })
.setOpacity(0.8).hide();
this.disp.insert(this.modal);
//ダイアログ・ウィンドウ
this.dialogResult = {
inputText: null,
command: null
};
this.dialogWin = new Element('DIV', { className: 'dialog_win' })
.setOpacity(0.8).hide();
this.disp.insert(this.dialogWin);
for (var i = 0; i < 3; i++) {
var newNode = new Element('DIV', { className: 'window' + (i + 1) });
if (i == 0) this.dialogWin.insert(newNode);
else prevPar.insert(newNode);
var prevPar = newNode;
if (i == 2) {
this.dialogText = new Element('DIV', { className: 'dialog_text' });
prevPar.insert(this.dialogText);
}
}
this.dialogText.update('
');
this.dialogForm = $(this.fixedId.dialogForm);
this.dialogMsg = $$('span.dialog_msg')[0];
this.inputText = this.dialogForm.findFirstElement();
this.commandOk = this.dialogForm.getInputs('button', 'ok').first();
this.commandCancel = this.dialogForm.getInputs('button', 'cancel').first();
// タイトルウィンドウ
this.titleWin = new Element('DIV', { className: 'title_win' })
.setOpacity(0.8).hide();
this.disp.insert(this.titleWin);
for (var i = 0; i < 3; i++) {
var newNode = new Element('DIV', { className: 'window' + (i + 1) });
if (i == 0) this.titleWin.insert(newNode);
else prevPar.insert(newNode);
var prevPar = newNode;
if (i == 2) {
this.titleText = new Element('DIV', { className: 'title_text' });
prevPar.insert(this.titleText);
}
}
// 警告ウィンドウ
this.warnWin = new Element('DIV', { className: 'warn_win' })
.setOpacity(0.8).hide();
this.disp.insert(this.warnWin);
for (var i = 0; i < 3; i++) {
var newNode = new Element('DIV', { className: 'window' + (i + 1) });
if (i == 0) this.warnWin.insert(newNode);
else prevPar.insert(newNode);
var prevPar = newNode;
if (i == 2) {
this.warnText = new Element('DIV', { className: 'warn_text' });
prevPar.insert(this.warnText);
}
}
// メインウィンドウ
this.mainWin = new Element('DIV', { className: 'main_win' })
.setOpacity(0.8).hide();
this.disp.insert(this.mainWin);
for (var i = 0; i < 3; i++) {
var newNode = new Element('DIV', { className: 'window' + (i + 1) });
if (i == 0) this.mainWin.insert(newNode);
else prevPar.insert(newNode);
var prevPar = newNode;
if (i == 2) {
this.mainText = new Element('DIV', { className: 'main_text' });
prevPar.insert(this.mainText);
}
}
// メインウィンドウ内のコンテンツ
this.imgFrm = new Element('DIV', { className: 'img_frm' });
this.charImg = new Element('IMG', { name: 'char_img', className: 'char_img' });
this.imgFrm.insert(this.charImg);
this.mainText.insert(this.imgFrm.hide());
this.charName = new Element('DIV', { className: 'char_name' });
this.mainText.insert(this.charName.hide());
this.message = new Element('DIV', { className: 'message' });
this.mainText.insert(this.message.hide());
this.selectedItem = null;
this.question = new Element('DIV', { className: 'question' }).hide();
this.mainText.insert(this.question);
this.winAns = [
new Element('DIV', { className: 'answer' }),
new Element('DIV', { className: 'answer' }).setStyle({ top: '75px' }),
new Element('DIV', { className: 'answer' }).setStyle({ top: '105px' })
];
this.winAns.each(function(element) {
this.mainText.insert(element.hide());
}.bind(this));
this.mainText.insert(this.winConfWrapper = new Element('DIV')
.setStyle({
position: 'relative',
left: '0px',
top: '75px'
})
.update('\r\n\r\n\r\n | \r\n | \r\n | \r\n
\r\n\r\n
')
.hide() );
this.winConf = [
$$('table.conf_table td.ok').first(),
$$('table.conf_table td.cancel').first()
];
this.blackSheet = new Element('DIV', { className: 'black_sheet' }).hide();
this.disp.insert(this.blackSheet);
this.pageNext = new Element('DIV', { className: 'page_next' }).hide();
this.disp.insert(this.pageNext);
//ノベル風テキスト表示
this.textWin = new Element('DIV', { className: 'text_win' })
.setOpacity(0.7).hide();
this.disp.insert(this.textWin);
//背景画像
this.bgImage = {};
this.bgImage['main'] = new Element('DIV', { className: 'bg_frm' })
.insert(new Element('IMG', { className: 'bg_img' }));
this.bgImage['sub'] = new Element('DIV', { className: 'bg_frm' })
.insert(new Element('IMG', { className: 'bg_img' }));
this.disp.insert(this.bgImage['main'].hide());
this.disp.insert(this.bgImage['sub'].hide());
//汎用画像のひな形オブジェクト
this.img = {};
this.imgTemp = new Element('DIV', { className: 'fg_frm' })
.insert(new Element('IMG', { className: 'fg_img' }) );
this.eventType = {
initVars: 'initVars',
createSimpleText: 'createSimpleText',
dispSimpleText: 'dispSimpleText',
typeSimpleText: 'typeSimpleText',
hideSimpleText: 'hideSimpleText',
showDialog: 'showDialog',
showWin: 'showWindow',
hideWin: 'hideWindow',
dispMsg: 'dispMessage',
typeMsg: 'typeMessage',
showQuestion: 'showQuestion',
showAnswer: 'showAnswer',
showConfirm: 'showConfirm',
clearMsg: 'clearMessage',
changeScene: 'changeScene',
toSelectedScene: 'toSelectedScene',
insertValue: 'insertSelectedValue',
insertResult: 'insertDialogResult',
executeCode: 'executeCode',
showText: 'showTextWin',
hideText: 'hideTextWin',
dispText: 'dispText',
typeText: 'typeText',
clearText: 'clearText',
createImage: 'createImage',
showImage: 'showImage',
hideImage: 'hideImage',
changeBgImg: 'changeBgImg',
showBgImage: 'showBackground',
hideBgImage: 'hideBackground',
playMusic: 'playEventMusic',
stopMusic: 'stopEventMusic',
showModal: 'showModalWindow',
hideModal: 'hideModalWindow',
clickToContinue: [Effect.ClickToContinue, this],
waitUntilClick: [Effect.WaitUntilClick, this],
waitToChoose: [Effect.WaitToChoose, this]
};
this.keyManager();
this.mouseEvents();
},
loadForFlash: function() {
if (typeof soundManager != 'undefined') return;
var script = new Element('SCRIPT', { src: this.path.smJS, type: 'text/javascript', charset: 'shift-jis' });
$$('head')[0].insert(script);
var interval = setInterval(function() {
if (typeof soundManager == 'undefined') return;
clearInterval(interval);
interval = null;
soundManager.url = this.path.smSWF;
soundManager.flashLoadTimeout = 1000;
soundManager.debugMode = false;
this.trackManager();
}.bind(this), 10);
},
trackManager: function() {
soundManager.onload = function(){
var track = {};
this.flash = true;
this.GData.music.BGM.each(function(attr) {
track[attr.name] = soundManager.createSound({
id: attr.name,
url: this.path.BGM + attr.url,
volume: 30
});
}.bind(this));
this.GData.music.sound.each(function(attr) {
track[attr.name] = soundManager.createSound({
id: attr.name,
url: this.path.snd + attr.url,
volume: 50
});
}.bind(this));
jsGame.track = track;
}.bind(this);
soundManager.onerror = function(){
this.flash = false;
};
},
playMusic: function() {
var trackName = arguments[0],
type = arguments[1],
options = arguments[2] || {};
if (type == 'bgm') this.playingNumber = { name: trackName, loop: options.loop };
if (this.mute) return;
if (options.skip && type == 'snd' && ! (this.flash || Prototype.Browser.IE)) return;
if (!this.flash) {
var mute = (options.mute) ? (Prototype.Browser.IE ? -10000 : false) : Prototype.Browser.IE ? 0 : true,
loop = (options.loop) ? [true, -1] : [false, 1];
if (type == 'bgm')
var data = this.GData.music.BGM, tracks = this.bgmTracks;
else
var data = this.GData.music.sound, tracks = this.soundTracks;
var trackUrl = (type == 'bgm' ? this.path.BGM : this.path.snd) + data.find(function(tr) {
return (tr.name == trackName);
}).url;
if (Prototype.Browser.Gecko && navigator.userAgent.indexOf("Win") > 0) {
if (navigator.plugins &&
$A(navigator.plugins).detect(function(p){
return p.name.indexOf('QuickTime') != -1
})) {
var objTag = new Element('OBJECT', {
type: 'audio/mpeg',
data: trackUrl,
width: 0,
height: 0
});
var prmTag1 = new Element('param'), prmTag2 = new Element('param');
prmTag1.setAttribute('name', 'loop');
prmTag1.setAttribute('value', loop[0]);
prmTag2.setAttribute('name', 'autostart');
prmTag2.setAttribute('value', mute);
objTag.insert(prmTag1);
objTag.insert(prmTag2);
tracks.insert(objTag);
return;
}
}
if (Prototype.Browser.IE) {
var bgTag = new Element('BGSOUND', {
src: trackUrl,
loop: loop[1],
volume: mute,
width: 0,
height: 0
});
tracks.insert(bgTag);
} else {
tracks.update('');
}
} else {
//フラッシュ使用時の処理
var mute = options.mute ? true : false,
loop = options.loop ? true : false;
if (mute) {
jsGame.track[trackName].load();
return;
}
jsGame.track[trackName].play({
onplay: function() {
this.trackList.push(trackName);
}.bind(this),
onfinish: function() {
if (loop)
jsGame.track[trackName].play();
}
});
}
},
stopMusic: function() {
//フラッシュ未使用の場合、BGMか効果音をそれぞれ選択("bgm"か"snd")。また引数なしで一括して停止させることができる。
var type = arguments[0] || 'both',
options = !Object.isString(arguments[0]) ? arguments[0] : arguments[1] || {};;
if (! this.flash) {
switch (type) {
case 'bgm':
this.bgmTracks.immediateDescendants().invoke('remove');
break;
case 'snd':
this.soundTracks.immediateDescendants().invoke('remove');
break;
default:
this.bgmTracks.immediateDescendants().invoke('remove');
this.soundTracks.immediateDescendants().invoke('remove');
}
} else {
//フラッシュ使用時の処理
if (type == 'bgm' || type == 'both') {
var bgmList = this.GData.music.BGM.pluck('name').findAll(function(element){
return this.trackList.indexOf(element) != -1;
}.bind(this));
if (bgmList) {
bgmList.each(function(tr){
jsGame.track[tr].stop();
});
}
}
if (type == 'snd' || type == 'both') {
var sndList = this.GData.music.sound.pluck('name').findAll(function(element){
return this.trackList.indexOf(element) != -1;
}.bind(this));
if (sndList) {
sndList.each(function(tr){
jsGame.track[tr].stop();
});
}
}
this.trackList = this.trackList.without(bgmList.concat(sndList));
}
},
keyManager: function() {
this.key = [];
this.keyPress = [];
this.keyCount = 256;
for (var i = 0; i < this.keyCount; i++) {
this.key[i] = false;
this.keyPress[i] = false;
}
document.observe('keydown', function(e) {
// Mozilla(Firefox, NN) and Opera
if (typeof event == 'undefined') {
var code = e.which;
this.key[code] = true;
// Internet Explorer
} else {
var code = event.keyCode;
this.key[code] = true;
}
this.keyPress[code] = true;
}.bind(this), false);
document.observe('keyup', function(e) {
// Mozilla(Firefox, NN) and Opera
if (typeof event == 'undefined') {
var code = e.which;
this.key[code] = false;
// Internet Explorer
} else {
var code = event.keyCode;
this.key[code] = false;
}
}.bind(this), false);
document.observe('keypress', function(e) {
// Mozilla(Firefox, NN) and Opera
if (typeof event == 'undefined') {
var code = e.which;
if (code == Event.KEY_RETURN) {
e.preventDefault();
e.stopPropagation();
}
// Internet Explorer
} else {
var code = event.keyCode;
if (code == Event.KEY_RETURN) {
event.returnValue = false;
event.cancelBubble = true;
}
}
}.bind(this), false);
},
isKeyUp: function(keyName) {
if (Object.isNumber(keyName))
return !this.key[keyName];
else
return !this.key[Event[keyName]];
},
isKeyDown: function(keyName) {
if (Object.isNumber(keyName))
return this.key[keyName];
else
return this.key[Event[keyName]];
},
isKeyPress: function(keyName) {
if (Object.isNumber(keyName)) {
if (this.keyPress[keyName] && !this.isKeyDown(keyName)) {
this.keyPress[keyName] = false;
return true;
}
else
return false;
}
else
if (this.keyPress[Event[keyName]] && !this.isKeyDown(keyName)) {
this.keyPress[Event[keyName]] = false;
return true;
}
else
return false;
},
mouseEvents: function() {
this.x = 0;
this.y = 0;
this.targetElm = null;
this.mouseDown = false;
this.mouseBtn = {
left: false,
center: false,
right: false
};
this.disp.observe('mousemove', function(e) {
this.x = Event.pointerX(e) - this.dispOffset.left;
this.y = Event.pointerY(e) - this.dispOffset.top;
}.bind(this), false);
this.disp.observe('resize', function(e) {
this.dispOffset = this.disp.cumulativeOffset();
}.bind(this), false);
this.disp.observe('mousedown', function(e) {
this.mouseDown = true;
this.targetElm = e.element();
this.eventObj = e;
if (Event.isLeftClick(e)) this.mouseBtn.left = true;
if (Event.isMiddleClick(e)) this.mouseBtn.center = true;
if (Event.isRightClick(e)) this.mouseBtn.right = true;
}.bind(this), false);
this.disp.observe('mouseup', function(e) {
if (Event.isLeftClick(e)) this.mouseBtn.left = false;
if (Event.isMiddleClick(e)) this.mouseBtn.center = false;
if (Event.isRightClick(e)) this.mouseBtn.right = false;
}.bind(this), false);
},
getMouseX: function() {
return this.x;
},
getMouseY: function() {
return this.y;
},
getMouseXY: function() {
return [this.x, this.y];
},
getTarget: function() {
return this.targetElm;
},
getEventObj: function() {
return this.eventObj;
},
isMouseBtn: function(btnName) {
return this.mouseBtn[btnName];
},
isMouseClick: function() {
if (this.mouseDown && !this.isMouseBtn('left')) {
this.mouseDown = false;
return true;
}
else
return false;
},
initVars: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
dataObj = param[0],
options = param[1] || {};
}
else {
var dataObj = arguments[0],
options = arguments[1] || {};
}
var copyObj = Object.toJSON(dataObj);
copyObj = copyObj.evalJSON();
if (dataObj.gameVars) {
$H(dataObj.gameVars).each(function(pair) {
if (Object.isFunction(pair.value))
copyObj.gameVars[pair.key] = pair.value;
});
}
new Effect.Event(Object.extend({
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
this.MData = Object.extend(this.MData, copyObj);
}.bind(this)
}, options));
},
createSimpleText: function() {
//第1引数がテキスト。第2引数はテキスト要素の識別ID、省略すると"text***"という風に自動的にIDを作成する。
//第3引数はオプション、locは表示座標[x, y]形式の配列で。
//styleはMorphエフェクトにならって、クラス名 or インラインのスタイル定義 or CSSプロパティのハッシュで指定可。
//tempにフィールド値を持つオブジェクトを指定すると、Prototype.jsのTemplateクラスを利用できる。
if (Object.isArray(arguments[0])) {
var param = arguments[0],
text = param[0],
textId = Object.isString(param[1]) ?
param[1] : 'text' + (this.currentTextId++).toPaddedString(3);
options = Object.isString(param[1]) ?
Object.extend({
loc: [0, 0],
style: { }
}, param[2] || { }) :
Object.extend({
loc: [0, 0],
style: { }
}, param[1] || {});
}
else {
var text = arguments[0],
textId = Object.isString(arguments[1]) ?
arguments[1] : 'text' + (this.currentTextId++).toPaddedString(3);
options = Object.isString(arguments[1]) ?
Object.extend({
loc: [0, 0],
style: { }
}, arguments[2] || { }) :
Object.extend({
loc: [0, 0],
style: { }
}, arguments[1] || {});
}
if (options.temp) {
if (options.temp == 'gameVars') {
var tpl = new Template(text);
text = tpl.evaluate(this.MData.gameVars);
}
else {
var parameter = this.findData(this.MData.template, options.temp) || {},
tpl = new Template(text);
text = tpl.evaluate(parameter);
}
}
var element = new Element('DIV', { id: textId }).setStyle({
zIndex: 200,
position: 'absolute',
left: options.loc[0] + 'px',
top: options.loc[1] + 'px'
}).update(text).hide();
this.disp.insert(element);
if (!Object.isString(options.style))
element.setStyle(options.style);
else {
if (options.style.include(':'))
element.setStyle(options.style);
else
element.addClassName(options.style);
}
return element;
},
dispSimpleText: function() {
//第1引数は登録したテキスト名。第2引数はオプション、delayはエフェクトを遅らせる時間。
//effectは"Appear"などエフェクト効果を任意で指定。effectOptでそのエフェクトのオプションを指定可。
if (Object.isArray(arguments[0])) {
var param = arguments[0],
name = param[0],
options = param[1] || {};
}
else {
var name = arguments[0],
options = arguments[1] || {};
}
var element = $(name),
effect = options.effect ?
options.effect === true ? 'Appear' : options.effect.capitalize() : null;
var effectOpt = Object.extend({
queue: { scope: this.effectScope, position: 'end' }
}, options.effectOpt || {});
if (effect)
Effect[effect](element, effectOpt);
else {
new Effect.Event(Object.extend({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
element.show();
}
}, options));
}
},
typeSimpleText: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
name = param[0],
options = param[1] || {};
}
else {
var name = arguments[0],
options = arguments[1] || {};
}
var element = $(name);
new Effect.Event(Object.extend({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
element.show();
Effect.tagifyText(element);
if (Prototype.Browser.WebKit)
element.descendants().invoke('setStyle', { float: 'left' });
var charSpan = element.immediateDescendants();
charSpan.invoke('setStyle', { visibility: 'hidden' });
new Effect.Typing(charSpan, this.disp, this);
}.bind(this)
}, options));
},
hideSimpleText: function() {
//第1引数は登録したテキスト名。第2引数はオプション、delayはエフェクトを遅らせる時間。
//effectは"Fade"などエフェクト効果を任意で指定。effectOptでそのエフェクトのオプションを指定可。
if (Object.isArray(arguments[0])) {
var param = arguments[0],
name = param[0],
options = param[1] || {};
}
else {
var name = arguments[0],
options = arguments[1] || {};
}
var element = $(name),
effect = options.effect ?
options.effect === true ? 'Fade' : options.effect.capitalize() : null;
var effectOpt = Object.extend({
queue: { scope: this.effectScope, position: 'end' }
}, options.effectOpt || {});
if (effect)
Effect[effect](element, effectOpt);
else {
new Effect.Event(Object.extend({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
element.hide();
}
}, options));
}
},
showDialog: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
dialogMsg = param[0],
options = Object.extend({
type: 'alert'
}, param[1] || {});
}
else {
var dialogMsg = arguments[0],
options = arguments[1] || {};
}
new Effect.Event(Object.extend({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
this.dialogResult = Object.extend(this.dialogResult, {
inputText: null,
command: null
});
if (options.temp) {
if (options.temp == 'gameVars') {
var tpl = new Template(dialogMsg);
dialogMsg = tpl.evaluate(this.MData.gameVars);
}
else {
var parameter = this.findData(this.MData.template, options.temp) || {},
tpl = new Template(dialogMsg);
dialogMsg = tpl.evaluate(parameter);
}
}
this.dialogMsg.update(dialogMsg);
this.modal.appear({
from: 0.2,
to: 0.8,
duration: 0.6,
queue: { scope: 'modal_' + this.effectScope, position: 'end' },
afterFinishInternal: function() {
this.dialogWin.show();
if (options.type == 'input') {
if (options.initValue)
this.inputText.setValue(options.initValue);
this.inputText.show().activate();
}
else {
this.inputText.hide();
}
if (options.enableCancel)
this.commandCancel.show();
else
this.commandCancel.hide();
}.bind(this)
} );
new Effect.WaitForDialog(options.type, this);
}.bind(this)
}, options));
},
showWindow: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
type = param[0] || 'main',
options = param[1] || {};
}
else {
var type = arguments[0] || 'main',
options = arguments[1] || {};
}
switch (type) {
case 'main':
Effect.Appear(this.mainWin, Object.extend({
from: 0.2,
to: 0.8,
duration: 0.6,
queue: { scope: this.effectScope, position: 'end' }
}, options));
break;
case 'main_img':
Effect.Appear(this.mainWin, Object.extend({
from: 0.2,
to: 0.8,
duration: 0.6,
queue: { scope: this.effectScope, position: 'end' },
afterSetup: function() {
this.blackSheet.show();
}.bind(this)
}, options));
break;
case 'warn':
Effect.Appear(this.warnWin, Object.extend({
from: 0.2,
to: 0.8,
duration: 0.6,
queue: { scope: this.effectScope, position: 'end' }
}, options));
break;
case 'title':
Effect.Appear(this.titleWin, Object.extend({
from: 0.2,
to: 0.8,
duration: 0.6,
queue: { scope: this.effectScope, position: 'end' }
}, options));
break;
}
},
hideWindow: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
type = param[0] || 'main',
options = param[1] || {};
}
else {
var type = arguments[0] || 'main',
options = arguments[1] || {};
}
switch (type) {
case 'main':
Effect.Fade(this.mainWin, Object.extend({
beforeSetup: function() {
this.blackSheet.hide();
}.bind(this),
from: 0.8,
to: 0.0,
duration: 0.6,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
this.message.hide();
this.charName.hide();
this.charImg.setAttribute('src', '');
this.imgFrm.hide();
}.bind(this)
}, options));
break;
case 'warn':
Effect.Fade(this.warnWin, Object.extend({
from: 0.8,
to: 0.0,
duration: 0.6,
queue: { scope: this.effectScope, position: 'end' }
}, options));
break;
case 'title':
Effect.Fade(this.titleWin, Object.extend({
from: 0.8,
to: 0.0,
duration: 0.6,
queue: { scope: this.effectScope, position: 'end' }
}, options));
break;
}
},
dispMessage: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
msg = param[0],
type = Object.isString(param[1]) ? param[1] : 'main',
options = (Object.isString(param[1]) ? param[2] : param[1]) || {};
}
else {
var msg = arguments[0],
type = Object.isString(arguments[1]) ? arguments[1] : 'main',
options = (Object.isString(arguments[1]) ? arguments[2] : arguments[1]) || {};
}
new Effect.Event(Object.extend({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
if (options.temp) {
if (options.temp == 'gameVars') {
var tpl = new Template(msg);
msg = tpl.evaluate(this.MData.gameVars);
}
else {
var parameter = this.findData(this.MData.template, options.temp) || {},
tpl = new Template(msg);
msg = tpl.evaluate(parameter);
}
}
if (options.alignToCenter) {
this.message.setStyle({ textAlign: 'center' }
/*{
display: 'table-cell',
verticalAlign: 'middle',
position: 'relative'
}
*/
);
}
else {
this.message.setStyle({ textAlign: 'left' });
}
switch (type) {
case 'main':
this.message.setStyle({
top: '14px',
left: '14px',
width: '592px',
height: '120px'
});
this.message.update(msg).show();
break;
case 'warn':
this.warnText.update(msg);
break;
case 'title':
this.titleText.update(msg);
break;
}
}.bind(this)
}, options));
},
typeMessage: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
msg = param[0];
if (param[1] && Object.isString(param[1]))
var chara = param[1], options = param[2] || {};
else
var chara = null, options = param[1] || {};
}
else {
var msg = arguments[0];
if (arguments[1] && Object.isString(arguments[1]))
var chara = arguments[1], options = arguments[2] || {};
else
var chara = null, options = arguments[1] || {};
}
new Effect.Event(Object.extend({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
if (options.temp) {
if (options.temp == 'gameVars') {
var tpl = new Template(msg);
msg = tpl.evaluate(this.MData.gameVars);
}
else {
var parameter = this.findData(this.MData.template, options.temp) || {},
tpl = new Template(msg);
msg = tpl.evaluate(parameter);
}
}
if (options.alignToCenter)
this.message.setStyle({ textAlign: 'center' });
else
this.message.setStyle({ textAlign: 'left' });
if (options.img) {
var offset = options.offset || [0, 0];
this.charImg.writeAttribute({ src: '' });
if (chara) {
this.message.setStyle({
top: '38px',
left: '140px',
height: '97px',
width: '467px'
});
this.charName.setStyle({
left: '140px',
width: '467px'
});
this.charName.update(chara);
this.charName.show();
} else {
this.message.setStyle({
top: '14px',
left: '140px',
height: '120px',
width: '467px'
});
this.charName.hide();
}
this.charImg.setStyle({
top: offset[1] * -96 + 'px',
left: offset[0] * -96 + 'px'
});
var imgUrl = this.imgObj[options.img].src;
this.charImg.writeAttribute({ src: imgUrl });
this.message.update(msg);
this.message.show();
this.imgFrm.show();
this.blackSheet.show();
} else {
if (chara) {
this.message.setStyle({
top: '38px',
left: '14px',
width: '592px',
height: '96px'
});
this.charName.setStyle({
left: '14px',
width: '592px'
});
this.charName.update(chara);
this.charName.show();
} else {
this.message.setStyle({
top: '14px',
left: '14px',
width: '592px',
height: '120px'
});
this.charName.hide();
}
this.message.update(msg);
this.message.show();
this.imgFrm.hide();
this.blackSheet.hide();
}
Effect.tagifyText(this.message);
if (Prototype.Browser.WebKit)
this.message.descendants().invoke('setStyle', { float: 'left' });
var charSpan = this.message.immediateDescendants();
charSpan.invoke('setStyle', { visibility: 'hidden' });
new Effect.Typing(charSpan, this.mainWin, this);
}.bind(this)
}, options));
},
clearMessage: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
options = param[0] || {};
}
else {
var options = arguments[0] || {};
}
new Effect.Event(Object.extend({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function(){
this.charImg.writeAttribute({ src: '' });
this.imgFrm.hide();
this.blackSheet.hide();
this.charName.hide().update('');
this.message.hide().update('');
this.question.hide().update('');
this.winAns.invoke('hide');
this.winAns.invoke('update', '');
this.winConf.invoke('hide');
this.winConf.invoke('update', '');
}.bind(this)
}, options));
},
showQuestion: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
question = param[0],
options = param[1] || {};
}
else {
var question = arguments[0],
options = arguments[1] || {};
}
new Effect.Event(Object.extend({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
if (options.temp) {
if (options.temp == 'gameVars') {
var tpl = new Template(question);
question = tpl.evaluate(this.MData.gameVars);
}
else {
var parameter = this.findData(this.MData.template, options.temp) || {},
tpl = new Template(question);
question = tpl.evaluate(parameter);
}
}
this.question.update(question).show();
Effect.tagifyText(this.question);
if (Prototype.Browser.WebKit)
this.question.descendants().invoke('setStyle', { float: 'left' });
var charSpan = this.question.immediateDescendants();
charSpan.invoke('setStyle', { visibility: 'hidden' });
new Effect.Typing(charSpan, this.mainWin, this);
}.bind(this)
}, options));
},
showAnswer: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
answers = Object.isArray(param[0]) ? param[0] : param,
options = Object.extend({
listNum: true,
alignToBtm: false
}, param[1] || {});
}
else {
var answers = arguments[0],
options = Object.extend({
listNum: true
}, arguments[1] || {});
}
if (options.listNum) {
answers = answers.zip(['1', '2', '3'], function(tuple) {
return tuple.reverse().join('、');
});
}
new Effect.Event(Object.extend({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
if (!options.alignToBtm) {
var posTop = [50, 78, 106];
this.winAns.each(function(element, index) {
element.setStyle({ top: posTop[index] + 'px' });
});
}
else {
var posTop = [62, 87, 112];
this.winAns.each(function(element, index) {
element.setStyle({ top: posTop[index] + 'px' });
});
}
if (options.temp) {
if (options.temp == 'gameVars') {
answers = answers.map(function(answer){
var tpl = new Template(answer);
return tpl.evaluate(this.MData.gameVars);
}.bind(this));
}
else {
var parameter = this.findData(this.MData.template, options.temp) || {};
answers = answers.map(function(answer){
var tpl = new Template(answer);
return tpl.evaluate(parameter);
}.bind(this));
}
}
this.winAns.each(function(element, index) {
element.update(answers[index]).setStyle({ color: '#FFF' })
.appear({
duration: 0.6,
queue: { scope: 'winAns_' + this.effectScope, position: 'parallel' }
});
});
}.bind(this)
}, options));
},
showConfirm: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
confirm = Object.isArray(param[0]) ? param[0] : param,
options = param[1] || {};
}
else {
var confirm = arguments[0],
options = arguments[1] || {};
}
new Effect.Event(Object.extend({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
if (options.temp) {
if (options.temp == 'gameVars') {
var tpl = new Template(confirm);
confirm = tpl.evaluate(this.MData.gameVars);
}
else {
var parameter = this.findData(this.MData.template, options.temp) || {},
tpl = new Template(confirm);
confirm = tpl.evaluate(parameter);
}
}
this.winConfWrapper.show();
this.winConf.each(function(element, index) {
element.stopObserving();
element.update(confirm[index]).setOpacity(0).appear({
duration: 0.6,
queue: { scope: 'winConf_' + this.effectScope, position: 'parallel' }
});
}.bind(this));
}.bind(this)
}, options));
},
toSelectedScene: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
scenes = Object.isArray(param[0]) ? param[0].map() : param.map();
}
else {
var scenes = $A(arguments).map();
}
new Effect.Event({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
if (this.selectedItem === null) return;
var selectedScene = scenes.find(function(value, index) {
return this.selectedItem == index;
}.bind(this));
this.changeScene(selectedScene);
this.selectedItem = null;
}.bind(this)
});
},
insertSelectedValue: function() {
var values = [];
if (Object.isArray(arguments[0])) {
var param = arguments[0],
changeVar = param[0],
values = param[1];
}
else {
var changeVar = arguments[0],
values = arguments[1];
}
new Effect.Event({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
if (this.selectedItem === null) return;
var value = values.find(function(val, index) {
return this.selectedItem == index;
}.bind(this)).toString();
var reg = /^[\+\-\*\/%]\d+/;
if (value.match(reg))
this.MData.gameVars[changeVar] = eval(this.MData.gameVars[changeVar] + value).round();
else
this.MData.gameVars[changeVar] = value;
this.selectedItem = null;
}.bind(this)
});
},
insertDialogResult: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
changeVar = param[0];
}
else
var changeVar = arguments[0];
new Effect.Event({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
if (this.dialogResult.command === null) return;
this.MData.gameVars[changeVar] = this.dialogResult.inputText !== null
? this.dialogResult.inputText : this.dialogResult.command;
this.dialogResult = Object.extend(this.dialogResult, {
inputText: null,
command: null
});
}.bind(this)
});
},
createFlag: function() {
var newFlag = {
id: 'flag' + (this.currentFlagNum++).toPaddedString(3),
flag: null
}
this.flag.push(newFlag);
return newFlag;
},
getFlag: function(flagId) {
return this.findData(this.flag, flagId).flag;
},
setFlag: function(flagId, bool) {
if (this.flag) {
if (typeof arguments[0] == 'boolean') {
var flagObj = this.createFlag();
flagObj.flag = arguments[0];
}
else {
if (this.findData(this.flag, flagId)) {
var flagObj = this.findData(this.flag, flagId);
flagObj.flag = bool;
}
else {
var flagObj = { id: flagId, flag: bool };
this.flag.push(flagObj)
}
}
return flagObj;
}
},
jumpTo: function() {
},
getStory: function() {
},
setStory: function() {
},
checkStory: function() {
},
changeScene: function() {
var sceneName = arguments[0];
new Effect.Event({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: this.addScene.bind(this, sceneName)
});
},
executeCode: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0];
if (Object.isFunction(param[0]))
var func = param[0];
}
else {
if (Object.isFunction(arguments[0])) {
var func = arguments[0];
}
}
new Effect.Event({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: func.bind(this)
});
},
createImage: function() {
//第1引数に登録された画像名、第2引数はオプションでオブジェクト形式で渡す。divでフレームのサイズ、imgで画像のサイズ、
//offsetでdivのオフセット、parentで親要素(省略された場合、this.dispに)を指定できる。
//例:{ div: [100, 100], img: [50, 50], offset: [50, 100], parent: obj }
if (Object.isArray(arguments[0])) {
var param = arguments[0],
name = param[0],
options = param[1] || {};
}
else {
var name = arguments[0],
options = arguments[1] || {};
}
if (this.img[name])
var index = this.img[name].length;
else {
this.img[name] = [];
var index = 0;
}
var imgDiv = this.img[name][index] = $(this.imgTemp.cloneNode(true)).hide();
imgDiv.identify();
if (options) {
if (options.div) {
imgDiv.setStyle({
width: options.div[0] + 'px',
height: options.div[1] + 'px'
});
}
if (options.offset) {
imgDiv.setStyle({
left: options.offset[0] + 'px',
top: options.offset[1] + 'px'
});
}
if (options.img) {
imgDiv.firstDescendant().setStyle({
width: options.img[0] + 'px',
height: options.img[1] + 'px'
});
}
}
var imgUrl = this.imgObj[name].src;
imgDiv.firstDescendant().writeAttribute('src', imgUrl);
if (options && options.parent)
options.parent.insert(imgDiv);
else
this.disp.insert(imgDiv);
return imgDiv;
},
showImage: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
name = param[0],
index = param[1] || this.img[name].length - 1,
options = param[2] || {};
}
else {
var name = arguments[0],
index = arguments[1] || this.img[name].length - 1,
options = arguments[2] || {};
}
Effect.Appear(this.img[name][index], Object.extend({
duration: 0.6,
queue: { scope: this.effectScope, position: 'end' }
}, options));
},
hideImage: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
name = param[0],
index = param[1] || this.img[name].length - 1,
options = param[2] || {};
}
else {
var name = arguments[0],
index = arguments[1] || this.img[name].length - 1,
options = arguments[2] || {};
}
Effect.Fade(this.img[name][index], Object.extend({
duration: 0.6,
queue: { scope: this.effectScope, position: 'end' }
}, options));
},
changeBgImg: function() {
//第1引数に登録した画像名、第2引数は省略可能だがサブ背景オブジェクトを使用するとき"sub"に。
if (Object.isArray(arguments[0])) {
var param = arguments[0],
imgUrl = this.imgObj[param[0]].src,
witch = param[1] || 'main';
}
else {
var imgUrl = this.imgObj[arguments[0]].src,
witch = arguments[1] || 'main';
}
new Effect.Event({
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function(){
this.bgImage[witch].firstDescendant().writeAttribute({ src: imgUrl });
}.bind(this)
});
},
showBackground: function() {
//第1引数はメインとサブのウィンドウを指定。"main"か"sub"で省略可能。
//第2引数はオプション、loc(x,y)、size(img要素のwidthを変更。デフォルトはauto、100%に変更するときなどに使う)。
if (Object.isArray(arguments[0])) {
var param = arguments[0],
win = param[0] || 'main',
options = Object.extend({
loc: [0, 0],
size: 'auto'
}, param[1] || {});
}
else {
var win = arguments[0] || 'main',
options = Object.extend({
loc: [0, 0],
size: 'auto'
}, arguments[1] || {});
}
Effect.Appear(this.bgImage[win], Object.extend({
beforeSetupInternal: function() {
this.bgImage[win].down('IMG').setStyle({ width: options.size });
this.bgImage[win].setStyle({
top: options.loc[1] + 'px',
left: options.loc[0] + 'px'
});
}.bind(this),
from: 0.2,
to: 1.0,
duration: 0.6,
queue: { scope: this.effectScope, position: 'end' }
}, options));
},
hideBackground: function() {
//第1引数は"main"か"sub"で省略可能。
//第2引数はdelay。
if (Object.isArray(arguments[0])) {
var param = arguments[0],
win = param[0] || 'main',
options = param[1] || {};
}
else {
var win = arguments[0] || 'main',
options = arguments[1] || {};
}
Effect.Fade(this.bgImage[win], Object.extend({
duration: 0.6,
queue: { scope: this.effectScope, position: 'end' }
}, options));
},
playEventMusic: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
trackName = param[0],
type = param[1] || 'bgm',
options = param[2] || {};
}
else {
var trackName = arguments[0],
type = arguments[1] || 'bgm',
options = arguments[2] || {};
}
new Effect.Event(Object.extend({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
this.playMusic(trackName, type, options);
}.bind(this)
}, options));
},
stopEventMusic: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
type = param[0] || 'bgm',
options = param[1] || {};
}
else {
var type = arguments[0] || 'bgm',
options = arguments[1] || {};
}
new Effect.Event(Object.extend({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
this.stopMusic(type, options);
}.bind(this)
}, options));
},
showTextWin: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
options = param[0] || {};
}
else {
var options = arguments[0] || {};
}
Effect.Appear(this.textWin, Object.extend({
from: 0.1,
to: 0.7,
duration: 0.6,
queue: { scope: this.effectScope, position: 'end' }
}, options));
},
hideTextWin: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
options = param[0] || {};
}
else {
var options = arguments[0] || {};
}
Effect.Fade(this.textWin, Object.extend({
from: 0.8,
to: 0.0,
duration: 0.6,
queue: { scope: this.effectScope, position: 'end' }
}, options));
},
dispText: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
psg = param[0],
options = param[1] || {};
}
else {
var psg = arguments[0],
options = arguments[1] || {};
}
new Effect.Event(Object.extend({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
if (options.temp) {
if (options.temp == 'gameVars') {
var tpl = new Template(psg);
psg = tpl.evaluate(this.MData.gameVars);
}
else {
var parameter = this.findData(this.MData.template, options.temp) || {},
tpl = new Template(psg);
psg = tpl.evaluate(parameter);
}
}
var passage = new Element('DIV', { className: 'passage' }).update(psg);
if (options.alignToCenter)
passage.setStyle({ textAlign: 'center' });
else
passage.setStyle({ textAlign: 'left' });
this.textWin.insert(passage);
}.bind(this)
}, options));
},
typeText: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
psg = param[0], options = param[1] || {};
}
else {
var psg = arguments[0], options = arguments[1] || {};
}
new Effect.Event(Object.extend({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
if (options.temp) {
if (options.temp == 'gameVars') {
var tpl = new Template(psg);
psg = tpl.evaluate(this.MData.gameVars);
}
else {
var parameter = this.findData(this.MData.template, options.temp) || {},
tpl = new Template(psg);
psg = tpl.evaluate(parameter);
}
}
var passage = new Element('DIV', { className: 'passage' }).update(psg);
if (options.alignToCenter)
passage.setStyle({ textAlign: 'center' });
else
passage.setStyle({ textAlign: 'left' });
this.textWin.insert(passage);
Effect.tagifyText(passage);
if (Prototype.Browser.WebKit)
passage.descendants().invoke('setStyle', { float: 'left' });
var charSpan = passage.immediateDescendants();
charSpan.invoke('setStyle', { visibility: 'hidden' });
new Effect.Typing(charSpan, this.textWin, this);
}.bind(this)
}, options));
},
clearText: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
options = param[0] || {};
}
else {
var options = arguments[0] || {};
}
new Effect.Event(Object.extend({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function(){
this.textWin.immediateDescendants().invoke('remove');
}.bind(this)
}, options));
},
showModalWindow: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
options = param[0] || {};
}
else {
var options = arguments[0] || {};
}
Effect.Appear(this.modal, Object.extend({
from: 0.2,
to: 0.8,
duration: 0.3,
queue: { scope: this.effectScope, position: 'end' }
}, options));
},
hideModalWindow: function() {
if (Object.isArray(arguments[0])) {
var param = arguments[0],
options = param[0] || {};
}
else {
var options = arguments[0] || {};
}
Effect.Fade(this.modal, Object.extend({
from: 0.8,
to: 0.0,
duration: 0.3,
queue: { scope: this.effectScope, position: 'end' }
}, options));
},
addScene: function(sceneName) {
if (!this.GData.eventData) return;
if (Object.isArray(arguments[1])) {
var param = arguments[1],
options = param[0] || {};
}
else {
var options = arguments[1] || {};
}
var eventObj = this.findData(this.GData.eventData, sceneName);
new Effect.Event(Object.extend({
delay: 0.05,
queue: { scope: this.effectScope, position: 'end' },
afterFinish: function() {
eventObj.data.each(function(event) {
if (Object.isArray(this.eventType[event.type])) {
var arg = this.eventType[event.type];
new arg[0](this[event.param], arg[1]);
}
else
this[this.eventType[event.type]](event.param);
}.bind(this));
}.bind(this)
}, options));
},
findData: function(array, param) {
if (Object.isArray(array)) {
return (array.find(function(obj) {
if (obj.id)
return obj.id == param ? true : false;
else if (obj.name)
return obj.name == param ? true : false;
}) );
}
else return false;
},
last: {}
});
Effect.Typing = Class.create(Effect.Base, {
initialize: function(element, eventElement, instance) {
if (((typeof element == 'object') ||
Object.isFunction(element)) &&
(element.length))
this.elements = element;
else
this.elements = $(element).childNodes;
this.instance = instance;
this.eventElement = eventElement;
this.options = Object.extend({
delay: 0.05,
duration: this.elements.length * 0.1,
fps: 10,
queue: { scope: this.instance.effectScope, position: 'front' }
}, arguments[1] || { });
this.interruption = false;
this.evtHandler = function() {
this.interruption = true;
};
this.eventElement.observe('click', function(e){
e.stop();
this.evtHandler();
}.bind(this));
this.eventElement.observe('dblclick', function(e) {
e.stop();
});
this.eventElement.observe('mousedown', function(e) {
e.stop();
});
this.start(this.options);
},
update: function(position) {
if (this.currentFrame <= this.elements.length)
(this.currentFrame).times(function(n) {
this.elements[n].setStyle({ visibility: 'visible' });
}.bind(this));
if (this.interruption || this.instance.isKeyPress('KEY_RETURN')) {
this.interruption = false;
this.render(1.0);
this.cancel();
this.event('beforeFinish');
if (this.finish) this.finish();
this.event('afterFinish');
var difference = 0,
queues = Effect.Queues.get(this.instance.effectScope).effects;
if (queues.length != 0) {
queues.each(function(effect, index) {
if (index == 0) {
difference = effect.startOn - new Date().getTime();
}
effect.startOn -= difference;
effect.finishOn -= difference;
});
}
}
},
finish: function() {
this.eventElement.stopObserving('click', this.evtHandler);
this.elements.invoke('setStyle', { visibility: 'visible' });
}
});
Effect.ClickToContinue = Class.create(Effect.Base, {
initialize: function(element, instance) {
this.element = $(element);
this.instance = instance;
this.clicked = false;
this.start(Object.extend({
delay: 0.05,
duration: 10000,
fps: 3,
queue: { scope: this.instance.effectScope, position: 'end' }
}, arguments[1] || { }));
},
setup: function() {
if (this.element.hasClassName('main_win')) {
this.instance.pageNext
.setStyle({
left: '604px',
top: '322px'
});
}
else if (this.element.hasClassName('text_win')) {
var element = this.element.immediateDescendants().last(),
elementsHeight = this.element.immediateDescendants().invoke('getHeight'),
accumulator = elementsHeight.inject(0, function(acc, n) { return acc + n + 10; })
this.instance.pageNext
.setStyle({
left: (parseInt(element.getStyle('paddingLeft')) + element.getWidth() - 5) + 'px',
top: accumulator + 'px'
});
}
this.element.observe('click', function(e) {
e.stop();
this.clicked = true;
}.bind(this));
this.element.observe('dblclick', function(e) {
e.stop();
});
this.element.observe('mousedown', function(e) {
e.stop();
});
},
update: function() {
if (this.clicked || this.instance.isKeyPress('KEY_RETURN')) {
if (this.instance.MData.systemVars.SE.onContinue)
this.instance.playMusic(this.instance.MData.systemVars.SE.onContinue, 'snd', { skip: true });
this.clicked = false;
this.render(1.0);
this.cancel();
this.event('beforeFinish');
if (this.finish) this.finish();
this.event('afterFinish');
var difference = 0,
queues = Effect.Queues.get(this.instance.effectScope).effects;
if (queues.length != 0) {
queues.each(function(effect, index) {
if (index == 0) {
difference = effect.startOn - new Date().getTime();
}
effect.startOn -= difference;
effect.finishOn -= difference;
});
}
}
else {
this.effectInst = Effect.toggle(this.instance.pageNext, 'appear', {
duration: 0.2,
queue: { scope: 'wait_' + this.instance.effectScope, position: 'end' }
});
}
},
finish: function() {
this.element.stopObserving();
if (this.effectInst) {
this.effectInst.cancel();
}
new Effect.Fade(this.instance.pageNext, {
duration: 0,
queue: { scope: 'wait_' + this.instance.effectScope, position: 'end' }
});
}
});
Effect.WaitUntilClick = Class.create(Effect.Base, {
initialize: function(element, instance) {
this.element = $(element);
this.instance = instance;
this.clicked = false;
this.start(Object.extend({
delay: 0.05,
duration: 10000,
fps: 100,
queue: { scope: this.instance.effectScope, position: 'end' }
}, arguments[1] || { }));
},
setup: function() {
this.element.observe('click', function(e) {
e.stop();
this.clicked = true;
}.bind(this));
this.element.observe('dblclick', function(e) {
e.stop();
});
this.element.observe('mousedown', function(e) {
e.stop();
});
},
update: function() {
if (this.clicked || this.instance.isKeyPress('KEY_RETURN')) {
if (this.instance.MData.systemVars.SE.onContinue)
this.instance.playMusic(this.instance.MData.systemVars.SE.onContinue, 'snd', { skip: true });
this.clicked = false;
this.render(1.0);
this.cancel();
this.event('beforeFinish');
if (this.finish) this.finish();
this.event('afterFinish');
var difference = 0,
queues = Effect.Queues.get(this.instance.effectScope).effects;
if (queues.length != 0) {
queues.each(function(effect, index) {
if (index == 0) {
difference = effect.startOn - new Date().getTime();
}
effect.startOn -= difference;
effect.finishOn -= difference;
});
}
}
},
finish: function() {
this.element.stopObserving();
}
});
Effect.WaitToChoose = Class.create(Effect.Base, {
initialize: function(elements, instance) {
this.elements = $(elements);
this.instance = instance;
this.clicked = false;
this.start(Object.extend({
delay: 0.05,
duration: 10000,
fps: 100,
queue: { scope: this.instance.effectScope, position: 'end' }
}, arguments[1] || { }));
},
setup: function() {
this.elements.each(function(element, index) {
if (this.elements == this.instance.winAns) {
element.observe('click', function(e) {
e.stop();
this.clicked = true;
this.instance.selectedItem = index;
element.setStyle({ color: '#FF8C00' });
}.bind(this))
.observe('mouseover', function() {
element.setStyle({ color: '#00BFFF', backgroundColor: '#333' });
})
.observe('mouseout', function() {
element.setStyle({ color: '#FFF', backgroundColor: '#000' });
});
}
else if (this.elements == this.instance.winConf) {
element.observe('click', function(e) {
e.stop();
this.clicked = true;
this.instance.selectedItem = index;
element.setStyle({ color: '#00BFFF' });
}.bind(this))
.observe('mouseover', function() {
element.morph({ backgroundColor: '#333' }, { duration: 0.3 });
}.bind(this))
.observe('mouseout', function() {
element.morph({ color: '#FF8C00', backgroundColor: '#000' }, { duration: 0.3 });
}.bind(this));
}
}.bind(this));
},
update: function() {
if (this.clicked) {
if (this.instance.MData.systemVars.SE.onSelectChoice)
this.instance.playMusic(this.instance.MData.systemVars.SE.onSelectChoice, 'snd', { skip: true });
this.clicked = false;
this.render(1.0);
this.cancel();
this.event('beforeFinish');
if (this.finish) this.finish();
this.event('afterFinish');
var difference = 0,
queues = Effect.Queues.get(this.instance.effectScope).effects;
if (queues.length != 0) {
queues.each(function(effect, index) {
if (index == 0) {
difference = effect.startOn - new Date().getTime();
}
effect.startOn -= difference;
effect.finishOn -= difference;
});
}
}
},
finish: function() {
this.instance.question.hide();
this.elements.invoke('hide');
this.elements.invoke('stopObserving');
this.elements.invoke('setStyle', { backgroundColor: '#000' });
}
});
Effect.WaitForDialog = Class.create(Effect.Base, {
initialize: function(type, instance) {
this.dialogType = type;
this.commandResult = null;
this.instance = instance;
this.formWin = this.instance.dialogWin;
this.formElement = this.instance.dialogForm;
this.inputText = this.instance.inputText;
this.commandOk = this.instance.commandOk;
this.commandCancel = this.instance.commandCancel;
this.start(Object.extend({
delay: 0.05,
duration: 10000,
fps: 100,
queue: { scope: this.instance.effectScope, position: 'front' }
}, arguments[1] || { }));
},
setup: function() {
this.commandOk.observe('click', function(e) {
e.stop();
this.commandResult = true;
}.bind(this));
this.commandCancel.observe('click', function(e) {
e.stop();
this.commandResult = false;
}.bind(this));
},
update: function() {
if (this.commandResult !== null || this.instance.isKeyPress('KEY_RETURN')) {
if (this.dialogType == 'input' && !this.inputText.present()) {
this.commandResult = null;
return;
}
if (this.instance.MData.systemVars.SE.onSelectChoice)
this.instance.playMusic(this.instance.MData.systemVars.SE.onSelectChoice, 'snd', { skip: true });
this.commandResult = true;
this.instance.dialogResult = Object.extend(this.instance.dialogResult, {
inputText: this.inputText.getValue(),
command: this.commandResult
});
this.commandResult = null;
this.render(1.0);
this.cancel();
this.event('beforeFinish');
if (this.finish) this.finish();
this.event('afterFinish');
var difference = 0,
queues = Effect.Queues.get(this.instance.effectScope).effects;
if (queues.length != 0) {
queues.each(function(effect, index) {
if (index == 0) {
difference = effect.startOn - new Date().getTime();
}
effect.startOn -= difference;
effect.finishOn -= difference;
});
}
}
},
finish: function() {
this.commandOk.stopObserving();
this.commandCancel.stopObserving();
this.instance.modal.fade({
duration: 0.6,
queue: { scope: 'modal_' + this.effectScope, position: 'end' }
});
this.formWin.fade({
duration: 0.6,
queue: { scope: 'formWin_' + this.effectScope, position: 'parallel' },
afterFinish: function() {
this.instance.dialogMsg.update('');
this.inputText.clear();
}.bind(this)
});
}
});
//The constructor for the ImagePreloader takes an array of image URLs and a call-back function as arguments.
function ImagePreloader(images, callBack) {
// store the callBack
this.callBack = callBack;
// initialize internal state.
this.nLoaded = 0;
this.nProcessed = 0;
this.aImages = new Array;
// record the number of images.
this.nImages = images.length;
// for each image, call preload()
for ( var i = 0; i < images.length; i++ ) {
this.preload(images[i]);
}
}
//The call-back function is stored for later use, then each image URL is passed
//into the preload() method.
ImagePreloader.prototype.preload = function(image) {
// create new Image object and add to array
var oImage = new Image;
this.aImages.push(oImage);
// set up event handlers for the Image object
oImage.onload = ImagePreloader.prototype.onload;
oImage.onerror = ImagePreloader.prototype.onerror;
oImage.onabort = ImagePreloader.prototype.onabort;
// assign pointer back to this.
oImage.oImagePreloader = this;
oImage.bLoaded = false;
// assign the .src property of the Image object
oImage.src = image;
}
//The preload function creates an Image object and assigns functions for the three Image events;
//onload, onerror and onabort. The onload event is raised when the image has been loaded into memory,
//the onerror event is raised when an error occurs while loading the image and the onabort event
//is raised if the user cancels the load by clicking the Stop button on the browser.
//A pointer to the ImagePreloader object is stored in each Image object to facilitate thcallBackck
//mechanism. An optional boolean flag can be added here to indicate whether the image loads properly or not.
//Finally, the “src” attribute is assigned to start the loading of the image.
ImagePreloader.prototype.onComplete = function() {
this.nProcessed++;
if ( this.nProcessed == this.nImages ) {
this.callBack(this.aImages, this.nLoaded);
}
}
ImagePreloader.prototype.onload = function() {
this.bLoaded = true;
this.oImagePreloader.nLoaded++;
this.oImagePreloader.onComplete();
}
ImagePreloader.prototype.onerror = function() {
this.bError = true;
this.oImagePreloader.onComplete();
}
ImagePreloader.prototype.onabort = function() {
this.bAbort = true;
this.oImagePreloader.onComplete();
}