Project1
标题: [持续更新]正在翻译RMMV的JS脚本,好大的坑. [打印本页]
作者: kula1900 时间: 2017-3-9 14:43
标题: [持续更新]正在翻译RMMV的JS脚本,好大的坑.
本帖最后由 kula1900 于 2017-3-10 20:55 编辑
希望哪个HTML达人写个CHM版本的。先开下我翻译完成的。
场景类,窗口类,本论坛的成员几乎玩坏了。
1页:rpg_objects.js
2页:rpg_managers.js
游戏对象类
1.游戏临时数据类
//-----------------------------------------------------------------------------
// Game_Temp
//
// The game object class for temporary data that is not included in save data.
// 游戏临时数据类
// 游戏对象类 临时数据不包括在存储数据。
function Game_Temp() {
this.initialize.apply(this, arguments);
}
// 游戏临时数据类.初始化
Game_Temp.prototype.initialize = function() {
this._isPlaytest = Utils.isOptionValid('test'); // 游戏临时数据类.游戏测试
this._commonEventId = 0; // 游戏临时数据类.公共事件ID
this._destinationX = null; // 游戏临时数据类.目的地X
this._destinationY = null; // 游戏临时数据类.目的地Y
};
// 游戏临时数据类.是否是游戏测试
Game_Temp.prototype.isPlaytest = function() {
return this._isPlaytest;
};
// 游戏临时数据类.保留公共事件
Game_Temp.prototype.reserveCommonEvent = function(commonEventId) {
this._commonEventId = commonEventId;
};
// 游戏临时数据类.清除公共事件
Game_Temp.prototype.clearCommonEvent = function() {
this._commonEventId = 0;
};
// 游戏临时数据类.是否存在保留的公共事件
Game_Temp.prototype.isCommonEventReserved = function() {
return this._commonEventId > 0;
};
// 游戏临时数据类.取保留公共事件
Game_Temp.prototype.reservedCommonEvent = function() {
return $dataCommonEvents[this._commonEventId];
};
// 游戏临时数据类.设置目的地
Game_Temp.prototype.setDestination = function(x, y) {
this._destinationX = x;
this._destinationY = y;
};
// 游戏临时数据类.清除目的地
Game_Temp.prototype.clearDestination = function() {
this._destinationX = null;
this._destinationY = null;
};
// 游戏临时数据类.目的地是否有效
Game_Temp.prototype.isDestinationValid = function() {
return this._destinationX !== null;
};
// 游戏临时数据类.取目的地X坐标
Game_Temp.prototype.destinationX = function() {
return this._destinationX;
};
// 游戏临时数据类.取目的地Y坐标
Game_Temp.prototype.destinationY = function() {
return this._destinationY;
};
//-----------------------------------------------------------------------------
// Game_Temp
//
// The game object class for temporary data that is not included in save data.
// 游戏临时数据类
// 游戏对象类 临时数据不包括在存储数据。
function Game_Temp() {
this.initialize.apply(this, arguments);
}
// 游戏临时数据类.初始化
Game_Temp.prototype.initialize = function() {
this._isPlaytest = Utils.isOptionValid('test'); // 游戏临时数据类.游戏测试
this._commonEventId = 0; // 游戏临时数据类.公共事件ID
this._destinationX = null; // 游戏临时数据类.目的地X
this._destinationY = null; // 游戏临时数据类.目的地Y
};
// 游戏临时数据类.是否是游戏测试
Game_Temp.prototype.isPlaytest = function() {
return this._isPlaytest;
};
// 游戏临时数据类.保留公共事件
Game_Temp.prototype.reserveCommonEvent = function(commonEventId) {
this._commonEventId = commonEventId;
};
// 游戏临时数据类.清除公共事件
Game_Temp.prototype.clearCommonEvent = function() {
this._commonEventId = 0;
};
// 游戏临时数据类.是否存在保留的公共事件
Game_Temp.prototype.isCommonEventReserved = function() {
return this._commonEventId > 0;
};
// 游戏临时数据类.取保留公共事件
Game_Temp.prototype.reservedCommonEvent = function() {
return $dataCommonEvents[this._commonEventId];
};
// 游戏临时数据类.设置目的地
Game_Temp.prototype.setDestination = function(x, y) {
this._destinationX = x;
this._destinationY = y;
};
// 游戏临时数据类.清除目的地
Game_Temp.prototype.clearDestination = function() {
this._destinationX = null;
this._destinationY = null;
};
// 游戏临时数据类.目的地是否有效
Game_Temp.prototype.isDestinationValid = function() {
return this._destinationX !== null;
};
// 游戏临时数据类.取目的地X坐标
Game_Temp.prototype.destinationX = function() {
return this._destinationX;
};
// 游戏临时数据类.取目的地Y坐标
Game_Temp.prototype.destinationY = function() {
return this._destinationY;
};
2.游戏系统类
//-----------------------------------------------------------------------------
// Game_System
//
// The game object class for the system data.
// 游戏系统类
// 游戏对象类 游戏系统对象
function Game_System() {
this.initialize.apply(this, arguments);
}
// 游戏系统类.初始化
Game_System.prototype.initialize = function() {
this._saveEnabled = true; // 游戏系统类.启用保存
this._menuEnabled = true; // 游戏系统类.启用菜单
this._encounterEnabled = true; // 游戏系统类.启用遇敌
this._formationEnabled = true; // 游戏系统类.启用队形
this._battleCount = 0; // 游戏系统类.战斗计数器
this._winCount = 0; // 游戏系统类.胜利计数器
this._escapeCount = 0; // 游戏系统类.逃跑计数器
this._saveCount = 0; // 游戏系统类.保存计数器
this._versionId = 0; // 游戏系统类.版本号
this._framesOnSave = 0; // 游戏系统类.保存的帧
this._bgmOnSave = null; // 游戏系统类.保存的BGM
this._bgsOnSave = null; // 游戏系统类.保存的BGS
this._windowTone = null; // 游戏系统类.窗口色掉
this._battleBgm = null; // 游戏系统类.战斗BGM
this._victoryMe = null; // 游戏系统类.胜利ME
this._defeatMe = null; // 游戏系统类.失败ME
this._savedBgm = null; // 游戏系统类.保存BGM音效
this._walkingBgm = null; // 游戏系统类.行走BGM
};
// 游戏系统类.是否是日语
Game_System.prototype.isJapanese = function() {
return $dataSystem.locale.match(/^ja/);
};
// 游戏系统类.是否是中文
Game_System.prototype.isChinese = function() {
return $dataSystem.locale.match(/^zh/);
};
// 游戏系统类.是否是韩语
Game_System.prototype.isKorean = function() {
return $dataSystem.locale.match(/^ko/);
};
// 游戏系统类.是否是中日韩语
Game_System.prototype.isCJK = function() {
return $dataSystem.locale.match(/^(ja|zh|ko)/);
};
// 游戏系统类.是否是俄罗斯语
Game_System.prototype.isRussian = function() {
return $dataSystem.locale.match(/^ru/);
};
// 游戏系统类.选择侧视图
Game_System.prototype.isSideView = function() {
return $dataSystem.optSideView;
};
// 游戏系统类.是否启用保存
Game_System.prototype.isSaveEnabled = function() {
return this._saveEnabled;
};
// 游戏系统类.禁用保存
Game_System.prototype.disableSave = function() {
this._saveEnabled = false;
};
// 游戏系统类.启用保存
Game_System.prototype.enableSave = function() {
this._saveEnabled = true;
};
// 游戏系统类.是否启用菜单
Game_System.prototype.isMenuEnabled = function() {
return this._menuEnabled;
};
// 游戏系统类.禁用菜单
Game_System.prototype.disableMenu = function() {
this._menuEnabled = false;
};
// 游戏系统类.启用菜单
Game_System.prototype.enableMenu = function() {
this._menuEnabled = true;
};
// 游戏系统类.是否启用遇敌
Game_System.prototype.isEncounterEnabled = function() {
return this._encounterEnabled;
};
// 游戏系统类.禁止遇敌
Game_System.prototype.disableEncounter = function() {
this._encounterEnabled = false;
};
// 游戏系统类.启用遇敌
Game_System.prototype.enableEncounter = function() {
this._encounterEnabled = true;
};
// 游戏系统类.是否启用队形
Game_System.prototype.isFormationEnabled = function() {
return this._formationEnabled;
};
// 游戏系统类.禁用队形
Game_System.prototype.disableFormation = function() {
this._formationEnabled = false;
};
// 游戏系统类.启用队形
Game_System.prototype.enableFormation = function() {
this._formationEnabled = true;
};
// 游戏系统类.取战斗计数器
Game_System.prototype.battleCount = function() {
return this._battleCount;
};
// 游戏系统类.取胜利计数器
Game_System.prototype.winCount = function() {
return this._winCount;
};
// 游戏系统类.取逃跑计数器
Game_System.prototype.escapeCount = function() {
return this._escapeCount;
};
// 游戏系统类.取保存计数器
Game_System.prototype.saveCount = function() {
return this._saveCount;
};
// 游戏系统类.取版本号
Game_System.prototype.versionId = function() {
return this._versionId;
};
// 游戏系统类.取窗口色调
Game_System.prototype.windowTone = function() {
return this._windowTone || $dataSystem.windowTone;
};
// 游戏系统类.设置窗口色调
Game_System.prototype.setWindowTone = function(value) {
this._windowTone = value;
};
// 游戏系统类.战斗BGM
Game_System.prototype.battleBgm = function() {
return this._battleBgm || $dataSystem.battleBgm;
};
// 游戏系统类.设置战斗BGM
Game_System.prototype.setBattleBgm = function(value) {
this._battleBgm = value;
};
// 游戏系统类.胜利ME
Game_System.prototype.victoryMe = function() {
return this._victoryMe || $dataSystem.victoryMe;
};
// 游戏系统类.设置胜利ME
Game_System.prototype.setVictoryMe = function(value) {
this._victoryMe = value;
};
// 游戏系统类.失败ME
Game_System.prototype.defeatMe = function() {
return this._defeatMe || $dataSystem.defeatMe;
};
// 游戏系统类.设置失败ME
Game_System.prototype.setDefeatMe = function(value) {
this._defeatMe = value;
};
// 游戏系统类.战斗开始事件
Game_System.prototype.onBattleStart = function() {
this._battleCount++;
};
// 游戏系统类.战斗胜利事件
Game_System.prototype.onBattleWin = function() {
this._winCount++;
};
// 游戏系统类.战斗逃跑成功事件
Game_System.prototype.onBattleEscape = function() {
this._escapeCount++;
};
// 游戏系统类.保存之前事件
Game_System.prototype.onBeforeSave = function() {
this._saveCount++; // 游戏系统类.保存计数器++
this._versionId = $dataSystem.versionId; // 游戏系统类.版本号 = $dataSystem.versionId
this._framesOnSave = Graphics.frameCount; // 游戏系统类.保存的帧 = 图形.帧计数器
this._bgmOnSave = AudioManager.saveBgm(); // 游戏系统类.保存的BGM = 音频管理器.保存BGM
this._bgsOnSave = AudioManager.saveBgs(); // 游戏系统类.保存的BGS = 音频管理器.保存BGS
};
// 游戏系统类.加载之后事件
Game_System.prototype.onAfterLoad = function() {
Graphics.frameCount = this._framesOnSave; // 图形.帧计数器 = 游戏系统类.保存的帧
AudioManager.playBgm(this._bgmOnSave); // 音频管理器.播放BGM(游戏系统类.保存的BGM)
AudioManager.playBgs(this._bgsOnSave); // 音频管理器.播放BGS(游戏系统类.保存的BGS)
};
// 游戏系统类.游戏时间
Game_System.prototype.playtime = function() {
return Math.floor(Graphics.frameCount / 60);// Math.进行下舍入(图形.帧计数器/60);
};
// 游戏系统类.游戏时间文本
Game_System.prototype.playtimeText = function() {
var hour = Math.floor(this.playtime() / 60 / 60); // 取小时
var min = Math.floor(this.playtime() / 60) % 60; // 取分钟
var sec = this.playtime() % 60; // 取秒数
return hour.padZero(2) + ':' + min.padZero(2) + ':' + sec.padZero(2);
};
// 游戏系统类.保存BGM
Game_System.prototype.saveBgm = function() {
this._savedBgm = AudioManager.saveBgm(); // 游戏系统类.保存的BGM = 音频管理器.保存BGM
};
// 游戏系统类.重播BGM
Game_System.prototype.replayBgm = function() {
if (this._savedBgm) {
AudioManager.replayBgm(this._savedBgm); // 音频管理器.重播BGM(游戏系统类.保存的BGM)
}
};
// 游戏系统类.保存行走BGM
Game_System.prototype.saveWalkingBgm = function() {
this._walkingBgm = AudioManager.saveBgm(); // 游戏系统类.行走BGM = 音频管理器.保存BGM
};
// 游戏系统类.重播行走BGM
Game_System.prototype.replayWalkingBgm = function() {
if (this._walkingBgm) {
AudioManager.playBgm(this._walkingBgm); // 音频管理器.重播BGM(游戏系统类.行走BGM)
}
}
;
//-----------------------------------------------------------------------------
// Game_System
//
// The game object class for the system data.
// 游戏系统类
// 游戏对象类 游戏系统对象
function Game_System() {
this.initialize.apply(this, arguments);
}
// 游戏系统类.初始化
Game_System.prototype.initialize = function() {
this._saveEnabled = true; // 游戏系统类.启用保存
this._menuEnabled = true; // 游戏系统类.启用菜单
this._encounterEnabled = true; // 游戏系统类.启用遇敌
this._formationEnabled = true; // 游戏系统类.启用队形
this._battleCount = 0; // 游戏系统类.战斗计数器
this._winCount = 0; // 游戏系统类.胜利计数器
this._escapeCount = 0; // 游戏系统类.逃跑计数器
this._saveCount = 0; // 游戏系统类.保存计数器
this._versionId = 0; // 游戏系统类.版本号
this._framesOnSave = 0; // 游戏系统类.保存的帧
this._bgmOnSave = null; // 游戏系统类.保存的BGM
this._bgsOnSave = null; // 游戏系统类.保存的BGS
this._windowTone = null; // 游戏系统类.窗口色掉
this._battleBgm = null; // 游戏系统类.战斗BGM
this._victoryMe = null; // 游戏系统类.胜利ME
this._defeatMe = null; // 游戏系统类.失败ME
this._savedBgm = null; // 游戏系统类.保存BGM音效
this._walkingBgm = null; // 游戏系统类.行走BGM
};
// 游戏系统类.是否是日语
Game_System.prototype.isJapanese = function() {
return $dataSystem.locale.match(/^ja/);
};
// 游戏系统类.是否是中文
Game_System.prototype.isChinese = function() {
return $dataSystem.locale.match(/^zh/);
};
// 游戏系统类.是否是韩语
Game_System.prototype.isKorean = function() {
return $dataSystem.locale.match(/^ko/);
};
// 游戏系统类.是否是中日韩语
Game_System.prototype.isCJK = function() {
return $dataSystem.locale.match(/^(ja|zh|ko)/);
};
// 游戏系统类.是否是俄罗斯语
Game_System.prototype.isRussian = function() {
return $dataSystem.locale.match(/^ru/);
};
// 游戏系统类.选择侧视图
Game_System.prototype.isSideView = function() {
return $dataSystem.optSideView;
};
// 游戏系统类.是否启用保存
Game_System.prototype.isSaveEnabled = function() {
return this._saveEnabled;
};
// 游戏系统类.禁用保存
Game_System.prototype.disableSave = function() {
this._saveEnabled = false;
};
// 游戏系统类.启用保存
Game_System.prototype.enableSave = function() {
this._saveEnabled = true;
};
// 游戏系统类.是否启用菜单
Game_System.prototype.isMenuEnabled = function() {
return this._menuEnabled;
};
// 游戏系统类.禁用菜单
Game_System.prototype.disableMenu = function() {
this._menuEnabled = false;
};
// 游戏系统类.启用菜单
Game_System.prototype.enableMenu = function() {
this._menuEnabled = true;
};
// 游戏系统类.是否启用遇敌
Game_System.prototype.isEncounterEnabled = function() {
return this._encounterEnabled;
};
// 游戏系统类.禁止遇敌
Game_System.prototype.disableEncounter = function() {
this._encounterEnabled = false;
};
// 游戏系统类.启用遇敌
Game_System.prototype.enableEncounter = function() {
this._encounterEnabled = true;
};
// 游戏系统类.是否启用队形
Game_System.prototype.isFormationEnabled = function() {
return this._formationEnabled;
};
// 游戏系统类.禁用队形
Game_System.prototype.disableFormation = function() {
this._formationEnabled = false;
};
// 游戏系统类.启用队形
Game_System.prototype.enableFormation = function() {
this._formationEnabled = true;
};
// 游戏系统类.取战斗计数器
Game_System.prototype.battleCount = function() {
return this._battleCount;
};
// 游戏系统类.取胜利计数器
Game_System.prototype.winCount = function() {
return this._winCount;
};
// 游戏系统类.取逃跑计数器
Game_System.prototype.escapeCount = function() {
return this._escapeCount;
};
// 游戏系统类.取保存计数器
Game_System.prototype.saveCount = function() {
return this._saveCount;
};
// 游戏系统类.取版本号
Game_System.prototype.versionId = function() {
return this._versionId;
};
// 游戏系统类.取窗口色调
Game_System.prototype.windowTone = function() {
return this._windowTone || $dataSystem.windowTone;
};
// 游戏系统类.设置窗口色调
Game_System.prototype.setWindowTone = function(value) {
this._windowTone = value;
};
// 游戏系统类.战斗BGM
Game_System.prototype.battleBgm = function() {
return this._battleBgm || $dataSystem.battleBgm;
};
// 游戏系统类.设置战斗BGM
Game_System.prototype.setBattleBgm = function(value) {
this._battleBgm = value;
};
// 游戏系统类.胜利ME
Game_System.prototype.victoryMe = function() {
return this._victoryMe || $dataSystem.victoryMe;
};
// 游戏系统类.设置胜利ME
Game_System.prototype.setVictoryMe = function(value) {
this._victoryMe = value;
};
// 游戏系统类.失败ME
Game_System.prototype.defeatMe = function() {
return this._defeatMe || $dataSystem.defeatMe;
};
// 游戏系统类.设置失败ME
Game_System.prototype.setDefeatMe = function(value) {
this._defeatMe = value;
};
// 游戏系统类.战斗开始事件
Game_System.prototype.onBattleStart = function() {
this._battleCount++;
};
// 游戏系统类.战斗胜利事件
Game_System.prototype.onBattleWin = function() {
this._winCount++;
};
// 游戏系统类.战斗逃跑成功事件
Game_System.prototype.onBattleEscape = function() {
this._escapeCount++;
};
// 游戏系统类.保存之前事件
Game_System.prototype.onBeforeSave = function() {
this._saveCount++; // 游戏系统类.保存计数器++
this._versionId = $dataSystem.versionId; // 游戏系统类.版本号 = $dataSystem.versionId
this._framesOnSave = Graphics.frameCount; // 游戏系统类.保存的帧 = 图形.帧计数器
this._bgmOnSave = AudioManager.saveBgm(); // 游戏系统类.保存的BGM = 音频管理器.保存BGM
this._bgsOnSave = AudioManager.saveBgs(); // 游戏系统类.保存的BGS = 音频管理器.保存BGS
};
// 游戏系统类.加载之后事件
Game_System.prototype.onAfterLoad = function() {
Graphics.frameCount = this._framesOnSave; // 图形.帧计数器 = 游戏系统类.保存的帧
AudioManager.playBgm(this._bgmOnSave); // 音频管理器.播放BGM(游戏系统类.保存的BGM)
AudioManager.playBgs(this._bgsOnSave); // 音频管理器.播放BGS(游戏系统类.保存的BGS)
};
// 游戏系统类.游戏时间
Game_System.prototype.playtime = function() {
return Math.floor(Graphics.frameCount / 60);// Math.进行下舍入(图形.帧计数器/60);
};
// 游戏系统类.游戏时间文本
Game_System.prototype.playtimeText = function() {
var hour = Math.floor(this.playtime() / 60 / 60); // 取小时
var min = Math.floor(this.playtime() / 60) % 60; // 取分钟
var sec = this.playtime() % 60; // 取秒数
return hour.padZero(2) + ':' + min.padZero(2) + ':' + sec.padZero(2);
};
// 游戏系统类.保存BGM
Game_System.prototype.saveBgm = function() {
this._savedBgm = AudioManager.saveBgm(); // 游戏系统类.保存的BGM = 音频管理器.保存BGM
};
// 游戏系统类.重播BGM
Game_System.prototype.replayBgm = function() {
if (this._savedBgm) {
AudioManager.replayBgm(this._savedBgm); // 音频管理器.重播BGM(游戏系统类.保存的BGM)
}
};
// 游戏系统类.保存行走BGM
Game_System.prototype.saveWalkingBgm = function() {
this._walkingBgm = AudioManager.saveBgm(); // 游戏系统类.行走BGM = 音频管理器.保存BGM
};
// 游戏系统类.重播行走BGM
Game_System.prototype.replayWalkingBgm = function() {
if (this._walkingBgm) {
AudioManager.playBgm(this._walkingBgm); // 音频管理器.重播BGM(游戏系统类.行走BGM)
}
}
;
3.游戏时间类
//-----------------------------------------------------------------------------
// Game_Timer
//
// The game object class for the timer.
// 游戏时间类
function Game_Timer() {
this.initialize.apply(this, arguments);
}
// 游戏时间类.初始化
Game_Timer.prototype.initialize = function() {
this._frames = 0; // 游戏时间类.帧数
this._working = false; // 游戏时间类.工作中
};
// 游戏时间类.更新(活动场景)
Game_Timer.prototype.update = function(sceneActive) {
// 活动场景 非空 且 游戏时间类.工作中 且 游戏时间类.帧数 > 0
if (sceneActive && this._working && this._frames > 0) {
this._frames--; // 游戏时间类.帧数--
if (this._frames === 0) { // 游戏时间类.帧数 === 0
this.onExpire(); // 游戏时间类.到期事件()
}
}
};
// 游戏时间类.开始
Game_Timer.prototype.start = function(count) {
this._frames = count;
this._working = true;
};
// 游戏时间类.停止
Game_Timer.prototype.stop = function() {
this._working = false;
};
// 游戏时间类.是否在工作中
Game_Timer.prototype.isWorking = function() {
return this._working;
};
// 游戏时间类.取分钟数
Game_Timer.prototype.seconds = function() {
return Math.floor(this._frames / 60);
};
// 游戏时间类.到期事件
Game_Timer.prototype.onExpire = function() {
BattleManager.abort(); // 战斗管理器.终止
};
//-----------------------------------------------------------------------------
// Game_Timer
//
// The game object class for the timer.
// 游戏时间类
function Game_Timer() {
this.initialize.apply(this, arguments);
}
// 游戏时间类.初始化
Game_Timer.prototype.initialize = function() {
this._frames = 0; // 游戏时间类.帧数
this._working = false; // 游戏时间类.工作中
};
// 游戏时间类.更新(活动场景)
Game_Timer.prototype.update = function(sceneActive) {
// 活动场景 非空 且 游戏时间类.工作中 且 游戏时间类.帧数 > 0
if (sceneActive && this._working && this._frames > 0) {
this._frames--; // 游戏时间类.帧数--
if (this._frames === 0) { // 游戏时间类.帧数 === 0
this.onExpire(); // 游戏时间类.到期事件()
}
}
};
// 游戏时间类.开始
Game_Timer.prototype.start = function(count) {
this._frames = count;
this._working = true;
};
// 游戏时间类.停止
Game_Timer.prototype.stop = function() {
this._working = false;
};
// 游戏时间类.是否在工作中
Game_Timer.prototype.isWorking = function() {
return this._working;
};
// 游戏时间类.取分钟数
Game_Timer.prototype.seconds = function() {
return Math.floor(this._frames / 60);
};
// 游戏时间类.到期事件
Game_Timer.prototype.onExpire = function() {
BattleManager.abort(); // 战斗管理器.终止
};
4.游戏消息类
//-----------------------------------------------------------------------------
// Game_Message
//
// The game object class for the state of the message window that displays text
// or selections, etc.
// 游戏消息类
// 游戏对象类 显示 状态消息窗口文本或选择等。
function Game_Message() {
this.initialize.apply(this, arguments);
}
// 游戏消息类.初始化
Game_Message.prototype.initialize = function() {
this.clear();
};
//---------------------------------------------------------------------------
// 游戏消息类.清除 (整理)
//---------------------------------------------------------------------------
Game_Message.prototype.clear = function() {
this._choiceCallback = null; // 游戏消息类.选择项目回调
//---------------------------------------------------------------------------
// 事件:显示文章 或 文章的滚动显示
//---------------------------------------------------------------------------
this._texts = []; // 游戏消息类.文本组
//---------------------------------------------------------------------------
// 事件:显示文章
//---------------------------------------------------------------------------
this._faceName = ''; // 游戏消息类.脸部图象名
this._faceIndex = 0; // 游戏消息类.脸部图象索引
this._background = 0; // 游戏消息类.背景
this._positionType = 2; // 游戏消息类.位置类型
//---------------------------------------------------------------------------
// 事件:文章的滚动显示
//---------------------------------------------------------------------------
this._scrollMode = false; // 游戏消息类.滚动模式
this._scrollSpeed = 2; // 游戏消息类.滚动速度
this._scrollNoFast = false; // 游戏消息类.禁止快进
//---------------------------------------------------------------------------
// 事件:显示选择项
//---------------------------------------------------------------------------
this._choices = []; // 游戏消息类.选择项组
this._choiceDefaultType = 0; // 游戏消息类.选择默认类型
this._choiceCancelType = 0; // 游戏消息类.选择取消类型
this._choiceBackground = 0; // 游戏消息类.选择背景
this._choicePositionType = 2; // 游戏消息类.选择位置类型
//---------------------------------------------------------------------------
// 事件:输入数值处理
//---------------------------------------------------------------------------
this._numInputVariableId = 0; // 游戏消息类.数字输入变量ID
this._numInputMaxDigits = 0; // 游戏消息类.数字输入最大位数
//---------------------------------------------------------------------------
// 事件:处理道具选择
//---------------------------------------------------------------------------
this._itemChoiceVariableId = 0; // 游戏消息类.道具选择变量Id
this._itemChoiceItypeId = 0; // 游戏消息类.道具类型Id
};
// 游戏消息类.取选择项组
Game_Message.prototype.choices = function() {
return this._choices;
};
// 游戏消息类.取脸部图像名称
Game_Message.prototype.faceName = function() {
return this._faceName;
};
// 游戏消息类.取脸部图像索引
Game_Message.prototype.faceIndex = function() {
return this._faceIndex;
};
// 游戏消息类.取背景
Game_Message.prototype.background = function() {
return this._background;
};
// 游戏消息类.取位置类型
Game_Message.prototype.positionType = function() {
return this._positionType;
};
// 游戏消息类.取选择默认类型
Game_Message.prototype.choiceDefaultType = function() {
return this._choiceDefaultType;
};
// 游戏消息类.取选择取消类型
Game_Message.prototype.choiceCancelType = function() {
return this._choiceCancelType;
};
// 游戏消息类.取选择背景
Game_Message.prototype.choiceBackground = function() {
return this._choiceBackground;
};
// 游戏消息类.取选择位置类型
Game_Message.prototype.choicePositionType = function() {
return this._choicePositionType;
};
// 游戏消息类.取数字输入变量ID
Game_Message.prototype.numInputVariableId = function() {
return this._numInputVariableId;
};
// 游戏消息类.取数字输入最大位数
Game_Message.prototype.numInputMaxDigits = function() {
return this._numInputMaxDigits;
};
// 游戏消息类.取道具选择变量Id
Game_Message.prototype.itemChoiceVariableId = function() {
return this._itemChoiceVariableId;
};
// 游戏消息类.取道具选择类型Id
Game_Message.prototype.itemChoiceItypeId = function() {
return this._itemChoiceItypeId;
};
// 游戏消息类.取滚动模式
Game_Message.prototype.scrollMode = function() {
return this._scrollMode;
};
// 游戏消息类.取滚动速度
Game_Message.prototype.scrollSpeed = function() {
return this._scrollSpeed;
};
// 游戏消息类.取是否禁止快进
Game_Message.prototype.scrollNoFast = function() {
return this._scrollNoFast;
};
// 游戏消息类.添加文本
Game_Message.prototype.add = function(text) {
this._texts.push(text); // 游戏消息类.文本组.投递()
};
// 游戏消息类.设置脸部图像
Game_Message.prototype.setFaceImage = function(faceName, faceIndex) {
this._faceName = faceName;
this._faceIndex = faceIndex;
};
// 游戏消息类.设置背景
Game_Message.prototype.setBackground = function(background) {
this._background = background;
};
// 游戏消息类.设置位置模式
Game_Message.prototype.setPositionType = function(positionType) {
this._positionType = positionType;
};
// 游戏消息类.设置选择
Game_Message.prototype.setChoices = function(choices, defaultType, cancelType) {
this._choices = choices;
this._choiceDefaultType = defaultType;
this._choiceCancelType = cancelType;
};
// 游戏消息类.设置选择背景
Game_Message.prototype.setChoiceBackground = function(background) {
this._choiceBackground = background;
};
// 游戏消息类.设置选择位置
Game_Message.prototype.setChoicePositionType = function(positionType) {
this._choicePositionType = positionType;
};
// 游戏消息类.设置数字输入
Game_Message.prototype.setNumberInput = function(variableId, maxDigits) {
this._numInputVariableId = variableId;
this._numInputMaxDigits = maxDigits;
};
// 游戏消息类.设置道具选择
Game_Message.prototype.setItemChoice = function(variableId, itemType) {
this._itemChoiceVariableId = variableId;
this._itemChoiceItypeId = itemType;
};
// 游戏消息类.设置文章的滚动显示
Game_Message.prototype.setScroll = function(speed, noFast) {
this._scrollMode = true;
this._scrollSpeed = speed;
this._scrollNoFast = noFast;
};
// 游戏消息类.设置选择回调
Game_Message.prototype.setChoiceCallback = function(callback) {
this._choiceCallback = callback;
};
// 游戏消息类.选择事件
Game_Message.prototype.onChoice = function(n) {
if (this._choiceCallback) {
this._choiceCallback(n);
this._choiceCallback = null;
}
};
// 游戏消息类.是否存在文本
Game_Message.prototype.hasText = function() {
return this._texts.length > 0;
};
// 游戏消息类.是否是显示选择项
Game_Message.prototype.isChoice = function() {
return this._choices.length > 0;
};
// 游戏消息类.是否是数字输入
Game_Message.prototype.isNumberInput = function() {
return this._numInputVariableId > 0;
};
// 游戏消息类.是否是道具选择
Game_Message.prototype.isItemChoice = function() {
return this._itemChoiceVariableId > 0;
};
// 游戏消息类.是否被占用
Game_Message.prototype.isBusy = function() {
return (this.hasText() || this.isChoice() ||
this.isNumberInput() || this.isItemChoice());
};
// 游戏消息类.新建页面
Game_Message.prototype.newPage = function() {
if (this._texts.length > 0) {
this._texts[this._texts.length - 1] += '\f';
}
};
// 游戏消息类.取全部文本
Game_Message.prototype.allText = function() {
return this._texts.reduce(function(previousValue, currentValue) {
return previousValue + '\n' + currentValue;
});
};
//-----------------------------------------------------------------------------
// Game_Message
//
// The game object class for the state of the message window that displays text
// or selections, etc.
// 游戏消息类
// 游戏对象类 显示 状态消息窗口文本或选择等。
function Game_Message() {
this.initialize.apply(this, arguments);
}
// 游戏消息类.初始化
Game_Message.prototype.initialize = function() {
this.clear();
};
//---------------------------------------------------------------------------
// 游戏消息类.清除 (整理)
//---------------------------------------------------------------------------
Game_Message.prototype.clear = function() {
this._choiceCallback = null; // 游戏消息类.选择项目回调
//---------------------------------------------------------------------------
// 事件:显示文章 或 文章的滚动显示
//---------------------------------------------------------------------------
this._texts = []; // 游戏消息类.文本组
//---------------------------------------------------------------------------
// 事件:显示文章
//---------------------------------------------------------------------------
this._faceName = ''; // 游戏消息类.脸部图象名
this._faceIndex = 0; // 游戏消息类.脸部图象索引
this._background = 0; // 游戏消息类.背景
this._positionType = 2; // 游戏消息类.位置类型
//---------------------------------------------------------------------------
// 事件:文章的滚动显示
//---------------------------------------------------------------------------
this._scrollMode = false; // 游戏消息类.滚动模式
this._scrollSpeed = 2; // 游戏消息类.滚动速度
this._scrollNoFast = false; // 游戏消息类.禁止快进
//---------------------------------------------------------------------------
// 事件:显示选择项
//---------------------------------------------------------------------------
this._choices = []; // 游戏消息类.选择项组
this._choiceDefaultType = 0; // 游戏消息类.选择默认类型
this._choiceCancelType = 0; // 游戏消息类.选择取消类型
this._choiceBackground = 0; // 游戏消息类.选择背景
this._choicePositionType = 2; // 游戏消息类.选择位置类型
//---------------------------------------------------------------------------
// 事件:输入数值处理
//---------------------------------------------------------------------------
this._numInputVariableId = 0; // 游戏消息类.数字输入变量ID
this._numInputMaxDigits = 0; // 游戏消息类.数字输入最大位数
//---------------------------------------------------------------------------
// 事件:处理道具选择
//---------------------------------------------------------------------------
this._itemChoiceVariableId = 0; // 游戏消息类.道具选择变量Id
this._itemChoiceItypeId = 0; // 游戏消息类.道具类型Id
};
// 游戏消息类.取选择项组
Game_Message.prototype.choices = function() {
return this._choices;
};
// 游戏消息类.取脸部图像名称
Game_Message.prototype.faceName = function() {
return this._faceName;
};
// 游戏消息类.取脸部图像索引
Game_Message.prototype.faceIndex = function() {
return this._faceIndex;
};
// 游戏消息类.取背景
Game_Message.prototype.background = function() {
return this._background;
};
// 游戏消息类.取位置类型
Game_Message.prototype.positionType = function() {
return this._positionType;
};
// 游戏消息类.取选择默认类型
Game_Message.prototype.choiceDefaultType = function() {
return this._choiceDefaultType;
};
// 游戏消息类.取选择取消类型
Game_Message.prototype.choiceCancelType = function() {
return this._choiceCancelType;
};
// 游戏消息类.取选择背景
Game_Message.prototype.choiceBackground = function() {
return this._choiceBackground;
};
// 游戏消息类.取选择位置类型
Game_Message.prototype.choicePositionType = function() {
return this._choicePositionType;
};
// 游戏消息类.取数字输入变量ID
Game_Message.prototype.numInputVariableId = function() {
return this._numInputVariableId;
};
// 游戏消息类.取数字输入最大位数
Game_Message.prototype.numInputMaxDigits = function() {
return this._numInputMaxDigits;
};
// 游戏消息类.取道具选择变量Id
Game_Message.prototype.itemChoiceVariableId = function() {
return this._itemChoiceVariableId;
};
// 游戏消息类.取道具选择类型Id
Game_Message.prototype.itemChoiceItypeId = function() {
return this._itemChoiceItypeId;
};
// 游戏消息类.取滚动模式
Game_Message.prototype.scrollMode = function() {
return this._scrollMode;
};
// 游戏消息类.取滚动速度
Game_Message.prototype.scrollSpeed = function() {
return this._scrollSpeed;
};
// 游戏消息类.取是否禁止快进
Game_Message.prototype.scrollNoFast = function() {
return this._scrollNoFast;
};
// 游戏消息类.添加文本
Game_Message.prototype.add = function(text) {
this._texts.push(text); // 游戏消息类.文本组.投递()
};
// 游戏消息类.设置脸部图像
Game_Message.prototype.setFaceImage = function(faceName, faceIndex) {
this._faceName = faceName;
this._faceIndex = faceIndex;
};
// 游戏消息类.设置背景
Game_Message.prototype.setBackground = function(background) {
this._background = background;
};
// 游戏消息类.设置位置模式
Game_Message.prototype.setPositionType = function(positionType) {
this._positionType = positionType;
};
// 游戏消息类.设置选择
Game_Message.prototype.setChoices = function(choices, defaultType, cancelType) {
this._choices = choices;
this._choiceDefaultType = defaultType;
this._choiceCancelType = cancelType;
};
// 游戏消息类.设置选择背景
Game_Message.prototype.setChoiceBackground = function(background) {
this._choiceBackground = background;
};
// 游戏消息类.设置选择位置
Game_Message.prototype.setChoicePositionType = function(positionType) {
this._choicePositionType = positionType;
};
// 游戏消息类.设置数字输入
Game_Message.prototype.setNumberInput = function(variableId, maxDigits) {
this._numInputVariableId = variableId;
this._numInputMaxDigits = maxDigits;
};
// 游戏消息类.设置道具选择
Game_Message.prototype.setItemChoice = function(variableId, itemType) {
this._itemChoiceVariableId = variableId;
this._itemChoiceItypeId = itemType;
};
// 游戏消息类.设置文章的滚动显示
Game_Message.prototype.setScroll = function(speed, noFast) {
this._scrollMode = true;
this._scrollSpeed = speed;
this._scrollNoFast = noFast;
};
// 游戏消息类.设置选择回调
Game_Message.prototype.setChoiceCallback = function(callback) {
this._choiceCallback = callback;
};
// 游戏消息类.选择事件
Game_Message.prototype.onChoice = function(n) {
if (this._choiceCallback) {
this._choiceCallback(n);
this._choiceCallback = null;
}
};
// 游戏消息类.是否存在文本
Game_Message.prototype.hasText = function() {
return this._texts.length > 0;
};
// 游戏消息类.是否是显示选择项
Game_Message.prototype.isChoice = function() {
return this._choices.length > 0;
};
// 游戏消息类.是否是数字输入
Game_Message.prototype.isNumberInput = function() {
return this._numInputVariableId > 0;
};
// 游戏消息类.是否是道具选择
Game_Message.prototype.isItemChoice = function() {
return this._itemChoiceVariableId > 0;
};
// 游戏消息类.是否被占用
Game_Message.prototype.isBusy = function() {
return (this.hasText() || this.isChoice() ||
this.isNumberInput() || this.isItemChoice());
};
// 游戏消息类.新建页面
Game_Message.prototype.newPage = function() {
if (this._texts.length > 0) {
this._texts[this._texts.length - 1] += '\f';
}
};
// 游戏消息类.取全部文本
Game_Message.prototype.allText = function() {
return this._texts.reduce(function(previousValue, currentValue) {
return previousValue + '\n' + currentValue;
});
};
5.游戏开关类
//-----------------------------------------------------------------------------
// Game_Switches
//
// The game object class for switches.
// 游戏开关类
function Game_Switches() {
this.initialize.apply(this, arguments);
}
// 游戏开关类.初始化
Game_Switches.prototype.initialize = function() {
this.clear();
};
// 游戏开关类.清除
Game_Switches.prototype.clear = function() {
this._data = [];
};
// 游戏开关类.取值
Game_Switches.prototype.value = function(switchId) {
return !!this._data[switchId];
};
// 游戏开关类.设置值
Game_Switches.prototype.setValue = function(switchId, value) {
if (switchId > 0 && switchId < $dataSystem.switches.length) {
this._data[switchId] = value;
this.onChange();
}
};
// 游戏开关类.改变值事件
Game_Switches.prototype.onChange = function() {
$gameMap.requestRefresh();
};
//-----------------------------------------------------------------------------
// Game_Switches
//
// The game object class for switches.
// 游戏开关类
function Game_Switches() {
this.initialize.apply(this, arguments);
}
// 游戏开关类.初始化
Game_Switches.prototype.initialize = function() {
this.clear();
};
// 游戏开关类.清除
Game_Switches.prototype.clear = function() {
this._data = [];
};
// 游戏开关类.取值
Game_Switches.prototype.value = function(switchId) {
return !!this._data[switchId];
};
// 游戏开关类.设置值
Game_Switches.prototype.setValue = function(switchId, value) {
if (switchId > 0 && switchId < $dataSystem.switches.length) {
this._data[switchId] = value;
this.onChange();
}
};
// 游戏开关类.改变值事件
Game_Switches.prototype.onChange = function() {
$gameMap.requestRefresh();
};
6.游戏变量类
//-----------------------------------------------------------------------------
// Game_Variables
//
// The game object class for variables.
// 游戏变量类
function Game_Variables() {
this.initialize.apply(this, arguments);
}
// 游戏变量类.初始化
Game_Variables.prototype.initialize = function() {
this.clear();
};
// 游戏变量类.清除
Game_Variables.prototype.clear = function() {
this._data = [];
};
// 游戏变量类.取值
Game_Variables.prototype.value = function(variableId) {
return this._data[variableId] || 0;
};
// 游戏变量类.设置值
Game_Variables.prototype.setValue = function(variableId, value) {
if (variableId > 0 && variableId < $dataSystem.variables.length) {
if (typeof value === 'number') {
value = Math.floor(value);
}
this._data[variableId] = value;
this.onChange();
}
};
// 游戏变量类.改变值事件
Game_Variables.prototype.onChange = function() {
$gameMap.requestRefresh();
};
//-----------------------------------------------------------------------------
// Game_Variables
//
// The game object class for variables.
// 游戏变量类
function Game_Variables() {
this.initialize.apply(this, arguments);
}
// 游戏变量类.初始化
Game_Variables.prototype.initialize = function() {
this.clear();
};
// 游戏变量类.清除
Game_Variables.prototype.clear = function() {
this._data = [];
};
// 游戏变量类.取值
Game_Variables.prototype.value = function(variableId) {
return this._data[variableId] || 0;
};
// 游戏变量类.设置值
Game_Variables.prototype.setValue = function(variableId, value) {
if (variableId > 0 && variableId < $dataSystem.variables.length) {
if (typeof value === 'number') {
value = Math.floor(value);
}
this._data[variableId] = value;
this.onChange();
}
};
// 游戏变量类.改变值事件
Game_Variables.prototype.onChange = function() {
$gameMap.requestRefresh();
};
7.游戏独立开关类
//-----------------------------------------------------------------------------
// Game_SelfSwitches
//
// The game object class for self switches.
// 游戏独立开关类
function Game_SelfSwitches() {
this.initialize.apply(this, arguments);
}
// 游戏独立开关类.初始化
Game_SelfSwitches.prototype.initialize = function() {
this.clear();
};
// 游戏独立开关类.清除
Game_SelfSwitches.prototype.clear = function() {
this._data = {};
};
// 游戏独立变量类.取值
Game_SelfSwitches.prototype.value = function(key) {
return !!this._data[key];
};
// 游戏独立开关类.设置值
Game_SelfSwitches.prototype.setValue = function(key, value) {
if (value) {
this._data[key] = true;
} else {
delete this._data[key];
}
this.onChange();
};
// 游戏独立开关类.改变值事件
Game_SelfSwitches.prototype.onChange = function() {
$gameMap.requestRefresh();
};
//-----------------------------------------------------------------------------
// Game_SelfSwitches
//
// The game object class for self switches.
// 游戏独立开关类
function Game_SelfSwitches() {
this.initialize.apply(this, arguments);
}
// 游戏独立开关类.初始化
Game_SelfSwitches.prototype.initialize = function() {
this.clear();
};
// 游戏独立开关类.清除
Game_SelfSwitches.prototype.clear = function() {
this._data = {};
};
// 游戏独立变量类.取值
Game_SelfSwitches.prototype.value = function(key) {
return !!this._data[key];
};
// 游戏独立开关类.设置值
Game_SelfSwitches.prototype.setValue = function(key, value) {
if (value) {
this._data[key] = true;
} else {
delete this._data[key];
}
this.onChange();
};
// 游戏独立开关类.改变值事件
Game_SelfSwitches.prototype.onChange = function() {
$gameMap.requestRefresh();
};
8.游戏屏幕类(本类最后几个没有翻译,准备睡觉了,每天开车跑长途,停更2天。)
//-----------------------------------------------------------------------------
// Game_Screen
//
// The game object class for screen effect data, such as changes in color tone
// and flashes.
// 游戏屏幕类
// 游戏屏幕效果数据对象类,如色调的变化和闪光。
function Game_Screen() {
this.initialize.apply(this, arguments);
}
// 游戏屏幕类.初始化
Game_Screen.prototype.initialize = function() {
this.clear();
};
// 游戏屏幕类.清除
Game_Screen.prototype.clear = function() {
this.clearFade(); // 游戏屏幕类.清除淡入淡出
this.clearTone(); // 游戏屏幕类.清除色调
this.clearFlash(); // 游戏屏幕类.清除闪烁
this.clearShake(); // 游戏屏幕类.清除震动
this.clearZoom(); // 游戏屏幕类.清除放大
this.clearWeather(); // 游戏屏幕类.清除天气
this.clearPictures(); // 游戏屏幕类.清除图片组
};
// 游戏屏幕类.战斗开始事件
Game_Screen.prototype.onBattleStart = function() {
this.clearFade(); // 游戏屏幕类.清除淡入淡出
this.clearFlash(); // 游戏屏幕类.清除闪烁
this.clearShake(); // 游戏屏幕类.清除震动
this.clearZoom(); // 游戏屏幕类.清除放大
this.eraseBattlePictures(); // 游戏屏幕类.擦除战斗图像
};
// 游戏屏幕类.取亮度
Game_Screen.prototype.brightness = function() {
return this._brightness;
};
// 游戏屏幕类.取色调
Game_Screen.prototype.tone = function() {
return this._tone;
};
// 游戏屏幕类.取闪烁颜色
Game_Screen.prototype.flashColor = function() {
return this._flashColor;
};
// 游戏屏幕类.取震动
Game_Screen.prototype.shake = function() {
return this._shake;
};
// 游戏屏幕类.取放大X
Game_Screen.prototype.zoomX = function() {
return this._zoomX;
};
// 游戏屏幕类.取放大Y
Game_Screen.prototype.zoomY = function() {
return this._zoomY;
};
// 游戏屏幕类.取放大比例
Game_Screen.prototype.zoomScale = function() {
return this._zoomScale;
};
// 游戏屏幕类.取天气类型
Game_Screen.prototype.weatherType = function() {
return this._weatherType;
};
// 游戏屏幕类.取天气强度
Game_Screen.prototype.weatherPower = function() {
return this._weatherPower;
};
// 游戏屏幕类.取图片
Game_Screen.prototype.picture = function(pictureId) {
var realPictureId = this.realPictureId(pictureId); // 游戏屏幕类.取图片真实ID(图片ID)
return this._pictures[realPictureId]; // 游戏屏幕类.图片组[图片真实ID]
};
// 游戏屏幕类.取图片真实ID
Game_Screen.prototype.realPictureId = function(pictureId) {
if ($gameParty.inBattle()) { // 游戏队伍类.在战斗中
return pictureId + this.maxPictures(); // 图片ID + 游戏屏幕类.取最大图片数量()
} else {
return pictureId; // 直接返回 图片ID
}
};
// 游戏屏幕类.清除淡入淡出
Game_Screen.prototype.clearFade = function() {
this._brightness = 255; // 游戏屏幕类.亮度 = 255
this._fadeOutDuration = 0; // 游戏屏幕类.淡出持续时间 = 0
this._fadeInDuration = 0; // 游戏屏幕类.淡入持续时间 = 0
};
// 游戏屏幕类.清除色调
Game_Screen.prototype.clearTone = function() {
this._tone = [0, 0, 0, 0]; // 游戏屏幕类.当前色调 = [R, G, B, 灰度]
this._toneTarget = [0, 0, 0, 0]; // 游戏屏幕类.目标色调 = [R, G, B, 灰度]
this._toneDuration = 0; // 游戏屏幕类.渐变转换需求时间 = 0
};
// 游戏屏幕类.清除闪烁
Game_Screen.prototype.clearFlash = function() {
this._flashColor = [0, 0, 0, 0]; // 游戏屏幕类.闪烁颜色 = [R, G, B, 强度]
this._flashDuration = 0; // 游戏屏幕类.持续时间 = 0
};
// 游戏屏幕类.清除震动
Game_Screen.prototype.clearShake = function() {
this._shakePower = 0; // 游戏屏幕类.震动强度 = 0
this._shakeSpeed = 0; // 游戏屏幕类.震动速度 = 0
this._shakeDuration = 0; // 游戏屏幕类.持续时间 = 0
this._shakeDirection = 1; // 游戏屏幕类.震动方向 = 1
this._shake = 0; // 游戏屏幕类.震动 = 0
};
// 游戏屏幕类.清除放大
Game_Screen.prototype.clearZoom = function() {
this._zoomX = 0; // 游戏屏幕类.放大X = 0
this._zoomY = 0; // 游戏屏幕类.放大Y = 0
this._zoomScale = 1; // 游戏屏幕类.当前放大比例 = 1
this._zoomScaleTarget = 1; // 游戏屏幕类.目标放大比例 = 1
this._zoomDuration = 0; // 游戏屏幕类.放大转换需求时间 = 0
};
// 游戏屏幕类.清除天气
Game_Screen.prototype.clearWeather = function() {
this._weatherType = 'none'; // 游戏屏幕类.天气类型 = "none"
this._weatherPower = 0; // 游戏屏幕类.天气当前强度 = 0
this._weatherPowerTarget = 0; // 游戏屏幕类.天气目标强度 = 0
this._weatherDuration = 0; // 游戏屏幕类.转换天气需求时间 = 0
};
// 游戏屏幕类.清除图片组
Game_Screen.prototype.clearPictures = function() {
this._pictures = [];
};
// 游戏屏幕类.擦除战斗图像
Game_Screen.prototype.eraseBattlePictures = function() {
this._pictures = this._pictures.slice(0, this.maxPictures() + 1);
};
// 游戏屏幕类.取最大图片数量
Game_Screen.prototype.maxPictures = function() {
return 100;
};
// 游戏屏幕类.开始淡出
Game_Screen.prototype.startFadeOut = function(duration) {
this._fadeOutDuration = duration; // 游戏屏幕类.淡出持续时间 = 持续时间
this._fadeInDuration = 0; // 游戏屏幕类.淡入持续时间 = 0
};
// 游戏屏幕类.开始淡入
Game_Screen.prototype.startFadeIn = function(duration) {
this._fadeInDuration = duration; // 游戏屏幕类.淡入持续时间 = 持续时间
this._fadeOutDuration = 0; // 游戏屏幕类.淡出持续时间 = 0
};
// 游戏屏幕类.开始染色(修改色调)
Game_Screen.prototype.startTint = function(tone, duration) {
this._toneTarget = tone.clone(); // 游戏屏幕类.目标色调
this._toneDuration = duration; // 游戏屏幕类.渐变转换需求时间
if (this._toneDuration === 0) { // 游戏屏幕类.渐变转换需求时间 === 0
this._tone = this._toneTarget.clone(); // 游戏屏幕类.当前色调 = 游戏屏幕类.目标色调
}
};
// 游戏屏幕类.开始闪烁
Game_Screen.prototype.startFlash = function(color, duration) {
this._flashColor = color.clone(); // 游戏屏幕类.闪烁颜色
this._flashDuration = duration; // 游戏屏幕类.持续时间
};
// 游戏屏幕类.开始震动
Game_Screen.prototype.startShake = function(power, speed, duration) {
this._shakePower = power; // 游戏屏幕类.震动强度
this._shakeSpeed = speed; // 游戏屏幕类.震动速度
this._shakeDuration = duration; // 游戏屏幕类.震动持续时间
};
// 游戏屏幕类.开始放大
Game_Screen.prototype.startZoom = function(x, y, scale, duration) {
this._zoomX = x; // 游戏屏幕类.放大X
this._zoomY = y; // 游戏屏幕类.放大Y
this._zoomScaleTarget = scale; // 游戏屏幕类.放大目标比例
this._zoomDuration = duration; // 游戏屏幕类.放大需求转换时间
};
// 游戏屏幕类.设置放大
Game_Screen.prototype.setZoom = function(x, y, scale) {
this._zoomX = x; // 游戏屏幕类.放大X
this._zoomY = y; // 游戏屏幕类.放大Y
this._zoomScale = scale; // 游戏屏幕类.放大比例
};
// 游戏屏幕类.改变天气
Game_Screen.prototype.changeWeather = function(type, power, duration) {
if (type !== 'none' || duration === 0) { // 如果预设置天气非none 且 持续时间 === 0
this._weatherType = type; // 游戏屏幕类.天气类型
}
this._weatherPowerTarget = type === 'none' ? 0 : power; // 游戏屏幕类.天气目标强度
this._weatherDuration = duration; // 游戏屏幕类.转换天气需求时间
if (duration === 0) {
this._weatherPower = this._weatherPowerTarget; // 游戏屏幕类.天气当前强度 = 游戏屏幕类.天气目标强度
}
};
// 游戏屏幕类.刷新
Game_Screen.prototype.update = function() {
this.updateFadeOut(); // 游戏屏幕类.刷新淡出
this.updateFadeIn(); // 游戏屏幕类.刷新淡入
this.updateTone(); // 游戏屏幕类.刷新色调
this.updateFlash(); // 游戏屏幕类.刷新闪烁
this.updateShake(); // 游戏屏幕类.刷新震动
this.updateZoom(); // 游戏屏幕类.刷新放大
this.updateWeather(); // 游戏屏幕类.刷新天气
this.updatePictures(); // 游戏屏幕类.刷新图片
};
// 游戏屏幕类.刷新淡出
Game_Screen.prototype.updateFadeOut = function() {
if (this._fadeOutDuration > 0) { // 游戏屏幕类.淡出持续时间 > 0
var d = this._fadeOutDuration;
this._brightness = (this._brightness * (d - 1)) / d; // 游戏屏幕类.亮度
this._fadeOutDuration--; // 游戏屏幕类.淡出持续时间--
}
};
// 游戏屏幕类.刷新淡入
Game_Screen.prototype.updateFadeIn = function() {
if (this._fadeInDuration > 0) { // 游戏屏幕类.淡入持续时间 > 0
var d = this._fadeInDuration;
this._brightness = (this._brightness * (d - 1) + 255) / d; // 游戏屏幕类.亮度
this._fadeInDuration--; // 游戏屏幕类.淡入持续时间--
}
};
// 游戏屏幕类.刷新色调
Game_Screen.prototype.updateTone = function() {
if (this._toneDuration > 0) { // 游戏屏幕类.渐变转换需求时间 > 0
var d = this._toneDuration;
// 修正[RGB&灰度](数学战五渣 不译...)
for (var i = 0; i < 4; i++) {
this._tone[i] = (this._tone[i] * (d - 1) + this._toneTarget[i]) / d;
}
this._toneDuration--; // 游戏屏幕类.渐变转换需求时间--
}
};
// 游戏屏幕类.刷新闪烁
Game_Screen.prototype.updateFlash = function() {
if (this._flashDuration > 0) { // 游戏屏幕类.闪烁持续时间 > 0
var d = this._flashDuration;
this._flashColor[3] *= (d - 1) / d; // 闪烁强度算法
this._flashDuration--; // 游戏屏幕类.闪烁持续时间--
}
};
// 游戏屏幕类.刷新震动
Game_Screen.prototype.updateShake = function() {
if (this._shakeDuration > 0 || this._shake !== 0) {
var delta = (this._shakePower * this._shakeSpeed * this._shakeDirection) / 10;
if (this._shakeDuration <= 1 && this._shake * (this._shake + delta) < 0) {
this._shake = 0;
} else {
this._shake += delta;
}
if (this._shake > this._shakePower * 2) {
this._shakeDirection = -1;
}
if (this._shake < - this._shakePower * 2) {
this._shakeDirection = 1;
}
this._shakeDuration--;
}
};
// 游戏屏幕类.刷新放大
Game_Screen.prototype.updateZoom = function() {
if (this._zoomDuration > 0) {
var d = this._zoomDuration;
var t = this._zoomScaleTarget;
this._zoomScale = (this._zoomScale * (d - 1) + t) / d;
this._zoomDuration--;
}
};
// 游戏屏幕类.刷新天气
Game_Screen.prototype.updateWeather = function() {
if (this._weatherDuration > 0) {
var d = this._weatherDuration;
var t = this._weatherPowerTarget;
this._weatherPower = (this._weatherPower * (d - 1) + t) / d;
this._weatherDuration--;
if (this._weatherDuration === 0 && this._weatherPowerTarget === 0) {
this._weatherType = 'none';
}
}
};
// 游戏屏幕类.刷新图片
Game_Screen.prototype.updatePictures = function() {
this._pictures.forEach(function(picture) {
if (picture) {
picture.update();
}
});
};
// 游戏屏幕类.开始伤害[事件]闪烁
Game_Screen.prototype.startFlashForDamage = function() {
this.startFlash([255, 0, 0, 128], 8); // 红色 [0-128] 强度 闪烁8帧
};
// 游戏屏幕类.显示图片
Game_Screen.prototype.showPicture = function(pictureId, name, origin, x, y,
scaleX, scaleY, opacity, blendMode) {
var realPictureId = this.realPictureId(pictureId);
var picture = new Game_Picture();
picture.show(name, origin, x, y, scaleX, scaleY, opacity, blendMode);
this._pictures[realPictureId] = picture;
};
// 游戏屏幕类.移动图片
Game_Screen.prototype.movePicture = function(pictureId, origin, x, y, scaleX,
scaleY, opacity, blendMode, duration) {
var picture = this.picture(pictureId);
if (picture) {
picture.move(origin, x, y, scaleX, scaleY, opacity, blendMode, duration);
}
};
// 游戏屏幕类.旋转图片
Game_Screen.prototype.rotatePicture = function(pictureId, speed) {
var picture = this.picture(pictureId);
if (picture) {
picture.rotate(speed);
}
};
// 游戏屏幕类.修改图片色调
Game_Screen.prototype.tintPicture = function(pictureId, tone, duration) {
var picture = this.picture(pictureId);
if (picture) {
picture.tint(tone, duration);
}
};
// 游戏屏幕类.清除图片
Game_Screen.prototype.erasePicture = function(pictureId) {
var realPictureId = this.realPictureId(pictureId);
this._pictures[realPictureId] = null;
};
//-----------------------------------------------------------------------------
// Game_Screen
//
// The game object class for screen effect data, such as changes in color tone
// and flashes.
// 游戏屏幕类
// 游戏屏幕效果数据对象类,如色调的变化和闪光。
function Game_Screen() {
this.initialize.apply(this, arguments);
}
// 游戏屏幕类.初始化
Game_Screen.prototype.initialize = function() {
this.clear();
};
// 游戏屏幕类.清除
Game_Screen.prototype.clear = function() {
this.clearFade(); // 游戏屏幕类.清除淡入淡出
this.clearTone(); // 游戏屏幕类.清除色调
this.clearFlash(); // 游戏屏幕类.清除闪烁
this.clearShake(); // 游戏屏幕类.清除震动
this.clearZoom(); // 游戏屏幕类.清除放大
this.clearWeather(); // 游戏屏幕类.清除天气
this.clearPictures(); // 游戏屏幕类.清除图片组
};
// 游戏屏幕类.战斗开始事件
Game_Screen.prototype.onBattleStart = function() {
this.clearFade(); // 游戏屏幕类.清除淡入淡出
this.clearFlash(); // 游戏屏幕类.清除闪烁
this.clearShake(); // 游戏屏幕类.清除震动
this.clearZoom(); // 游戏屏幕类.清除放大
this.eraseBattlePictures(); // 游戏屏幕类.擦除战斗图像
};
// 游戏屏幕类.取亮度
Game_Screen.prototype.brightness = function() {
return this._brightness;
};
// 游戏屏幕类.取色调
Game_Screen.prototype.tone = function() {
return this._tone;
};
// 游戏屏幕类.取闪烁颜色
Game_Screen.prototype.flashColor = function() {
return this._flashColor;
};
// 游戏屏幕类.取震动
Game_Screen.prototype.shake = function() {
return this._shake;
};
// 游戏屏幕类.取放大X
Game_Screen.prototype.zoomX = function() {
return this._zoomX;
};
// 游戏屏幕类.取放大Y
Game_Screen.prototype.zoomY = function() {
return this._zoomY;
};
// 游戏屏幕类.取放大比例
Game_Screen.prototype.zoomScale = function() {
return this._zoomScale;
};
// 游戏屏幕类.取天气类型
Game_Screen.prototype.weatherType = function() {
return this._weatherType;
};
// 游戏屏幕类.取天气强度
Game_Screen.prototype.weatherPower = function() {
return this._weatherPower;
};
// 游戏屏幕类.取图片
Game_Screen.prototype.picture = function(pictureId) {
var realPictureId = this.realPictureId(pictureId); // 游戏屏幕类.取图片真实ID(图片ID)
return this._pictures[realPictureId]; // 游戏屏幕类.图片组[图片真实ID]
};
// 游戏屏幕类.取图片真实ID
Game_Screen.prototype.realPictureId = function(pictureId) {
if ($gameParty.inBattle()) { // 游戏队伍类.在战斗中
return pictureId + this.maxPictures(); // 图片ID + 游戏屏幕类.取最大图片数量()
} else {
return pictureId; // 直接返回 图片ID
}
};
// 游戏屏幕类.清除淡入淡出
Game_Screen.prototype.clearFade = function() {
this._brightness = 255; // 游戏屏幕类.亮度 = 255
this._fadeOutDuration = 0; // 游戏屏幕类.淡出持续时间 = 0
this._fadeInDuration = 0; // 游戏屏幕类.淡入持续时间 = 0
};
// 游戏屏幕类.清除色调
Game_Screen.prototype.clearTone = function() {
this._tone = [0, 0, 0, 0]; // 游戏屏幕类.当前色调 = [R, G, B, 灰度]
this._toneTarget = [0, 0, 0, 0]; // 游戏屏幕类.目标色调 = [R, G, B, 灰度]
this._toneDuration = 0; // 游戏屏幕类.渐变转换需求时间 = 0
};
// 游戏屏幕类.清除闪烁
Game_Screen.prototype.clearFlash = function() {
this._flashColor = [0, 0, 0, 0]; // 游戏屏幕类.闪烁颜色 = [R, G, B, 强度]
this._flashDuration = 0; // 游戏屏幕类.持续时间 = 0
};
// 游戏屏幕类.清除震动
Game_Screen.prototype.clearShake = function() {
this._shakePower = 0; // 游戏屏幕类.震动强度 = 0
this._shakeSpeed = 0; // 游戏屏幕类.震动速度 = 0
this._shakeDuration = 0; // 游戏屏幕类.持续时间 = 0
this._shakeDirection = 1; // 游戏屏幕类.震动方向 = 1
this._shake = 0; // 游戏屏幕类.震动 = 0
};
// 游戏屏幕类.清除放大
Game_Screen.prototype.clearZoom = function() {
this._zoomX = 0; // 游戏屏幕类.放大X = 0
this._zoomY = 0; // 游戏屏幕类.放大Y = 0
this._zoomScale = 1; // 游戏屏幕类.当前放大比例 = 1
this._zoomScaleTarget = 1; // 游戏屏幕类.目标放大比例 = 1
this._zoomDuration = 0; // 游戏屏幕类.放大转换需求时间 = 0
};
// 游戏屏幕类.清除天气
Game_Screen.prototype.clearWeather = function() {
this._weatherType = 'none'; // 游戏屏幕类.天气类型 = "none"
this._weatherPower = 0; // 游戏屏幕类.天气当前强度 = 0
this._weatherPowerTarget = 0; // 游戏屏幕类.天气目标强度 = 0
this._weatherDuration = 0; // 游戏屏幕类.转换天气需求时间 = 0
};
// 游戏屏幕类.清除图片组
Game_Screen.prototype.clearPictures = function() {
this._pictures = [];
};
// 游戏屏幕类.擦除战斗图像
Game_Screen.prototype.eraseBattlePictures = function() {
this._pictures = this._pictures.slice(0, this.maxPictures() + 1);
};
// 游戏屏幕类.取最大图片数量
Game_Screen.prototype.maxPictures = function() {
return 100;
};
// 游戏屏幕类.开始淡出
Game_Screen.prototype.startFadeOut = function(duration) {
this._fadeOutDuration = duration; // 游戏屏幕类.淡出持续时间 = 持续时间
this._fadeInDuration = 0; // 游戏屏幕类.淡入持续时间 = 0
};
// 游戏屏幕类.开始淡入
Game_Screen.prototype.startFadeIn = function(duration) {
this._fadeInDuration = duration; // 游戏屏幕类.淡入持续时间 = 持续时间
this._fadeOutDuration = 0; // 游戏屏幕类.淡出持续时间 = 0
};
// 游戏屏幕类.开始染色(修改色调)
Game_Screen.prototype.startTint = function(tone, duration) {
this._toneTarget = tone.clone(); // 游戏屏幕类.目标色调
this._toneDuration = duration; // 游戏屏幕类.渐变转换需求时间
if (this._toneDuration === 0) { // 游戏屏幕类.渐变转换需求时间 === 0
this._tone = this._toneTarget.clone(); // 游戏屏幕类.当前色调 = 游戏屏幕类.目标色调
}
};
// 游戏屏幕类.开始闪烁
Game_Screen.prototype.startFlash = function(color, duration) {
this._flashColor = color.clone(); // 游戏屏幕类.闪烁颜色
this._flashDuration = duration; // 游戏屏幕类.持续时间
};
// 游戏屏幕类.开始震动
Game_Screen.prototype.startShake = function(power, speed, duration) {
this._shakePower = power; // 游戏屏幕类.震动强度
this._shakeSpeed = speed; // 游戏屏幕类.震动速度
this._shakeDuration = duration; // 游戏屏幕类.震动持续时间
};
// 游戏屏幕类.开始放大
Game_Screen.prototype.startZoom = function(x, y, scale, duration) {
this._zoomX = x; // 游戏屏幕类.放大X
this._zoomY = y; // 游戏屏幕类.放大Y
this._zoomScaleTarget = scale; // 游戏屏幕类.放大目标比例
this._zoomDuration = duration; // 游戏屏幕类.放大需求转换时间
};
// 游戏屏幕类.设置放大
Game_Screen.prototype.setZoom = function(x, y, scale) {
this._zoomX = x; // 游戏屏幕类.放大X
this._zoomY = y; // 游戏屏幕类.放大Y
this._zoomScale = scale; // 游戏屏幕类.放大比例
};
// 游戏屏幕类.改变天气
Game_Screen.prototype.changeWeather = function(type, power, duration) {
if (type !== 'none' || duration === 0) { // 如果预设置天气非none 且 持续时间 === 0
this._weatherType = type; // 游戏屏幕类.天气类型
}
this._weatherPowerTarget = type === 'none' ? 0 : power; // 游戏屏幕类.天气目标强度
this._weatherDuration = duration; // 游戏屏幕类.转换天气需求时间
if (duration === 0) {
this._weatherPower = this._weatherPowerTarget; // 游戏屏幕类.天气当前强度 = 游戏屏幕类.天气目标强度
}
};
// 游戏屏幕类.刷新
Game_Screen.prototype.update = function() {
this.updateFadeOut(); // 游戏屏幕类.刷新淡出
this.updateFadeIn(); // 游戏屏幕类.刷新淡入
this.updateTone(); // 游戏屏幕类.刷新色调
this.updateFlash(); // 游戏屏幕类.刷新闪烁
this.updateShake(); // 游戏屏幕类.刷新震动
this.updateZoom(); // 游戏屏幕类.刷新放大
this.updateWeather(); // 游戏屏幕类.刷新天气
this.updatePictures(); // 游戏屏幕类.刷新图片
};
// 游戏屏幕类.刷新淡出
Game_Screen.prototype.updateFadeOut = function() {
if (this._fadeOutDuration > 0) { // 游戏屏幕类.淡出持续时间 > 0
var d = this._fadeOutDuration;
this._brightness = (this._brightness * (d - 1)) / d; // 游戏屏幕类.亮度
this._fadeOutDuration--; // 游戏屏幕类.淡出持续时间--
}
};
// 游戏屏幕类.刷新淡入
Game_Screen.prototype.updateFadeIn = function() {
if (this._fadeInDuration > 0) { // 游戏屏幕类.淡入持续时间 > 0
var d = this._fadeInDuration;
this._brightness = (this._brightness * (d - 1) + 255) / d; // 游戏屏幕类.亮度
this._fadeInDuration--; // 游戏屏幕类.淡入持续时间--
}
};
// 游戏屏幕类.刷新色调
Game_Screen.prototype.updateTone = function() {
if (this._toneDuration > 0) { // 游戏屏幕类.渐变转换需求时间 > 0
var d = this._toneDuration;
// 修正[RGB&灰度](数学战五渣 不译...)
for (var i = 0; i < 4; i++) {
this._tone[i] = (this._tone[i] * (d - 1) + this._toneTarget[i]) / d;
}
this._toneDuration--; // 游戏屏幕类.渐变转换需求时间--
}
};
// 游戏屏幕类.刷新闪烁
Game_Screen.prototype.updateFlash = function() {
if (this._flashDuration > 0) { // 游戏屏幕类.闪烁持续时间 > 0
var d = this._flashDuration;
this._flashColor[3] *= (d - 1) / d; // 闪烁强度算法
this._flashDuration--; // 游戏屏幕类.闪烁持续时间--
}
};
// 游戏屏幕类.刷新震动
Game_Screen.prototype.updateShake = function() {
if (this._shakeDuration > 0 || this._shake !== 0) {
var delta = (this._shakePower * this._shakeSpeed * this._shakeDirection) / 10;
if (this._shakeDuration <= 1 && this._shake * (this._shake + delta) < 0) {
this._shake = 0;
} else {
this._shake += delta;
}
if (this._shake > this._shakePower * 2) {
this._shakeDirection = -1;
}
if (this._shake < - this._shakePower * 2) {
this._shakeDirection = 1;
}
this._shakeDuration--;
}
};
// 游戏屏幕类.刷新放大
Game_Screen.prototype.updateZoom = function() {
if (this._zoomDuration > 0) {
var d = this._zoomDuration;
var t = this._zoomScaleTarget;
this._zoomScale = (this._zoomScale * (d - 1) + t) / d;
this._zoomDuration--;
}
};
// 游戏屏幕类.刷新天气
Game_Screen.prototype.updateWeather = function() {
if (this._weatherDuration > 0) {
var d = this._weatherDuration;
var t = this._weatherPowerTarget;
this._weatherPower = (this._weatherPower * (d - 1) + t) / d;
this._weatherDuration--;
if (this._weatherDuration === 0 && this._weatherPowerTarget === 0) {
this._weatherType = 'none';
}
}
};
// 游戏屏幕类.刷新图片
Game_Screen.prototype.updatePictures = function() {
this._pictures.forEach(function(picture) {
if (picture) {
picture.update();
}
});
};
// 游戏屏幕类.开始伤害[事件]闪烁
Game_Screen.prototype.startFlashForDamage = function() {
this.startFlash([255, 0, 0, 128], 8); // 红色 [0-128] 强度 闪烁8帧
};
// 游戏屏幕类.显示图片
Game_Screen.prototype.showPicture = function(pictureId, name, origin, x, y,
scaleX, scaleY, opacity, blendMode) {
var realPictureId = this.realPictureId(pictureId);
var picture = new Game_Picture();
picture.show(name, origin, x, y, scaleX, scaleY, opacity, blendMode);
this._pictures[realPictureId] = picture;
};
// 游戏屏幕类.移动图片
Game_Screen.prototype.movePicture = function(pictureId, origin, x, y, scaleX,
scaleY, opacity, blendMode, duration) {
var picture = this.picture(pictureId);
if (picture) {
picture.move(origin, x, y, scaleX, scaleY, opacity, blendMode, duration);
}
};
// 游戏屏幕类.旋转图片
Game_Screen.prototype.rotatePicture = function(pictureId, speed) {
var picture = this.picture(pictureId);
if (picture) {
picture.rotate(speed);
}
};
// 游戏屏幕类.修改图片色调
Game_Screen.prototype.tintPicture = function(pictureId, tone, duration) {
var picture = this.picture(pictureId);
if (picture) {
picture.tint(tone, duration);
}
};
// 游戏屏幕类.清除图片
Game_Screen.prototype.erasePicture = function(pictureId) {
var realPictureId = this.realPictureId(pictureId);
this._pictures[realPictureId] = null;
};
1.数据管理器类
//-----------------------------------------------------------------------------
// DataManager
//
// The static class that manages the database and game objects.
// 数据管理器
// 静态类 管理数据库与游戏对象
function DataManager() {
throw new Error('This is a static class'); // 当实例化时抛出异常
}
// JSON 数据库
var $dataActors = null; // 角色数据
var $dataClasses = null; // 职业数据
var $dataSkills = null; // 特技/技能数据
var $dataItems = null; // 物品数据
var $dataWeapons = null; // 武器数据
var $dataArmors = null; // 防具数据
var $dataEnemies = null; // 敌人数据
var $dataTroops = null; // 敌群数据
var $dataStates = null; // 状态数据
var $dataAnimations = null; // 动画数据
var $dataTilesets = null; // 图块组数据
var $dataCommonEvents = null; // 公共事件数据
var $dataSystem = null; // 系统数据
var $dataMapInfos = null; // 地图信息数据
var $dataMap = null; // 地图数据
// 类全局变量 与 RGSS 很相似
var $gameTemp = null; // Game_Temp 类 游戏临时数据类
var $gameSystem = null; // Game_System 类 游戏系统类
var $gameScreen = null; // Game_Screen 类 游戏屏幕类
var $gameTimer = null; // Game_Time 类 游戏时间类
var $gameMessage = null; // Game_Message 类 游戏消息类 (不知道是不是 WINDOWS 消息 想想也不是 人家都跨平台了。。。我又想起了 C++)
var $gameSwitches = null; // Game_Switches 类 游戏开关类
var $gameVariables = null; // Game_Variables 类 游戏变量类
var $gameSelfSwitches = null; // Game_SelfSwitches 类 游戏独立开关类
var $gameActors = null; // Game_Actors 类 游戏角色组类
var $gameParty = null; // Game_Party 类 游戏队伍类
var $gameTroop = null; // Game_Troop 类 游戏敌群类
var $gameMap = null; // Game_Map 类 游戏地图类
var $gamePlayer = null; // Game_Player 类 游戏玩家类
var $testEvent = null; // testEvent 类 测试事件类
DataManager._globalId = 'RPGMV'; // 数据管理器.全局ID
DataManager._lastAccessedId = 1; // 数据管理器.最后数据ID
DataManager._errorUrl = null; // 数据管理器.错误网络地址
// 数据管理器(JSON)
DataManager._databaseFiles = [
{ name: '$dataActors', src: 'Actors.json' },
{ name: '$dataClasses', src: 'Classes.json' },
{ name: '$dataSkills', src: 'Skills.json' },
{ name: '$dataItems', src: 'Items.json' },
{ name: '$dataWeapons', src: 'Weapons.json' },
{ name: '$dataArmors', src: 'Armors.json' },
{ name: '$dataEnemies', src: 'Enemies.json' },
{ name: '$dataTroops', src: 'Troops.json' },
{ name: '$dataStates', src: 'States.json' },
{ name: '$dataAnimations', src: 'Animations.json' },
{ name: '$dataTilesets', src: 'Tilesets.json' },
{ name: '$dataCommonEvents', src: 'CommonEvents.json' },
{ name: '$dataSystem', src: 'System.json' },
{ name: '$dataMapInfos', src: 'MapInfos.json' }
];
// 数据管理器.加载数据库
DataManager.loadDatabase = function() {
var test = this.isBattleTest() || this.isEventTest(); // 是否战斗测试 或 事件测试
var prefix = test ? 'Test_' : ''; // 前缀
// 循环遍历数据库文件组
for (var i = 0; i < this._databaseFiles.length; i++) {
var name = this._databaseFiles[i].name; // 数据库名称
var src = this._databaseFiles[i].src; // 数据库源
this.loadDataFile(name, prefix + src); // 加载数据文件(数据库名称, 数据库源)
}
if (this.isEventTest()) { // 是否战斗测试?
this.loadDataFile('$testEvent', prefix + 'Event.json'); // 加载测试事件数据
}
};
// 数据管理器.加载数据文件
DataManager.loadDataFile = function(name, src) {
var xhr = new XMLHttpRequest(); // 实例化 XML HTTP 请求
var url = 'data/' + src; // 数据库文件路径
xhr.open('GET', url); // GET 请求
xhr.overrideMimeType('application/json'); // 将响应数据 转换置 JSON
xhr.onload = function() { // 请求数据全部加载完毕事件
if (xhr.status < 400) { // 判断 HTTP 状态码(具体百度HTTP状态码)
window[name] = JSON.parse(xhr.responseText); // JSON 解析(请求返回的JSON 格式数据)
DataManager.onLoad(window[name]); // 调用->数据管理器.加载事件
}
};
xhr.onerror = function() { // 请求数据时发生错误
DataManager._errorUrl = DataManager._errorUrl || url;
};
window[name] = null; // 初始化 window[name]
xhr.send(); // 发送请求
};
// 数据管理器.数据库是否已经加载
DataManager.isDatabaseLoaded = function() {
this.checkError(); // 数据管理器.检查错误
// 循环遍历数据库文件组
for (var i = 0; i < this._databaseFiles.length; i++) {
if (!window[this._databaseFiles[i].name]) {
return false;
}
}
return true;
};
// 数据管理器.加载地图数据
DataManager.loadMapData = function(mapId) {
if (mapId > 0) {
var filename = 'Map%1.json'.format(mapId.padZero(3)); // 格式化成 Map000.json (如果需要修正地图上限估计需要修改此处吧)
this.loadDataFile('$dataMap', filename); // 加载地图数据
} else {
this.makeEmptyMap(); // 制一个空地图
}
};
// 数据管理器.制作一个空地图(100*100)
DataManager.makeEmptyMap = function() {
$dataMap = {};
$dataMap.data = [];
$dataMap.events = [];
$dataMap.width = 100;
$dataMap.height = 100;
$dataMap.scrollType = 3;
};
// 数据管理器.地图是否已经加载
DataManager.isMapLoaded = function() {
this.checkError(); // 数据管理器.检查错误
return !!$dataMap;
};
// 数据管理器.加载事件
DataManager.onLoad = function(object) {
var array;
if (object === $dataMap) { // 如果是地图数据
this.extractMetadata(object); // 数据管理器.提取元数据()
array = object.events; // array = 地图事件数据组
} else {
array = object;
}
if (Array.isArray(array)) { // 判断是否为数组
for (var i = 0; i < array.length; i++) { // 遍历数组
var data = array[i];
if (data && data.note !== undefined) {
this.extractMetadata(data); // 数据管理器.提取元数据()
}
}
}
};
// 数据管理器.提取元数据() <元数据都在注释里>
DataManager.extractMetadata = function(data) {
// 举个简单的元数据格式 <tool:rmmv>
var re = /<([^<>:]+)(:?)([^>]*)>/g; // 全局匹配
data.meta = {};
for (;;) {
var match = re.exec(data.note); // 匹配
if (match) {
if (match[2] === ':') {
data.meta[match[1]] = match[3]; // data.meta["tool"] = rmmv;
} else {
data.meta[match[1]] = true; // 缺省时表示为 bool 且值 为 true
}
} else {
break;
}
}
};
// 数据管理器.检查错误
DataManager.checkError = function() {
if (DataManager._errorUrl) {
throw new Error('Failed to load: ' + DataManager._errorUrl);
}
};
// 数据管理器.是否为战斗测试
DataManager.isBattleTest = function() {
return Utils.isOptionValid('btest');
};
// 数据管理器.是否为事件测试
DataManager.isEventTest = function() {
return Utils.isOptionValid('etest');
};
// 数据管理器.是否为特技数据
DataManager.isSkill = function(item) {
return item && $dataSkills.contains(item);
};
// 数据管理器.是否为物品数据
DataManager.isItem = function(item) {
return item && $dataItems.contains(item);
};
// 数据管理器.是否为武器数据
DataManager.isWeapon = function(item) {
return item && $dataWeapons.contains(item);
};
// 数据管理器.是否为防具数据
DataManager.isArmor = function(item) {
return item && $dataArmors.contains(item);
};
// 数据管理器.创建游戏对象
DataManager.createGameObjects = function() {
$gameTemp = new Game_Temp(); // Game_Temp 类 游戏临时数据类
$gameSystem = new Game_System(); // Game_System 类 游戏系统类
$gameScreen = new Game_Screen(); // Game_Screen 类 游戏屏幕类
$gameTimer = new Game_Timer(); // Game_Time 类 游戏时间类
$gameMessage = new Game_Message(); // Game_Message 类 游戏消息类
$gameSwitches = new Game_Switches(); // Game_Switches 类 游戏开关类
$gameVariables = new Game_Variables(); // Game_Variables 类 游戏变量类
$gameSelfSwitches = new Game_SelfSwitches(); // Game_SelfSwitches 类 游戏独立开关类
$gameActors = new Game_Actors(); // Game_Actors 类 游戏角色组类
$gameParty = new Game_Party(); // Game_Party 类 游戏队伍类
$gameTroop = new Game_Troop(); // Game_Troop 类 游戏敌群类
$gameMap = new Game_Map(); // Game_Map 类 游戏地图类
$gamePlayer = new Game_Player(); // Game_Player 类 游戏玩家类
};
// 数据管理器.开始新游戏
DataManager.setupNewGame = function() {
this.createGameObjects(); // 数据管理器.创建游戏对象
this.selectSavefileForNewGame(); // 数据管理器.选择保存文件从新游戏????
$gameParty.setupStartingMembers(); // 游戏队伍类.设置开始成员
$gamePlayer.reserveTransfer($dataSystem.startMapId, $dataSystem.startX, $dataSystem.startY); // 游戏玩家类.复位传送至(系统数据.开始地图ID, 系统数据.开始X坐标, 系统数据.开始Y坐标)
Graphics.frameCount = 0; // Graphics(图形).帧数初始化为0
};
// 数据管理器.设置战斗测试
DataManager.setupBattleTest = function() {
this.createGameObjects(); // 数据管理器.创建游戏对象
$gameParty.setupBattleTest(); // 游戏队伍类.设置战斗测试
BattleManager.setup($dataSystem.testTroopId, true, false); // 战斗管理器.设置(系统数据类.测试队伍ID)
BattleManager.setBattleTest(true); // 战斗管理器.设置战斗测试(true)
BattleManager.playBattleBgm(); // 战斗管理器.播放战斗BGM
};
// 数据管理器.设置事件测试
DataManager.setupEventTest = function() {
this.createGameObjects(); // 数据管理器.创建游戏对象
this.selectSavefileForNewGame(); // 数据管理器.选择保存文件从新游戏????
$gameParty.setupStartingMembers(); // 游戏队伍类.设置开始成员
$gamePlayer.reserveTransfer(-1, 8, 6); // 游戏玩家类.复位传送至(-1, 8, 6)
$gamePlayer.setTransparent(false); // 游戏玩家类.设置透明(false)
};
// 数据管理器.加载全局信息
DataManager.loadGlobalInfo = function() {
var json;
try {
json = StorageManager.load(0); // 存储管理器.加载()
} catch (e) {
console.error(e); // 控制台.输出错误信息
return [];
}
if (json) {
var globalInfo = JSON.parse(json); // JSON.解析
for (var i = 1; i <= this.maxSavefiles(); i++) {
if (!StorageManager.exists(i)) { // 存储管理器.是否存在(ID)
delete globalInfo[i]; // 删除信息(ID)
}
}
return globalInfo;
} else {
return [];
}
};
// 数据管理器.保存全局信息
DataManager.saveGlobalInfo = function(info) {
StorageManager.save(0, JSON.stringify(info)); // 存储管理器.保存
};
// 数据管理器.是否为本游戏文件
DataManager.isThisGameFile = function(savefileId) {
var globalInfo = this.loadGlobalInfo(); // 数据管理器.加载全局信息
if (globalInfo && globalInfo[savefileId]) { // 全局信息[保存文件ID] 非 NULL
if (StorageManager.isLocalMode()) { // 存储管理器.是否本地模式
return true;
} else {
var savefile = globalInfo[savefileId]; // 保存文件信息
return (savefile.globalId === this._globalId && // 保存文件信息.全局ID === 数据管理器.全局ID
savefile.title === $dataSystem.gameTitle); // 保存文件信息.标题 === 系统数据类.游戏标题
}
} else {
return false;
}
};
// 数据管理器.是否为本游戏文件_扩展函数
DataManager.isThisGameFileEx = function(savefileId, globalInfo) {
if (globalInfo[savefileId]) { // 全局信息[保存文件ID] 非 NULL
if (StorageManager.isLocalMode()) { // 存储管理器.是否本地模式
return true;
} else {
var savefile = globalInfo[savefileId]; // 保存文件信息
return (savefile.globalId === this._globalId && // 保存文件信息.全局ID === 数据管理器.全局ID
savefile.title === $dataSystem.gameTitle); // 保存文件信息.标题 === 系统数据类.游戏标题
}
}
return false;
};
// 数据管理器.是否保存的文件(任意)
DataManager.isAnySavefileExists = function() {
var globalInfo = this.loadGlobalInfo(); // 数据管理器.加载全局信息
if (globalInfo) {
for (var i = 1; i < globalInfo.length; i++) {
// optimize
//if (this.isThisGameFile(i)) {
if (this.isThisGameFileEx(i, globalInfo)) { // 数据管理器.是否为本游戏文件
return true;
}
}
}
return false;
};
// 数据管理器.最新保存文件标识
DataManager.latestSavefileId = function() {
var globalInfo = this.loadGlobalInfo(); // 数据管理器.加载全局信息
var savefileId = 1;
var timestamp = 0; // 时间戳
if (globalInfo) {
for (var i = 1; i < globalInfo.length; i++) {
// optimize
// if (this.isThisGameFile(i) && globalInfo[i].timestamp > timestamp) {
// 数据管理器.是否为本游戏文件(i) 且 全局信息[i]
if (this.isThisGameFileEx(i, globalInfo) && globalInfo[i].timestamp > timestamp) {
timestamp = globalInfo[i].timestamp; // 设置当前最大时间戳
savefileId = i; // 设置保存文件ID
}
}
}
return savefileId;
};
// 数据管理器.加载全部保存文件图像
DataManager.loadAllSavefileImages = function() {
var globalInfo = this.loadGlobalInfo(); // 数据管理器.加载全局信息
if (globalInfo) {
for (var i = 1; i < globalInfo.length; i++) {
// optimize
// if (this.isThisGameFile(i)) {
if (this.isThisGameFileEx(i, globalInfo)) // 数据管理器.是否为本游戏文件(i)
var info = globalInfo[i];
this.loadSavefileImages(info); // 数据管理器.加载保存文件图像组
}
}
}
};
// 数据管理器.加载保存文件图像组
DataManager.loadSavefileImages = function(info) {
if (info.characters) {
for (var i = 0; i < info.characters.length; i++) {
ImageManager.loadCharacter(info.characters[i][0]); // 图像管理器.加载人物图像
}
}
if (info.faces) {
for (var j = 0; j < info.faces.length; j++) {
ImageManager.loadFace(info.faces[j][0]); // 图像管理器.加载脸部图像
}
}
};
// 数据管理器.保存文件最大数量
DataManager.maxSavefiles = function() {
return 20;
};
// 数据管理器.保存游戏
DataManager.saveGame = function(savefileId) {
try {
return this.saveGameWithoutRescue(savefileId); // 数据管理器.保存游戏(无拯救)
} catch (e) {
console.error(e);
try {
StorageManager.remove(savefileId); // 数据管理器.删除
} catch (e2) {
}
return false;
}
};
// 数据管理器.加载游戏
DataManager.loadGame = function(savefileId) {
try {
return this.loadGameWithoutRescue(savefileId); // 数据管理器.加载游戏(无拯救)
} catch (e) {
console.error(e);
return false;
}
};
// 数据管理器.加载(保存文件信息)
DataManager.loadSavefileInfo = function(savefileId) {
var globalInfo = this.loadGlobalInfo();
return (globalInfo && globalInfo[savefileId]) ? globalInfo[savefileId] : null;
};
// 数据管理权.最后保存的数据文件ID
DataManager.lastAccessedSavefileId = function() {
return this._lastAccessedId;
};
// 数据管理器.保存游戏(无拯救)
DataManager.saveGameWithoutRescue = function(savefileId) {
var json = JsonEx.stringify(this.makeSaveContents()); // 将 数据管理器.制保存内容 转换为 JSON 字符串。
if (json.length >= 200000) {
console.warn('Save data too big!');
}
StorageManager.save(savefileId, json); // 存储管理器.保存
this._lastAccessedId = savefileId; // 设置最后数据库ID
var globalInfo = this.loadGlobalInfo() || [];
globalInfo[savefileId] = this.makeSavefileInfo(); // 设置全局信息[保存ID] = 数据管理器.制保存文件信息
this.saveGlobalInfo(globalInfo); // 数据管理器.保存全局信息
return true;
};
// 数据管理器.加载游戏(无拯救)
DataManager.loadGameWithoutRescue = function(savefileId) {
var globalInfo = this.loadGlobalInfo(); // 数据管理器.加载全局信息
// optimize
// if (this.isThisGameFile(savefileId)) {
// 数据管理器.是否为本游戏文件(i)
if (this.isThisGameFileEx(savefileId, globalInfo)) {
var json = StorageManager.load(savefileId); // 存储管理器.加载()
this.createGameObjects(); // 数据管理器.创建游戏对象
this.extractSaveContents(JsonEx.parse(json)); // 数据管理器.提取保存内容(JsonEx.解析(json))
this._lastAccessedId = savefileId; // 设置最后数据库ID
return true;
} else {
return false;
}
};
// 数据管理器.选择保存文件从新游戏???
DataManager.selectSavefileForNewGame = function() {
var globalInfo = this.loadGlobalInfo(); // 数据管理器.加载全局信息
this._lastAccessedId = 1; // 数据管理器.最后数据ID = 1
if (globalInfo) {
var numSavefiles = Math.max(0, globalInfo.length - 1); // 存储文件数量
if (numSavefiles < this.maxSavefiles()) {
this._lastAccessedId = numSavefiles + 1;
} else {
var timestamp = Number.MAX_VALUE; // 时间戳 = JS.Number.MAX_VALUE
for (var i = 1; i < globalInfo.length; i++) {
if (!globalInfo[i]) {
this._lastAccessedId = i;
break;
}
if (globalInfo[i].timestamp < timestamp) {
timestamp = globalInfo[i].timestamp;
this._lastAccessedId = i;
}
}
}
}
};
// 数据管理器.制保存文件信息
DataManager.makeSavefileInfo = function() {
var info = {};
info.globalId = this._globalId;
info.title = $dataSystem.gameTitle;
info.characters = $gameParty.charactersForSavefile();
info.faces = $gameParty.facesForSavefile();
info.playtime = $gameSystem.playtimeText();
info.timestamp = Date.now();
return info;
};
// 数据管理器.制保存内容
DataManager.makeSaveContents = function() {
// A save data does not contain $gameTemp, $gameMessage, and $gameTroop.
var contents = {};
contents.system = $gameSystem;
contents.screen = $gameScreen;
contents.timer = $gameTimer;
contents.switches = $gameSwitches;
contents.variables = $gameVariables;
contents.selfSwitches = $gameSelfSwitches;
contents.actors = $gameActors;
contents.party = $gameParty;
contents.map = $gameMap;
contents.player = $gamePlayer;
return contents;
};
// 数据管理器.提取保存内容
DataManager.extractSaveContents = function(contents) {
$gameSystem = contents.system;
$gameScreen = contents.screen;
$gameTimer = contents.timer;
$gameSwitches = contents.switches;
$gameVariables = contents.variables;
$gameSelfSwitches = contents.selfSwitches;
$gameActors = contents.actors;
$gameParty = contents.party;
$gameMap = contents.map;
$gamePlayer = contents.player;
};
//-----------------------------------------------------------------------------
// DataManager
//
// The static class that manages the database and game objects.
// 数据管理器
// 静态类 管理数据库与游戏对象
function DataManager() {
throw new Error('This is a static class'); // 当实例化时抛出异常
}
// JSON 数据库
var $dataActors = null; // 角色数据
var $dataClasses = null; // 职业数据
var $dataSkills = null; // 特技/技能数据
var $dataItems = null; // 物品数据
var $dataWeapons = null; // 武器数据
var $dataArmors = null; // 防具数据
var $dataEnemies = null; // 敌人数据
var $dataTroops = null; // 敌群数据
var $dataStates = null; // 状态数据
var $dataAnimations = null; // 动画数据
var $dataTilesets = null; // 图块组数据
var $dataCommonEvents = null; // 公共事件数据
var $dataSystem = null; // 系统数据
var $dataMapInfos = null; // 地图信息数据
var $dataMap = null; // 地图数据
// 类全局变量 与 RGSS 很相似
var $gameTemp = null; // Game_Temp 类 游戏临时数据类
var $gameSystem = null; // Game_System 类 游戏系统类
var $gameScreen = null; // Game_Screen 类 游戏屏幕类
var $gameTimer = null; // Game_Time 类 游戏时间类
var $gameMessage = null; // Game_Message 类 游戏消息类 (不知道是不是 WINDOWS 消息 想想也不是 人家都跨平台了。。。我又想起了 C++)
var $gameSwitches = null; // Game_Switches 类 游戏开关类
var $gameVariables = null; // Game_Variables 类 游戏变量类
var $gameSelfSwitches = null; // Game_SelfSwitches 类 游戏独立开关类
var $gameActors = null; // Game_Actors 类 游戏角色组类
var $gameParty = null; // Game_Party 类 游戏队伍类
var $gameTroop = null; // Game_Troop 类 游戏敌群类
var $gameMap = null; // Game_Map 类 游戏地图类
var $gamePlayer = null; // Game_Player 类 游戏玩家类
var $testEvent = null; // testEvent 类 测试事件类
DataManager._globalId = 'RPGMV'; // 数据管理器.全局ID
DataManager._lastAccessedId = 1; // 数据管理器.最后数据ID
DataManager._errorUrl = null; // 数据管理器.错误网络地址
// 数据管理器(JSON)
DataManager._databaseFiles = [
{ name: '$dataActors', src: 'Actors.json' },
{ name: '$dataClasses', src: 'Classes.json' },
{ name: '$dataSkills', src: 'Skills.json' },
{ name: '$dataItems', src: 'Items.json' },
{ name: '$dataWeapons', src: 'Weapons.json' },
{ name: '$dataArmors', src: 'Armors.json' },
{ name: '$dataEnemies', src: 'Enemies.json' },
{ name: '$dataTroops', src: 'Troops.json' },
{ name: '$dataStates', src: 'States.json' },
{ name: '$dataAnimations', src: 'Animations.json' },
{ name: '$dataTilesets', src: 'Tilesets.json' },
{ name: '$dataCommonEvents', src: 'CommonEvents.json' },
{ name: '$dataSystem', src: 'System.json' },
{ name: '$dataMapInfos', src: 'MapInfos.json' }
];
// 数据管理器.加载数据库
DataManager.loadDatabase = function() {
var test = this.isBattleTest() || this.isEventTest(); // 是否战斗测试 或 事件测试
var prefix = test ? 'Test_' : ''; // 前缀
// 循环遍历数据库文件组
for (var i = 0; i < this._databaseFiles.length; i++) {
var name = this._databaseFiles[i].name; // 数据库名称
var src = this._databaseFiles[i].src; // 数据库源
this.loadDataFile(name, prefix + src); // 加载数据文件(数据库名称, 数据库源)
}
if (this.isEventTest()) { // 是否战斗测试?
this.loadDataFile('$testEvent', prefix + 'Event.json'); // 加载测试事件数据
}
};
// 数据管理器.加载数据文件
DataManager.loadDataFile = function(name, src) {
var xhr = new XMLHttpRequest(); // 实例化 XML HTTP 请求
var url = 'data/' + src; // 数据库文件路径
xhr.open('GET', url); // GET 请求
xhr.overrideMimeType('application/json'); // 将响应数据 转换置 JSON
xhr.onload = function() { // 请求数据全部加载完毕事件
if (xhr.status < 400) { // 判断 HTTP 状态码(具体百度HTTP状态码)
window[name] = JSON.parse(xhr.responseText); // JSON 解析(请求返回的JSON 格式数据)
DataManager.onLoad(window[name]); // 调用->数据管理器.加载事件
}
};
xhr.onerror = function() { // 请求数据时发生错误
DataManager._errorUrl = DataManager._errorUrl || url;
};
window[name] = null; // 初始化 window[name]
xhr.send(); // 发送请求
};
// 数据管理器.数据库是否已经加载
DataManager.isDatabaseLoaded = function() {
this.checkError(); // 数据管理器.检查错误
// 循环遍历数据库文件组
for (var i = 0; i < this._databaseFiles.length; i++) {
if (!window[this._databaseFiles[i].name]) {
return false;
}
}
return true;
};
// 数据管理器.加载地图数据
DataManager.loadMapData = function(mapId) {
if (mapId > 0) {
var filename = 'Map%1.json'.format(mapId.padZero(3)); // 格式化成 Map000.json (如果需要修正地图上限估计需要修改此处吧)
this.loadDataFile('$dataMap', filename); // 加载地图数据
} else {
this.makeEmptyMap(); // 制一个空地图
}
};
// 数据管理器.制作一个空地图(100*100)
DataManager.makeEmptyMap = function() {
$dataMap = {};
$dataMap.data = [];
$dataMap.events = [];
$dataMap.width = 100;
$dataMap.height = 100;
$dataMap.scrollType = 3;
};
// 数据管理器.地图是否已经加载
DataManager.isMapLoaded = function() {
this.checkError(); // 数据管理器.检查错误
return !!$dataMap;
};
// 数据管理器.加载事件
DataManager.onLoad = function(object) {
var array;
if (object === $dataMap) { // 如果是地图数据
this.extractMetadata(object); // 数据管理器.提取元数据()
array = object.events; // array = 地图事件数据组
} else {
array = object;
}
if (Array.isArray(array)) { // 判断是否为数组
for (var i = 0; i < array.length; i++) { // 遍历数组
var data = array[i];
if (data && data.note !== undefined) {
this.extractMetadata(data); // 数据管理器.提取元数据()
}
}
}
};
// 数据管理器.提取元数据() <元数据都在注释里>
DataManager.extractMetadata = function(data) {
// 举个简单的元数据格式 <tool:rmmv>
var re = /<([^<>:]+)(:?)([^>]*)>/g; // 全局匹配
data.meta = {};
for (;;) {
var match = re.exec(data.note); // 匹配
if (match) {
if (match[2] === ':') {
data.meta[match[1]] = match[3]; // data.meta["tool"] = rmmv;
} else {
data.meta[match[1]] = true; // 缺省时表示为 bool 且值 为 true
}
} else {
break;
}
}
};
// 数据管理器.检查错误
DataManager.checkError = function() {
if (DataManager._errorUrl) {
throw new Error('Failed to load: ' + DataManager._errorUrl);
}
};
// 数据管理器.是否为战斗测试
DataManager.isBattleTest = function() {
return Utils.isOptionValid('btest');
};
// 数据管理器.是否为事件测试
DataManager.isEventTest = function() {
return Utils.isOptionValid('etest');
};
// 数据管理器.是否为特技数据
DataManager.isSkill = function(item) {
return item && $dataSkills.contains(item);
};
// 数据管理器.是否为物品数据
DataManager.isItem = function(item) {
return item && $dataItems.contains(item);
};
// 数据管理器.是否为武器数据
DataManager.isWeapon = function(item) {
return item && $dataWeapons.contains(item);
};
// 数据管理器.是否为防具数据
DataManager.isArmor = function(item) {
return item && $dataArmors.contains(item);
};
// 数据管理器.创建游戏对象
DataManager.createGameObjects = function() {
$gameTemp = new Game_Temp(); // Game_Temp 类 游戏临时数据类
$gameSystem = new Game_System(); // Game_System 类 游戏系统类
$gameScreen = new Game_Screen(); // Game_Screen 类 游戏屏幕类
$gameTimer = new Game_Timer(); // Game_Time 类 游戏时间类
$gameMessage = new Game_Message(); // Game_Message 类 游戏消息类
$gameSwitches = new Game_Switches(); // Game_Switches 类 游戏开关类
$gameVariables = new Game_Variables(); // Game_Variables 类 游戏变量类
$gameSelfSwitches = new Game_SelfSwitches(); // Game_SelfSwitches 类 游戏独立开关类
$gameActors = new Game_Actors(); // Game_Actors 类 游戏角色组类
$gameParty = new Game_Party(); // Game_Party 类 游戏队伍类
$gameTroop = new Game_Troop(); // Game_Troop 类 游戏敌群类
$gameMap = new Game_Map(); // Game_Map 类 游戏地图类
$gamePlayer = new Game_Player(); // Game_Player 类 游戏玩家类
};
// 数据管理器.开始新游戏
DataManager.setupNewGame = function() {
this.createGameObjects(); // 数据管理器.创建游戏对象
this.selectSavefileForNewGame(); // 数据管理器.选择保存文件从新游戏????
$gameParty.setupStartingMembers(); // 游戏队伍类.设置开始成员
$gamePlayer.reserveTransfer($dataSystem.startMapId, $dataSystem.startX, $dataSystem.startY); // 游戏玩家类.复位传送至(系统数据.开始地图ID, 系统数据.开始X坐标, 系统数据.开始Y坐标)
Graphics.frameCount = 0; // Graphics(图形).帧数初始化为0
};
// 数据管理器.设置战斗测试
DataManager.setupBattleTest = function() {
this.createGameObjects(); // 数据管理器.创建游戏对象
$gameParty.setupBattleTest(); // 游戏队伍类.设置战斗测试
BattleManager.setup($dataSystem.testTroopId, true, false); // 战斗管理器.设置(系统数据类.测试队伍ID)
BattleManager.setBattleTest(true); // 战斗管理器.设置战斗测试(true)
BattleManager.playBattleBgm(); // 战斗管理器.播放战斗BGM
};
// 数据管理器.设置事件测试
DataManager.setupEventTest = function() {
this.createGameObjects(); // 数据管理器.创建游戏对象
this.selectSavefileForNewGame(); // 数据管理器.选择保存文件从新游戏????
$gameParty.setupStartingMembers(); // 游戏队伍类.设置开始成员
$gamePlayer.reserveTransfer(-1, 8, 6); // 游戏玩家类.复位传送至(-1, 8, 6)
$gamePlayer.setTransparent(false); // 游戏玩家类.设置透明(false)
};
// 数据管理器.加载全局信息
DataManager.loadGlobalInfo = function() {
var json;
try {
json = StorageManager.load(0); // 存储管理器.加载()
} catch (e) {
console.error(e); // 控制台.输出错误信息
return [];
}
if (json) {
var globalInfo = JSON.parse(json); // JSON.解析
for (var i = 1; i <= this.maxSavefiles(); i++) {
if (!StorageManager.exists(i)) { // 存储管理器.是否存在(ID)
delete globalInfo[i]; // 删除信息(ID)
}
}
return globalInfo;
} else {
return [];
}
};
// 数据管理器.保存全局信息
DataManager.saveGlobalInfo = function(info) {
StorageManager.save(0, JSON.stringify(info)); // 存储管理器.保存
};
// 数据管理器.是否为本游戏文件
DataManager.isThisGameFile = function(savefileId) {
var globalInfo = this.loadGlobalInfo(); // 数据管理器.加载全局信息
if (globalInfo && globalInfo[savefileId]) { // 全局信息[保存文件ID] 非 NULL
if (StorageManager.isLocalMode()) { // 存储管理器.是否本地模式
return true;
} else {
var savefile = globalInfo[savefileId]; // 保存文件信息
return (savefile.globalId === this._globalId && // 保存文件信息.全局ID === 数据管理器.全局ID
savefile.title === $dataSystem.gameTitle); // 保存文件信息.标题 === 系统数据类.游戏标题
}
} else {
return false;
}
};
// 数据管理器.是否为本游戏文件_扩展函数
DataManager.isThisGameFileEx = function(savefileId, globalInfo) {
if (globalInfo[savefileId]) { // 全局信息[保存文件ID] 非 NULL
if (StorageManager.isLocalMode()) { // 存储管理器.是否本地模式
return true;
} else {
var savefile = globalInfo[savefileId]; // 保存文件信息
return (savefile.globalId === this._globalId && // 保存文件信息.全局ID === 数据管理器.全局ID
savefile.title === $dataSystem.gameTitle); // 保存文件信息.标题 === 系统数据类.游戏标题
}
}
return false;
};
// 数据管理器.是否保存的文件(任意)
DataManager.isAnySavefileExists = function() {
var globalInfo = this.loadGlobalInfo(); // 数据管理器.加载全局信息
if (globalInfo) {
for (var i = 1; i < globalInfo.length; i++) {
// optimize
//if (this.isThisGameFile(i)) {
if (this.isThisGameFileEx(i, globalInfo)) { // 数据管理器.是否为本游戏文件
return true;
}
}
}
return false;
};
// 数据管理器.最新保存文件标识
DataManager.latestSavefileId = function() {
var globalInfo = this.loadGlobalInfo(); // 数据管理器.加载全局信息
var savefileId = 1;
var timestamp = 0; // 时间戳
if (globalInfo) {
for (var i = 1; i < globalInfo.length; i++) {
// optimize
// if (this.isThisGameFile(i) && globalInfo[i].timestamp > timestamp) {
// 数据管理器.是否为本游戏文件(i) 且 全局信息[i]
if (this.isThisGameFileEx(i, globalInfo) && globalInfo[i].timestamp > timestamp) {
timestamp = globalInfo[i].timestamp; // 设置当前最大时间戳
savefileId = i; // 设置保存文件ID
}
}
}
return savefileId;
};
// 数据管理器.加载全部保存文件图像
DataManager.loadAllSavefileImages = function() {
var globalInfo = this.loadGlobalInfo(); // 数据管理器.加载全局信息
if (globalInfo) {
for (var i = 1; i < globalInfo.length; i++) {
// optimize
// if (this.isThisGameFile(i)) {
if (this.isThisGameFileEx(i, globalInfo)) // 数据管理器.是否为本游戏文件(i)
var info = globalInfo[i];
this.loadSavefileImages(info); // 数据管理器.加载保存文件图像组
}
}
}
};
// 数据管理器.加载保存文件图像组
DataManager.loadSavefileImages = function(info) {
if (info.characters) {
for (var i = 0; i < info.characters.length; i++) {
ImageManager.loadCharacter(info.characters[i][0]); // 图像管理器.加载人物图像
}
}
if (info.faces) {
for (var j = 0; j < info.faces.length; j++) {
ImageManager.loadFace(info.faces[j][0]); // 图像管理器.加载脸部图像
}
}
};
// 数据管理器.保存文件最大数量
DataManager.maxSavefiles = function() {
return 20;
};
// 数据管理器.保存游戏
DataManager.saveGame = function(savefileId) {
try {
return this.saveGameWithoutRescue(savefileId); // 数据管理器.保存游戏(无拯救)
} catch (e) {
console.error(e);
try {
StorageManager.remove(savefileId); // 数据管理器.删除
} catch (e2) {
}
return false;
}
};
// 数据管理器.加载游戏
DataManager.loadGame = function(savefileId) {
try {
return this.loadGameWithoutRescue(savefileId); // 数据管理器.加载游戏(无拯救)
} catch (e) {
console.error(e);
return false;
}
};
// 数据管理器.加载(保存文件信息)
DataManager.loadSavefileInfo = function(savefileId) {
var globalInfo = this.loadGlobalInfo();
return (globalInfo && globalInfo[savefileId]) ? globalInfo[savefileId] : null;
};
// 数据管理权.最后保存的数据文件ID
DataManager.lastAccessedSavefileId = function() {
return this._lastAccessedId;
};
// 数据管理器.保存游戏(无拯救)
DataManager.saveGameWithoutRescue = function(savefileId) {
var json = JsonEx.stringify(this.makeSaveContents()); // 将 数据管理器.制保存内容 转换为 JSON 字符串。
if (json.length >= 200000) {
console.warn('Save data too big!');
}
StorageManager.save(savefileId, json); // 存储管理器.保存
this._lastAccessedId = savefileId; // 设置最后数据库ID
var globalInfo = this.loadGlobalInfo() || [];
globalInfo[savefileId] = this.makeSavefileInfo(); // 设置全局信息[保存ID] = 数据管理器.制保存文件信息
this.saveGlobalInfo(globalInfo); // 数据管理器.保存全局信息
return true;
};
// 数据管理器.加载游戏(无拯救)
DataManager.loadGameWithoutRescue = function(savefileId) {
var globalInfo = this.loadGlobalInfo(); // 数据管理器.加载全局信息
// optimize
// if (this.isThisGameFile(savefileId)) {
// 数据管理器.是否为本游戏文件(i)
if (this.isThisGameFileEx(savefileId, globalInfo)) {
var json = StorageManager.load(savefileId); // 存储管理器.加载()
this.createGameObjects(); // 数据管理器.创建游戏对象
this.extractSaveContents(JsonEx.parse(json)); // 数据管理器.提取保存内容(JsonEx.解析(json))
this._lastAccessedId = savefileId; // 设置最后数据库ID
return true;
} else {
return false;
}
};
// 数据管理器.选择保存文件从新游戏???
DataManager.selectSavefileForNewGame = function() {
var globalInfo = this.loadGlobalInfo(); // 数据管理器.加载全局信息
this._lastAccessedId = 1; // 数据管理器.最后数据ID = 1
if (globalInfo) {
var numSavefiles = Math.max(0, globalInfo.length - 1); // 存储文件数量
if (numSavefiles < this.maxSavefiles()) {
this._lastAccessedId = numSavefiles + 1;
} else {
var timestamp = Number.MAX_VALUE; // 时间戳 = JS.Number.MAX_VALUE
for (var i = 1; i < globalInfo.length; i++) {
if (!globalInfo[i]) {
this._lastAccessedId = i;
break;
}
if (globalInfo[i].timestamp < timestamp) {
timestamp = globalInfo[i].timestamp;
this._lastAccessedId = i;
}
}
}
}
};
// 数据管理器.制保存文件信息
DataManager.makeSavefileInfo = function() {
var info = {};
info.globalId = this._globalId;
info.title = $dataSystem.gameTitle;
info.characters = $gameParty.charactersForSavefile();
info.faces = $gameParty.facesForSavefile();
info.playtime = $gameSystem.playtimeText();
info.timestamp = Date.now();
return info;
};
// 数据管理器.制保存内容
DataManager.makeSaveContents = function() {
// A save data does not contain $gameTemp, $gameMessage, and $gameTroop.
var contents = {};
contents.system = $gameSystem;
contents.screen = $gameScreen;
contents.timer = $gameTimer;
contents.switches = $gameSwitches;
contents.variables = $gameVariables;
contents.selfSwitches = $gameSelfSwitches;
contents.actors = $gameActors;
contents.party = $gameParty;
contents.map = $gameMap;
contents.player = $gamePlayer;
return contents;
};
// 数据管理器.提取保存内容
DataManager.extractSaveContents = function(contents) {
$gameSystem = contents.system;
$gameScreen = contents.screen;
$gameTimer = contents.timer;
$gameSwitches = contents.switches;
$gameVariables = contents.variables;
$gameSelfSwitches = contents.selfSwitches;
$gameActors = contents.actors;
$gameParty = contents.party;
$gameMap = contents.map;
$gamePlayer = contents.player;
};
2.配置管理器类
//-----------------------------------------------------------------------------
// ConfigManager
//
// The static class that manages the configuration data.
// 配置管理器
// 静态类 管理配置数据
// ------ 选项配置
function ConfigManager() {
throw new Error('This is a static class');
}
ConfigManager.alwaysDash = false; // 始终冲刺
ConfigManager.commandRemember = false; // 记住命令
// 配置管理器.BGM 音量
Object.defineProperty(ConfigManager, 'bgmVolume', {
get: function() {
return AudioManager._bgmVolume;
},
set: function(value) {
AudioManager.bgmVolume = value;
},
configurable: true
});
// 配置管理器.BGS 音量
Object.defineProperty(ConfigManager, 'bgsVolume', {
get: function() {
return AudioManager.bgsVolume;
},
set: function(value) {
AudioManager.bgsVolume = value;
},
configurable: true
});
// 配置管理器.ME 音量
Object.defineProperty(ConfigManager, 'meVolume', {
get: function() {
return AudioManager.meVolume;
},
set: function(value) {
AudioManager.meVolume = value;
},
configurable: true
});
// 配置管理器.SE 音量
Object.defineProperty(ConfigManager, 'seVolume', {
get: function() {
return AudioManager.seVolume;
},
set: function(value) {
AudioManager.seVolume = value;
},
configurable: true
});
// 配置管理器.加载
ConfigManager.load = function() {
var json;
var config = {};
try {
json = StorageManager.load(-1); // 存储管理器.加载(-1)
} catch (e) {
console.error(e);
}
if (json) {
config = JSON.parse(json); // 配置 = JSON.解析()
}
this.applyData(config); // 配置管理器.应用数据()
};
// 配置管理器.保存
ConfigManager.save = function() {
StorageManager.save(-1, JSON.stringify(this.makeData())); // 存储管理器.保存(-1, 将 配置管理器.制保存内容 转换为 JSON 字符串。)
};
// 配置管理器.制作数据
ConfigManager.makeData = function() {
var config = {};
config.alwaysDash = this.alwaysDash; // 总是冲刺
config.commandRemember = this.commandRemember; // 记住命令
config.bgmVolume = this.bgmVolume; // BGM 音量
config.bgsVolume = this.bgsVolume; // BGS 音量
config.meVolume = this.meVolume; // ME 音量
config.seVolume = this.seVolume; // SE 音量
return config;
};
// 配置管理器.应用数据
ConfigManager.applyData = function(config) {
this.alwaysDash = this.readFlag(config, 'alwaysDash'); // 读取标记(总是冲刺)
this.commandRemember = this.readFlag(config, 'commandRemember'); // 读取标记(记住命令)
this.bgmVolume = this.readVolume(config, 'bgmVolume'); // 读取值(BGM 音量)
this.bgsVolume = this.readVolume(config, 'bgsVolume'); // 读取值(BGS 音量)
this.meVolume = this.readVolume(config, 'meVolume'); // 读取值(ME 音量)
this.seVolume = this.readVolume(config, 'seVolume'); // 读取值(SE 音量)
};
// 配置管理器.读取标记
ConfigManager.readFlag = function(config, name) {
return !!config[name];
};
// 配置管理器.读取值
ConfigManager.readVolume = function(config, name) {
var value = config[name];
if (value !== undefined) {
return Number(value).clamp(0, 100); // 返回一个大小不超出(0, 100)的数字值。 (<99>:99)(<102>:100)(<-1>:0)
} else {
return 100;
}
};
//-----------------------------------------------------------------------------
// ConfigManager
//
// The static class that manages the configuration data.
// 配置管理器
// 静态类 管理配置数据
// ------ 选项配置
function ConfigManager() {
throw new Error('This is a static class');
}
ConfigManager.alwaysDash = false; // 始终冲刺
ConfigManager.commandRemember = false; // 记住命令
// 配置管理器.BGM 音量
Object.defineProperty(ConfigManager, 'bgmVolume', {
get: function() {
return AudioManager._bgmVolume;
},
set: function(value) {
AudioManager.bgmVolume = value;
},
configurable: true
});
// 配置管理器.BGS 音量
Object.defineProperty(ConfigManager, 'bgsVolume', {
get: function() {
return AudioManager.bgsVolume;
},
set: function(value) {
AudioManager.bgsVolume = value;
},
configurable: true
});
// 配置管理器.ME 音量
Object.defineProperty(ConfigManager, 'meVolume', {
get: function() {
return AudioManager.meVolume;
},
set: function(value) {
AudioManager.meVolume = value;
},
configurable: true
});
// 配置管理器.SE 音量
Object.defineProperty(ConfigManager, 'seVolume', {
get: function() {
return AudioManager.seVolume;
},
set: function(value) {
AudioManager.seVolume = value;
},
configurable: true
});
// 配置管理器.加载
ConfigManager.load = function() {
var json;
var config = {};
try {
json = StorageManager.load(-1); // 存储管理器.加载(-1)
} catch (e) {
console.error(e);
}
if (json) {
config = JSON.parse(json); // 配置 = JSON.解析()
}
this.applyData(config); // 配置管理器.应用数据()
};
// 配置管理器.保存
ConfigManager.save = function() {
StorageManager.save(-1, JSON.stringify(this.makeData())); // 存储管理器.保存(-1, 将 配置管理器.制保存内容 转换为 JSON 字符串。)
};
// 配置管理器.制作数据
ConfigManager.makeData = function() {
var config = {};
config.alwaysDash = this.alwaysDash; // 总是冲刺
config.commandRemember = this.commandRemember; // 记住命令
config.bgmVolume = this.bgmVolume; // BGM 音量
config.bgsVolume = this.bgsVolume; // BGS 音量
config.meVolume = this.meVolume; // ME 音量
config.seVolume = this.seVolume; // SE 音量
return config;
};
// 配置管理器.应用数据
ConfigManager.applyData = function(config) {
this.alwaysDash = this.readFlag(config, 'alwaysDash'); // 读取标记(总是冲刺)
this.commandRemember = this.readFlag(config, 'commandRemember'); // 读取标记(记住命令)
this.bgmVolume = this.readVolume(config, 'bgmVolume'); // 读取值(BGM 音量)
this.bgsVolume = this.readVolume(config, 'bgsVolume'); // 读取值(BGS 音量)
this.meVolume = this.readVolume(config, 'meVolume'); // 读取值(ME 音量)
this.seVolume = this.readVolume(config, 'seVolume'); // 读取值(SE 音量)
};
// 配置管理器.读取标记
ConfigManager.readFlag = function(config, name) {
return !!config[name];
};
// 配置管理器.读取值
ConfigManager.readVolume = function(config, name) {
var value = config[name];
if (value !== undefined) {
return Number(value).clamp(0, 100); // 返回一个大小不超出(0, 100)的数字值。 (<99>:99)(<102>:100)(<-1>:0)
} else {
return 100;
}
};
3.存储管理器类(翻译完后我知道 RMMV 本地存储与网络存储的原理是什么了。其中有个函数里面太复杂,我无法翻译,留个高手吧)
3.1 存储管理器类 - 未翻译函数
// 未翻译的函数
// 存储管理器.本地存储文件目录路径
StorageManager.localFileDirectoryPath = function() {
var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/save/'); // 这个正则要逆向可太为难我这正则表达式战五渣的孩子了 ⊙﹏⊙b汗
if (path.match(/^\/([A-Z]\:)/)) {
path = path.slice(1);
}
return decodeURIComponent(path);
};
// 未翻译的函数
// 存储管理器.本地存储文件目录路径
StorageManager.localFileDirectoryPath = function() {
var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/save/'); // 这个正则要逆向可太为难我这正则表达式战五渣的孩子了 ⊙﹏⊙b汗
if (path.match(/^\/([A-Z]\:)/)) {
path = path.slice(1);
}
return decodeURIComponent(path);
};
3.2 存储管理器类 - 完整版:
//-----------------------------------------------------------------------------
// StorageManager
//
// The static class that manages storage for saving game data.
// 存储管理器
// 静态类 管理保存游戏数据的存储
function StorageManager() {
throw new Error('This is a static class');
}
// 存储管理器.保存
StorageManager.save = function(savefileId, json) {
if (this.isLocalMode()) { // 存储管理器.是否本地模式
this.saveToLocalFile(savefileId, json); // 存储管理器.保存到本地存储文件
} else {
this.saveToWebStorage(savefileId, json); // 存储管理器.保存到WEB存储文件
}
};
// 存储管理器.加载
StorageManager.load = function(savefileId) {
if (this.isLocalMode()) { // 存储管理器.是否本地模式
return this.loadFromLocalFile(savefileId); // 存储管理器.加载本地存储文件
} else {
return this.loadFromWebStorage(savefileId); // 存储管理器.加载WEB存储文件
}
};
// 存储管理器.是否存在存储文件
StorageManager.exists = function(savefileId) {
if (this.isLocalMode()) { // 存储管理器.是否本地模式
return this.localFileExists(savefileId); // 存储管理器.本地存储文件是否存在
} else {
return this.webStorageExists(savefileId); // 存储管理器.WEB存储文件是否存在
}
};
// 存储管理器.删除存储文件
StorageManager.remove = function(savefileId) {
if (this.isLocalMode()) { // 存储管理器.是否本地模式
this.removeLocalFile(savefileId); // 存储管理器.删除本地存储文件
} else {
this.removeWebStorage(savefileId); // 存储管理器.删除WEB存储文件
}
};
// 存储管理器.是否本地模式
StorageManager.isLocalMode = function() {
return Utils.isNwjs();
};
// 存储管理器.保存到本地存储文件
StorageManager.saveToLocalFile = function(savefileId, json) {
var data = LZString.compressToBase64(json); // LZ-String.压缩到Base64
var fs = require('fs'); // nodejs.require('fs') - 文件模块
var dirPath = this.localFileDirectoryPath(); // 存储管理器.本地存储文件目录路径
var filePath = this.localFilePath(savefileId); // 存储管理器.本地存储文件路径
if (!fs.existsSync(dirPath)) { // nodejs 库 检测保存目录是否存在
fs.mkdirSync(dirPath); // nodejs 库 创建目录
}
fs.writeFileSync(filePath, data); // nodejs 库 写到文件(同步)
};
// 存储管理器.加载本地存储文件
StorageManager.loadFromLocalFile = function(savefileId) {
var data = null;
var fs = require('fs'); // nodejs.require('fs') - 文件模块
var filePath = this.localFilePath(savefileId); // 存储管理器.本地存储文件路径
if (fs.existsSync(filePath)) { // nodejs 库 检测预打开文件是否存在
data = fs.readFileSync(filePath, { encoding: 'utf8' }); // nodejs 库 读文件数据(同步) utf8 编码
}
return LZString.decompressFromBase64(data); // LZ-String 从Base64解压缩
};
// 存储管理器.本地存储文件是否存在
StorageManager.localFileExists = function(savefileId) {
var fs = require('fs'); // nodejs.require('fs') - 文件模块
return fs.existsSync(this.localFilePath(savefileId)); // nodejs 库 检测(存储管理器.本地存储文件路径)是否存在
};
// 存储管理器.删除本地存储文件
StorageManager.removeLocalFile = function(savefileId) {
var fs = require('fs'); // nodejs.require('fs') - 文件模块
var filePath = this.localFilePath(savefileId); // 存储管理器.本地存储文件路径
if (fs.existsSync(filePath)) { // nodejs 库 检测指定文件是否存在
fs.unlinkSync(filePath); // nodejs 库 删除指定文件
}
};
// 存储管理器.保存到WEB存储文件
StorageManager.saveToWebStorage = function(savefileId, json) {
var key = this.webStorageKey(savefileId); // 存储管理器.WEB存储KEY
var data = LZString.compressToBase64(json); // LZ-String.压缩到Base64
localStorage.setItem(key, data); // <HTML5>本地存储.设置项目(WEB_KEY, 数据)
};
// 存储管理器.加载WEB存储文件
StorageManager.loadFromWebStorage = function(savefileId) {
var key = this.webStorageKey(savefileId); // 存储管理器.WEB存储KEY
var data = localStorage.getItem(key); // <HTML5>本地存储.取项目(WEB_KEY)
return LZString.decompressFromBase64(data); // LZ-String 从Base64解压缩
};
// 存储管理器.WEB存储文件是否存在
StorageManager.webStorageExists = function(savefileId) {
var key = this.webStorageKey(savefileId); // 存储管理器.WEB存储KEY
return !!localStorage.getItem(key); // return !!<HTML5>本地存储.取项目(WEB_KEY)
};
// 存储管理器.删除WEB存储文件
StorageManager.removeWebStorage = function(savefileId) {
var key = this.webStorageKey(savefileId); // 存储管理器.WEB存储KEY
localStorage.removeItem(key); // <HTML5>本地存储.删除项目(WEB_KEY)
};
// 存储管理器.本地存储文件目录路径
StorageManager.localFileDirectoryPath = function() {
var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/save/');
if (path.match(/^\/([A-Z]\:)/)) {
path = path.slice(1);
}
return decodeURIComponent(path);
};
// 存储管理器.本地存储文件路径
StorageManager.localFilePath = function(savefileId) {
var name;
if (savefileId < 0) {
name = 'config.rpgsave'; // 配置管理器
} else if (savefileId === 0) {
name = 'global.rpgsave'; // 全局信息
} else {
name = 'file%1.rpgsave'.format(savefileId); // 格式化成 file00.rpgsave
}
return this.localFileDirectoryPath() + name;
};
// 存储管理器.WEB存储KEY
StorageManager.webStorageKey = function(savefileId) {
if (savefileId < 0) {
return 'RPG Config'; // 配置管理器
} else if (savefileId === 0) {
return 'RPG Global'; // 全局信息
} else {
return 'RPG File%1'.format(savefileId); // 格式化成 RPG File00.rpgsave
}
};
//-----------------------------------------------------------------------------
// StorageManager
//
// The static class that manages storage for saving game data.
// 存储管理器
// 静态类 管理保存游戏数据的存储
function StorageManager() {
throw new Error('This is a static class');
}
// 存储管理器.保存
StorageManager.save = function(savefileId, json) {
if (this.isLocalMode()) { // 存储管理器.是否本地模式
this.saveToLocalFile(savefileId, json); // 存储管理器.保存到本地存储文件
} else {
this.saveToWebStorage(savefileId, json); // 存储管理器.保存到WEB存储文件
}
};
// 存储管理器.加载
StorageManager.load = function(savefileId) {
if (this.isLocalMode()) { // 存储管理器.是否本地模式
return this.loadFromLocalFile(savefileId); // 存储管理器.加载本地存储文件
} else {
return this.loadFromWebStorage(savefileId); // 存储管理器.加载WEB存储文件
}
};
// 存储管理器.是否存在存储文件
StorageManager.exists = function(savefileId) {
if (this.isLocalMode()) { // 存储管理器.是否本地模式
return this.localFileExists(savefileId); // 存储管理器.本地存储文件是否存在
} else {
return this.webStorageExists(savefileId); // 存储管理器.WEB存储文件是否存在
}
};
// 存储管理器.删除存储文件
StorageManager.remove = function(savefileId) {
if (this.isLocalMode()) { // 存储管理器.是否本地模式
this.removeLocalFile(savefileId); // 存储管理器.删除本地存储文件
} else {
this.removeWebStorage(savefileId); // 存储管理器.删除WEB存储文件
}
};
// 存储管理器.是否本地模式
StorageManager.isLocalMode = function() {
return Utils.isNwjs();
};
// 存储管理器.保存到本地存储文件
StorageManager.saveToLocalFile = function(savefileId, json) {
var data = LZString.compressToBase64(json); // LZ-String.压缩到Base64
var fs = require('fs'); // nodejs.require('fs') - 文件模块
var dirPath = this.localFileDirectoryPath(); // 存储管理器.本地存储文件目录路径
var filePath = this.localFilePath(savefileId); // 存储管理器.本地存储文件路径
if (!fs.existsSync(dirPath)) { // nodejs 库 检测保存目录是否存在
fs.mkdirSync(dirPath); // nodejs 库 创建目录
}
fs.writeFileSync(filePath, data); // nodejs 库 写到文件(同步)
};
// 存储管理器.加载本地存储文件
StorageManager.loadFromLocalFile = function(savefileId) {
var data = null;
var fs = require('fs'); // nodejs.require('fs') - 文件模块
var filePath = this.localFilePath(savefileId); // 存储管理器.本地存储文件路径
if (fs.existsSync(filePath)) { // nodejs 库 检测预打开文件是否存在
data = fs.readFileSync(filePath, { encoding: 'utf8' }); // nodejs 库 读文件数据(同步) utf8 编码
}
return LZString.decompressFromBase64(data); // LZ-String 从Base64解压缩
};
// 存储管理器.本地存储文件是否存在
StorageManager.localFileExists = function(savefileId) {
var fs = require('fs'); // nodejs.require('fs') - 文件模块
return fs.existsSync(this.localFilePath(savefileId)); // nodejs 库 检测(存储管理器.本地存储文件路径)是否存在
};
// 存储管理器.删除本地存储文件
StorageManager.removeLocalFile = function(savefileId) {
var fs = require('fs'); // nodejs.require('fs') - 文件模块
var filePath = this.localFilePath(savefileId); // 存储管理器.本地存储文件路径
if (fs.existsSync(filePath)) { // nodejs 库 检测指定文件是否存在
fs.unlinkSync(filePath); // nodejs 库 删除指定文件
}
};
// 存储管理器.保存到WEB存储文件
StorageManager.saveToWebStorage = function(savefileId, json) {
var key = this.webStorageKey(savefileId); // 存储管理器.WEB存储KEY
var data = LZString.compressToBase64(json); // LZ-String.压缩到Base64
localStorage.setItem(key, data); // <HTML5>本地存储.设置项目(WEB_KEY, 数据)
};
// 存储管理器.加载WEB存储文件
StorageManager.loadFromWebStorage = function(savefileId) {
var key = this.webStorageKey(savefileId); // 存储管理器.WEB存储KEY
var data = localStorage.getItem(key); // <HTML5>本地存储.取项目(WEB_KEY)
return LZString.decompressFromBase64(data); // LZ-String 从Base64解压缩
};
// 存储管理器.WEB存储文件是否存在
StorageManager.webStorageExists = function(savefileId) {
var key = this.webStorageKey(savefileId); // 存储管理器.WEB存储KEY
return !!localStorage.getItem(key); // return !!<HTML5>本地存储.取项目(WEB_KEY)
};
// 存储管理器.删除WEB存储文件
StorageManager.removeWebStorage = function(savefileId) {
var key = this.webStorageKey(savefileId); // 存储管理器.WEB存储KEY
localStorage.removeItem(key); // <HTML5>本地存储.删除项目(WEB_KEY)
};
// 存储管理器.本地存储文件目录路径
StorageManager.localFileDirectoryPath = function() {
var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/save/');
if (path.match(/^\/([A-Z]\:)/)) {
path = path.slice(1);
}
return decodeURIComponent(path);
};
// 存储管理器.本地存储文件路径
StorageManager.localFilePath = function(savefileId) {
var name;
if (savefileId < 0) {
name = 'config.rpgsave'; // 配置管理器
} else if (savefileId === 0) {
name = 'global.rpgsave'; // 全局信息
} else {
name = 'file%1.rpgsave'.format(savefileId); // 格式化成 file00.rpgsave
}
return this.localFileDirectoryPath() + name;
};
// 存储管理器.WEB存储KEY
StorageManager.webStorageKey = function(savefileId) {
if (savefileId < 0) {
return 'RPG Config'; // 配置管理器
} else if (savefileId === 0) {
return 'RPG Global'; // 全局信息
} else {
return 'RPG File%1'.format(savefileId); // 格式化成 RPG File00.rpgsave
}
};
4.图像管理器
//-----------------------------------------------------------------------------
// ImageManager
//
// The static class that loads images, creates bitmap objects and retains them.
// 图像管理器
// 静态类 管理加载图像与创建位图对象并保存
function ImageManager() {
throw new Error('This is a static class');
}
// 图像管理器.缓存
ImageManager._cache = {};
// 图像管理器.加载动画
ImageManager.loadAnimation = function(filename, hue) {
return this.loadBitmap('img/animations/', filename, hue, true);
};
// 图像管理器.加载战斗背景图1
ImageManager.loadBattleback1 = function(filename, hue) {
return this.loadBitmap('img/battlebacks1/', filename, hue, true);
};
// 图像管理器.加载战斗背景图2
ImageManager.loadBattleback2 = function(filename, hue) {
return this.loadBitmap('img/battlebacks2/', filename, hue, true);
};
// 图像管理器.加载敌人图像
ImageManager.loadEnemy = function(filename, hue) {
return this.loadBitmap('img/enemies/', filename, hue, true);
};
// 图像管理器.加载人物图像
ImageManager.loadCharacter = function(filename, hue) {
return this.loadBitmap('img/characters/', filename, hue, false);
};
// 图像管理器.加载脸部图像
ImageManager.loadFace = function(filename, hue) {
return this.loadBitmap('img/faces/', filename, hue, true);
};
// 图像管理器.加载远景图
ImageManager.loadParallax = function(filename, hue) {
return this.loadBitmap('img/parallaxes/', filename, hue, true);
};
// 图像管理器.加载图片
ImageManager.loadPicture = function(filename, hue) {
return this.loadBitmap('img/pictures/', filename, hue, true);
};
// 图像管理器.加载横版战斗人物
ImageManager.loadSvActor = function(filename, hue) {
return this.loadBitmap('img/sv_actors/', filename, hue, false);
};
// 图像管理器.加载横版战斗敌人
ImageManager.loadSvEnemy = function(filename, hue) {
return this.loadBitmap('img/sv_enemies/', filename, hue, true);
};
// 图像管理器.加载系统图像
ImageManager.loadSystem = function(filename, hue) {
return this.loadBitmap('img/system/', filename, hue, false);
};
// 图像管理器.加载图像集(地图元件)
ImageManager.loadTileset = function(filename, hue) {
return this.loadBitmap('img/tilesets/', filename, hue, false);
};
// 图像管理器.加载标题1
ImageManager.loadTitle1 = function(filename, hue) {
return this.loadBitmap('img/titles1/', filename, hue, true);
};
// 图像管理器.加载标题2
ImageManager.loadTitle2 = function(filename, hue) {
return this.loadBitmap('img/titles2/', filename, hue, true);
};
// 图像管理器.加载图像
ImageManager.loadBitmap = function(folder, filename, hue, smooth) {
if (filename) {
var path = folder + encodeURIComponent(filename) + '.png'; // 文件夹+URI编码压缩(filename)
var bitmap = this.loadNormalBitmap(path, hue || 0); // 图像管理器.加载正常图像
bitmap.smooth = smooth; // 光滑
return bitmap;
} else {
return this.loadEmptyBitmap(); // 图像管理器.加载空图像
}
};
// 图像管理器.加载空图像
ImageManager.loadEmptyBitmap = function() {
if (!this._cache[null]) {
this._cache[null] = new Bitmap();
}
return this._cache[null];
};
// 图像管理器.加载正常图像
ImageManager.loadNormalBitmap = function(path, hue) {
var key = path + ':' + hue;
if (!this._cache[key]) {
var bitmap = Bitmap.load(path);
bitmap.addLoadListener(function() { // bitmap 添加一个回调函数,在位图被加载时调用该函数。
bitmap.rotateHue(hue); // bitmap 变换位图的色相。
});
this._cache[key] = bitmap;
}
return this._cache[key];
};
// 图像管理器.清除
ImageManager.clear = function() {
this._cache = {};
};
// 图像管理器.是否就绪
ImageManager.isReady = function() {
for (var key in this._cache) {
var bitmap = this._cache[key];
if (bitmap.isError()) {
throw new Error('Failed to load: ' + bitmap.url);
}
if (!bitmap.isReady()) {
return false;
}
}
return true;
};
// 图像管理器.是否人物对象
ImageManager.isObjectCharacter = function(filename) {
var sign = filename.match(/^[\!\$]+/);
return sign && sign[0].contains('!');
};
// 图像管理器.是否为人物(大图像)
ImageManager.isBigCharacter = function(filename) {
var sign = filename.match(/^[\!\$]+/);
return sign && sign[0].contains('$');
};
// 图像管理器.是否远景滚动图(0)????
ImageManager.isZeroParallax = function(filename) {
return filename.charAt(0) === '!';
};
//-----------------------------------------------------------------------------
// ImageManager
//
// The static class that loads images, creates bitmap objects and retains them.
// 图像管理器
// 静态类 管理加载图像与创建位图对象并保存
function ImageManager() {
throw new Error('This is a static class');
}
// 图像管理器.缓存
ImageManager._cache = {};
// 图像管理器.加载动画
ImageManager.loadAnimation = function(filename, hue) {
return this.loadBitmap('img/animations/', filename, hue, true);
};
// 图像管理器.加载战斗背景图1
ImageManager.loadBattleback1 = function(filename, hue) {
return this.loadBitmap('img/battlebacks1/', filename, hue, true);
};
// 图像管理器.加载战斗背景图2
ImageManager.loadBattleback2 = function(filename, hue) {
return this.loadBitmap('img/battlebacks2/', filename, hue, true);
};
// 图像管理器.加载敌人图像
ImageManager.loadEnemy = function(filename, hue) {
return this.loadBitmap('img/enemies/', filename, hue, true);
};
// 图像管理器.加载人物图像
ImageManager.loadCharacter = function(filename, hue) {
return this.loadBitmap('img/characters/', filename, hue, false);
};
// 图像管理器.加载脸部图像
ImageManager.loadFace = function(filename, hue) {
return this.loadBitmap('img/faces/', filename, hue, true);
};
// 图像管理器.加载远景图
ImageManager.loadParallax = function(filename, hue) {
return this.loadBitmap('img/parallaxes/', filename, hue, true);
};
// 图像管理器.加载图片
ImageManager.loadPicture = function(filename, hue) {
return this.loadBitmap('img/pictures/', filename, hue, true);
};
// 图像管理器.加载横版战斗人物
ImageManager.loadSvActor = function(filename, hue) {
return this.loadBitmap('img/sv_actors/', filename, hue, false);
};
// 图像管理器.加载横版战斗敌人
ImageManager.loadSvEnemy = function(filename, hue) {
return this.loadBitmap('img/sv_enemies/', filename, hue, true);
};
// 图像管理器.加载系统图像
ImageManager.loadSystem = function(filename, hue) {
return this.loadBitmap('img/system/', filename, hue, false);
};
// 图像管理器.加载图像集(地图元件)
ImageManager.loadTileset = function(filename, hue) {
return this.loadBitmap('img/tilesets/', filename, hue, false);
};
// 图像管理器.加载标题1
ImageManager.loadTitle1 = function(filename, hue) {
return this.loadBitmap('img/titles1/', filename, hue, true);
};
// 图像管理器.加载标题2
ImageManager.loadTitle2 = function(filename, hue) {
return this.loadBitmap('img/titles2/', filename, hue, true);
};
// 图像管理器.加载图像
ImageManager.loadBitmap = function(folder, filename, hue, smooth) {
if (filename) {
var path = folder + encodeURIComponent(filename) + '.png'; // 文件夹+URI编码压缩(filename)
var bitmap = this.loadNormalBitmap(path, hue || 0); // 图像管理器.加载正常图像
bitmap.smooth = smooth; // 光滑
return bitmap;
} else {
return this.loadEmptyBitmap(); // 图像管理器.加载空图像
}
};
// 图像管理器.加载空图像
ImageManager.loadEmptyBitmap = function() {
if (!this._cache[null]) {
this._cache[null] = new Bitmap();
}
return this._cache[null];
};
// 图像管理器.加载正常图像
ImageManager.loadNormalBitmap = function(path, hue) {
var key = path + ':' + hue;
if (!this._cache[key]) {
var bitmap = Bitmap.load(path);
bitmap.addLoadListener(function() { // bitmap 添加一个回调函数,在位图被加载时调用该函数。
bitmap.rotateHue(hue); // bitmap 变换位图的色相。
});
this._cache[key] = bitmap;
}
return this._cache[key];
};
// 图像管理器.清除
ImageManager.clear = function() {
this._cache = {};
};
// 图像管理器.是否就绪
ImageManager.isReady = function() {
for (var key in this._cache) {
var bitmap = this._cache[key];
if (bitmap.isError()) {
throw new Error('Failed to load: ' + bitmap.url);
}
if (!bitmap.isReady()) {
return false;
}
}
return true;
};
// 图像管理器.是否人物对象
ImageManager.isObjectCharacter = function(filename) {
var sign = filename.match(/^[\!\$]+/);
return sign && sign[0].contains('!');
};
// 图像管理器.是否为人物(大图像)
ImageManager.isBigCharacter = function(filename) {
var sign = filename.match(/^[\!\$]+/);
return sign && sign[0].contains('$');
};
// 图像管理器.是否远景滚动图(0)????
ImageManager.isZeroParallax = function(filename) {
return filename.charAt(0) === '!';
};
5.音频管理器
//-----------------------------------------------------------------------------
// AudioManager
//
// The static class that handles BGM, BGS, ME and SE.
// 音频管理器
// 静态类 管理 BGM BGS ME SE
function AudioManager() {
throw new Error('This is a static class');
}
// 音量
AudioManager._bgmVolume = 100;
AudioManager._bgsVolume = 100;
AudioManager._meVolume = 100;
AudioManager._seVolume = 100;
AudioManager._currentBgm = null; // 当前 BGM
AudioManager._currentBgs = null; // 当前 BGS
AudioManager._bgmBuffer = null; // BGM 缓存
AudioManager._bgsBuffer = null; // BGS 缓存
AudioManager._meBuffer = null; // ME 缓存
AudioManager._seBuffers = []; // SE 缓存
AudioManager._staticBuffers = []; // 静态缓存组
AudioManager._replayFadeTime = 0.5; // 重播淡入淡出时间
AudioManager._path = 'audio/'; // 音频路径
// 音频管理器.BGM 音量
Object.defineProperty(AudioManager, 'bgmVolume', {
get: function() {
return this._bgmVolume;
},
set: function(value) {
this._bgmVolume = value;
this.updateBgmParameters(this._currentBgm); // 音频管理器.刷新BGM播放参数
},
configurable: true
});
// 音频管理器.BGS 音量
Object.defineProperty(AudioManager, 'bgsVolume', {
get: function() {
return this._bgsVolume;
},
set: function(value) {
this._bgsVolume = value;
this.updateBgsParameters(this._currentBgs); // 音频管理器.刷新BGS播放参数
},
configurable: true
});
// 音频管理器.ME 音量
Object.defineProperty(AudioManager, 'meVolume', {
get: function() {
return this._meVolume;
},
set: function(value) {
this._meVolume = value;
this.updateMeParameters(this._currentMe); // 音频管理器.刷新ME播放参数
},
configurable: true
});
// 音频管理器.SE 音量
Object.defineProperty(AudioManager, 'seVolume', {
get: function() {
return this._seVolume;
},
set: function(value) {
this._seVolume = value;
},
configurable: true
});
// 音频管理器.播放BGM
AudioManager.playBgm = function(bgm, pos) {
if (this.isCurrentBgm(bgm)) { // 音频管理器.是否当前BGM
this.updateBgmParameters(bgm); // 音频管理器.刷新BGM播放参数
} else {
this.stopBgm(); // 音频管理器.停止BGM
if (bgm.name) {
this._bgmBuffer = this.createBuffer('bgm', bgm.name); // 音频管理器.创建缓存
this.updateBgmParameters(bgm); // 音频管理器.刷新BGM播放参数
if (!this._meBuffer) {
this._bgmBuffer.play(true, pos || 0); // 音频管理器.BGM缓存.播放
}
}
}
this.updateCurrentBgm(bgm, pos); // 音频管理器.刷新当前BGM
};
// 音频管理器.重播BGM
AudioManager.replayBgm = function(bgm) {
if (this.isCurrentBgm(bgm)) { // 音频管理器.是否当前BGM
this.updateBgmParameters(bgm); // 音频管理器.刷新BGM播放参数
} else {
this.playBgm(bgm, bgm.pos); // 音频管理器.播放BGM
if (this._bgmBuffer) {
this._bgmBuffer.fadeIn(this._replayFadeTime); // 音频管理器.BGM缓存.淡入
}
}
};
// 音频管理器.是否当前BGM
AudioManager.isCurrentBgm = function(bgm) {
return (this._currentBgm && this._bgmBuffer &&
this._currentBgm.name === bgm.name);
};
// 音频管理器.刷新BGM播放参数
AudioManager.updateBgmParameters = function(bgm) {
this.updateBufferParameters(this._bgmBuffer, this._bgmVolume, bgm);
};
// 音频管理器.刷新当前BGM
AudioManager.updateCurrentBgm = function(bgm, pos) {
this._currentBgm = {
name: bgm.name,
volume: bgm.volume,
pitch: bgm.pitch, // 音调
pan: bgm.pan, // 声调
pos: pos
};
};
// 音频管理器.停止BGM
AudioManager.stopBgm = function() {
if (this._bgmBuffer) {
this._bgmBuffer.stop(); // 音频管理器.BGM缓存.停止
this._bgmBuffer = null;
this._currentBgm = null;
}
};
// 音频管理器.淡出BGM
AudioManager.fadeOutBgm = function(duration) {
if (this._bgmBuffer && this._currentBgm) {
this._bgmBuffer.fadeOut(duration); // 音频管理器.BGM缓存.淡出
this._currentBgm = null;
}
};
// 音频管理器.淡入BGM
AudioManager.fadeInBgm = function(duration) {
if (this._bgmBuffer && this._currentBgm) {
this._bgmBuffer.fadeIn(duration); // 音频管理器.BGM缓存.淡入
}
};
// 音频管理器.播放BGS
AudioManager.playBgs = function(bgs, pos) {
if (this.isCurrentBgs(bgs)) {
this.updateBgsParameters(bgs); // 音频管理器.刷新BGS播放参数
} else {
this.stopBgs(); // 音频管理器.停止BGS
if (bgs.name) {
this._bgsBuffer = this.createBuffer('bgs', bgs.name); // 音频管理器.创建缓存
this.updateBgsParameters(bgs); // 音频管理器.刷新BGS播放参数
this._bgsBuffer.play(true, pos || 0); // 音频管理器.BGS缓存.播放
}
}
this.updateCurrentBgs(bgs, pos); // 音频管理器.刷新BGS播放参数
};
// 音频管理器.重播BGS
AudioManager.replayBgs = function(bgs) {
if (this.isCurrentBgs(bgs)) {
this.updateBgsParameters(bgs); // 音频管理器.刷新BGS播放参数
} else {
this.playBgs(bgs, bgs.pos); // 音频管理器.播放BGS
if (this._bgsBuffer) {
this._bgsBuffer.fadeIn(this._replayFadeTime); // 音频管理器.BGS缓存.淡入
}
}
};
// 音频管理器.是否当前BGS
AudioManager.isCurrentBgs = function(bgs) {
return (this._currentBgs && this._bgsBuffer &&
this._currentBgs.name === bgs.name);
};
// 音频管理器.刷新BGS播放参数
AudioManager.updateBgsParameters = function(bgs) {
this.updateBufferParameters(this._bgsBuffer, this._bgsVolume, bgs); // 音频管理器.刷新缓存参数
};
// 音频管理器.刷新当前BGS
AudioManager.updateCurrentBgs = function(bgs, pos) {
this._currentBgs = {
name: bgs.name,
volume: bgs.volume,
pitch: bgs.pitch,
pan: bgs.pan,
pos: pos
};
};
// 音频管理器.停止BGS
AudioManager.stopBgs = function() {
if (this._bgsBuffer) {
this._bgsBuffer.stop(); // 音频管理器.BGS缓存.停止
this._bgsBuffer = null;
this._currentBgs = null;
}
};
// 音频管理器.淡出BGS
AudioManager.fadeOutBgs = function(duration) {
if (this._bgsBuffer && this._currentBgs) {
this._bgsBuffer.fadeOut(duration); // 音频管理器.BGS缓存.淡出
this._currentBgs = null;
}
};
// 音频管理器.淡入BGS
AudioManager.fadeInBgs = function(duration) {
if (this._bgsBuffer && this._currentBgs) {
this._bgsBuffer.fadeIn(duration); // 音频管理器.BGS缓存.淡入
}
};
// 音频管理器.播放ME
AudioManager.playMe = function(me) {
this.stopMe(); // 音频管理器.停止ME
if (me.name) {
if (this._bgmBuffer && this._currentBgm) {
this._currentBgm.pos = this._bgmBuffer.seek(); // 音频管理器.当前BGM.位置 = 音频管理器.BGM缓存.寻求()
this._bgmBuffer.stop(); // 音频管理器.BGM缓存.停止
}
this._meBuffer = this.createBuffer('me', me.name); // 音频管理器.创建缓存
this.updateMeParameters(me); // 音频管理器.刷新ME播放参数
this._meBuffer.play(false); // 音频管理器.ME缓存.播放
this._meBuffer.addStopListener(this.stopMe.bind(this)); // 音频管理器.ME缓存.添加停止回调函数(音频管理器.停止ME.绑定(this)/* bind 可以防止丢失 this */)
}
};
// 音频管理器.刷新ME播放参数
AudioManager.updateMeParameters = function(me) {
this.updateBufferParameters(this._meBuffer, this._meVolume, me); // 音频管理器.刷新缓存参数
};
// 音频管理器.淡出ME
AudioManager.fadeOutMe = function(duration) {
if (this._meBuffer) {
this._meBuffer.fadeOut(duration); // 音频管理器.ME缓存.淡出
}
};
// custom add
// 音频管理器.淡入ME
AudioManager.fadeInMe = function(duration) {
if (this._meBuffer) {
this._meBuffer.fadeIn(duration); // 音频管理器.ME缓存.淡入
}
};
//-----------------------------------------------------------------------------------------------------------
// 音频管理器.停止ME
AudioManager.stopMe = function() {
if (this._meBuffer) {
this._meBuffer.stop(); // 音频管理器.ME缓存.停止()
this._meBuffer = null;
// 音频管理器.BGM缓存存在 且 音频管理器.当前BGM缓存存在 且 音频管理器.BGM缓存.正在播放()
if (this._bgmBuffer && this._currentBgm && !this._bgmBuffer.isPlaying()) {
this._bgmBuffer.play(true, this._currentBgm.pos); // 音频管理器.BGM缓存.播放()
this._bgmBuffer.fadeIn(this._replayFadeTime); // 音频管理器.BGM缓存.淡入()
}
}
};
// 音频管理器.播放SE
AudioManager.playSe = function(se) {
if (se.name) {
// 过滤掉正在播放中的SE
this._seBuffers = this._seBuffers.filter(function(audio) {
return audio.isPlaying();
});
var buffer = this.createBuffer('se', se.name); // 音频管理器.创建缓存
this.updateSeParameters(buffer, se); // 音频管理器.刷新SE播放参数
buffer.play(false); // 新创建SE缓存.播放
this._seBuffers.push(buffer); // 音频管理器.SE缓存组.投递(新创建SE)
}
};
// 音频管理器.刷新SE播放参数
AudioManager.updateSeParameters = function(buffer, se) {
this.updateBufferParameters(buffer, this._seVolume, se); // 音频管理器.刷新缓存参数()
};
// 音频管理器.停止SE
AudioManager.stopSe = function() {
// ES5 新增 Array.遍历函数
// function callback(value, [index], [object])
this._seBuffers.forEach(function(buffer) {
buffer.stop(); // WebAudio/Html5Audio.停止
});
this._seBuffers = []; // 音频管理器.SE缓存组 清空
};
// 音频管理器.播放静态SE
AudioManager.playStaticSe = function(se) {
if (se.name) {
this.loadStaticSe(se); // 音频管理器.加载静态SE
// 遍历 音频管理器.静态SE组
for (var i = 0; i < this._staticBuffers.length; i++) {
var buffer = this._staticBuffers[i];
if (buffer._reservedSeName === se.name) {
buffer.stop(); // WebAudio/Html5Audio.停止
this.updateSeParameters(buffer, se); // 音频管理器.刷新SE播放参数
buffer.play(false); // WebAudio/Html5Audio.播放
break;
}
}
}
};
// 音频管理器.加载静态SE
AudioManager.loadStaticSe = function(se) {
if (se.name && !this.isStaticSe(se)) {
var buffer = this.createBuffer('se', se.name); // 音频管理器.创建缓存
buffer._reservedSeName = se.name;
this._staticBuffers.push(buffer); // 音频管理器.静态缓存.投递(新创建SE)
if (this.shouldUseHtml5Audio()) { // 音频管理器.是否应该使用 Html5Audio
Html5Audio.setStaticSe(buffer._url); // Html5Audio.设置静态SE
}
}
};
// 音频管理器.是否为静态SE
AudioManager.isStaticSe = function(se) {
// 遍历 音频管理器.静态缓存组
for (var i = 0; i < this._staticBuffers.length; i++) {
var buffer = this._staticBuffers[i];
// 缓存.保留SE名 === SE.名
if (buffer._reservedSeName === se.name) {
return true;
}
}
return false;
};
// 音频管理器.停止所有音频
AudioManager.stopAll = function() {
this.stopMe(); // 音频管理器.停止ME
this.stopBgm(); // 音频管理器.停止BGM
this.stopBgs(); // 音频管理器.停止BGS
this.stopSe(); // 音频管理器.停止SE
};
// 音频管理器.保存BGM
AudioManager.saveBgm = function() {
if (this._currentBgm) {
var bgm = this._currentBgm;
return {
name: bgm.name,
volume: bgm.volume,
pitch: bgm.pitch,
pan: bgm.pan,
pos: this._bgmBuffer ? this._bgmBuffer.seek() : 0
};
} else {
return this.makeEmptyAudioObject(); // 音频管理器.制空音频对象
}
};
// 音频管理器.保存BGS
AudioManager.saveBgs = function() {
if (this._currentBgs) {
var bgs = this._currentBgs;
return {
name: bgs.name,
volume: bgs.volume,
pitch: bgs.pitch,
pan: bgs.pan,
pos: this._bgsBuffer ? this._bgsBuffer.seek() : 0
};
} else {
return this.makeEmptyAudioObject(); // 音频管理器.制空音频对象
}
};
// 音频管理器.制空音频对象
AudioManager.makeEmptyAudioObject = function() {
return { name: '', volume: 0, pitch: 0 };
};
// 音频管理器.创建缓存
AudioManager.createBuffer = function(folder, name) {
var ext = this.audioFileExt(); // 音频管理器.音频文件后缀名
var url = this._path + folder + '/' + encodeURIComponent(name) + ext; // 音频管理器.路径+文件夹+URI编码压缩(name)+后缀名
if (this.shouldUseHtml5Audio() && folder === 'bgm') { // 音频管理器.是否应该使用HTML5Aduio 且 目录 === 'bgm'
Html5Audio.setup(url); // Html5Audio.设置
return Html5Audio;
} else {
return new WebAudio(url); // 创建 WebAudio
}
};
// 音频管理器.刷新缓存参数
AudioManager.updateBufferParameters = function(buffer, configVolume, audio) {
if (buffer && audio) {
buffer.volume = configVolume * (audio.volume || 0) / 10000;
buffer.pitch = (audio.pitch || 0) / 100;
buffer.pan = (audio.pan || 0) / 100;
}
};
// 音频管理器.音频文件扩展
AudioManager.audioFileExt = function() {
if (WebAudio.canPlayOgg() && !Utils.isMobileDevice()) {
return '.ogg';
} else {
return '.m4a';
}
};
// 音频管理器.是否需要使用HTML5音频
AudioManager.shouldUseHtml5Audio = function() {
// 我们使用HTML5音频播放背景音乐而不是Web Audio API
// decodeAudioData()很慢在Android的Chrome。
return Utils.isAndroidChrome();
};
// 音频管理器.检查错误集
AudioManager.checkErrors = function() {
this.checkWebAudioError(this._bgmBuffer); // 音频管理器.检查网页音频错误(音频管理器.BGM缓存)
this.checkWebAudioError(this._bgsBuffer); // 音频管理器.检查网页音频错误(音频管理器.BGS缓存)
this.checkWebAudioError(this._meBuffer); // 音频管理器.检查网页音频错误(音频管理器.ME缓存)
// 音频管理器.SE缓存组.遍历数组
this._seBuffers.forEach(function(buffer) {
this.checkWebAudioError(buffer); // 音频管理器.检查网页音频错误(buffer).绑定(this)
}.bind(this));
this._staticBuffers.forEach(function(buffer) {
this.checkWebAudioError(buffer); // 音频管理器.检查网页音频错误(buffer).绑定(this)
}.bind(this));
};
// 音频管理器.检查网页音频错误
AudioManager.checkWebAudioError = function(webAudio) {
if (webAudio && webAudio.isError()) {
throw new Error('Failed to load: ' + webAudio.url);
}
};
//-----------------------------------------------------------------------------
// AudioManager
//
// The static class that handles BGM, BGS, ME and SE.
// 音频管理器
// 静态类 管理 BGM BGS ME SE
function AudioManager() {
throw new Error('This is a static class');
}
// 音量
AudioManager._bgmVolume = 100;
AudioManager._bgsVolume = 100;
AudioManager._meVolume = 100;
AudioManager._seVolume = 100;
AudioManager._currentBgm = null; // 当前 BGM
AudioManager._currentBgs = null; // 当前 BGS
AudioManager._bgmBuffer = null; // BGM 缓存
AudioManager._bgsBuffer = null; // BGS 缓存
AudioManager._meBuffer = null; // ME 缓存
AudioManager._seBuffers = []; // SE 缓存
AudioManager._staticBuffers = []; // 静态缓存组
AudioManager._replayFadeTime = 0.5; // 重播淡入淡出时间
AudioManager._path = 'audio/'; // 音频路径
// 音频管理器.BGM 音量
Object.defineProperty(AudioManager, 'bgmVolume', {
get: function() {
return this._bgmVolume;
},
set: function(value) {
this._bgmVolume = value;
this.updateBgmParameters(this._currentBgm); // 音频管理器.刷新BGM播放参数
},
configurable: true
});
// 音频管理器.BGS 音量
Object.defineProperty(AudioManager, 'bgsVolume', {
get: function() {
return this._bgsVolume;
},
set: function(value) {
this._bgsVolume = value;
this.updateBgsParameters(this._currentBgs); // 音频管理器.刷新BGS播放参数
},
configurable: true
});
// 音频管理器.ME 音量
Object.defineProperty(AudioManager, 'meVolume', {
get: function() {
return this._meVolume;
},
set: function(value) {
this._meVolume = value;
this.updateMeParameters(this._currentMe); // 音频管理器.刷新ME播放参数
},
configurable: true
});
// 音频管理器.SE 音量
Object.defineProperty(AudioManager, 'seVolume', {
get: function() {
return this._seVolume;
},
set: function(value) {
this._seVolume = value;
},
configurable: true
});
// 音频管理器.播放BGM
AudioManager.playBgm = function(bgm, pos) {
if (this.isCurrentBgm(bgm)) { // 音频管理器.是否当前BGM
this.updateBgmParameters(bgm); // 音频管理器.刷新BGM播放参数
} else {
this.stopBgm(); // 音频管理器.停止BGM
if (bgm.name) {
this._bgmBuffer = this.createBuffer('bgm', bgm.name); // 音频管理器.创建缓存
this.updateBgmParameters(bgm); // 音频管理器.刷新BGM播放参数
if (!this._meBuffer) {
this._bgmBuffer.play(true, pos || 0); // 音频管理器.BGM缓存.播放
}
}
}
this.updateCurrentBgm(bgm, pos); // 音频管理器.刷新当前BGM
};
// 音频管理器.重播BGM
AudioManager.replayBgm = function(bgm) {
if (this.isCurrentBgm(bgm)) { // 音频管理器.是否当前BGM
this.updateBgmParameters(bgm); // 音频管理器.刷新BGM播放参数
} else {
this.playBgm(bgm, bgm.pos); // 音频管理器.播放BGM
if (this._bgmBuffer) {
this._bgmBuffer.fadeIn(this._replayFadeTime); // 音频管理器.BGM缓存.淡入
}
}
};
// 音频管理器.是否当前BGM
AudioManager.isCurrentBgm = function(bgm) {
return (this._currentBgm && this._bgmBuffer &&
this._currentBgm.name === bgm.name);
};
// 音频管理器.刷新BGM播放参数
AudioManager.updateBgmParameters = function(bgm) {
this.updateBufferParameters(this._bgmBuffer, this._bgmVolume, bgm);
};
// 音频管理器.刷新当前BGM
AudioManager.updateCurrentBgm = function(bgm, pos) {
this._currentBgm = {
name: bgm.name,
volume: bgm.volume,
pitch: bgm.pitch, // 音调
pan: bgm.pan, // 声调
pos: pos
};
};
// 音频管理器.停止BGM
AudioManager.stopBgm = function() {
if (this._bgmBuffer) {
this._bgmBuffer.stop(); // 音频管理器.BGM缓存.停止
this._bgmBuffer = null;
this._currentBgm = null;
}
};
// 音频管理器.淡出BGM
AudioManager.fadeOutBgm = function(duration) {
if (this._bgmBuffer && this._currentBgm) {
this._bgmBuffer.fadeOut(duration); // 音频管理器.BGM缓存.淡出
this._currentBgm = null;
}
};
// 音频管理器.淡入BGM
AudioManager.fadeInBgm = function(duration) {
if (this._bgmBuffer && this._currentBgm) {
this._bgmBuffer.fadeIn(duration); // 音频管理器.BGM缓存.淡入
}
};
// 音频管理器.播放BGS
AudioManager.playBgs = function(bgs, pos) {
if (this.isCurrentBgs(bgs)) {
this.updateBgsParameters(bgs); // 音频管理器.刷新BGS播放参数
} else {
this.stopBgs(); // 音频管理器.停止BGS
if (bgs.name) {
this._bgsBuffer = this.createBuffer('bgs', bgs.name); // 音频管理器.创建缓存
this.updateBgsParameters(bgs); // 音频管理器.刷新BGS播放参数
this._bgsBuffer.play(true, pos || 0); // 音频管理器.BGS缓存.播放
}
}
this.updateCurrentBgs(bgs, pos); // 音频管理器.刷新BGS播放参数
};
// 音频管理器.重播BGS
AudioManager.replayBgs = function(bgs) {
if (this.isCurrentBgs(bgs)) {
this.updateBgsParameters(bgs); // 音频管理器.刷新BGS播放参数
} else {
this.playBgs(bgs, bgs.pos); // 音频管理器.播放BGS
if (this._bgsBuffer) {
this._bgsBuffer.fadeIn(this._replayFadeTime); // 音频管理器.BGS缓存.淡入
}
}
};
// 音频管理器.是否当前BGS
AudioManager.isCurrentBgs = function(bgs) {
return (this._currentBgs && this._bgsBuffer &&
this._currentBgs.name === bgs.name);
};
// 音频管理器.刷新BGS播放参数
AudioManager.updateBgsParameters = function(bgs) {
this.updateBufferParameters(this._bgsBuffer, this._bgsVolume, bgs); // 音频管理器.刷新缓存参数
};
// 音频管理器.刷新当前BGS
AudioManager.updateCurrentBgs = function(bgs, pos) {
this._currentBgs = {
name: bgs.name,
volume: bgs.volume,
pitch: bgs.pitch,
pan: bgs.pan,
pos: pos
};
};
// 音频管理器.停止BGS
AudioManager.stopBgs = function() {
if (this._bgsBuffer) {
this._bgsBuffer.stop(); // 音频管理器.BGS缓存.停止
this._bgsBuffer = null;
this._currentBgs = null;
}
};
// 音频管理器.淡出BGS
AudioManager.fadeOutBgs = function(duration) {
if (this._bgsBuffer && this._currentBgs) {
this._bgsBuffer.fadeOut(duration); // 音频管理器.BGS缓存.淡出
this._currentBgs = null;
}
};
// 音频管理器.淡入BGS
AudioManager.fadeInBgs = function(duration) {
if (this._bgsBuffer && this._currentBgs) {
this._bgsBuffer.fadeIn(duration); // 音频管理器.BGS缓存.淡入
}
};
// 音频管理器.播放ME
AudioManager.playMe = function(me) {
this.stopMe(); // 音频管理器.停止ME
if (me.name) {
if (this._bgmBuffer && this._currentBgm) {
this._currentBgm.pos = this._bgmBuffer.seek(); // 音频管理器.当前BGM.位置 = 音频管理器.BGM缓存.寻求()
this._bgmBuffer.stop(); // 音频管理器.BGM缓存.停止
}
this._meBuffer = this.createBuffer('me', me.name); // 音频管理器.创建缓存
this.updateMeParameters(me); // 音频管理器.刷新ME播放参数
this._meBuffer.play(false); // 音频管理器.ME缓存.播放
this._meBuffer.addStopListener(this.stopMe.bind(this)); // 音频管理器.ME缓存.添加停止回调函数(音频管理器.停止ME.绑定(this)/* bind 可以防止丢失 this */)
}
};
// 音频管理器.刷新ME播放参数
AudioManager.updateMeParameters = function(me) {
this.updateBufferParameters(this._meBuffer, this._meVolume, me); // 音频管理器.刷新缓存参数
};
// 音频管理器.淡出ME
AudioManager.fadeOutMe = function(duration) {
if (this._meBuffer) {
this._meBuffer.fadeOut(duration); // 音频管理器.ME缓存.淡出
}
};
// custom add
// 音频管理器.淡入ME
AudioManager.fadeInMe = function(duration) {
if (this._meBuffer) {
this._meBuffer.fadeIn(duration); // 音频管理器.ME缓存.淡入
}
};
//-----------------------------------------------------------------------------------------------------------
// 音频管理器.停止ME
AudioManager.stopMe = function() {
if (this._meBuffer) {
this._meBuffer.stop(); // 音频管理器.ME缓存.停止()
this._meBuffer = null;
// 音频管理器.BGM缓存存在 且 音频管理器.当前BGM缓存存在 且 音频管理器.BGM缓存.正在播放()
if (this._bgmBuffer && this._currentBgm && !this._bgmBuffer.isPlaying()) {
this._bgmBuffer.play(true, this._currentBgm.pos); // 音频管理器.BGM缓存.播放()
this._bgmBuffer.fadeIn(this._replayFadeTime); // 音频管理器.BGM缓存.淡入()
}
}
};
// 音频管理器.播放SE
AudioManager.playSe = function(se) {
if (se.name) {
// 过滤掉正在播放中的SE
this._seBuffers = this._seBuffers.filter(function(audio) {
return audio.isPlaying();
});
var buffer = this.createBuffer('se', se.name); // 音频管理器.创建缓存
this.updateSeParameters(buffer, se); // 音频管理器.刷新SE播放参数
buffer.play(false); // 新创建SE缓存.播放
this._seBuffers.push(buffer); // 音频管理器.SE缓存组.投递(新创建SE)
}
};
// 音频管理器.刷新SE播放参数
AudioManager.updateSeParameters = function(buffer, se) {
this.updateBufferParameters(buffer, this._seVolume, se); // 音频管理器.刷新缓存参数()
};
// 音频管理器.停止SE
AudioManager.stopSe = function() {
// ES5 新增 Array.遍历函数
// function callback(value, [index], [object])
this._seBuffers.forEach(function(buffer) {
buffer.stop(); // WebAudio/Html5Audio.停止
});
this._seBuffers = []; // 音频管理器.SE缓存组 清空
};
// 音频管理器.播放静态SE
AudioManager.playStaticSe = function(se) {
if (se.name) {
this.loadStaticSe(se); // 音频管理器.加载静态SE
// 遍历 音频管理器.静态SE组
for (var i = 0; i < this._staticBuffers.length; i++) {
var buffer = this._staticBuffers[i];
if (buffer._reservedSeName === se.name) {
buffer.stop(); // WebAudio/Html5Audio.停止
this.updateSeParameters(buffer, se); // 音频管理器.刷新SE播放参数
buffer.play(false); // WebAudio/Html5Audio.播放
break;
}
}
}
};
// 音频管理器.加载静态SE
AudioManager.loadStaticSe = function(se) {
if (se.name && !this.isStaticSe(se)) {
var buffer = this.createBuffer('se', se.name); // 音频管理器.创建缓存
buffer._reservedSeName = se.name;
this._staticBuffers.push(buffer); // 音频管理器.静态缓存.投递(新创建SE)
if (this.shouldUseHtml5Audio()) { // 音频管理器.是否应该使用 Html5Audio
Html5Audio.setStaticSe(buffer._url); // Html5Audio.设置静态SE
}
}
};
// 音频管理器.是否为静态SE
AudioManager.isStaticSe = function(se) {
// 遍历 音频管理器.静态缓存组
for (var i = 0; i < this._staticBuffers.length; i++) {
var buffer = this._staticBuffers[i];
// 缓存.保留SE名 === SE.名
if (buffer._reservedSeName === se.name) {
return true;
}
}
return false;
};
// 音频管理器.停止所有音频
AudioManager.stopAll = function() {
this.stopMe(); // 音频管理器.停止ME
this.stopBgm(); // 音频管理器.停止BGM
this.stopBgs(); // 音频管理器.停止BGS
this.stopSe(); // 音频管理器.停止SE
};
// 音频管理器.保存BGM
AudioManager.saveBgm = function() {
if (this._currentBgm) {
var bgm = this._currentBgm;
return {
name: bgm.name,
volume: bgm.volume,
pitch: bgm.pitch,
pan: bgm.pan,
pos: this._bgmBuffer ? this._bgmBuffer.seek() : 0
};
} else {
return this.makeEmptyAudioObject(); // 音频管理器.制空音频对象
}
};
// 音频管理器.保存BGS
AudioManager.saveBgs = function() {
if (this._currentBgs) {
var bgs = this._currentBgs;
return {
name: bgs.name,
volume: bgs.volume,
pitch: bgs.pitch,
pan: bgs.pan,
pos: this._bgsBuffer ? this._bgsBuffer.seek() : 0
};
} else {
return this.makeEmptyAudioObject(); // 音频管理器.制空音频对象
}
};
// 音频管理器.制空音频对象
AudioManager.makeEmptyAudioObject = function() {
return { name: '', volume: 0, pitch: 0 };
};
// 音频管理器.创建缓存
AudioManager.createBuffer = function(folder, name) {
var ext = this.audioFileExt(); // 音频管理器.音频文件后缀名
var url = this._path + folder + '/' + encodeURIComponent(name) + ext; // 音频管理器.路径+文件夹+URI编码压缩(name)+后缀名
if (this.shouldUseHtml5Audio() && folder === 'bgm') { // 音频管理器.是否应该使用HTML5Aduio 且 目录 === 'bgm'
Html5Audio.setup(url); // Html5Audio.设置
return Html5Audio;
} else {
return new WebAudio(url); // 创建 WebAudio
}
};
// 音频管理器.刷新缓存参数
AudioManager.updateBufferParameters = function(buffer, configVolume, audio) {
if (buffer && audio) {
buffer.volume = configVolume * (audio.volume || 0) / 10000;
buffer.pitch = (audio.pitch || 0) / 100;
buffer.pan = (audio.pan || 0) / 100;
}
};
// 音频管理器.音频文件扩展
AudioManager.audioFileExt = function() {
if (WebAudio.canPlayOgg() && !Utils.isMobileDevice()) {
return '.ogg';
} else {
return '.m4a';
}
};
// 音频管理器.是否需要使用HTML5音频
AudioManager.shouldUseHtml5Audio = function() {
// 我们使用HTML5音频播放背景音乐而不是Web Audio API
// decodeAudioData()很慢在Android的Chrome。
return Utils.isAndroidChrome();
};
// 音频管理器.检查错误集
AudioManager.checkErrors = function() {
this.checkWebAudioError(this._bgmBuffer); // 音频管理器.检查网页音频错误(音频管理器.BGM缓存)
this.checkWebAudioError(this._bgsBuffer); // 音频管理器.检查网页音频错误(音频管理器.BGS缓存)
this.checkWebAudioError(this._meBuffer); // 音频管理器.检查网页音频错误(音频管理器.ME缓存)
// 音频管理器.SE缓存组.遍历数组
this._seBuffers.forEach(function(buffer) {
this.checkWebAudioError(buffer); // 音频管理器.检查网页音频错误(buffer).绑定(this)
}.bind(this));
this._staticBuffers.forEach(function(buffer) {
this.checkWebAudioError(buffer); // 音频管理器.检查网页音频错误(buffer).绑定(this)
}.bind(this));
};
// 音频管理器.检查网页音频错误
AudioManager.checkWebAudioError = function(webAudio) {
if (webAudio && webAudio.isError()) {
throw new Error('Failed to load: ' + webAudio.url);
}
};
6.声音管理器
//-----------------------------------------------------------------------------
// SoundManager
//
// The static class that plays sound effects defined in the database.
// 声音管理器
// 静态类 管理数据库中定义声音效果
function SoundManager() {
throw new Error('This is a static class');
}
// 声音管理器.预加载重要的声音
SoundManager.preloadImportantSounds = function() {
this.loadSystemSound(0);
this.loadSystemSound(1);
this.loadSystemSound(2);
this.loadSystemSound(3);
};
// 声音管理器.加载系统声音
SoundManager.loadSystemSound = function(n) {
if ($dataSystem) {
AudioManager.loadStaticSe($dataSystem.sounds[n]); // 音频管理器.加载静态SE
}
};
// 声音管理器.播放系统声音
SoundManager.playSystemSound = function(n) {
if ($dataSystem) {
AudioManager.playStaticSe($dataSystem.sounds[n]); // 音频管理器.播放静态SE
}
};
// 声音管理器.播放光标音效
SoundManager.playCursor = function() {
this.playSystemSound(0);
};
// 声音管理器.播放确定音效
SoundManager.playOk = function() {
this.playSystemSound(1);
};
// 声音管理器.播放取消音效
SoundManager.playCancel = function() {
this.playSystemSound(2);
};
// 声音管理器.蜂鸣
SoundManager.playBuzzer = function() {
this.playSystemSound(3);
};
// 声音管理器.播放装备音效
SoundManager.playEquip = function() {
this.playSystemSound(4);
};
// 声音管理器.播放保存音效
SoundManager.playSave = function() {
this.playSystemSound(5);
};
// 声音管理器.播放加载音效
SoundManager.playLoad = function() {
this.playSystemSound(6);
};
// 声音管理器.播放战斗开始音效
SoundManager.playBattleStart = function() {
this.playSystemSound(7);
};
// 声音管理器.播放战斗逃跑音效
SoundManager.playEscape = function() {
this.playSystemSound(8);
};
// 声音管理器.播放敌人攻击音效
SoundManager.playEnemyAttack = function() {
this.playSystemSound(9);
};
// 声音管理器.播放敌人损伤音效
SoundManager.playEnemyDamage = function() {
this.playSystemSound(10);
};
// 声音管理器.播放敌人死亡音效
SoundManager.playEnemyCollapse = function() {
this.playSystemSound(11);
};
// 声音管理器.播放BOOS死亡音效1
SoundManager.playBossCollapse1 = function() {
this.playSystemSound(12);
};
// 声音管理器.播放BOOS死亡音效2
SoundManager.playBossCollapse2 = function() {
this.playSystemSound(13);
};
// 声音管理器.播放角色损伤音效
SoundManager.playActorDamage = function() {
this.playSystemSound(14);
};
// 声音管理器.播放角色死亡音效
SoundManager.playActorCollapse = function() {
this.playSystemSound(15);
};
// 声音管理器.播放恢复音效
SoundManager.playRecovery = function() {
this.playSystemSound(16);
};
// 声音管理器.播放闪避音效
SoundManager.playMiss = function() {
this.playSystemSound(17);
};
// 声音管理器.播放逃避音效(混乱中...与MISS 区别???)
SoundManager.playEvasion = function() {
this.playSystemSound(18);
};
// 声音管理器.播放魔法逃避音效
SoundManager.playMagicEvasion = function() {
this.playSystemSound(19);
};
// 声音管理器.播放反射音效
SoundManager.playReflection = function() {
this.playSystemSound(20);
};
// 声音管理器.播放商店(购物?)音效
SoundManager.playShop = function() {
this.playSystemSound(21);
};
// 声音管理器.播放使用物品音效
SoundManager.playUseItem = function() {
this.playSystemSound(22);
};
// 声音管理器.播放使用特技音效
SoundManager.playUseSkill = function() {
this.playSystemSound(23);
};
//-----------------------------------------------------------------------------
// SoundManager
//
// The static class that plays sound effects defined in the database.
// 声音管理器
// 静态类 管理数据库中定义声音效果
function SoundManager() {
throw new Error('This is a static class');
}
// 声音管理器.预加载重要的声音
SoundManager.preloadImportantSounds = function() {
this.loadSystemSound(0);
this.loadSystemSound(1);
this.loadSystemSound(2);
this.loadSystemSound(3);
};
// 声音管理器.加载系统声音
SoundManager.loadSystemSound = function(n) {
if ($dataSystem) {
AudioManager.loadStaticSe($dataSystem.sounds[n]); // 音频管理器.加载静态SE
}
};
// 声音管理器.播放系统声音
SoundManager.playSystemSound = function(n) {
if ($dataSystem) {
AudioManager.playStaticSe($dataSystem.sounds[n]); // 音频管理器.播放静态SE
}
};
// 声音管理器.播放光标音效
SoundManager.playCursor = function() {
this.playSystemSound(0);
};
// 声音管理器.播放确定音效
SoundManager.playOk = function() {
this.playSystemSound(1);
};
// 声音管理器.播放取消音效
SoundManager.playCancel = function() {
this.playSystemSound(2);
};
// 声音管理器.蜂鸣
SoundManager.playBuzzer = function() {
this.playSystemSound(3);
};
// 声音管理器.播放装备音效
SoundManager.playEquip = function() {
this.playSystemSound(4);
};
// 声音管理器.播放保存音效
SoundManager.playSave = function() {
this.playSystemSound(5);
};
// 声音管理器.播放加载音效
SoundManager.playLoad = function() {
this.playSystemSound(6);
};
// 声音管理器.播放战斗开始音效
SoundManager.playBattleStart = function() {
this.playSystemSound(7);
};
// 声音管理器.播放战斗逃跑音效
SoundManager.playEscape = function() {
this.playSystemSound(8);
};
// 声音管理器.播放敌人攻击音效
SoundManager.playEnemyAttack = function() {
this.playSystemSound(9);
};
// 声音管理器.播放敌人损伤音效
SoundManager.playEnemyDamage = function() {
this.playSystemSound(10);
};
// 声音管理器.播放敌人死亡音效
SoundManager.playEnemyCollapse = function() {
this.playSystemSound(11);
};
// 声音管理器.播放BOOS死亡音效1
SoundManager.playBossCollapse1 = function() {
this.playSystemSound(12);
};
// 声音管理器.播放BOOS死亡音效2
SoundManager.playBossCollapse2 = function() {
this.playSystemSound(13);
};
// 声音管理器.播放角色损伤音效
SoundManager.playActorDamage = function() {
this.playSystemSound(14);
};
// 声音管理器.播放角色死亡音效
SoundManager.playActorCollapse = function() {
this.playSystemSound(15);
};
// 声音管理器.播放恢复音效
SoundManager.playRecovery = function() {
this.playSystemSound(16);
};
// 声音管理器.播放闪避音效
SoundManager.playMiss = function() {
this.playSystemSound(17);
};
// 声音管理器.播放逃避音效(混乱中...与MISS 区别???)
SoundManager.playEvasion = function() {
this.playSystemSound(18);
};
// 声音管理器.播放魔法逃避音效
SoundManager.playMagicEvasion = function() {
this.playSystemSound(19);
};
// 声音管理器.播放反射音效
SoundManager.playReflection = function() {
this.playSystemSound(20);
};
// 声音管理器.播放商店(购物?)音效
SoundManager.playShop = function() {
this.playSystemSound(21);
};
// 声音管理器.播放使用物品音效
SoundManager.playUseItem = function() {
this.playSystemSound(22);
};
// 声音管理器.播放使用特技音效
SoundManager.playUseSkill = function() {
this.playSystemSound(23);
};
7.文本管理器(这里有个点没搞懂,,,等待更新)
//-----------------------------------------------------------------------------
// TextManager
//
// The static class that handles terms and messages.
// 文本管理器
// 静态类 管理术语与消息
function TextManager() {
throw new Error('This is a static class');
}
// 文本管理器.基本术语
TextManager.basic = function(basicId) {
return $dataSystem.terms.basic[basicId] || '';
};
// 文本管理器.参数
TextManager.param = function(paramId) {
return $dataSystem.terms.params[paramId] || '';
};
// 文本管理器.命令术语
TextManager.command = function(commandId) {
return $dataSystem.terms.commands[commandId] || '';
};
// 文本管理器.消息术语
TextManager.message = function(messageId) {
return $dataSystem.terms.messages[messageId] || '';
};
TextManager.getter = function(method, param) {
return {
get: function() {
return this[method](param);
},
configurable: true
};
};
// 文本管理器.货币单位
Object.defineProperty(TextManager, 'currencyUnit', {
get: function() { return $dataSystem.currencyUnit; },
configurable: true
});
Object.defineProperties(TextManager, {
level : TextManager.getter('basic', 0),
levelA : TextManager.getter('basic', 1),
hp : TextManager.getter('basic', 2),
hpA : TextManager.getter('basic', 3),
mp : TextManager.getter('basic', 4),
mpA : TextManager.getter('basic', 5),
tp : TextManager.getter('basic', 6),
tpA : TextManager.getter('basic', 7),
exp : TextManager.getter('basic', 8),
expA : TextManager.getter('basic', 9),
fight : TextManager.getter('command', 0),
escape : TextManager.getter('command', 1),
attack : TextManager.getter('command', 2),
guard : TextManager.getter('command', 3),
item : TextManager.getter('command', 4),
skill : TextManager.getter('command', 5),
equip : TextManager.getter('command', 6),
status : TextManager.getter('command', 7),
formation : TextManager.getter('command', 8),
save : TextManager.getter('command', 9),
gameEnd : TextManager.getter('command', 10),
options : TextManager.getter('command', 11),
weapon : TextManager.getter('command', 12),
armor : TextManager.getter('command', 13),
keyItem : TextManager.getter('command', 14),
equip2 : TextManager.getter('command', 15),
optimize : TextManager.getter('command', 16),
clear : TextManager.getter('command', 17),
newGame : TextManager.getter('command', 18),
continue_ : TextManager.getter('command', 19),
toTitle : TextManager.getter('command', 21),
cancel : TextManager.getter('command', 22),
buy : TextManager.getter('command', 24),
sell : TextManager.getter('command', 25),
alwaysDash : TextManager.getter('message', 'alwaysDash'),
commandRemember : TextManager.getter('message', 'commandRemember'),
bgmVolume : TextManager.getter('message', 'bgmVolume'),
bgsVolume : TextManager.getter('message', 'bgsVolume'),
meVolume : TextManager.getter('message', 'meVolume'),
seVolume : TextManager.getter('message', 'seVolume'),
possession : TextManager.getter('message', 'possession'),
expTotal : TextManager.getter('message', 'expTotal'),
expNext : TextManager.getter('message', 'expNext'),
saveMessage : TextManager.getter('message', 'saveMessage'),
loadMessage : TextManager.getter('message', 'loadMessage'),
file : TextManager.getter('message', 'file'),
partyName : TextManager.getter('message', 'partyName'),
emerge : TextManager.getter('message', 'emerge'),
preemptive : TextManager.getter('message', 'preemptive'),
surprise : TextManager.getter('message', 'surprise'),
escapeStart : TextManager.getter('message', 'escapeStart'),
escapeFailure : TextManager.getter('message', 'escapeFailure'),
victory : TextManager.getter('message', 'victory'),
defeat : TextManager.getter('message', 'defeat'),
obtainExp : TextManager.getter('message', 'obtainExp'),
obtainGold : TextManager.getter('message', 'obtainGold'),
obtainItem : TextManager.getter('message', 'obtainItem'),
levelUp : TextManager.getter('message', 'levelUp'),
obtainSkill : TextManager.getter('message', 'obtainSkill'),
useItem : TextManager.getter('message', 'useItem'),
criticalToEnemy : TextManager.getter('message', 'criticalToEnemy'),
criticalToActor : TextManager.getter('message', 'criticalToActor'),
actorDamage : TextManager.getter('message', 'actorDamage'),
actorRecovery : TextManager.getter('message', 'actorRecovery'),
actorGain : TextManager.getter('message', 'actorGain'),
actorLoss : TextManager.getter('message', 'actorLoss'),
actorDrain : TextManager.getter('message', 'actorDrain'),
actorNoDamage : TextManager.getter('message', 'actorNoDamage'),
actorNoHit : TextManager.getter('message', 'actorNoHit'),
enemyDamage : TextManager.getter('message', 'enemyDamage'),
enemyRecovery : TextManager.getter('message', 'enemyRecovery'),
enemyGain : TextManager.getter('message', 'enemyGain'),
enemyLoss : TextManager.getter('message', 'enemyLoss'),
enemyDrain : TextManager.getter('message', 'enemyDrain'),
enemyNoDamage : TextManager.getter('message', 'enemyNoDamage'),
enemyNoHit : TextManager.getter('message', 'enemyNoHit'),
evasion : TextManager.getter('message', 'evasion'),
magicEvasion : TextManager.getter('message', 'magicEvasion'),
magicReflection : TextManager.getter('message', 'magicReflection'),
counterAttack : TextManager.getter('message', 'counterAttack'),
substitute : TextManager.getter('message', 'substitute'),
buffAdd : TextManager.getter('message', 'buffAdd'),
debuffAdd : TextManager.getter('message', 'debuffAdd'),
buffRemove : TextManager.getter('message', 'buffRemove'),
actionFailure : TextManager.getter('message', 'actionFailure'),
});
//-----------------------------------------------------------------------------
// TextManager
//
// The static class that handles terms and messages.
// 文本管理器
// 静态类 管理术语与消息
function TextManager() {
throw new Error('This is a static class');
}
// 文本管理器.基本术语
TextManager.basic = function(basicId) {
return $dataSystem.terms.basic[basicId] || '';
};
// 文本管理器.参数
TextManager.param = function(paramId) {
return $dataSystem.terms.params[paramId] || '';
};
// 文本管理器.命令术语
TextManager.command = function(commandId) {
return $dataSystem.terms.commands[commandId] || '';
};
// 文本管理器.消息术语
TextManager.message = function(messageId) {
return $dataSystem.terms.messages[messageId] || '';
};
TextManager.getter = function(method, param) {
return {
get: function() {
return this[method](param);
},
configurable: true
};
};
// 文本管理器.货币单位
Object.defineProperty(TextManager, 'currencyUnit', {
get: function() { return $dataSystem.currencyUnit; },
configurable: true
});
Object.defineProperties(TextManager, {
level : TextManager.getter('basic', 0),
levelA : TextManager.getter('basic', 1),
hp : TextManager.getter('basic', 2),
hpA : TextManager.getter('basic', 3),
mp : TextManager.getter('basic', 4),
mpA : TextManager.getter('basic', 5),
tp : TextManager.getter('basic', 6),
tpA : TextManager.getter('basic', 7),
exp : TextManager.getter('basic', 8),
expA : TextManager.getter('basic', 9),
fight : TextManager.getter('command', 0),
escape : TextManager.getter('command', 1),
attack : TextManager.getter('command', 2),
guard : TextManager.getter('command', 3),
item : TextManager.getter('command', 4),
skill : TextManager.getter('command', 5),
equip : TextManager.getter('command', 6),
status : TextManager.getter('command', 7),
formation : TextManager.getter('command', 8),
save : TextManager.getter('command', 9),
gameEnd : TextManager.getter('command', 10),
options : TextManager.getter('command', 11),
weapon : TextManager.getter('command', 12),
armor : TextManager.getter('command', 13),
keyItem : TextManager.getter('command', 14),
equip2 : TextManager.getter('command', 15),
optimize : TextManager.getter('command', 16),
clear : TextManager.getter('command', 17),
newGame : TextManager.getter('command', 18),
continue_ : TextManager.getter('command', 19),
toTitle : TextManager.getter('command', 21),
cancel : TextManager.getter('command', 22),
buy : TextManager.getter('command', 24),
sell : TextManager.getter('command', 25),
alwaysDash : TextManager.getter('message', 'alwaysDash'),
commandRemember : TextManager.getter('message', 'commandRemember'),
bgmVolume : TextManager.getter('message', 'bgmVolume'),
bgsVolume : TextManager.getter('message', 'bgsVolume'),
meVolume : TextManager.getter('message', 'meVolume'),
seVolume : TextManager.getter('message', 'seVolume'),
possession : TextManager.getter('message', 'possession'),
expTotal : TextManager.getter('message', 'expTotal'),
expNext : TextManager.getter('message', 'expNext'),
saveMessage : TextManager.getter('message', 'saveMessage'),
loadMessage : TextManager.getter('message', 'loadMessage'),
file : TextManager.getter('message', 'file'),
partyName : TextManager.getter('message', 'partyName'),
emerge : TextManager.getter('message', 'emerge'),
preemptive : TextManager.getter('message', 'preemptive'),
surprise : TextManager.getter('message', 'surprise'),
escapeStart : TextManager.getter('message', 'escapeStart'),
escapeFailure : TextManager.getter('message', 'escapeFailure'),
victory : TextManager.getter('message', 'victory'),
defeat : TextManager.getter('message', 'defeat'),
obtainExp : TextManager.getter('message', 'obtainExp'),
obtainGold : TextManager.getter('message', 'obtainGold'),
obtainItem : TextManager.getter('message', 'obtainItem'),
levelUp : TextManager.getter('message', 'levelUp'),
obtainSkill : TextManager.getter('message', 'obtainSkill'),
useItem : TextManager.getter('message', 'useItem'),
criticalToEnemy : TextManager.getter('message', 'criticalToEnemy'),
criticalToActor : TextManager.getter('message', 'criticalToActor'),
actorDamage : TextManager.getter('message', 'actorDamage'),
actorRecovery : TextManager.getter('message', 'actorRecovery'),
actorGain : TextManager.getter('message', 'actorGain'),
actorLoss : TextManager.getter('message', 'actorLoss'),
actorDrain : TextManager.getter('message', 'actorDrain'),
actorNoDamage : TextManager.getter('message', 'actorNoDamage'),
actorNoHit : TextManager.getter('message', 'actorNoHit'),
enemyDamage : TextManager.getter('message', 'enemyDamage'),
enemyRecovery : TextManager.getter('message', 'enemyRecovery'),
enemyGain : TextManager.getter('message', 'enemyGain'),
enemyLoss : TextManager.getter('message', 'enemyLoss'),
enemyDrain : TextManager.getter('message', 'enemyDrain'),
enemyNoDamage : TextManager.getter('message', 'enemyNoDamage'),
enemyNoHit : TextManager.getter('message', 'enemyNoHit'),
evasion : TextManager.getter('message', 'evasion'),
magicEvasion : TextManager.getter('message', 'magicEvasion'),
magicReflection : TextManager.getter('message', 'magicReflection'),
counterAttack : TextManager.getter('message', 'counterAttack'),
substitute : TextManager.getter('message', 'substitute'),
buffAdd : TextManager.getter('message', 'buffAdd'),
debuffAdd : TextManager.getter('message', 'debuffAdd'),
buffRemove : TextManager.getter('message', 'buffRemove'),
actionFailure : TextManager.getter('message', 'actionFailure'),
});
8.场景管理器
//-----------------------------------------------------------------------------
// SceneManager
//
// The static class that manages scene transitions.
// 场景管理器
// 静态类 管理场景转换
function SceneManager() {
throw new Error('This is a static class');
}
SceneManager._scene = null; // 场景管理器.场景
SceneManager._nextScene = null; // 场景管理器.下个场景
SceneManager._stack = []; // 场景管理器.栈
SceneManager._stopped = false; // 场景管理器.已经停止
SceneManager._sceneStarted = false; // 场景管理器.场景已经开始
SceneManager._exiting = false; // 场景管理器.正在退出
SceneManager._previousClass = null; // 场景管理器.上节类
SceneManager._backgroundBitmap = null; // 场景管理器.背景图
SceneManager._screenWidth = 816; // 场景管理器.场景宽度
SceneManager._screenHeight = 624; // 场景管理器.场景高度
SceneManager._boxWidth = 816; // 场景管理器.容器宽度
SceneManager._boxHeight = 624; // 场景管理器.容器高度
// 场景管理器.运行
SceneManager.run = function(sceneClass) {
try {
this.initialize(); // 场景管理器.初始化
this.goto(sceneClass); // 场景管理器.跳转
this.requestUpdate(); // 场景管理器.请求更新
} catch (e) {
this.catchException(e);
}
};
// 场景管理器.初始化
SceneManager.initialize = function() {
this.initGraphics(); // 场景管理器.初始化图形
this.checkFileAccess(); // 场景管理器.检查文件数据
this.initAudio(); // 场景管理器.初始化音频
this.initInput(); // 场景管理器.初始化输入
this.initNwjs(); // 场景管理器.初始化Nwjs
this.checkPluginErrors(); // 场景管理器.检查插件错误
this.setupErrorHandlers(); // 场景管理器.设置错误处理程序
};
// 场景管理器.初始化图形
SceneManager.initGraphics = function() {
var type = this.preferableRendererType(); // 场景管理器.首选渲染类型
Graphics.initialize(this._screenWidth, this._screenHeight, type); // 图形.初始化
Graphics.boxWidth = this._boxWidth; // 图形.窗口显示区域的宽度
Graphics.boxHeight = this._boxHeight; // 图形.窗口显示区域的高度
Graphics.setLoadingImage('img/system/Loading.png'); // 图形.设置正在加载中图像
// 是否需要显示 FPS
if (Utils.isOptionValid('showfps')) {
Graphics.showFps(); // 图形.显示FPS
}
// 渲染类型是否为 WebGL
if (type === 'webgl') {
this.checkWebGL(); // 场景管理器.检查WebGL
}
};
// 场景管理器.首选渲染类型
SceneManager.preferableRendererType = function() {
if (Utils.isOptionValid('canvas')) {
return 'canvas';
} else if (Utils.isOptionValid('webgl')) {
return 'webgl';
} else if (this.shouldUseCanvasRenderer()) {
return 'canvas';
} else {
return 'auto';
}
};
// 场景管理器.应该使用的Canvas渲染器
SceneManager.shouldUseCanvasRenderer = function() {
return Utils.isMobileDevice();
};
// 场景管理器.检查WebGL
SceneManager.checkWebGL = function() {
if (!Graphics.hasWebGL()) {
throw new Error('Your browser does not support WebGL.');
}
};
// 场景管理器.检查文件数据
SceneManager.checkFileAccess = function() {
if (!Utils.canReadGameFiles()) {
throw new Error('Your browser does not allow to read local files.');
}
};
// 场景管理器.初始化音频
SceneManager.initAudio = function() {
var noAudio = Utils.isOptionValid('noaudio');
if (!WebAudio.initialize(noAudio) && !noAudio) {
throw new Error('Your browser does not support Web Audio API.');
}
};
// 场景管理器.初始化输入
SceneManager.initInput = function() {
Input.initialize();
TouchInput.initialize();
};
// 场景管理器.初始化Nwjs <node-webkit>
SceneManager.initNwjs = function() {
if (Utils.isNwjs()) {
var gui = require('nw.gui'); // nodejs - nw.gui 模块
var win = gui.Window.get(); // 取gui 窗口
if (process.platform === 'darwin' && !win.menu) {
var menubar = new gui.Menu({ type: 'menubar' });
var option = { hideEdit: true, hideWindow: true };
menubar.createMacBuiltin('Game', option);
win.menu = menubar;
}
}
};
// 场景管理器.检查插件错误
SceneManager.checkPluginErrors = function() {
PluginManager.checkErrors();
};
// 场景管理器.设置错误处理程序
SceneManager.setupErrorHandlers = function() {
window.addEventListener('error', this.onError.bind(this));
document.addEventListener('keydown', this.onKeyDown.bind(this));
};
// 场景管理器.请求更新
SceneManager.requestUpdate = function() {
if (!this._stopped) {
requestAnimationFrame(this.update.bind(this));
}
};
// 场景管理器更新
SceneManager.update = function() {
try {
this.tickStart(); // 场景管理器.帧开始
this.updateInputData();// 场景管理器.刷新输入数据
this.updateMain(); // 场景管理器.主刷新
this.tickEnd(); // 场景管理器.帧结束
} catch (e) {
this.catchException(e);
}
};
// 场景管理器.终止
SceneManager.terminate = function() {
window.close();
};
// 场景管理器.发生错误事件
SceneManager.onError = function(e) {
console.error(e.message);
console.error(e.filename, e.lineno);
try {
this.stop(); // 场景管理器.停止
Graphics.printError('Error', e.message);
AudioManager.stopAll(); // 音频管理器.停止所有音频
} catch (e2) {
}
};
// 场景管理器.键被按下事件
SceneManager.onKeyDown = function(event) {
if (!event.ctrlKey && !event.altKey) {
switch (event.keyCode) {
case 116: // F5
if (Utils.isNwjs()) {
location.reload(); // 刷新页面
}
break;
case 119: // F8
if (Utils.isNwjs() && Utils.isOptionValid('test')) {
require('nw.gui').Window.get().showDevTools(); // Dev Tools
}
break;
}
}
};
// 场景管理器.异常捕获
SceneManager.catchException = function(e) {
if (e instanceof Error) {
Graphics.printError(e.name, e.message); // 图形.打印错误
console.error(e.stack);
} else {
Graphics.printError('UnknownError', e); // 图形.打印错误
}
AudioManager.stopAll(); // 音频管理器.停止所有音频
this.stop(); // 场景管理器.停止
};
// 场景管理器.帧开始
SceneManager.tickStart = function() {
Graphics.tickStart(); // 图形.帧开始
};
// 场景管理器.帧结束
SceneManager.tickEnd = function() {
Graphics.tickEnd(); // 图形.帧结束
};
// 场景管理器.更新输入数据
SceneManager.updateInputData = function() {
Input.update(); // 输入.刷新()
TouchInput.update(); // 触摸输入.刷新()
};
// 场景管理器.主更新
SceneManager.updateMain = function() {
this.changeScene(); // 场景管理器.改变场景
this.updateScene(); // 场景管理器.刷新场景
this.renderScene(); // 场景管理器.渲染场景
this.requestUpdate(); // 场景管理器.请求更新
};
// 场景管理器.改变场景
SceneManager.changeScene = function() {
// 场景管理器.场景是否正在改变 且 !场景管理器.当前场景是否正忙
if (this.isSceneChanging() && !this.isCurrentSceneBusy()) {
if (this._scene) {
this._scene.terminate(); // 场景管理器.场景.终止
this._previousClass = this._scene.constructor; // 场景管理器.上节类 = 场景管理器.场景.构造
}
this._scene = this._nextScene; // 场景管理器.场景 = 场景管理器.下个场景
if (this._scene) {
this._scene.create(); // 场景管理器.场景.创建
this._nextScene = null; // 场景管理器.下个场景 = null
this._sceneStarted = false; // 场景管理器.场景已经开始 = false
this.onSceneCreate(); // 场景管理器.场景创建事件
}
if (this._exiting) { // 场景管理器.正在退出中
this.terminate(); // 场景管理器.终止
}
}
};
// 场景管理器.更新场景
SceneManager.updateScene = function() {
if (this._scene) {
// !场景管理器.场景已经开始 且 场景管理器.场景.已经准备就绪
if (!this._sceneStarted && this._scene.isReady()) {
this._scene.start(); // 场景管理器.场景.开始
this._sceneStarted = true; // 场景管理器.场景已经开始 = true
this.onSceneStart(); // 场景管理器.场景开始事件
}
if (this.isCurrentSceneStarted()) { // 场景管理器.当前场景是否已经开始
this._scene.update(); // 场景管理器.场景.刷新
}
}
};
// 场景管理器.渲染场景
SceneManager.renderScene = function() {
if (this.isCurrentSceneStarted()) { // 场景管理器.当前场景是否已经开始
Graphics.render(this._scene); // 图形.渲染(场景管理器.场景)
} else if (this._scene) {
this.onSceneLoading(); // 场景管理器.场景加载中事件
}
};
// 场景管理器.场景创建事件
SceneManager.onSceneCreate = function() {
Graphics.startLoading(); // 图形.开始正在读取中() // 初始化“正在读取中”状态的计时器。
};
// 场景管理器.场景开始事件
SceneManager.onSceneStart = function() {
Graphics.endLoading(); // 图形.结束正在读取中() // 清除“正在读取中”状态的图片。
};
// 场景管理器.场景加载中事件
SceneManager.onSceneLoading = function() {
Graphics.updateLoading(); // 图形.刷新正在读取中() // 累加“正在读取中”状态的计时器时间,必要时,显示“正在读取中”状态设置的图片。
};
// 场景管理器.场景是否在改变中
SceneManager.isSceneChanging = function() {
return this._exiting || !!this._nextScene;
};
// 场景管理器.当前场景是否被占用
SceneManager.isCurrentSceneBusy = function() {
return this._scene && this._scene.isBusy();
};
// 场景管理器.当前场景是否已经开始
SceneManager.isCurrentSceneStarted = function() {
return this._scene && this._sceneStarted;
};
// 场景管理器.是否为下个场景
SceneManager.isNextScene = function(sceneClass) {
return this._nextScene && this._nextScene.constructor === sceneClass;
};
// 场景管理器.是否为以前场景
SceneManager.isPreviousScene = function(sceneClass) {
return this._previousClass === sceneClass;
};
// 场景管理器.跳转
SceneManager.goto = function(sceneClass) {
if (sceneClass) {
this._nextScene = new sceneClass(); // 场景管理器.下个场景 = 实例化 sceneClass
}
if (this._scene) {
this._scene.stop(); // 场景管理器.场景.结束()
}
};
// 翻译下面两个让我想起了汇编
// push ebp
// mov ebp, esp
// ......
// mov esp, ebp
// pop ebp
// ret
// 场景管理器.传递
SceneManager.push = function(sceneClass) {
this._stack.push(this._scene.constructor); // 场景管理器.栈.投递(场景管理器.场景.构造)
this.goto(sceneClass); // 场景管理器.跳转
};
// 场景管理器.弹出
SceneManager.pop = function() {
if (this._stack.length > 0) {
this.goto(this._stack.pop()); // 场景管理器.跳转(场景管理器.栈.弹出)
} else {
this.exit();
}
};
// 场景管理器.退出
SceneManager.exit = function() {
this.goto(null);
this._exiting = true;
};
// 场景管理器.清除栈
SceneManager.clearStack = function() {
this._stack = [];
};
// 场景管理器.停止
SceneManager.stop = function() {
this._stopped = true;
};
// 场景管理器.开始准备下个场景
SceneManager.prepareNextScene = function() {
this._nextScene.prepare.apply(this._nextScene, arguments);
};
// 场景管理器.截图
SceneManager.snap = function() {
return Bitmap.snap(this._scene);
};
// 场景管理器.背景截图
SceneManager.snapForBackground = function() {
this._backgroundBitmap = this.snap();
this._backgroundBitmap.blur();
};
// 场景管理器.背景图像
SceneManager.backgroundBitmap = function() {
return this._backgroundBitmap;
};
//-----------------------------------------------------------------------------
// SceneManager
//
// The static class that manages scene transitions.
// 场景管理器
// 静态类 管理场景转换
function SceneManager() {
throw new Error('This is a static class');
}
SceneManager._scene = null; // 场景管理器.场景
SceneManager._nextScene = null; // 场景管理器.下个场景
SceneManager._stack = []; // 场景管理器.栈
SceneManager._stopped = false; // 场景管理器.已经停止
SceneManager._sceneStarted = false; // 场景管理器.场景已经开始
SceneManager._exiting = false; // 场景管理器.正在退出
SceneManager._previousClass = null; // 场景管理器.上节类
SceneManager._backgroundBitmap = null; // 场景管理器.背景图
SceneManager._screenWidth = 816; // 场景管理器.场景宽度
SceneManager._screenHeight = 624; // 场景管理器.场景高度
SceneManager._boxWidth = 816; // 场景管理器.容器宽度
SceneManager._boxHeight = 624; // 场景管理器.容器高度
// 场景管理器.运行
SceneManager.run = function(sceneClass) {
try {
this.initialize(); // 场景管理器.初始化
this.goto(sceneClass); // 场景管理器.跳转
this.requestUpdate(); // 场景管理器.请求更新
} catch (e) {
this.catchException(e);
}
};
// 场景管理器.初始化
SceneManager.initialize = function() {
this.initGraphics(); // 场景管理器.初始化图形
this.checkFileAccess(); // 场景管理器.检查文件数据
this.initAudio(); // 场景管理器.初始化音频
this.initInput(); // 场景管理器.初始化输入
this.initNwjs(); // 场景管理器.初始化Nwjs
this.checkPluginErrors(); // 场景管理器.检查插件错误
this.setupErrorHandlers(); // 场景管理器.设置错误处理程序
};
// 场景管理器.初始化图形
SceneManager.initGraphics = function() {
var type = this.preferableRendererType(); // 场景管理器.首选渲染类型
Graphics.initialize(this._screenWidth, this._screenHeight, type); // 图形.初始化
Graphics.boxWidth = this._boxWidth; // 图形.窗口显示区域的宽度
Graphics.boxHeight = this._boxHeight; // 图形.窗口显示区域的高度
Graphics.setLoadingImage('img/system/Loading.png'); // 图形.设置正在加载中图像
// 是否需要显示 FPS
if (Utils.isOptionValid('showfps')) {
Graphics.showFps(); // 图形.显示FPS
}
// 渲染类型是否为 WebGL
if (type === 'webgl') {
this.checkWebGL(); // 场景管理器.检查WebGL
}
};
// 场景管理器.首选渲染类型
SceneManager.preferableRendererType = function() {
if (Utils.isOptionValid('canvas')) {
return 'canvas';
} else if (Utils.isOptionValid('webgl')) {
return 'webgl';
} else if (this.shouldUseCanvasRenderer()) {
return 'canvas';
} else {
return 'auto';
}
};
// 场景管理器.应该使用的Canvas渲染器
SceneManager.shouldUseCanvasRenderer = function() {
return Utils.isMobileDevice();
};
// 场景管理器.检查WebGL
SceneManager.checkWebGL = function() {
if (!Graphics.hasWebGL()) {
throw new Error('Your browser does not support WebGL.');
}
};
// 场景管理器.检查文件数据
SceneManager.checkFileAccess = function() {
if (!Utils.canReadGameFiles()) {
throw new Error('Your browser does not allow to read local files.');
}
};
// 场景管理器.初始化音频
SceneManager.initAudio = function() {
var noAudio = Utils.isOptionValid('noaudio');
if (!WebAudio.initialize(noAudio) && !noAudio) {
throw new Error('Your browser does not support Web Audio API.');
}
};
// 场景管理器.初始化输入
SceneManager.initInput = function() {
Input.initialize();
TouchInput.initialize();
};
// 场景管理器.初始化Nwjs <node-webkit>
SceneManager.initNwjs = function() {
if (Utils.isNwjs()) {
var gui = require('nw.gui'); // nodejs - nw.gui 模块
var win = gui.Window.get(); // 取gui 窗口
if (process.platform === 'darwin' && !win.menu) {
var menubar = new gui.Menu({ type: 'menubar' });
var option = { hideEdit: true, hideWindow: true };
menubar.createMacBuiltin('Game', option);
win.menu = menubar;
}
}
};
// 场景管理器.检查插件错误
SceneManager.checkPluginErrors = function() {
PluginManager.checkErrors();
};
// 场景管理器.设置错误处理程序
SceneManager.setupErrorHandlers = function() {
window.addEventListener('error', this.onError.bind(this));
document.addEventListener('keydown', this.onKeyDown.bind(this));
};
// 场景管理器.请求更新
SceneManager.requestUpdate = function() {
if (!this._stopped) {
requestAnimationFrame(this.update.bind(this));
}
};
// 场景管理器更新
SceneManager.update = function() {
try {
this.tickStart(); // 场景管理器.帧开始
this.updateInputData();// 场景管理器.刷新输入数据
this.updateMain(); // 场景管理器.主刷新
this.tickEnd(); // 场景管理器.帧结束
} catch (e) {
this.catchException(e);
}
};
// 场景管理器.终止
SceneManager.terminate = function() {
window.close();
};
// 场景管理器.发生错误事件
SceneManager.onError = function(e) {
console.error(e.message);
console.error(e.filename, e.lineno);
try {
this.stop(); // 场景管理器.停止
Graphics.printError('Error', e.message);
AudioManager.stopAll(); // 音频管理器.停止所有音频
} catch (e2) {
}
};
// 场景管理器.键被按下事件
SceneManager.onKeyDown = function(event) {
if (!event.ctrlKey && !event.altKey) {
switch (event.keyCode) {
case 116: // F5
if (Utils.isNwjs()) {
location.reload(); // 刷新页面
}
break;
case 119: // F8
if (Utils.isNwjs() && Utils.isOptionValid('test')) {
require('nw.gui').Window.get().showDevTools(); // Dev Tools
}
break;
}
}
};
// 场景管理器.异常捕获
SceneManager.catchException = function(e) {
if (e instanceof Error) {
Graphics.printError(e.name, e.message); // 图形.打印错误
console.error(e.stack);
} else {
Graphics.printError('UnknownError', e); // 图形.打印错误
}
AudioManager.stopAll(); // 音频管理器.停止所有音频
this.stop(); // 场景管理器.停止
};
// 场景管理器.帧开始
SceneManager.tickStart = function() {
Graphics.tickStart(); // 图形.帧开始
};
// 场景管理器.帧结束
SceneManager.tickEnd = function() {
Graphics.tickEnd(); // 图形.帧结束
};
// 场景管理器.更新输入数据
SceneManager.updateInputData = function() {
Input.update(); // 输入.刷新()
TouchInput.update(); // 触摸输入.刷新()
};
// 场景管理器.主更新
SceneManager.updateMain = function() {
this.changeScene(); // 场景管理器.改变场景
this.updateScene(); // 场景管理器.刷新场景
this.renderScene(); // 场景管理器.渲染场景
this.requestUpdate(); // 场景管理器.请求更新
};
// 场景管理器.改变场景
SceneManager.changeScene = function() {
// 场景管理器.场景是否正在改变 且 !场景管理器.当前场景是否正忙
if (this.isSceneChanging() && !this.isCurrentSceneBusy()) {
if (this._scene) {
this._scene.terminate(); // 场景管理器.场景.终止
this._previousClass = this._scene.constructor; // 场景管理器.上节类 = 场景管理器.场景.构造
}
this._scene = this._nextScene; // 场景管理器.场景 = 场景管理器.下个场景
if (this._scene) {
this._scene.create(); // 场景管理器.场景.创建
this._nextScene = null; // 场景管理器.下个场景 = null
this._sceneStarted = false; // 场景管理器.场景已经开始 = false
this.onSceneCreate(); // 场景管理器.场景创建事件
}
if (this._exiting) { // 场景管理器.正在退出中
this.terminate(); // 场景管理器.终止
}
}
};
// 场景管理器.更新场景
SceneManager.updateScene = function() {
if (this._scene) {
// !场景管理器.场景已经开始 且 场景管理器.场景.已经准备就绪
if (!this._sceneStarted && this._scene.isReady()) {
this._scene.start(); // 场景管理器.场景.开始
this._sceneStarted = true; // 场景管理器.场景已经开始 = true
this.onSceneStart(); // 场景管理器.场景开始事件
}
if (this.isCurrentSceneStarted()) { // 场景管理器.当前场景是否已经开始
this._scene.update(); // 场景管理器.场景.刷新
}
}
};
// 场景管理器.渲染场景
SceneManager.renderScene = function() {
if (this.isCurrentSceneStarted()) { // 场景管理器.当前场景是否已经开始
Graphics.render(this._scene); // 图形.渲染(场景管理器.场景)
} else if (this._scene) {
this.onSceneLoading(); // 场景管理器.场景加载中事件
}
};
// 场景管理器.场景创建事件
SceneManager.onSceneCreate = function() {
Graphics.startLoading(); // 图形.开始正在读取中() // 初始化“正在读取中”状态的计时器。
};
// 场景管理器.场景开始事件
SceneManager.onSceneStart = function() {
Graphics.endLoading(); // 图形.结束正在读取中() // 清除“正在读取中”状态的图片。
};
// 场景管理器.场景加载中事件
SceneManager.onSceneLoading = function() {
Graphics.updateLoading(); // 图形.刷新正在读取中() // 累加“正在读取中”状态的计时器时间,必要时,显示“正在读取中”状态设置的图片。
};
// 场景管理器.场景是否在改变中
SceneManager.isSceneChanging = function() {
return this._exiting || !!this._nextScene;
};
// 场景管理器.当前场景是否被占用
SceneManager.isCurrentSceneBusy = function() {
return this._scene && this._scene.isBusy();
};
// 场景管理器.当前场景是否已经开始
SceneManager.isCurrentSceneStarted = function() {
return this._scene && this._sceneStarted;
};
// 场景管理器.是否为下个场景
SceneManager.isNextScene = function(sceneClass) {
return this._nextScene && this._nextScene.constructor === sceneClass;
};
// 场景管理器.是否为以前场景
SceneManager.isPreviousScene = function(sceneClass) {
return this._previousClass === sceneClass;
};
// 场景管理器.跳转
SceneManager.goto = function(sceneClass) {
if (sceneClass) {
this._nextScene = new sceneClass(); // 场景管理器.下个场景 = 实例化 sceneClass
}
if (this._scene) {
this._scene.stop(); // 场景管理器.场景.结束()
}
};
// 翻译下面两个让我想起了汇编
// push ebp
// mov ebp, esp
// ......
// mov esp, ebp
// pop ebp
// ret
// 场景管理器.传递
SceneManager.push = function(sceneClass) {
this._stack.push(this._scene.constructor); // 场景管理器.栈.投递(场景管理器.场景.构造)
this.goto(sceneClass); // 场景管理器.跳转
};
// 场景管理器.弹出
SceneManager.pop = function() {
if (this._stack.length > 0) {
this.goto(this._stack.pop()); // 场景管理器.跳转(场景管理器.栈.弹出)
} else {
this.exit();
}
};
// 场景管理器.退出
SceneManager.exit = function() {
this.goto(null);
this._exiting = true;
};
// 场景管理器.清除栈
SceneManager.clearStack = function() {
this._stack = [];
};
// 场景管理器.停止
SceneManager.stop = function() {
this._stopped = true;
};
// 场景管理器.开始准备下个场景
SceneManager.prepareNextScene = function() {
this._nextScene.prepare.apply(this._nextScene, arguments);
};
// 场景管理器.截图
SceneManager.snap = function() {
return Bitmap.snap(this._scene);
};
// 场景管理器.背景截图
SceneManager.snapForBackground = function() {
this._backgroundBitmap = this.snap();
this._backgroundBitmap.blur();
};
// 场景管理器.背景图像
SceneManager.backgroundBitmap = function() {
return this._backgroundBitmap;
};
9.战斗管理器(这里有几个函数没有翻译-等待更新)
//-----------------------------------------------------------------------------
// BattleManager
//
// The static class that manages battle progress.
// 战斗管理器
// 静态类 管理战斗进度消息
function BattleManager() {
throw new Error('This is a static class');
}
// 战斗管理器.设置
BattleManager.setup = function(troopId, canEscape, canLose) {
this.initMembers(); // 战斗管理器.初始化成员
this._canEscape = canEscape; // 战斗管理器.可以逃跑
this._canLose = canLose; // 战斗管理器.可以失败
$gameTroop.setup(troopId); // 游戏敌群类.设置(敌群ID)
$gameScreen.onBattleStart(); // 游戏屏幕类.战斗开始事件()
this.makeEscapeRatio(); // 战斗管理器.制逃避率();
};
// 战斗管理器.初始化成员
BattleManager.initMembers = function() {
this._phase = 'init'; // 战斗管理器.阶段
this._canEscape = false; // 战斗管理器.可逃跑
this._canLose = false; // 战斗管理器.可失败
this._battleTest = false; // 战斗管理器.战斗测试
this._eventCallback = null; // 战斗管理器.事件回调
this._preemptive = false; // 战斗管理器.先发制人
this._surprise = false; // 战斗管理器.突然袭击
this._actorIndex = -1; // 战斗管理器.角色索引
this._actionForcedBattler = null; // 战斗管理器.强制战斗行动
this._mapBgm = null; // 战斗管理器.地图BGM
this._mapBgs = null; // 战斗管理器.地图BGS
this._actionBattlers = []; // 战斗管理器.战斗行动人员组
this._subject = null; // 战斗管理器.行动者 Game_Actor || Game_Enemy
this._action = null; // 战斗管理器.行动 Game_Action
this._targets = []; // 战斗管理器.目标组
this._logWindow = null; // 战斗管理器.日志窗口
this._statusWindow = null; // 战斗管理器.状态窗口
this._spriteset = null; // 战斗管理器.精灵
this._escapeRatio = 0; // 战斗管理器.逃跑率
this._escaped = false; // 战斗管理器.已经逃跑
this._rewards = {}; // 战斗管理器.奖励
};
// 战斗管理器.是否为战斗测试
BattleManager.isBattleTest = function() {
return this._battleTest;
};
// 战斗管理器.设置战斗测试
BattleManager.setBattleTest = function(battleTest) {
this._battleTest = battleTest;
};
// 战斗管理器.设置事件回调
BattleManager.setEventCallback = function(callback) {
this._eventCallback = callback;
};
// 战斗管理器.设置日志窗口
BattleManager.setLogWindow = function(logWindow) {
this._logWindow = logWindow;
};
// 战斗管理器.设置状态窗口
BattleManager.setStatusWindow = function(statusWindow) {
this._statusWindow = statusWindow;
};
// 战斗管理器.设置精灵
BattleManager.setSpriteset = function(spriteset) {
this._spriteset = spriteset;
};
// 战斗管理器.遇敌事件
BattleManager.onEncounter = function() {
this._preemptive = (Math.random() < this.ratePreemptive()); // 先发制人算法
this._surprise = (Math.random() < this.rateSurprise() && !this._preemptive); // 会心一击算法
};
// 战斗管理器.敏捷率
BattleManager.ratePreemptive = function() {
return $gameParty.ratePreemptive($gameTroop.agility());
};
//
BattleManager.rateSurprise = function() {
return $gameParty.rateSurprise($gameTroop.agility());
};
// 战斗管理器.保存BGM和BGS
BattleManager.saveBgmAndBgs = function() {
this._mapBgm = AudioManager.saveBgm(); // 音频管理器.保存BGM
this._mapBgs = AudioManager.saveBgs(); // 音频管理器.保存BGS
};
// 战斗管理器.播放战斗BGM
BattleManager.playBattleBgm = function() {
AudioManager.playBgm($gameSystem.battleBgm()); // 音频管理器.播放BGM(游戏系统类.战斗BGM)
AudioManager.stopBgs(); // 音频管理器.停止BGS
};
// 战斗管理器.播放胜利SE
BattleManager.playVictoryMe = function() {
AudioManager.playMe($gameSystem.victoryMe()); // 音频管理器.播放ME(游戏系统类.胜利ME)
};
// 战斗管理器.播放失败ME
BattleManager.playDefeatMe = function() {
AudioManager.playMe($gameSystem.defeatMe()); // 音频管理器.播放ME(游戏系统类.失败ME)
};
// 战斗管理器.重播BGM和BGS
BattleManager.replayBgmAndBgs = function() {
if (this._mapBgm) {
AudioManager.replayBgm(this._mapBgm); // 音频管理器.重播BGM(战斗管理器.地图BGM)
} else {
AudioManager.stopBgm(); // 音频管理器.停止BGM
}
if (this._mapBgs) { // 战斗管理器.地图BGS
AudioManager.replayBgs(this._mapBgs); // 音频管理器.重播BGS(战斗管理器.地图BGS)
}
};
// 战斗管理器.制逃避率
BattleManager.makeEscapeRatio = function() {
this._escapeRatio = 0.5 * $gameParty.agility() / $gameTroop.agility();
};
// 战斗管理器.更新
BattleManager.update = function() {
if (!this.isBusy() && !this.updateEvent()) {
switch (this._phase) {
case 'start':
this.startInput(); // 战斗管理器.开始输入
break;
case 'turn':
this.updateTurn(); // 战斗管理器.刷新回合
break;
case 'action':
this.updateAction(); // 战斗管理器.刷新行动
break;
case 'turnEnd':
this.updateTurnEnd(); // 战斗管理器.刷新回合结束
break;
case 'battleEnd':
this.updateBattleEnd(); // 战斗管理器.刷新战斗结束
break;
}
}
};
// 战斗管理器.更新事件
BattleManager.updateEvent = function() {
switch (this._phase) {
case 'start':
case 'turn':
case 'turnEnd':
if (this.isActionForced()) {
this.processForcedAction(); // 战斗管理器.强制行动流程
return true;
} else {
return this.updateEventMain(); // 战斗管理器.主刷新事件
}
}
return this.checkAbort(); // 战斗管理器.检查是否战斗已经终止
};
// 战斗管理器.主刷新事件
BattleManager.updateEventMain = function() {
$gameTroop.updateInterpreter(); // 游戏敌群类.刷新事件解释器
$gameParty.requestMotionRefresh(); // 游戏队伍类.请求动态刷新
// 游戏敌群类.事件正在运行 或 战斗管理器.检查战斗是否已经结束
if ($gameTroop.isEventRunning() || this.checkBattleEnd()) {
return true;
}
// 游戏敌群类.设置战斗事件
$gameTroop.setupBattleEvent();
// 游戏敌群类.事件正在运行 或 场景管理器.场景是否在改变中
if ($gameTroop.isEventRunning() || SceneManager.isSceneChanging()) {
return true;
}
return false;
};
// 战斗管理器.是否正忙
BattleManager.isBusy = function() {
// 游戏消息类.是否正忙 或 战斗管理器.精灵.是否正忙 或 战斗管理器.日志窗口.是否正忙
return ($gameMessage.isBusy() || this._spriteset.isBusy() ||
this._logWindow.isBusy());
};
// 战斗管理器.是否正在输入中
BattleManager.isInputting = function() {
return this._phase === 'input';
};
// 战斗管理器.是否在一回合中
BattleManager.isInTurn = function() {
return this._phase === 'turn';
};
// 战斗管理器.是否一回合已经结束
BattleManager.isTurnEnd = function() {
return this._phase === 'turnEnd';
};
// 战斗管理器.是否已经终止
BattleManager.isAborting = function() {
return this._phase === 'aborting';
};
// 战斗管理器.是否战斗已经结束
BattleManager.isBattleEnd = function() {
return this._phase === 'battleEnd';
};
// 战斗管理器.是否可以逃跑
BattleManager.canEscape = function() {
return this._canEscape;
};
// 战斗管理器.是否可以失去
BattleManager.canLose = function() {
return this._canLose;
};
// 战斗管理器.是否已经逃跑
BattleManager.isEscaped = function() {
return this._escaped;
};
// 战斗管理器.角色
BattleManager.actor = function() {
return this._actorIndex >= 0 ? $gameParty.members()[this._actorIndex] : null;
};
// 战斗管理器.清除角色
BattleManager.clearActor = function() {
this.changeActor(-1, '');
};
// 战斗管理器.更改角色
BattleManager.changeActor = function(newActorIndex, lastActorActionState) {
var lastActor = this.actor(); // 保存当前角色
this._actorIndex = newActorIndex; // 设置当前角色索引
var newActor = this.actor(); // 再取出设置的角色
if (lastActor) { // 设置最后角色的动作状态
lastActor.setActionState(lastActorActionState);
}
if (newActor) { // 设置新角色的动作状态
newActor.setActionState('inputting');
}
};
// 战斗管理器.开始战斗
BattleManager.startBattle = function() {
this._phase = 'start';
$gameSystem.onBattleStart(); // 游戏系统类.战斗开始事件
$gameParty.onBattleStart(); // 游戏队伍类.战斗开始事件
$gameTroop.onBattleStart(); // 游戏敌群类.战斗开始事件
this.displayStartMessages(); // 战斗管理器.显示开始消息
};
// 战斗管理器.显示启动信息
BattleManager.displayStartMessages = function() {
// 游戏敌群类.敌人名称组.遍历数组
$gameTroop.enemyNames().forEach(function(name) {
$gameMessage.add(TextManager.emerge.format(name)); // 游戏消息类.添加(消息术语管理器.出现.格式化(name)) -> 格式化成 xxx出现
});
if (this._preemptive) { // 是否先发制人
$gameMessage.add(TextManager.preemptive.format($gameParty.name())); // 游戏消息类.添加(消息术语管理器.出现.格式化(name)) -> 格式化成 xxx先发制人
} else if (this._surprise) { // 是否突然袭击
$gameMessage.add(TextManager.surprise.format($gameParty.name())); // 游戏消息类.添加(消息术语管理器.出现.格式化(name)) -> 格式化成 xxx突然袭击
}
};
// 战斗管理器.开始输入
BattleManager.startInput = function() {
this._phase = 'input';
$gameParty.makeActions(); // 游戏队伍类.做出行动
$gameTroop.makeActions(); // 游戏敌群类.做出行动
this.clearActor(); // 战斗管理器.清除角色
if (this._surprise || !$gameParty.canInput()) { // 战斗管理器.突然袭击 或 游戏队伍类.是否可以输入
this.startTurn(); // 战斗管理器.开始一回合
}
};
// 战斗管理器.输入操作
BattleManager.inputtingAction = function() {
return this.actor() ? this.actor().inputtingAction() : null;
};
// 战斗管理器.选择下个动作
BattleManager.selectNextCommand = function() {
do {
if (!this.actor() || !this.actor().selectNextCommand()) {
this.changeActor(this._actorIndex + 1, 'waiting'); // 战斗管理器.更改角色
if (this._actorIndex >= $gameParty.size()) { // 战斗管理器.当前角色索引 >= 游戏队伍类.人员数量
this.startTurn(); // 战斗管理器.开始一回合
break; // 跳出循环
}
}
} while (!this.actor().canInput());
};
// 战斗管理器.选择上一个命令
BattleManager.selectPreviousCommand = function() {
do {
if (!this.actor() || !this.actor().selectPreviousCommand()) {
this.changeActor(this._actorIndex - 1, 'undecided'); // 战斗管理器.更改角色
if (this._actorIndex < 0) { // 战斗管理器.当前角色索引 < 0
return;
}
}
} while (!this.actor().canInput());
};
// 战斗管理器.刷新状态
BattleManager.refreshStatus = function() {
this._statusWindow.refresh(); // 战斗管理器.状态窗口.刷新
};
// 战斗管理器.开始一回合
BattleManager.startTurn = function() {
this._phase = 'turn';
this.clearActor(); // 战斗管理器.清除角色
$gameTroop.increaseTurn(); // 游戏敌群类.增加回合
this.makeActionOrders(); // 战斗管理器.作行动命令
$gameParty.requestMotionRefresh(); // 游戏队伍类.请求动态刷新
this._logWindow.startTurn();
};
// 战斗管理器.刷新回合
BattleManager.updateTurn = function() {
$gameParty.requestMotionRefresh(); // 游戏队伍类.请求动态刷新
if (!this._subject) { // 战斗管理器.行动者
this._subject = this.getNextSubject(); // 战斗管理器.取下个行动者
}
if (this._subject) {
this.processTurn(); // 战斗管理器.流程回合
} else {
this.endTurn(); // 战斗管理器.结束一回合
}
};
// 战斗管理器.流程回合
BattleManager.processTurn = function() {
var subject = this._subject; // 战斗管理器.行动者
var action = subject.currentAction(); // 取 行动者.当前动作
if (action) {
action.prepare(); // 动作.准备
if (action.isValid()) {
this.startAction();
}
subject.removeCurrentAction(); // 行动者.移除当前动作
} else {
subject.onAllActionsEnd(); // 行动者.全部动作结束事件
this.refreshStatus(); // 战斗管理器.刷新状态
this._logWindow.displayAutoAffectedStatus(subject); // 战斗管理器.日志窗口.显示自动受影响状况
this._logWindow.displayCurrentState(subject); // 战斗管理器.日志窗口.显示当前状态
this._logWindow.displayRegeneration(subject); // 战斗管理器.日志窗口.显示恢复
this._subject = this.getNextSubject(); // 战斗管理器.行动者 = 战斗管理器.取下个行动者
}
};
// 战斗管理器.结束一回合
BattleManager.endTurn = function() {
this._phase = 'turnEnd'; // 战斗管理器.阶段
this._preemptive = false; // 战斗管理器.先发制人 = false
this._surprise = false; // 战斗管理器.突然袭击 = false
// 战斗管理器.全部战斗成员.遍历
this.allBattleMembers().forEach(function(battler) {
battler.onTurnEnd(); // 战斗者.结束一回合
this.refreshStatus(); // 战斗管理器.刷新状态
this._logWindow.displayAutoAffectedStatus(battler); // 战斗管理器.日志窗口.显示自动受影响状况
this._logWindow.displayRegeneration(battler); // 战斗管理器.日志窗口.显示恢复
}, this);
};
// 战斗管理器.刷新回合结束
BattleManager.updateTurnEnd = function() {
this.startInput();
};
// 战斗管理器.取下个行动者
BattleManager.getNextSubject = function() {
for (;;) {
var battler = this._actionBattlers.shift(); // 战斗者 = 战斗管理器.战斗行动人员组.左移
if (!battler) {
return null;
}
if (battler.isBattleMember() && battler.isAlive()) { // 战斗者.是否为战斗成员 且 战斗者.是否生存
return battler;
}
}
};
// 战斗管理器.全部战斗成员
BattleManager.allBattleMembers = function() {
return $gameParty.members().concat($gameTroop.members());
};
// 战斗管理器.作行动命令
BattleManager.makeActionOrders = function() {
var battlers = [];
if (!this._surprise) { // !战斗管理器.突然袭击
battlers = battlers.concat($gameParty.members()); // 参战人员组 连接数组 游戏队伍类.成员组
}
if (!this._preemptive) { // !战斗管理器.先发制人
battlers = battlers.concat($gameTroop.members()); // 参战人员组 连接数组 游戏敌群类.成员组
}
// 参战人员组 遍历
battlers.forEach(function(battler) {
battler.makeSpeed(); // 参战人员组.制速度
});
// 参战人员组.排序() 详见:Array.sort
battlers.sort(function(a, b) {
return b.speed() - a.speed();
});
this._actionBattlers = battlers; // 战斗管理器.战斗行动人员组 = 参战人员组
};
// 战斗管理器.开始行动
BattleManager.startAction = function() {
var subject = this._subject; // 战斗管理器.行动者
var action = subject.currentAction(); // 行动者.当前动作
var targets = action.makeTargets(); // 动作.置目标组
this._phase = 'action';
this._action = action; // 战斗管理器.动作 = action = 行动者.当前动作
this._targets = targets; // 战斗管理器.目标组 = targets = 行动者.当前动作.置目标组
subject.useItem(action.item()); // 行动者.使用物品(动作.物品数据)
this._action.applyGlobal(); // 战斗管理器.动作.应用全局()
this.refreshStatus(); // 战斗管理器.刷新状态()
this._logWindow.startAction(subject, action, targets); // 战斗管理器.日志窗口.开始行动(行动者, 动作, 目标组)
};
// 战斗管理器.刷新行动
BattleManager.updateAction = function() {
var target = this._targets.shift(); // 目标 = 战斗管理器.目标组.左移()
if (target) {
this.invokeAction(this._subject, target); // 战斗管理器.调用行动(战斗管理器.行动者, 目标)
} else {
this.endAction(); // 战斗管理器.结束行动
}
};
// 战斗管理器.结束行动
BattleManager.endAction = function() {
this._logWindow.endAction(this._subject); // 战斗管理器.日志窗口.结束行动(战斗管理器.行动者)
this._phase = 'turn';
};
// 战斗管理器.调用行动
BattleManager.invokeAction = function(subject, target) {
this._logWindow.push('pushBaseLine'); // 战斗管理器.日志窗口.投递()
if (Math.random() < this._action.itemCnt(target)) {
this.invokeCounterAttack(subject, target); // 战斗管理器.调用反击(行动者, 目标)
} else if (Math.random() < this._action.itemMrf(target)) {
this.invokeMagicReflection(subject, target); // 战斗管理器.调用魔法发射(行动者, 目标)
} else {
this.invokeNormalAction(subject, target); // 战斗管理器.调用正常行动(行动者, 目标)
}
subject.setLastTarget(target); // 行动者.设置最后目标(目标)
this._logWindow.push('popBaseLine'); // 战斗管理器.日志窗口.投递()
this.refreshStatus(); // 战斗管理器.刷新状态
};
// 战斗管理器.调用正常行动
BattleManager.invokeNormalAction = function(subject, target) {
var realTarget = this.applySubstitute(target);
this._action.apply(realTarget);
this._logWindow.displayActionResults(subject, realTarget);
};
// 战斗管理器.调用反击
BattleManager.invokeCounterAttack = function(subject, target) {
var action = new Game_Action(target);
action.setAttack();
action.apply(subject);
this._logWindow.displayCounter(target);
this._logWindow.displayActionResults(subject, subject);
};
// 战斗管理器.调用魔法发射
BattleManager.invokeMagicReflection = function(subject, target) {
this._logWindow.displayReflection(target);
this._action.apply(subject);
this._logWindow.displayActionResults(subject, subject);
};
// 战斗管理器.应用代替者
BattleManager.applySubstitute = function(target) {
if (this.checkSubstitute(target)) {
var substitute = target.friendsUnit().substituteBattler();
if (substitute && target !== substitute) {
this._logWindow.displaySubstitute(substitute, target);
return substitute;
}
}
return target;
};
// 战斗管理器.检查代替者
BattleManager.checkSubstitute = function(target) {
return target.isDying() && !this._action.isCertainHit();
};
// 战斗管理器.是否强制行动
BattleManager.isActionForced = function() {
return !!this._actionForcedBattler;
};
// 战斗管理器.强制行动
BattleManager.forceAction = function(battler) {
this._actionForcedBattler = battler;
var index = this._actionBattlers.indexOf(battler);
if (index >= 0) {
this._actionBattlers.splice(index, 1);
}
};
// 战斗管理器.强制行动流程
BattleManager.processForcedAction = function() {
if (this._actionForcedBattler) {
this._subject = this._actionForcedBattler;
this._actionForcedBattler = null;
this.startAction();
this._subject.removeCurrentAction();
}
};
// 战斗管理器.终止
BattleManager.abort = function() {
this._phase = 'aborting';
};
// 战斗管理器.检查是否战斗已经结束
BattleManager.checkBattleEnd = function() {
if (this._phase) {
if (this.checkAbort()) {
return true;
} else if ($gameParty.isAllDead()) {
this.processDefeat();
return true;
} else if ($gameTroop.isAllDead()) {
this.processVictory();
return true;
}
}
return false;
};
// 战斗管理器.检查是否战斗已经终止
BattleManager.checkAbort = function() {
if ($gameParty.isEmpty() || this.isAborting()) {
this.processAbort();
return true;
}
return false;
};
// 战斗管理器.胜利过程
BattleManager.processVictory = function() {
$gameParty.removeBattleStates();
$gameParty.performVictory();
this.playVictoryMe();
this.replayBgmAndBgs();
this.makeRewards();
this.displayVictoryMessage();
this.displayRewards();
this.gainRewards();
this.endBattle(0);
};
// 战斗管理器.逃跑过程
BattleManager.processEscape = function() {
$gameParty.removeBattleStates();
$gameParty.performEscape();
SoundManager.playEscape();
var success = this._preemptive ? true : (Math.random() < this._escapeRatio);
if (success) {
this.displayEscapeSuccessMessage();
this._escaped = true;
this.processAbort();
} else {
this.displayEscapeFailureMessage();
this._escapeRatio += 0.1;
$gameParty.clearActions();
this.startTurn();
}
return success;
};
// 战斗管理器.终止过程
BattleManager.processAbort = function() {
this.replayBgmAndBgs();
this.endBattle(1);
};
// 战斗管理器.失败过程
BattleManager.processDefeat = function() {
this.displayDefeatMessage();
this.playDefeatMe();
if (this._canLose) {
this.replayBgmAndBgs();
} else {
AudioManager.stopBgm();
}
this.endBattle(2);
};
// 战斗管理器.结束战斗
BattleManager.endBattle = function(result) {
this._phase = 'battleEnd';
if (this._eventCallback) {
this._eventCallback(result);
}
if (result === 0) {
$gameSystem.onBattleWin();
} else if (this._escaped) {
$gameSystem.onBattleEscape();
}
};
// 战斗管理器.刷新战斗结束
BattleManager.updateBattleEnd = function() {
if (this.isBattleTest()) {
AudioManager.stopBgm();
SceneManager.exit();
} else if ($gameParty.isAllDead()) {
if (this._canLose) {
$gameParty.reviveBattleMembers();
SceneManager.pop();
} else {
SceneManager.goto(Scene_Gameover);
}
} else {
SceneManager.pop();
}
this._phase = null;
};
// 战斗管理器.制奖励
BattleManager.makeRewards = function() {
this._rewards = {};
this._rewards.gold = $gameTroop.goldTotal();
this._rewards.exp = $gameTroop.expTotal();
this._rewards.items = $gameTroop.makeDropItems();
};
// 战斗管理器.显示胜利消息
BattleManager.displayVictoryMessage = function() {
$gameMessage.add(TextManager.victory.format($gameParty.name()));
};
// 战斗管理器.显示失败消息
BattleManager.displayDefeatMessage = function() {
$gameMessage.add(TextManager.defeat.format($gameParty.name()));
};
// 战斗管理器.显示逃跑消息
BattleManager.displayEscapeSuccessMessage = function() {
$gameMessage.add(TextManager.escapeStart.format($gameParty.name()));
};
// 战斗管理器.显示逃跑失败消息
BattleManager.displayEscapeFailureMessage = function() {
$gameMessage.add(TextManager.escapeStart.format($gameParty.name()));
$gameMessage.add('\\.' + TextManager.escapeFailure);
};
// 战斗管理器.显示奖励消息
BattleManager.displayRewards = function() {
this.displayExp();
this.displayGold();
this.displayDropItems();
};
// 战斗管理器.显示奖励消息-经验
BattleManager.displayExp = function() {
var exp = this._rewards.exp;
if (exp > 0) {
var text = TextManager.obtainExp.format(exp, TextManager.exp);
$gameMessage.add('\\.' + text);
}
};
// 战斗管理器.显示奖励消息-金币
BattleManager.displayGold = function() {
var gold = this._rewards.gold;
if (gold > 0) {
$gameMessage.add('\\.' + TextManager.obtainGold.format(gold));
}
};
// 战斗管理器.显示奖励消息-掉落的物品
BattleManager.displayDropItems = function() {
var items = this._rewards.items;
if (items.length > 0) {
$gameMessage.newPage();
items.forEach(function(item) {
$gameMessage.add(TextManager.obtainItem.format(item.name));
});
}
};
// 战斗管理器.获得奖励
BattleManager.gainRewards = function() {
this.gainExp(); // 战斗管理器.获得经验
this.gainGold(); // 战斗管理器.获得金币
this.gainDropItems(); // 战斗管理器.获得物品组
};
// 战斗管理器.获得经验
BattleManager.gainExp = function() {
var exp = this._rewards.exp; // 经验值 = 战斗管理器.奖励.经验值
// 游戏队伍类.全体成员组.遍历数组()
$gameParty.allMembers().forEach(function(actor) {
actor.gainExp(exp); // 角色.获得经验(经验值)
});
};
// 战斗管理器.获得金币
BattleManager.gainGold = function() {
$gameParty.gainGold(this._rewards.gold); // 游戏队伍类.获得金币(战斗管理器.奖励.金币)
};
// 战斗管理器.获得物品组
BattleManager.gainDropItems = function() {
var items = this._rewards.items; // 物品组 = 战斗管理器.奖励.物品组
// 物品组.遍历数组
items.forEach(function(item) {
$gameParty.gainItem(item, 1); // 游戏队伍类.获得物品(物品, 1)
});
};
//-----------------------------------------------------------------------------
// BattleManager
//
// The static class that manages battle progress.
// 战斗管理器
// 静态类 管理战斗进度消息
function BattleManager() {
throw new Error('This is a static class');
}
// 战斗管理器.设置
BattleManager.setup = function(troopId, canEscape, canLose) {
this.initMembers(); // 战斗管理器.初始化成员
this._canEscape = canEscape; // 战斗管理器.可以逃跑
this._canLose = canLose; // 战斗管理器.可以失败
$gameTroop.setup(troopId); // 游戏敌群类.设置(敌群ID)
$gameScreen.onBattleStart(); // 游戏屏幕类.战斗开始事件()
this.makeEscapeRatio(); // 战斗管理器.制逃避率();
};
// 战斗管理器.初始化成员
BattleManager.initMembers = function() {
this._phase = 'init'; // 战斗管理器.阶段
this._canEscape = false; // 战斗管理器.可逃跑
this._canLose = false; // 战斗管理器.可失败
this._battleTest = false; // 战斗管理器.战斗测试
this._eventCallback = null; // 战斗管理器.事件回调
this._preemptive = false; // 战斗管理器.先发制人
this._surprise = false; // 战斗管理器.突然袭击
this._actorIndex = -1; // 战斗管理器.角色索引
this._actionForcedBattler = null; // 战斗管理器.强制战斗行动
this._mapBgm = null; // 战斗管理器.地图BGM
this._mapBgs = null; // 战斗管理器.地图BGS
this._actionBattlers = []; // 战斗管理器.战斗行动人员组
this._subject = null; // 战斗管理器.行动者 Game_Actor || Game_Enemy
this._action = null; // 战斗管理器.行动 Game_Action
this._targets = []; // 战斗管理器.目标组
this._logWindow = null; // 战斗管理器.日志窗口
this._statusWindow = null; // 战斗管理器.状态窗口
this._spriteset = null; // 战斗管理器.精灵
this._escapeRatio = 0; // 战斗管理器.逃跑率
this._escaped = false; // 战斗管理器.已经逃跑
this._rewards = {}; // 战斗管理器.奖励
};
// 战斗管理器.是否为战斗测试
BattleManager.isBattleTest = function() {
return this._battleTest;
};
// 战斗管理器.设置战斗测试
BattleManager.setBattleTest = function(battleTest) {
this._battleTest = battleTest;
};
// 战斗管理器.设置事件回调
BattleManager.setEventCallback = function(callback) {
this._eventCallback = callback;
};
// 战斗管理器.设置日志窗口
BattleManager.setLogWindow = function(logWindow) {
this._logWindow = logWindow;
};
// 战斗管理器.设置状态窗口
BattleManager.setStatusWindow = function(statusWindow) {
this._statusWindow = statusWindow;
};
// 战斗管理器.设置精灵
BattleManager.setSpriteset = function(spriteset) {
this._spriteset = spriteset;
};
// 战斗管理器.遇敌事件
BattleManager.onEncounter = function() {
this._preemptive = (Math.random() < this.ratePreemptive()); // 先发制人算法
this._surprise = (Math.random() < this.rateSurprise() && !this._preemptive); // 会心一击算法
};
// 战斗管理器.敏捷率
BattleManager.ratePreemptive = function() {
return $gameParty.ratePreemptive($gameTroop.agility());
};
//
BattleManager.rateSurprise = function() {
return $gameParty.rateSurprise($gameTroop.agility());
};
// 战斗管理器.保存BGM和BGS
BattleManager.saveBgmAndBgs = function() {
this._mapBgm = AudioManager.saveBgm(); // 音频管理器.保存BGM
this._mapBgs = AudioManager.saveBgs(); // 音频管理器.保存BGS
};
// 战斗管理器.播放战斗BGM
BattleManager.playBattleBgm = function() {
AudioManager.playBgm($gameSystem.battleBgm()); // 音频管理器.播放BGM(游戏系统类.战斗BGM)
AudioManager.stopBgs(); // 音频管理器.停止BGS
};
// 战斗管理器.播放胜利SE
BattleManager.playVictoryMe = function() {
AudioManager.playMe($gameSystem.victoryMe()); // 音频管理器.播放ME(游戏系统类.胜利ME)
};
// 战斗管理器.播放失败ME
BattleManager.playDefeatMe = function() {
AudioManager.playMe($gameSystem.defeatMe()); // 音频管理器.播放ME(游戏系统类.失败ME)
};
// 战斗管理器.重播BGM和BGS
BattleManager.replayBgmAndBgs = function() {
if (this._mapBgm) {
AudioManager.replayBgm(this._mapBgm); // 音频管理器.重播BGM(战斗管理器.地图BGM)
} else {
AudioManager.stopBgm(); // 音频管理器.停止BGM
}
if (this._mapBgs) { // 战斗管理器.地图BGS
AudioManager.replayBgs(this._mapBgs); // 音频管理器.重播BGS(战斗管理器.地图BGS)
}
};
// 战斗管理器.制逃避率
BattleManager.makeEscapeRatio = function() {
this._escapeRatio = 0.5 * $gameParty.agility() / $gameTroop.agility();
};
// 战斗管理器.更新
BattleManager.update = function() {
if (!this.isBusy() && !this.updateEvent()) {
switch (this._phase) {
case 'start':
this.startInput(); // 战斗管理器.开始输入
break;
case 'turn':
this.updateTurn(); // 战斗管理器.刷新回合
break;
case 'action':
this.updateAction(); // 战斗管理器.刷新行动
break;
case 'turnEnd':
this.updateTurnEnd(); // 战斗管理器.刷新回合结束
break;
case 'battleEnd':
this.updateBattleEnd(); // 战斗管理器.刷新战斗结束
break;
}
}
};
// 战斗管理器.更新事件
BattleManager.updateEvent = function() {
switch (this._phase) {
case 'start':
case 'turn':
case 'turnEnd':
if (this.isActionForced()) {
this.processForcedAction(); // 战斗管理器.强制行动流程
return true;
} else {
return this.updateEventMain(); // 战斗管理器.主刷新事件
}
}
return this.checkAbort(); // 战斗管理器.检查是否战斗已经终止
};
// 战斗管理器.主刷新事件
BattleManager.updateEventMain = function() {
$gameTroop.updateInterpreter(); // 游戏敌群类.刷新事件解释器
$gameParty.requestMotionRefresh(); // 游戏队伍类.请求动态刷新
// 游戏敌群类.事件正在运行 或 战斗管理器.检查战斗是否已经结束
if ($gameTroop.isEventRunning() || this.checkBattleEnd()) {
return true;
}
// 游戏敌群类.设置战斗事件
$gameTroop.setupBattleEvent();
// 游戏敌群类.事件正在运行 或 场景管理器.场景是否在改变中
if ($gameTroop.isEventRunning() || SceneManager.isSceneChanging()) {
return true;
}
return false;
};
// 战斗管理器.是否正忙
BattleManager.isBusy = function() {
// 游戏消息类.是否正忙 或 战斗管理器.精灵.是否正忙 或 战斗管理器.日志窗口.是否正忙
return ($gameMessage.isBusy() || this._spriteset.isBusy() ||
this._logWindow.isBusy());
};
// 战斗管理器.是否正在输入中
BattleManager.isInputting = function() {
return this._phase === 'input';
};
// 战斗管理器.是否在一回合中
BattleManager.isInTurn = function() {
return this._phase === 'turn';
};
// 战斗管理器.是否一回合已经结束
BattleManager.isTurnEnd = function() {
return this._phase === 'turnEnd';
};
// 战斗管理器.是否已经终止
BattleManager.isAborting = function() {
return this._phase === 'aborting';
};
// 战斗管理器.是否战斗已经结束
BattleManager.isBattleEnd = function() {
return this._phase === 'battleEnd';
};
// 战斗管理器.是否可以逃跑
BattleManager.canEscape = function() {
return this._canEscape;
};
// 战斗管理器.是否可以失去
BattleManager.canLose = function() {
return this._canLose;
};
// 战斗管理器.是否已经逃跑
BattleManager.isEscaped = function() {
return this._escaped;
};
// 战斗管理器.角色
BattleManager.actor = function() {
return this._actorIndex >= 0 ? $gameParty.members()[this._actorIndex] : null;
};
// 战斗管理器.清除角色
BattleManager.clearActor = function() {
this.changeActor(-1, '');
};
// 战斗管理器.更改角色
BattleManager.changeActor = function(newActorIndex, lastActorActionState) {
var lastActor = this.actor(); // 保存当前角色
this._actorIndex = newActorIndex; // 设置当前角色索引
var newActor = this.actor(); // 再取出设置的角色
if (lastActor) { // 设置最后角色的动作状态
lastActor.setActionState(lastActorActionState);
}
if (newActor) { // 设置新角色的动作状态
newActor.setActionState('inputting');
}
};
// 战斗管理器.开始战斗
BattleManager.startBattle = function() {
this._phase = 'start';
$gameSystem.onBattleStart(); // 游戏系统类.战斗开始事件
$gameParty.onBattleStart(); // 游戏队伍类.战斗开始事件
$gameTroop.onBattleStart(); // 游戏敌群类.战斗开始事件
this.displayStartMessages(); // 战斗管理器.显示开始消息
};
// 战斗管理器.显示启动信息
BattleManager.displayStartMessages = function() {
// 游戏敌群类.敌人名称组.遍历数组
$gameTroop.enemyNames().forEach(function(name) {
$gameMessage.add(TextManager.emerge.format(name)); // 游戏消息类.添加(消息术语管理器.出现.格式化(name)) -> 格式化成 xxx出现
});
if (this._preemptive) { // 是否先发制人
$gameMessage.add(TextManager.preemptive.format($gameParty.name())); // 游戏消息类.添加(消息术语管理器.出现.格式化(name)) -> 格式化成 xxx先发制人
} else if (this._surprise) { // 是否突然袭击
$gameMessage.add(TextManager.surprise.format($gameParty.name())); // 游戏消息类.添加(消息术语管理器.出现.格式化(name)) -> 格式化成 xxx突然袭击
}
};
// 战斗管理器.开始输入
BattleManager.startInput = function() {
this._phase = 'input';
$gameParty.makeActions(); // 游戏队伍类.做出行动
$gameTroop.makeActions(); // 游戏敌群类.做出行动
this.clearActor(); // 战斗管理器.清除角色
if (this._surprise || !$gameParty.canInput()) { // 战斗管理器.突然袭击 或 游戏队伍类.是否可以输入
this.startTurn(); // 战斗管理器.开始一回合
}
};
// 战斗管理器.输入操作
BattleManager.inputtingAction = function() {
return this.actor() ? this.actor().inputtingAction() : null;
};
// 战斗管理器.选择下个动作
BattleManager.selectNextCommand = function() {
do {
if (!this.actor() || !this.actor().selectNextCommand()) {
this.changeActor(this._actorIndex + 1, 'waiting'); // 战斗管理器.更改角色
if (this._actorIndex >= $gameParty.size()) { // 战斗管理器.当前角色索引 >= 游戏队伍类.人员数量
this.startTurn(); // 战斗管理器.开始一回合
break; // 跳出循环
}
}
} while (!this.actor().canInput());
};
// 战斗管理器.选择上一个命令
BattleManager.selectPreviousCommand = function() {
do {
if (!this.actor() || !this.actor().selectPreviousCommand()) {
this.changeActor(this._actorIndex - 1, 'undecided'); // 战斗管理器.更改角色
if (this._actorIndex < 0) { // 战斗管理器.当前角色索引 < 0
return;
}
}
} while (!this.actor().canInput());
};
// 战斗管理器.刷新状态
BattleManager.refreshStatus = function() {
this._statusWindow.refresh(); // 战斗管理器.状态窗口.刷新
};
// 战斗管理器.开始一回合
BattleManager.startTurn = function() {
this._phase = 'turn';
this.clearActor(); // 战斗管理器.清除角色
$gameTroop.increaseTurn(); // 游戏敌群类.增加回合
this.makeActionOrders(); // 战斗管理器.作行动命令
$gameParty.requestMotionRefresh(); // 游戏队伍类.请求动态刷新
this._logWindow.startTurn();
};
// 战斗管理器.刷新回合
BattleManager.updateTurn = function() {
$gameParty.requestMotionRefresh(); // 游戏队伍类.请求动态刷新
if (!this._subject) { // 战斗管理器.行动者
this._subject = this.getNextSubject(); // 战斗管理器.取下个行动者
}
if (this._subject) {
this.processTurn(); // 战斗管理器.流程回合
} else {
this.endTurn(); // 战斗管理器.结束一回合
}
};
// 战斗管理器.流程回合
BattleManager.processTurn = function() {
var subject = this._subject; // 战斗管理器.行动者
var action = subject.currentAction(); // 取 行动者.当前动作
if (action) {
action.prepare(); // 动作.准备
if (action.isValid()) {
this.startAction();
}
subject.removeCurrentAction(); // 行动者.移除当前动作
} else {
subject.onAllActionsEnd(); // 行动者.全部动作结束事件
this.refreshStatus(); // 战斗管理器.刷新状态
this._logWindow.displayAutoAffectedStatus(subject); // 战斗管理器.日志窗口.显示自动受影响状况
this._logWindow.displayCurrentState(subject); // 战斗管理器.日志窗口.显示当前状态
this._logWindow.displayRegeneration(subject); // 战斗管理器.日志窗口.显示恢复
this._subject = this.getNextSubject(); // 战斗管理器.行动者 = 战斗管理器.取下个行动者
}
};
// 战斗管理器.结束一回合
BattleManager.endTurn = function() {
this._phase = 'turnEnd'; // 战斗管理器.阶段
this._preemptive = false; // 战斗管理器.先发制人 = false
this._surprise = false; // 战斗管理器.突然袭击 = false
// 战斗管理器.全部战斗成员.遍历
this.allBattleMembers().forEach(function(battler) {
battler.onTurnEnd(); // 战斗者.结束一回合
this.refreshStatus(); // 战斗管理器.刷新状态
this._logWindow.displayAutoAffectedStatus(battler); // 战斗管理器.日志窗口.显示自动受影响状况
this._logWindow.displayRegeneration(battler); // 战斗管理器.日志窗口.显示恢复
}, this);
};
// 战斗管理器.刷新回合结束
BattleManager.updateTurnEnd = function() {
this.startInput();
};
// 战斗管理器.取下个行动者
BattleManager.getNextSubject = function() {
for (;;) {
var battler = this._actionBattlers.shift(); // 战斗者 = 战斗管理器.战斗行动人员组.左移
if (!battler) {
return null;
}
if (battler.isBattleMember() && battler.isAlive()) { // 战斗者.是否为战斗成员 且 战斗者.是否生存
return battler;
}
}
};
// 战斗管理器.全部战斗成员
BattleManager.allBattleMembers = function() {
return $gameParty.members().concat($gameTroop.members());
};
// 战斗管理器.作行动命令
BattleManager.makeActionOrders = function() {
var battlers = [];
if (!this._surprise) { // !战斗管理器.突然袭击
battlers = battlers.concat($gameParty.members()); // 参战人员组 连接数组 游戏队伍类.成员组
}
if (!this._preemptive) { // !战斗管理器.先发制人
battlers = battlers.concat($gameTroop.members()); // 参战人员组 连接数组 游戏敌群类.成员组
}
// 参战人员组 遍历
battlers.forEach(function(battler) {
battler.makeSpeed(); // 参战人员组.制速度
});
// 参战人员组.排序() 详见:Array.sort
battlers.sort(function(a, b) {
return b.speed() - a.speed();
});
this._actionBattlers = battlers; // 战斗管理器.战斗行动人员组 = 参战人员组
};
// 战斗管理器.开始行动
BattleManager.startAction = function() {
var subject = this._subject; // 战斗管理器.行动者
var action = subject.currentAction(); // 行动者.当前动作
var targets = action.makeTargets(); // 动作.置目标组
this._phase = 'action';
this._action = action; // 战斗管理器.动作 = action = 行动者.当前动作
this._targets = targets; // 战斗管理器.目标组 = targets = 行动者.当前动作.置目标组
subject.useItem(action.item()); // 行动者.使用物品(动作.物品数据)
this._action.applyGlobal(); // 战斗管理器.动作.应用全局()
this.refreshStatus(); // 战斗管理器.刷新状态()
this._logWindow.startAction(subject, action, targets); // 战斗管理器.日志窗口.开始行动(行动者, 动作, 目标组)
};
// 战斗管理器.刷新行动
BattleManager.updateAction = function() {
var target = this._targets.shift(); // 目标 = 战斗管理器.目标组.左移()
if (target) {
this.invokeAction(this._subject, target); // 战斗管理器.调用行动(战斗管理器.行动者, 目标)
} else {
this.endAction(); // 战斗管理器.结束行动
}
};
// 战斗管理器.结束行动
BattleManager.endAction = function() {
this._logWindow.endAction(this._subject); // 战斗管理器.日志窗口.结束行动(战斗管理器.行动者)
this._phase = 'turn';
};
// 战斗管理器.调用行动
BattleManager.invokeAction = function(subject, target) {
this._logWindow.push('pushBaseLine'); // 战斗管理器.日志窗口.投递()
if (Math.random() < this._action.itemCnt(target)) {
this.invokeCounterAttack(subject, target); // 战斗管理器.调用反击(行动者, 目标)
} else if (Math.random() < this._action.itemMrf(target)) {
this.invokeMagicReflection(subject, target); // 战斗管理器.调用魔法发射(行动者, 目标)
} else {
this.invokeNormalAction(subject, target); // 战斗管理器.调用正常行动(行动者, 目标)
}
subject.setLastTarget(target); // 行动者.设置最后目标(目标)
this._logWindow.push('popBaseLine'); // 战斗管理器.日志窗口.投递()
this.refreshStatus(); // 战斗管理器.刷新状态
};
// 战斗管理器.调用正常行动
BattleManager.invokeNormalAction = function(subject, target) {
var realTarget = this.applySubstitute(target);
this._action.apply(realTarget);
this._logWindow.displayActionResults(subject, realTarget);
};
// 战斗管理器.调用反击
BattleManager.invokeCounterAttack = function(subject, target) {
var action = new Game_Action(target);
action.setAttack();
action.apply(subject);
this._logWindow.displayCounter(target);
this._logWindow.displayActionResults(subject, subject);
};
// 战斗管理器.调用魔法发射
BattleManager.invokeMagicReflection = function(subject, target) {
this._logWindow.displayReflection(target);
this._action.apply(subject);
this._logWindow.displayActionResults(subject, subject);
};
// 战斗管理器.应用代替者
BattleManager.applySubstitute = function(target) {
if (this.checkSubstitute(target)) {
var substitute = target.friendsUnit().substituteBattler();
if (substitute && target !== substitute) {
this._logWindow.displaySubstitute(substitute, target);
return substitute;
}
}
return target;
};
// 战斗管理器.检查代替者
BattleManager.checkSubstitute = function(target) {
return target.isDying() && !this._action.isCertainHit();
};
// 战斗管理器.是否强制行动
BattleManager.isActionForced = function() {
return !!this._actionForcedBattler;
};
// 战斗管理器.强制行动
BattleManager.forceAction = function(battler) {
this._actionForcedBattler = battler;
var index = this._actionBattlers.indexOf(battler);
if (index >= 0) {
this._actionBattlers.splice(index, 1);
}
};
// 战斗管理器.强制行动流程
BattleManager.processForcedAction = function() {
if (this._actionForcedBattler) {
this._subject = this._actionForcedBattler;
this._actionForcedBattler = null;
this.startAction();
this._subject.removeCurrentAction();
}
};
// 战斗管理器.终止
BattleManager.abort = function() {
this._phase = 'aborting';
};
// 战斗管理器.检查是否战斗已经结束
BattleManager.checkBattleEnd = function() {
if (this._phase) {
if (this.checkAbort()) {
return true;
} else if ($gameParty.isAllDead()) {
this.processDefeat();
return true;
} else if ($gameTroop.isAllDead()) {
this.processVictory();
return true;
}
}
return false;
};
// 战斗管理器.检查是否战斗已经终止
BattleManager.checkAbort = function() {
if ($gameParty.isEmpty() || this.isAborting()) {
this.processAbort();
return true;
}
return false;
};
// 战斗管理器.胜利过程
BattleManager.processVictory = function() {
$gameParty.removeBattleStates();
$gameParty.performVictory();
this.playVictoryMe();
this.replayBgmAndBgs();
this.makeRewards();
this.displayVictoryMessage();
this.displayRewards();
this.gainRewards();
this.endBattle(0);
};
// 战斗管理器.逃跑过程
BattleManager.processEscape = function() {
$gameParty.removeBattleStates();
$gameParty.performEscape();
SoundManager.playEscape();
var success = this._preemptive ? true : (Math.random() < this._escapeRatio);
if (success) {
this.displayEscapeSuccessMessage();
this._escaped = true;
this.processAbort();
} else {
this.displayEscapeFailureMessage();
this._escapeRatio += 0.1;
$gameParty.clearActions();
this.startTurn();
}
return success;
};
// 战斗管理器.终止过程
BattleManager.processAbort = function() {
this.replayBgmAndBgs();
this.endBattle(1);
};
// 战斗管理器.失败过程
BattleManager.processDefeat = function() {
this.displayDefeatMessage();
this.playDefeatMe();
if (this._canLose) {
this.replayBgmAndBgs();
} else {
AudioManager.stopBgm();
}
this.endBattle(2);
};
// 战斗管理器.结束战斗
BattleManager.endBattle = function(result) {
this._phase = 'battleEnd';
if (this._eventCallback) {
this._eventCallback(result);
}
if (result === 0) {
$gameSystem.onBattleWin();
} else if (this._escaped) {
$gameSystem.onBattleEscape();
}
};
// 战斗管理器.刷新战斗结束
BattleManager.updateBattleEnd = function() {
if (this.isBattleTest()) {
AudioManager.stopBgm();
SceneManager.exit();
} else if ($gameParty.isAllDead()) {
if (this._canLose) {
$gameParty.reviveBattleMembers();
SceneManager.pop();
} else {
SceneManager.goto(Scene_Gameover);
}
} else {
SceneManager.pop();
}
this._phase = null;
};
// 战斗管理器.制奖励
BattleManager.makeRewards = function() {
this._rewards = {};
this._rewards.gold = $gameTroop.goldTotal();
this._rewards.exp = $gameTroop.expTotal();
this._rewards.items = $gameTroop.makeDropItems();
};
// 战斗管理器.显示胜利消息
BattleManager.displayVictoryMessage = function() {
$gameMessage.add(TextManager.victory.format($gameParty.name()));
};
// 战斗管理器.显示失败消息
BattleManager.displayDefeatMessage = function() {
$gameMessage.add(TextManager.defeat.format($gameParty.name()));
};
// 战斗管理器.显示逃跑消息
BattleManager.displayEscapeSuccessMessage = function() {
$gameMessage.add(TextManager.escapeStart.format($gameParty.name()));
};
// 战斗管理器.显示逃跑失败消息
BattleManager.displayEscapeFailureMessage = function() {
$gameMessage.add(TextManager.escapeStart.format($gameParty.name()));
$gameMessage.add('\\.' + TextManager.escapeFailure);
};
// 战斗管理器.显示奖励消息
BattleManager.displayRewards = function() {
this.displayExp();
this.displayGold();
this.displayDropItems();
};
// 战斗管理器.显示奖励消息-经验
BattleManager.displayExp = function() {
var exp = this._rewards.exp;
if (exp > 0) {
var text = TextManager.obtainExp.format(exp, TextManager.exp);
$gameMessage.add('\\.' + text);
}
};
// 战斗管理器.显示奖励消息-金币
BattleManager.displayGold = function() {
var gold = this._rewards.gold;
if (gold > 0) {
$gameMessage.add('\\.' + TextManager.obtainGold.format(gold));
}
};
// 战斗管理器.显示奖励消息-掉落的物品
BattleManager.displayDropItems = function() {
var items = this._rewards.items;
if (items.length > 0) {
$gameMessage.newPage();
items.forEach(function(item) {
$gameMessage.add(TextManager.obtainItem.format(item.name));
});
}
};
// 战斗管理器.获得奖励
BattleManager.gainRewards = function() {
this.gainExp(); // 战斗管理器.获得经验
this.gainGold(); // 战斗管理器.获得金币
this.gainDropItems(); // 战斗管理器.获得物品组
};
// 战斗管理器.获得经验
BattleManager.gainExp = function() {
var exp = this._rewards.exp; // 经验值 = 战斗管理器.奖励.经验值
// 游戏队伍类.全体成员组.遍历数组()
$gameParty.allMembers().forEach(function(actor) {
actor.gainExp(exp); // 角色.获得经验(经验值)
});
};
// 战斗管理器.获得金币
BattleManager.gainGold = function() {
$gameParty.gainGold(this._rewards.gold); // 游戏队伍类.获得金币(战斗管理器.奖励.金币)
};
// 战斗管理器.获得物品组
BattleManager.gainDropItems = function() {
var items = this._rewards.items; // 物品组 = 战斗管理器.奖励.物品组
// 物品组.遍历数组
items.forEach(function(item) {
$gameParty.gainItem(item, 1); // 游戏队伍类.获得物品(物品, 1)
});
};
10.插件管理器(这里只翻译了函数名-具体没有翻译(很简单))
//-----------------------------------------------------------------------------
// PluginManager
//
// The static class that manages the plugins.
// 插件管理器
// 静态类 - 管理插件的类
function PluginManager() {
throw new Error('This is a static class');
}
PluginManager._path = 'js/plugins/'; // 插件路径
PluginManager._scripts = []; // 脚本组
PluginManager._errorUrls = []; // 错误网络地址
PluginManager._parameters = {}; // 参数
// 插件管理器.设置
PluginManager.setup = function(plugins) {
plugins.forEach(function(plugin) {
if (plugin.status && !this._scripts.contains(plugin.name)) {
this.setParameters(plugin.name, plugin.parameters);
this.loadScript(plugin.name + '.js');
this._scripts.push(plugin.name);
}
}, this);
};
// 插件管理器.检查错误
PluginManager.checkErrors = function() {
var url = this._errorUrls.shift();
if (url) {
throw new Error('Failed to load: ' + url);
}
};
// 插件管理器.参数
PluginManager.parameters = function(name) {
return this._parameters[name.toLowerCase()] || {};
};
// 插件管理器.设置参数
PluginManager.setParameters = function(name, parameters) {
this._parameters[name.toLowerCase()] = parameters;
};
// 插件管理器.加载脚本
PluginManager.loadScript = function(name) {
var url = this._path + name;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
script.async = false;
script.onerror = this.onError.bind(this);
script._url = url;
document.body.appendChild(script);
};
// 插件管理器.错误事件
PluginManager.onError = function(e) {
this._errorUrls.push(e.target._url);
};
//-----------------------------------------------------------------------------
// PluginManager
//
// The static class that manages the plugins.
// 插件管理器
// 静态类 - 管理插件的类
function PluginManager() {
throw new Error('This is a static class');
}
PluginManager._path = 'js/plugins/'; // 插件路径
PluginManager._scripts = []; // 脚本组
PluginManager._errorUrls = []; // 错误网络地址
PluginManager._parameters = {}; // 参数
// 插件管理器.设置
PluginManager.setup = function(plugins) {
plugins.forEach(function(plugin) {
if (plugin.status && !this._scripts.contains(plugin.name)) {
this.setParameters(plugin.name, plugin.parameters);
this.loadScript(plugin.name + '.js');
this._scripts.push(plugin.name);
}
}, this);
};
// 插件管理器.检查错误
PluginManager.checkErrors = function() {
var url = this._errorUrls.shift();
if (url) {
throw new Error('Failed to load: ' + url);
}
};
// 插件管理器.参数
PluginManager.parameters = function(name) {
return this._parameters[name.toLowerCase()] || {};
};
// 插件管理器.设置参数
PluginManager.setParameters = function(name, parameters) {
this._parameters[name.toLowerCase()] = parameters;
};
// 插件管理器.加载脚本
PluginManager.loadScript = function(name) {
var url = this._path + name;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
script.async = false;
script.onerror = this.onError.bind(this);
script._url = url;
document.body.appendChild(script);
};
// 插件管理器.错误事件
PluginManager.onError = function(e) {
this._errorUrls.push(e.target._url);
};
作者: 青鸫 时间: 2017-3-9 18:53
天天天天哪!!!!!大佬辛苦了!!!谢谢大佬!!给大佬端茶!
作者: walf_man 时间: 2017-3-9 19:07
此坑略大,做的非常好,翻译准确到位,而且格式工整。加油!
作者: kula1900 时间: 2017-3-9 19:09
开胃小菜,翻译全部后,上传哈。
作者: 埋头farm 时间: 2017-3-9 19:21
辛苦了,支持一波
作者: r8u3s4h7 时间: 2017-3-9 20:38
大工程啊
好厉害
作者: shitake 时间: 2017-3-10 12:10
噗 你这自己过一遍的话 代码技能绝对是大涨一截
我就懒得梳一遍 都是用到哪看到那233
作者: 雾影药师 时间: 2017-3-10 12:21
造福吾等萌新是也~
作者: 柳岳枫 时间: 2017-3-10 13:19
MV区越来越活跃了 赞良心干货帖
再看看注册时间
膜拜!
作者: q312092921 时间: 2017-3-13 06:14
哦,这个好,这个好
作者: mikeyh01 时间: 2017-3-13 12:39
楼主的细心令人佩服
作者: 汪汪 时间: 2017-3-14 15:28
本帖最后由 汪汪 于 2017-3-14 15:34 编辑
[交流讨论] 【机翻】rpg_mv_js 基于mv 版本1.3.5
https://rpg.blue/forum.php?mod=v ... 385523&mobile=2
或许可以参考下。我翻译的很差。。
作者: lirn 时间: 2017-3-18 23:27
不弄个打包下载的地址吗?
作者: homya 时间: 2017-7-29 17:25
V5 87~~就喜欢楼主这样的好人!~
作者: xjzsq 时间: 2017-8-6 23:42
建议弄到GitHub上,另外这个大神也在弄这个,可以和他合作一下:
https://github.com/wangwangxinga ... /%E6%B3%A8%E9%87%8A
作者: 447924513 时间: 2019-8-16 17:24
大佬牛逼
欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |