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.游戏临时数据类
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // Game_Temp
  3. //
  4. // The game object class for temporary data that is not included in save data.
  5. // 游戏临时数据类
  6. // 游戏对象类 临时数据不包括在存储数据。
  7. function Game_Temp() {
  8.     this.initialize.apply(this, arguments);
  9. }
  10. // 游戏临时数据类.初始化
  11. Game_Temp.prototype.initialize = function() {
  12.     this._isPlaytest = Utils.isOptionValid('test');   // 游戏临时数据类.游戏测试
  13.     this._commonEventId = 0;                          // 游戏临时数据类.公共事件ID
  14.     this._destinationX = null;                        // 游戏临时数据类.目的地X
  15.     this._destinationY = null;                        // 游戏临时数据类.目的地Y
  16. };
  17. // 游戏临时数据类.是否是游戏测试
  18. Game_Temp.prototype.isPlaytest = function() {
  19.     return this._isPlaytest;
  20. };
  21. // 游戏临时数据类.保留公共事件
  22. Game_Temp.prototype.reserveCommonEvent = function(commonEventId) {
  23.     this._commonEventId = commonEventId;
  24. };
  25. // 游戏临时数据类.清除公共事件
  26. Game_Temp.prototype.clearCommonEvent = function() {
  27.     this._commonEventId = 0;
  28. };
  29. // 游戏临时数据类.是否存在保留的公共事件
  30. Game_Temp.prototype.isCommonEventReserved = function() {
  31.     return this._commonEventId > 0;
  32. };
  33. // 游戏临时数据类.取保留公共事件
  34. Game_Temp.prototype.reservedCommonEvent = function() {
  35.     return $dataCommonEvents[this._commonEventId];
  36. };
  37. // 游戏临时数据类.设置目的地
  38. Game_Temp.prototype.setDestination = function(x, y) {
  39.     this._destinationX = x;
  40.     this._destinationY = y;
  41. };
  42. // 游戏临时数据类.清除目的地
  43. Game_Temp.prototype.clearDestination = function() {
  44.     this._destinationX = null;
  45.     this._destinationY = null;
  46. };
  47. // 游戏临时数据类.目的地是否有效
  48. Game_Temp.prototype.isDestinationValid = function() {
  49.     return this._destinationX !== null;
  50. };
  51. // 游戏临时数据类.取目的地X坐标
  52. Game_Temp.prototype.destinationX = function() {
  53.     return this._destinationX;
  54. };
  55. // 游戏临时数据类.取目的地Y坐标
  56. Game_Temp.prototype.destinationY = function() {
  57.     return this._destinationY;
  58. };

2.游戏系统类
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // Game_System
  3. //
  4. // The game object class for the system data.
  5. // 游戏系统类
  6. // 游戏对象类 游戏系统对象
  7. function Game_System() {
  8.     this.initialize.apply(this, arguments);
  9. }
  10. // 游戏系统类.初始化
  11. Game_System.prototype.initialize = function() {
  12.     this._saveEnabled = true;         // 游戏系统类.启用保存
  13.     this._menuEnabled = true;         // 游戏系统类.启用菜单
  14.     this._encounterEnabled = true;    // 游戏系统类.启用遇敌
  15.     this._formationEnabled = true;    // 游戏系统类.启用队形
  16.     this._battleCount = 0;            // 游戏系统类.战斗计数器
  17.     this._winCount = 0;               // 游戏系统类.胜利计数器
  18.     this._escapeCount = 0;            // 游戏系统类.逃跑计数器
  19.     this._saveCount = 0;              // 游戏系统类.保存计数器
  20.     this._versionId = 0;              // 游戏系统类.版本号
  21.     this._framesOnSave = 0;           // 游戏系统类.保存的帧
  22.     this._bgmOnSave = null;           // 游戏系统类.保存的BGM
  23.     this._bgsOnSave = null;           // 游戏系统类.保存的BGS
  24.     this._windowTone = null;          // 游戏系统类.窗口色掉
  25.     this._battleBgm = null;           // 游戏系统类.战斗BGM
  26.     this._victoryMe = null;           // 游戏系统类.胜利ME
  27.     this._defeatMe = null;            // 游戏系统类.失败ME
  28.     this._savedBgm = null;            // 游戏系统类.保存BGM音效
  29.     this._walkingBgm = null;          // 游戏系统类.行走BGM
  30. };
  31. // 游戏系统类.是否是日语
  32. Game_System.prototype.isJapanese = function() {
  33.     return $dataSystem.locale.match(/^ja/);
  34. };
  35. // 游戏系统类.是否是中文
  36. Game_System.prototype.isChinese = function() {
  37.     return $dataSystem.locale.match(/^zh/);
  38. };
  39. // 游戏系统类.是否是韩语
  40. Game_System.prototype.isKorean = function() {
  41.     return $dataSystem.locale.match(/^ko/);
  42. };
  43. // 游戏系统类.是否是中日韩语
  44. Game_System.prototype.isCJK = function() {
  45.     return $dataSystem.locale.match(/^(ja|zh|ko)/);
  46. };
  47. // 游戏系统类.是否是俄罗斯语
  48. Game_System.prototype.isRussian = function() {
  49.     return $dataSystem.locale.match(/^ru/);
  50. };
  51. // 游戏系统类.选择侧视图
  52. Game_System.prototype.isSideView = function() {
  53.     return $dataSystem.optSideView;
  54. };
  55. // 游戏系统类.是否启用保存
  56. Game_System.prototype.isSaveEnabled = function() {
  57.     return this._saveEnabled;
  58. };
  59. // 游戏系统类.禁用保存
  60. Game_System.prototype.disableSave = function() {
  61.     this._saveEnabled = false;
  62. };
  63. // 游戏系统类.启用保存
  64. Game_System.prototype.enableSave = function() {
  65.     this._saveEnabled = true;
  66. };
  67. // 游戏系统类.是否启用菜单
  68. Game_System.prototype.isMenuEnabled = function() {
  69.     return this._menuEnabled;
  70. };
  71. // 游戏系统类.禁用菜单
  72. Game_System.prototype.disableMenu = function() {
  73.     this._menuEnabled = false;
  74. };
  75. // 游戏系统类.启用菜单
  76. Game_System.prototype.enableMenu = function() {
  77.     this._menuEnabled = true;
  78. };
  79. // 游戏系统类.是否启用遇敌
  80. Game_System.prototype.isEncounterEnabled = function() {
  81.     return this._encounterEnabled;
  82. };
  83. // 游戏系统类.禁止遇敌
  84. Game_System.prototype.disableEncounter = function() {
  85.     this._encounterEnabled = false;
  86. };
  87. // 游戏系统类.启用遇敌
  88. Game_System.prototype.enableEncounter = function() {
  89.     this._encounterEnabled = true;
  90. };
  91. // 游戏系统类.是否启用队形
  92. Game_System.prototype.isFormationEnabled = function() {
  93.     return this._formationEnabled;
  94. };
  95. // 游戏系统类.禁用队形
  96. Game_System.prototype.disableFormation = function() {
  97.     this._formationEnabled = false;
  98. };
  99. // 游戏系统类.启用队形
  100. Game_System.prototype.enableFormation = function() {
  101.     this._formationEnabled = true;
  102. };
  103. // 游戏系统类.取战斗计数器
  104. Game_System.prototype.battleCount = function() {
  105.     return this._battleCount;
  106. };
  107. // 游戏系统类.取胜利计数器
  108. Game_System.prototype.winCount = function() {
  109.     return this._winCount;
  110. };
  111. // 游戏系统类.取逃跑计数器
  112. Game_System.prototype.escapeCount = function() {
  113.     return this._escapeCount;
  114. };
  115. // 游戏系统类.取保存计数器
  116. Game_System.prototype.saveCount = function() {
  117.     return this._saveCount;
  118. };
  119. // 游戏系统类.取版本号
  120. Game_System.prototype.versionId = function() {
  121.     return this._versionId;
  122. };
  123. // 游戏系统类.取窗口色调
  124. Game_System.prototype.windowTone = function() {
  125.     return this._windowTone || $dataSystem.windowTone;
  126. };
  127. // 游戏系统类.设置窗口色调
  128. Game_System.prototype.setWindowTone = function(value) {
  129.     this._windowTone = value;
  130. };
  131. // 游戏系统类.战斗BGM
  132. Game_System.prototype.battleBgm = function() {
  133.     return this._battleBgm || $dataSystem.battleBgm;
  134. };
  135. // 游戏系统类.设置战斗BGM
  136. Game_System.prototype.setBattleBgm = function(value) {
  137.     this._battleBgm = value;
  138. };
  139. // 游戏系统类.胜利ME
  140. Game_System.prototype.victoryMe = function() {
  141.     return this._victoryMe || $dataSystem.victoryMe;
  142. };
  143. // 游戏系统类.设置胜利ME
  144. Game_System.prototype.setVictoryMe = function(value) {
  145.     this._victoryMe = value;
  146. };
  147. // 游戏系统类.失败ME
  148. Game_System.prototype.defeatMe = function() {
  149.     return this._defeatMe || $dataSystem.defeatMe;
  150. };
  151. // 游戏系统类.设置失败ME
  152. Game_System.prototype.setDefeatMe = function(value) {
  153.     this._defeatMe = value;
  154. };
  155. // 游戏系统类.战斗开始事件
  156. Game_System.prototype.onBattleStart = function() {
  157.     this._battleCount++;
  158. };
  159. // 游戏系统类.战斗胜利事件
  160. Game_System.prototype.onBattleWin = function() {
  161.     this._winCount++;
  162. };
  163. // 游戏系统类.战斗逃跑成功事件
  164. Game_System.prototype.onBattleEscape = function() {
  165.     this._escapeCount++;
  166. };
  167. // 游戏系统类.保存之前事件
  168. Game_System.prototype.onBeforeSave = function() {
  169.     this._saveCount++;                          // 游戏系统类.保存计数器++
  170.     this._versionId = $dataSystem.versionId;    // 游戏系统类.版本号 = $dataSystem.versionId
  171.     this._framesOnSave = Graphics.frameCount;   // 游戏系统类.保存的帧 = 图形.帧计数器
  172.     this._bgmOnSave = AudioManager.saveBgm();   // 游戏系统类.保存的BGM = 音频管理器.保存BGM
  173.     this._bgsOnSave = AudioManager.saveBgs();   // 游戏系统类.保存的BGS = 音频管理器.保存BGS
  174. };
  175. // 游戏系统类.加载之后事件
  176. Game_System.prototype.onAfterLoad = function() {
  177.     Graphics.frameCount = this._framesOnSave;   // 图形.帧计数器 = 游戏系统类.保存的帧
  178.     AudioManager.playBgm(this._bgmOnSave);      // 音频管理器.播放BGM(游戏系统类.保存的BGM)
  179.     AudioManager.playBgs(this._bgsOnSave);      // 音频管理器.播放BGS(游戏系统类.保存的BGS)
  180. };
  181. // 游戏系统类.游戏时间
  182. Game_System.prototype.playtime = function() {
  183.     return Math.floor(Graphics.frameCount / 60);// Math.进行下舍入(图形.帧计数器/60);
  184. };
  185. // 游戏系统类.游戏时间文本
  186. Game_System.prototype.playtimeText = function() {
  187.     var hour = Math.floor(this.playtime() / 60 / 60);  // 取小时
  188.     var min = Math.floor(this.playtime() / 60) % 60;   // 取分钟
  189.     var sec = this.playtime() % 60;                    // 取秒数
  190.     return hour.padZero(2) + ':' + min.padZero(2) + ':' + sec.padZero(2);
  191. };
  192. // 游戏系统类.保存BGM
  193. Game_System.prototype.saveBgm = function() {
  194.     this._savedBgm = AudioManager.saveBgm();    // 游戏系统类.保存的BGM = 音频管理器.保存BGM
  195. };
  196. // 游戏系统类.重播BGM
  197. Game_System.prototype.replayBgm = function() {
  198.     if (this._savedBgm) {
  199.         AudioManager.replayBgm(this._savedBgm);  // 音频管理器.重播BGM(游戏系统类.保存的BGM)
  200.     }
  201. };
  202. // 游戏系统类.保存行走BGM
  203. Game_System.prototype.saveWalkingBgm = function() {
  204.     this._walkingBgm = AudioManager.saveBgm();  // 游戏系统类.行走BGM = 音频管理器.保存BGM
  205. };
  206. // 游戏系统类.重播行走BGM
  207. Game_System.prototype.replayWalkingBgm = function() {
  208.     if (this._walkingBgm) {
  209.         AudioManager.playBgm(this._walkingBgm); // 音频管理器.重播BGM(游戏系统类.行走BGM)
  210.     }
  211. }
  212. ;

3.游戏时间类
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // Game_Timer
  3. //
  4. // The game object class for the timer.
  5. // 游戏时间类
  6. function Game_Timer() {
  7.     this.initialize.apply(this, arguments);
  8. }
  9. // 游戏时间类.初始化
  10. Game_Timer.prototype.initialize = function() {
  11.     this._frames = 0;      // 游戏时间类.帧数
  12.     this._working = false; // 游戏时间类.工作中
  13. };
  14. // 游戏时间类.更新(活动场景)
  15. Game_Timer.prototype.update = function(sceneActive) {
  16.         // 活动场景 非空 且 游戏时间类.工作中  且 游戏时间类.帧数 > 0
  17.     if (sceneActive && this._working && this._frames > 0) {
  18.         this._frames--;            // 游戏时间类.帧数--
  19.         if (this._frames === 0) {  // 游戏时间类.帧数 === 0
  20.             this.onExpire();       // 游戏时间类.到期事件()
  21.         }
  22.     }
  23. };
  24. // 游戏时间类.开始
  25. Game_Timer.prototype.start = function(count) {
  26.     this._frames = count;
  27.     this._working = true;
  28. };
  29. // 游戏时间类.停止
  30. Game_Timer.prototype.stop = function() {
  31.     this._working = false;
  32. };
  33. // 游戏时间类.是否在工作中
  34. Game_Timer.prototype.isWorking = function() {
  35.     return this._working;
  36. };
  37. // 游戏时间类.取分钟数
  38. Game_Timer.prototype.seconds = function() {
  39.     return Math.floor(this._frames / 60);
  40. };
  41. // 游戏时间类.到期事件
  42. Game_Timer.prototype.onExpire = function() {
  43.     BattleManager.abort();   // 战斗管理器.终止
  44. };

4.游戏消息类
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // Game_Message
  3. //
  4. // The game object class for the state of the message window that displays text
  5. // or selections, etc.
  6. // 游戏消息类
  7. // 游戏对象类 显示 状态消息窗口文本或选择等。
  8. function Game_Message() {
  9.     this.initialize.apply(this, arguments);
  10. }
  11. // 游戏消息类.初始化
  12. Game_Message.prototype.initialize = function() {
  13.     this.clear();
  14. };
  15. //---------------------------------------------------------------------------
  16. // 游戏消息类.清除 (整理)
  17. //---------------------------------------------------------------------------
  18. Game_Message.prototype.clear = function() {
  19.         this._choiceCallback = null;           // 游戏消息类.选择项目回调
  20.         //---------------------------------------------------------------------------
  21.         // 事件:显示文章 或 文章的滚动显示
  22.         //---------------------------------------------------------------------------
  23.     this._texts = [];                      // 游戏消息类.文本组
  24.         //---------------------------------------------------------------------------
  25.         // 事件:显示文章
  26.         //---------------------------------------------------------------------------
  27.     this._faceName = '';                   // 游戏消息类.脸部图象名
  28.     this._faceIndex = 0;                   // 游戏消息类.脸部图象索引
  29.     this._background = 0;                  // 游戏消息类.背景
  30.     this._positionType = 2;                // 游戏消息类.位置类型
  31.         //---------------------------------------------------------------------------
  32.         // 事件:文章的滚动显示
  33.         //---------------------------------------------------------------------------
  34.     this._scrollMode = false;              // 游戏消息类.滚动模式
  35.     this._scrollSpeed = 2;                 // 游戏消息类.滚动速度
  36.     this._scrollNoFast = false;            // 游戏消息类.禁止快进
  37.         //---------------------------------------------------------------------------
  38.         // 事件:显示选择项
  39.         //---------------------------------------------------------------------------
  40.         this._choices = [];                    // 游戏消息类.选择项组
  41.     this._choiceDefaultType = 0;           // 游戏消息类.选择默认类型
  42.     this._choiceCancelType = 0;            // 游戏消息类.选择取消类型
  43.     this._choiceBackground = 0;            // 游戏消息类.选择背景
  44.     this._choicePositionType = 2;          // 游戏消息类.选择位置类型
  45.         //---------------------------------------------------------------------------
  46.         // 事件:输入数值处理
  47.         //---------------------------------------------------------------------------
  48.     this._numInputVariableId = 0;          // 游戏消息类.数字输入变量ID
  49.     this._numInputMaxDigits = 0;           // 游戏消息类.数字输入最大位数
  50.         //---------------------------------------------------------------------------
  51.         // 事件:处理道具选择
  52.         //---------------------------------------------------------------------------
  53.     this._itemChoiceVariableId = 0;        // 游戏消息类.道具选择变量Id
  54.     this._itemChoiceItypeId = 0;           // 游戏消息类.道具类型Id
  55. };
  56. // 游戏消息类.取选择项组
  57. Game_Message.prototype.choices = function() {
  58.     return this._choices;
  59. };
  60. // 游戏消息类.取脸部图像名称
  61. Game_Message.prototype.faceName = function() {
  62.     return this._faceName;
  63. };
  64. // 游戏消息类.取脸部图像索引
  65. Game_Message.prototype.faceIndex = function() {
  66.     return this._faceIndex;
  67. };
  68. // 游戏消息类.取背景
  69. Game_Message.prototype.background = function() {
  70.     return this._background;
  71. };
  72. // 游戏消息类.取位置类型
  73. Game_Message.prototype.positionType = function() {
  74.     return this._positionType;
  75. };
  76. // 游戏消息类.取选择默认类型
  77. Game_Message.prototype.choiceDefaultType = function() {
  78.     return this._choiceDefaultType;
  79. };
  80. // 游戏消息类.取选择取消类型
  81. Game_Message.prototype.choiceCancelType = function() {
  82.     return this._choiceCancelType;
  83. };
  84. // 游戏消息类.取选择背景
  85. Game_Message.prototype.choiceBackground = function() {
  86.     return this._choiceBackground;
  87. };
  88. // 游戏消息类.取选择位置类型
  89. Game_Message.prototype.choicePositionType = function() {
  90.     return this._choicePositionType;
  91. };
  92. // 游戏消息类.取数字输入变量ID
  93. Game_Message.prototype.numInputVariableId = function() {
  94.     return this._numInputVariableId;
  95. };
  96. // 游戏消息类.取数字输入最大位数
  97. Game_Message.prototype.numInputMaxDigits = function() {
  98.     return this._numInputMaxDigits;
  99. };
  100. // 游戏消息类.取道具选择变量Id
  101. Game_Message.prototype.itemChoiceVariableId = function() {
  102.     return this._itemChoiceVariableId;
  103. };
  104. // 游戏消息类.取道具选择类型Id
  105. Game_Message.prototype.itemChoiceItypeId = function() {
  106.     return this._itemChoiceItypeId;
  107. };
  108. // 游戏消息类.取滚动模式
  109. Game_Message.prototype.scrollMode = function() {
  110.     return this._scrollMode;
  111. };
  112. // 游戏消息类.取滚动速度
  113. Game_Message.prototype.scrollSpeed = function() {
  114.     return this._scrollSpeed;
  115. };
  116. // 游戏消息类.取是否禁止快进
  117. Game_Message.prototype.scrollNoFast = function() {
  118.     return this._scrollNoFast;
  119. };
  120. // 游戏消息类.添加文本
  121. Game_Message.prototype.add = function(text) {
  122.     this._texts.push(text);  // 游戏消息类.文本组.投递()
  123. };
  124. // 游戏消息类.设置脸部图像
  125. Game_Message.prototype.setFaceImage = function(faceName, faceIndex) {
  126.     this._faceName = faceName;
  127.     this._faceIndex = faceIndex;
  128. };
  129. // 游戏消息类.设置背景
  130. Game_Message.prototype.setBackground = function(background) {
  131.     this._background = background;
  132. };
  133. // 游戏消息类.设置位置模式
  134. Game_Message.prototype.setPositionType = function(positionType) {
  135.     this._positionType = positionType;
  136. };
  137. // 游戏消息类.设置选择
  138. Game_Message.prototype.setChoices = function(choices, defaultType, cancelType) {
  139.     this._choices = choices;
  140.     this._choiceDefaultType = defaultType;
  141.     this._choiceCancelType = cancelType;
  142. };
  143. // 游戏消息类.设置选择背景
  144. Game_Message.prototype.setChoiceBackground = function(background) {
  145.     this._choiceBackground = background;
  146. };
  147. // 游戏消息类.设置选择位置
  148. Game_Message.prototype.setChoicePositionType = function(positionType) {
  149.     this._choicePositionType = positionType;
  150. };
  151. // 游戏消息类.设置数字输入
  152. Game_Message.prototype.setNumberInput = function(variableId, maxDigits) {
  153.     this._numInputVariableId = variableId;
  154.     this._numInputMaxDigits = maxDigits;
  155. };
  156. // 游戏消息类.设置道具选择
  157. Game_Message.prototype.setItemChoice = function(variableId, itemType) {
  158.     this._itemChoiceVariableId = variableId;
  159.     this._itemChoiceItypeId = itemType;
  160. };
  161. // 游戏消息类.设置文章的滚动显示
  162. Game_Message.prototype.setScroll = function(speed, noFast) {
  163.     this._scrollMode = true;
  164.     this._scrollSpeed = speed;
  165.     this._scrollNoFast = noFast;
  166. };
  167. // 游戏消息类.设置选择回调
  168. Game_Message.prototype.setChoiceCallback = function(callback) {
  169.     this._choiceCallback = callback;
  170. };
  171. // 游戏消息类.选择事件
  172. Game_Message.prototype.onChoice = function(n) {
  173.     if (this._choiceCallback) {
  174.         this._choiceCallback(n);
  175.         this._choiceCallback = null;
  176.     }
  177. };
  178. // 游戏消息类.是否存在文本
  179. Game_Message.prototype.hasText = function() {
  180.     return this._texts.length > 0;
  181. };
  182. // 游戏消息类.是否是显示选择项
  183. Game_Message.prototype.isChoice = function() {
  184.     return this._choices.length > 0;
  185. };
  186. // 游戏消息类.是否是数字输入
  187. Game_Message.prototype.isNumberInput = function() {
  188.     return this._numInputVariableId > 0;
  189. };
  190. // 游戏消息类.是否是道具选择
  191. Game_Message.prototype.isItemChoice = function() {
  192.     return this._itemChoiceVariableId > 0;
  193. };
  194. // 游戏消息类.是否被占用
  195. Game_Message.prototype.isBusy = function() {
  196.     return (this.hasText() || this.isChoice() ||
  197.             this.isNumberInput() || this.isItemChoice());
  198. };
  199. // 游戏消息类.新建页面
  200. Game_Message.prototype.newPage = function() {
  201.     if (this._texts.length > 0) {
  202.         this._texts[this._texts.length - 1] += '\f';
  203.     }
  204. };
  205. // 游戏消息类.取全部文本
  206. Game_Message.prototype.allText = function() {
  207.     return this._texts.reduce(function(previousValue, currentValue) {
  208.         return previousValue + '\n' + currentValue;
  209.     });
  210. };

5.游戏开关类
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // Game_Switches
  3. //
  4. // The game object class for switches.
  5. // 游戏开关类
  6.  
  7. function Game_Switches() {
  8.     this.initialize.apply(this, arguments);
  9. }
  10. // 游戏开关类.初始化
  11. Game_Switches.prototype.initialize = function() {
  12.     this.clear();
  13. };
  14. // 游戏开关类.清除
  15. Game_Switches.prototype.clear = function() {
  16.     this._data = [];
  17. };
  18. // 游戏开关类.取值
  19. Game_Switches.prototype.value = function(switchId) {
  20.     return !!this._data[switchId];
  21. };
  22. // 游戏开关类.设置值
  23. Game_Switches.prototype.setValue = function(switchId, value) {
  24.     if (switchId > 0 && switchId < $dataSystem.switches.length) {
  25.         this._data[switchId] = value;
  26.         this.onChange();
  27.     }
  28. };
  29. // 游戏开关类.改变值事件
  30. Game_Switches.prototype.onChange = function() {
  31.     $gameMap.requestRefresh();
  32. };

6.游戏变量类
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // Game_Variables
  3. //
  4. // The game object class for variables.
  5. // 游戏变量类
  6.  
  7. function Game_Variables() {
  8.     this.initialize.apply(this, arguments);
  9. }
  10. // 游戏变量类.初始化
  11. Game_Variables.prototype.initialize = function() {
  12.     this.clear();
  13. };
  14. // 游戏变量类.清除
  15. Game_Variables.prototype.clear = function() {
  16.     this._data = [];
  17. };
  18. // 游戏变量类.取值
  19. Game_Variables.prototype.value = function(variableId) {
  20.     return this._data[variableId] || 0;
  21. };
  22. // 游戏变量类.设置值
  23. Game_Variables.prototype.setValue = function(variableId, value) {
  24.     if (variableId > 0 && variableId < $dataSystem.variables.length) {
  25.         if (typeof value === 'number') {
  26.             value = Math.floor(value);
  27.         }
  28.         this._data[variableId] = value;
  29.         this.onChange();
  30.     }
  31. };
  32. // 游戏变量类.改变值事件
  33. Game_Variables.prototype.onChange = function() {
  34.     $gameMap.requestRefresh();
  35. };

7.游戏独立开关类
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // Game_SelfSwitches
  3. //
  4. // The game object class for self switches.
  5. // 游戏独立开关类
  6.  
  7. function Game_SelfSwitches() {
  8.     this.initialize.apply(this, arguments);
  9. }
  10. // 游戏独立开关类.初始化
  11. Game_SelfSwitches.prototype.initialize = function() {
  12.     this.clear();
  13. };
  14. // 游戏独立开关类.清除
  15. Game_SelfSwitches.prototype.clear = function() {
  16.     this._data = {};
  17. };
  18. // 游戏独立变量类.取值
  19. Game_SelfSwitches.prototype.value = function(key) {
  20.     return !!this._data[key];
  21. };
  22. // 游戏独立开关类.设置值
  23. Game_SelfSwitches.prototype.setValue = function(key, value) {
  24.     if (value) {
  25.         this._data[key] = true;
  26.     } else {
  27.         delete this._data[key];
  28.     }
  29.     this.onChange();
  30. };
  31. // 游戏独立开关类.改变值事件
  32. Game_SelfSwitches.prototype.onChange = function() {
  33.     $gameMap.requestRefresh();
  34. };

8.游戏屏幕类(本类最后几个没有翻译,准备睡觉了,每天开车跑长途,停更2天。)
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // Game_Screen
  3. //
  4. // The game object class for screen effect data, such as changes in color tone
  5. // and flashes.
  6. // 游戏屏幕类
  7. // 游戏屏幕效果数据对象类,如色调的变化和闪光。
  8.  
  9. function Game_Screen() {
  10.     this.initialize.apply(this, arguments);
  11. }
  12. // 游戏屏幕类.初始化
  13. Game_Screen.prototype.initialize = function() {
  14.     this.clear();
  15. };
  16. // 游戏屏幕类.清除
  17. Game_Screen.prototype.clear = function() {
  18.     this.clearFade();         // 游戏屏幕类.清除淡入淡出
  19.     this.clearTone();         // 游戏屏幕类.清除色调
  20.     this.clearFlash();        // 游戏屏幕类.清除闪烁
  21.     this.clearShake();        // 游戏屏幕类.清除震动
  22.     this.clearZoom();         // 游戏屏幕类.清除放大
  23.     this.clearWeather();      // 游戏屏幕类.清除天气
  24.     this.clearPictures();     // 游戏屏幕类.清除图片组
  25. };
  26. // 游戏屏幕类.战斗开始事件
  27. Game_Screen.prototype.onBattleStart = function() {
  28.     this.clearFade();         // 游戏屏幕类.清除淡入淡出
  29.     this.clearFlash();        // 游戏屏幕类.清除闪烁
  30.     this.clearShake();        // 游戏屏幕类.清除震动
  31.     this.clearZoom();         // 游戏屏幕类.清除放大
  32.     this.eraseBattlePictures(); // 游戏屏幕类.擦除战斗图像
  33. };
  34. // 游戏屏幕类.取亮度
  35. Game_Screen.prototype.brightness = function() {
  36.     return this._brightness;
  37. };
  38. // 游戏屏幕类.取色调
  39. Game_Screen.prototype.tone = function() {
  40.     return this._tone;
  41. };
  42. // 游戏屏幕类.取闪烁颜色
  43. Game_Screen.prototype.flashColor = function() {
  44.     return this._flashColor;
  45. };
  46. // 游戏屏幕类.取震动
  47. Game_Screen.prototype.shake = function() {
  48.     return this._shake;
  49. };
  50. // 游戏屏幕类.取放大X
  51. Game_Screen.prototype.zoomX = function() {
  52.     return this._zoomX;
  53. };
  54. // 游戏屏幕类.取放大Y
  55. Game_Screen.prototype.zoomY = function() {
  56.     return this._zoomY;
  57. };
  58. // 游戏屏幕类.取放大比例
  59. Game_Screen.prototype.zoomScale = function() {
  60.     return this._zoomScale;
  61. };
  62. // 游戏屏幕类.取天气类型
  63. Game_Screen.prototype.weatherType = function() {
  64.     return this._weatherType;
  65. };
  66. // 游戏屏幕类.取天气强度
  67. Game_Screen.prototype.weatherPower = function() {
  68.     return this._weatherPower;
  69. };
  70. // 游戏屏幕类.取图片
  71. Game_Screen.prototype.picture = function(pictureId) {
  72.     var realPictureId = this.realPictureId(pictureId);  // 游戏屏幕类.取图片真实ID(图片ID)
  73.     return this._pictures[realPictureId];               // 游戏屏幕类.图片组[图片真实ID]
  74. };
  75. // 游戏屏幕类.取图片真实ID
  76. Game_Screen.prototype.realPictureId = function(pictureId) {
  77.     if ($gameParty.inBattle()) {               // 游戏队伍类.在战斗中
  78.         return pictureId + this.maxPictures(); // 图片ID + 游戏屏幕类.取最大图片数量()
  79.     } else {
  80.         return pictureId;                      // 直接返回 图片ID
  81.     }
  82. };
  83. // 游戏屏幕类.清除淡入淡出
  84. Game_Screen.prototype.clearFade = function() {
  85.     this._brightness = 255;        // 游戏屏幕类.亮度 = 255
  86.     this._fadeOutDuration = 0;     // 游戏屏幕类.淡出持续时间 = 0
  87.     this._fadeInDuration = 0;      // 游戏屏幕类.淡入持续时间 = 0
  88. };
  89. // 游戏屏幕类.清除色调
  90. Game_Screen.prototype.clearTone = function() {
  91.     this._tone = [0, 0, 0, 0];         // 游戏屏幕类.当前色调 = [R, G, B, 灰度]
  92.     this._toneTarget = [0, 0, 0, 0];   // 游戏屏幕类.目标色调 = [R, G, B, 灰度]
  93.     this._toneDuration = 0;            // 游戏屏幕类.渐变转换需求时间 = 0
  94. };
  95. // 游戏屏幕类.清除闪烁
  96. Game_Screen.prototype.clearFlash = function() {
  97.     this._flashColor = [0, 0, 0, 0];   // 游戏屏幕类.闪烁颜色 = [R, G, B, 强度]
  98.     this._flashDuration = 0;           // 游戏屏幕类.持续时间 = 0
  99. };
  100. // 游戏屏幕类.清除震动
  101. Game_Screen.prototype.clearShake = function() {
  102.     this._shakePower = 0;              // 游戏屏幕类.震动强度 = 0
  103.     this._shakeSpeed = 0;              // 游戏屏幕类.震动速度 = 0
  104.     this._shakeDuration = 0;           // 游戏屏幕类.持续时间 = 0
  105.     this._shakeDirection = 1;          // 游戏屏幕类.震动方向 = 1
  106.     this._shake = 0;                   // 游戏屏幕类.震动 = 0
  107. };
  108. // 游戏屏幕类.清除放大
  109. Game_Screen.prototype.clearZoom = function() {
  110.     this._zoomX = 0;                   // 游戏屏幕类.放大X = 0
  111.     this._zoomY = 0;                   // 游戏屏幕类.放大Y = 0
  112.     this._zoomScale = 1;               // 游戏屏幕类.当前放大比例 = 1
  113.     this._zoomScaleTarget = 1;         // 游戏屏幕类.目标放大比例 = 1
  114.     this._zoomDuration = 0;            // 游戏屏幕类.放大转换需求时间 = 0
  115. };
  116. // 游戏屏幕类.清除天气
  117. Game_Screen.prototype.clearWeather = function() {
  118.     this._weatherType = 'none';        // 游戏屏幕类.天气类型 = "none"
  119.     this._weatherPower = 0;            // 游戏屏幕类.天气当前强度 = 0
  120.     this._weatherPowerTarget = 0;      // 游戏屏幕类.天气目标强度 = 0
  121.     this._weatherDuration = 0;         // 游戏屏幕类.转换天气需求时间 = 0
  122. };
  123. // 游戏屏幕类.清除图片组
  124. Game_Screen.prototype.clearPictures = function() {
  125.     this._pictures = [];
  126. };
  127. // 游戏屏幕类.擦除战斗图像
  128. Game_Screen.prototype.eraseBattlePictures = function() {
  129.     this._pictures = this._pictures.slice(0, this.maxPictures() + 1);
  130. };
  131. // 游戏屏幕类.取最大图片数量
  132. Game_Screen.prototype.maxPictures = function() {
  133.     return 100;
  134. };
  135. // 游戏屏幕类.开始淡出
  136. Game_Screen.prototype.startFadeOut = function(duration) {
  137.     this._fadeOutDuration = duration;      // 游戏屏幕类.淡出持续时间 = 持续时间
  138.     this._fadeInDuration = 0;              // 游戏屏幕类.淡入持续时间 = 0
  139. };
  140. // 游戏屏幕类.开始淡入
  141. Game_Screen.prototype.startFadeIn = function(duration) {
  142.     this._fadeInDuration = duration;      // 游戏屏幕类.淡入持续时间 = 持续时间
  143.     this._fadeOutDuration = 0;            // 游戏屏幕类.淡出持续时间 = 0
  144. };
  145. // 游戏屏幕类.开始染色(修改色调)
  146. Game_Screen.prototype.startTint = function(tone, duration) {
  147.     this._toneTarget = tone.clone();           // 游戏屏幕类.目标色调
  148.     this._toneDuration = duration;             // 游戏屏幕类.渐变转换需求时间
  149.     if (this._toneDuration === 0) {            // 游戏屏幕类.渐变转换需求时间 === 0
  150.         this._tone = this._toneTarget.clone(); // 游戏屏幕类.当前色调 = 游戏屏幕类.目标色调
  151.     }
  152. };
  153. // 游戏屏幕类.开始闪烁
  154. Game_Screen.prototype.startFlash = function(color, duration) {
  155.     this._flashColor = color.clone();  // 游戏屏幕类.闪烁颜色
  156.     this._flashDuration = duration;    // 游戏屏幕类.持续时间
  157. };
  158. // 游戏屏幕类.开始震动
  159. Game_Screen.prototype.startShake = function(power, speed, duration) {
  160.     this._shakePower = power;           // 游戏屏幕类.震动强度
  161.     this._shakeSpeed = speed;           // 游戏屏幕类.震动速度
  162.     this._shakeDuration = duration;     // 游戏屏幕类.震动持续时间
  163. };
  164. // 游戏屏幕类.开始放大
  165. Game_Screen.prototype.startZoom = function(x, y, scale, duration) {
  166.     this._zoomX = x;                    // 游戏屏幕类.放大X
  167.     this._zoomY = y;                    // 游戏屏幕类.放大Y
  168.     this._zoomScaleTarget = scale;      // 游戏屏幕类.放大目标比例
  169.     this._zoomDuration = duration;      // 游戏屏幕类.放大需求转换时间
  170. };
  171. // 游戏屏幕类.设置放大
  172. Game_Screen.prototype.setZoom = function(x, y, scale) {
  173.     this._zoomX = x;                    // 游戏屏幕类.放大X
  174.     this._zoomY = y;                    // 游戏屏幕类.放大Y
  175.     this._zoomScale = scale;            // 游戏屏幕类.放大比例
  176. };
  177. // 游戏屏幕类.改变天气
  178. Game_Screen.prototype.changeWeather = function(type, power, duration) {
  179.     if (type !== 'none' || duration === 0) {                 // 如果预设置天气非none 且 持续时间 === 0
  180.         this._weatherType = type;                            // 游戏屏幕类.天气类型
  181.     }
  182.     this._weatherPowerTarget = type === 'none' ? 0 : power;  // 游戏屏幕类.天气目标强度
  183.     this._weatherDuration = duration;                        // 游戏屏幕类.转换天气需求时间
  184.     if (duration === 0) {
  185.         this._weatherPower = this._weatherPowerTarget;       // 游戏屏幕类.天气当前强度 = 游戏屏幕类.天气目标强度
  186.     }
  187. };
  188. // 游戏屏幕类.刷新
  189. Game_Screen.prototype.update = function() {
  190.     this.updateFadeOut();  // 游戏屏幕类.刷新淡出
  191.     this.updateFadeIn();   // 游戏屏幕类.刷新淡入
  192.     this.updateTone();     // 游戏屏幕类.刷新色调
  193.     this.updateFlash();    // 游戏屏幕类.刷新闪烁
  194.     this.updateShake();    // 游戏屏幕类.刷新震动
  195.     this.updateZoom();     // 游戏屏幕类.刷新放大
  196.     this.updateWeather();  // 游戏屏幕类.刷新天气
  197.     this.updatePictures(); // 游戏屏幕类.刷新图片
  198. };
  199. // 游戏屏幕类.刷新淡出
  200. Game_Screen.prototype.updateFadeOut = function() {
  201.     if (this._fadeOutDuration > 0) {                         // 游戏屏幕类.淡出持续时间 > 0
  202.         var d = this._fadeOutDuration;                       
  203.         this._brightness = (this._brightness * (d - 1)) / d; // 游戏屏幕类.亮度
  204.         this._fadeOutDuration--;                             // 游戏屏幕类.淡出持续时间--
  205.     }
  206. };
  207. // 游戏屏幕类.刷新淡入
  208. Game_Screen.prototype.updateFadeIn = function() {
  209.     if (this._fadeInDuration > 0) {                                // 游戏屏幕类.淡入持续时间 > 0
  210.         var d = this._fadeInDuration;
  211.         this._brightness = (this._brightness * (d - 1) + 255) / d; // 游戏屏幕类.亮度
  212.         this._fadeInDuration--;                                    // 游戏屏幕类.淡入持续时间--
  213.     }
  214. };
  215. // 游戏屏幕类.刷新色调
  216. Game_Screen.prototype.updateTone = function() {
  217.     if (this._toneDuration > 0) {                                  // 游戏屏幕类.渐变转换需求时间 > 0
  218.         var d = this._toneDuration;
  219.                 // 修正[RGB&灰度](数学战五渣 不译...)
  220.         for (var i = 0; i < 4; i++) {
  221.             this._tone[i] = (this._tone[i] * (d - 1) + this._toneTarget[i]) / d;
  222.         }
  223.         this._toneDuration--;                                      // 游戏屏幕类.渐变转换需求时间--
  224.     }
  225. };
  226. // 游戏屏幕类.刷新闪烁
  227. Game_Screen.prototype.updateFlash = function() {
  228.     if (this._flashDuration > 0) {                                 // 游戏屏幕类.闪烁持续时间 > 0
  229.         var d = this._flashDuration;                              
  230.         this._flashColor[3] *= (d - 1) / d;                        // 闪烁强度算法
  231.         this._flashDuration--;                                     // 游戏屏幕类.闪烁持续时间--
  232.     }
  233. };
  234. // 游戏屏幕类.刷新震动
  235. Game_Screen.prototype.updateShake = function() {
  236.     if (this._shakeDuration > 0 || this._shake !== 0) {
  237.         var delta = (this._shakePower * this._shakeSpeed * this._shakeDirection) / 10;
  238.         if (this._shakeDuration <= 1 && this._shake * (this._shake + delta) < 0) {
  239.             this._shake = 0;
  240.         } else {
  241.             this._shake += delta;
  242.         }
  243.         if (this._shake > this._shakePower * 2) {
  244.             this._shakeDirection = -1;
  245.         }
  246.         if (this._shake < - this._shakePower * 2) {
  247.             this._shakeDirection = 1;
  248.         }
  249.         this._shakeDuration--;
  250.     }
  251. };
  252. // 游戏屏幕类.刷新放大
  253. Game_Screen.prototype.updateZoom = function() {
  254.     if (this._zoomDuration > 0) {
  255.         var d = this._zoomDuration;
  256.         var t = this._zoomScaleTarget;
  257.         this._zoomScale = (this._zoomScale * (d - 1) + t) / d;
  258.         this._zoomDuration--;
  259.     }
  260. };
  261. // 游戏屏幕类.刷新天气
  262. Game_Screen.prototype.updateWeather = function() {
  263.     if (this._weatherDuration > 0) {
  264.         var d = this._weatherDuration;
  265.         var t = this._weatherPowerTarget;
  266.         this._weatherPower = (this._weatherPower * (d - 1) + t) / d;
  267.         this._weatherDuration--;
  268.         if (this._weatherDuration === 0 && this._weatherPowerTarget === 0) {
  269.             this._weatherType = 'none';
  270.         }
  271.     }
  272. };
  273. // 游戏屏幕类.刷新图片
  274. Game_Screen.prototype.updatePictures = function() {
  275.     this._pictures.forEach(function(picture) {
  276.         if (picture) {
  277.             picture.update();
  278.         }
  279.     });
  280. };
  281. // 游戏屏幕类.开始伤害[事件]闪烁
  282. Game_Screen.prototype.startFlashForDamage = function() {
  283.     this.startFlash([255, 0, 0, 128], 8);  // 红色 [0-128] 强度 闪烁8帧
  284. };
  285. // 游戏屏幕类.显示图片
  286. Game_Screen.prototype.showPicture = function(pictureId, name, origin, x, y,
  287.                                              scaleX, scaleY, opacity, blendMode) {
  288.     var realPictureId = this.realPictureId(pictureId);
  289.     var picture = new Game_Picture();
  290.     picture.show(name, origin, x, y, scaleX, scaleY, opacity, blendMode);
  291.     this._pictures[realPictureId] = picture;
  292. };
  293. // 游戏屏幕类.移动图片
  294. Game_Screen.prototype.movePicture = function(pictureId, origin, x, y, scaleX,
  295.                                              scaleY, opacity, blendMode, duration) {
  296.     var picture = this.picture(pictureId);
  297.     if (picture) {
  298.         picture.move(origin, x, y, scaleX, scaleY, opacity, blendMode, duration);
  299.     }
  300. };
  301. // 游戏屏幕类.旋转图片
  302. Game_Screen.prototype.rotatePicture = function(pictureId, speed) {
  303.     var picture = this.picture(pictureId);
  304.     if (picture) {
  305.         picture.rotate(speed);
  306.     }
  307. };
  308. // 游戏屏幕类.修改图片色调
  309. Game_Screen.prototype.tintPicture = function(pictureId, tone, duration) {
  310.     var picture = this.picture(pictureId);
  311.     if (picture) {
  312.         picture.tint(tone, duration);
  313.     }
  314. };
  315. // 游戏屏幕类.清除图片
  316. Game_Screen.prototype.erasePicture = function(pictureId) {
  317.     var realPictureId = this.realPictureId(pictureId);
  318.     this._pictures[realPictureId] = null;
  319. };


1.数据管理器类
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // DataManager
  3. //
  4. // The static class that manages the database and game objects.
  5. // 数据管理器
  6. // 静态类 管理数据库与游戏对象
  7. function DataManager() {
  8.     throw new Error('This is a static class');              // 当实例化时抛出异常
  9. }
  10. // JSON 数据库
  11. var $dataActors       = null; // 角色数据
  12. var $dataClasses      = null; // 职业数据
  13. var $dataSkills       = null; // 特技/技能数据
  14. var $dataItems        = null; // 物品数据
  15. var $dataWeapons      = null; // 武器数据
  16. var $dataArmors       = null; // 防具数据
  17. var $dataEnemies      = null; // 敌人数据
  18. var $dataTroops       = null; // 敌群数据
  19. var $dataStates       = null; // 状态数据
  20. var $dataAnimations   = null; // 动画数据
  21. var $dataTilesets     = null; // 图块组数据
  22. var $dataCommonEvents = null; // 公共事件数据
  23. var $dataSystem       = null; // 系统数据
  24. var $dataMapInfos     = null; // 地图信息数据
  25. var $dataMap          = null; // 地图数据
  26. // 类全局变量 与 RGSS 很相似
  27. var $gameTemp         = null; // Game_Temp         类 游戏临时数据类
  28. var $gameSystem       = null; // Game_System       类 游戏系统类
  29. var $gameScreen       = null; // Game_Screen       类 游戏屏幕类
  30. var $gameTimer        = null; // Game_Time         类 游戏时间类
  31. var $gameMessage      = null; // Game_Message      类 游戏消息类 (不知道是不是 WINDOWS 消息 想想也不是 人家都跨平台了。。。我又想起了 C++)
  32. var $gameSwitches     = null; // Game_Switches     类 游戏开关类
  33. var $gameVariables    = null; // Game_Variables    类 游戏变量类
  34. var $gameSelfSwitches = null; // Game_SelfSwitches 类 游戏独立开关类
  35. var $gameActors       = null; // Game_Actors       类 游戏角色组类
  36. var $gameParty        = null; // Game_Party        类 游戏队伍类
  37. var $gameTroop        = null; // Game_Troop        类 游戏敌群类
  38. var $gameMap          = null; // Game_Map          类 游戏地图类
  39. var $gamePlayer       = null; // Game_Player       类 游戏玩家类
  40.  
  41. var $testEvent        = null; // testEvent         类 测试事件类
  42.  
  43.  
  44. DataManager._globalId       = 'RPGMV';   // 数据管理器.全局ID
  45. DataManager._lastAccessedId = 1;         // 数据管理器.最后数据ID
  46. DataManager._errorUrl       = null;      // 数据管理器.错误网络地址
  47.  
  48. // 数据管理器(JSON)
  49. DataManager._databaseFiles = [
  50.     { name: '$dataActors',       src: 'Actors.json'       },
  51.     { name: '$dataClasses',      src: 'Classes.json'      },
  52.     { name: '$dataSkills',       src: 'Skills.json'       },
  53.     { name: '$dataItems',        src: 'Items.json'        },
  54.     { name: '$dataWeapons',      src: 'Weapons.json'      },
  55.     { name: '$dataArmors',       src: 'Armors.json'       },
  56.     { name: '$dataEnemies',      src: 'Enemies.json'      },
  57.     { name: '$dataTroops',       src: 'Troops.json'       },
  58.     { name: '$dataStates',       src: 'States.json'       },
  59.     { name: '$dataAnimations',   src: 'Animations.json'   },
  60.     { name: '$dataTilesets',     src: 'Tilesets.json'     },
  61.     { name: '$dataCommonEvents', src: 'CommonEvents.json' },
  62.     { name: '$dataSystem',       src: 'System.json'       },
  63.     { name: '$dataMapInfos',     src: 'MapInfos.json'     }
  64. ];
  65. // 数据管理器.加载数据库
  66. DataManager.loadDatabase = function() {
  67.     var test = this.isBattleTest() || this.isEventTest();   // 是否战斗测试 或 事件测试
  68.     var prefix = test ? 'Test_' : '';                       // 前缀
  69.         // 循环遍历数据库文件组
  70.     for (var i = 0; i < this._databaseFiles.length; i++) {
  71.         var name = this._databaseFiles[i].name;   // 数据库名称
  72.         var src = this._databaseFiles[i].src;     // 数据库源
  73.         this.loadDataFile(name, prefix + src);    // 加载数据文件(数据库名称, 数据库源)
  74.     }
  75.     if (this.isEventTest()) {                     // 是否战斗测试?
  76.         this.loadDataFile('$testEvent', prefix + 'Event.json');   // 加载测试事件数据
  77.     }
  78. };
  79. // 数据管理器.加载数据文件
  80. DataManager.loadDataFile = function(name, src) {
  81.     var xhr = new XMLHttpRequest();             // 实例化 XML HTTP 请求
  82.     var url = 'data/' + src;                    // 数据库文件路径
  83.     xhr.open('GET', url);                       // GET 请求
  84.     xhr.overrideMimeType('application/json');   // 将响应数据 转换置 JSON
  85.     xhr.onload = function() {                   // 请求数据全部加载完毕事件
  86.         if (xhr.status < 400) {                 // 判断 HTTP 状态码(具体百度HTTP状态码)
  87.             window[name] = JSON.parse(xhr.responseText); // JSON 解析(请求返回的JSON 格式数据)
  88.             DataManager.onLoad(window[name]);            // 调用->数据管理器.加载事件
  89.         }
  90.     };
  91.     xhr.onerror = function() {                  // 请求数据时发生错误
  92.         DataManager._errorUrl = DataManager._errorUrl || url;
  93.     };
  94.     window[name] = null;                        // 初始化 window[name]
  95.     xhr.send();                                 // 发送请求
  96. };
  97. // 数据管理器.数据库是否已经加载
  98. DataManager.isDatabaseLoaded = function() {
  99.     this.checkError();                          // 数据管理器.检查错误
  100.         // 循环遍历数据库文件组
  101.     for (var i = 0; i < this._databaseFiles.length; i++) {
  102.         if (!window[this._databaseFiles[i].name]) {
  103.             return false;
  104.         }
  105.     }
  106.     return true;
  107. };
  108. // 数据管理器.加载地图数据
  109. DataManager.loadMapData = function(mapId) {
  110.     if (mapId > 0) {
  111.         var filename = 'Map%1.json'.format(mapId.padZero(3));    // 格式化成  Map000.json (如果需要修正地图上限估计需要修改此处吧)
  112.         this.loadDataFile('$dataMap', filename);                 // 加载地图数据
  113.     } else {
  114.         this.makeEmptyMap();    // 制一个空地图
  115.     }
  116. };
  117. // 数据管理器.制作一个空地图(100*100)
  118. DataManager.makeEmptyMap = function() {
  119.     $dataMap = {};
  120.     $dataMap.data = [];
  121.     $dataMap.events = [];
  122.     $dataMap.width = 100;
  123.     $dataMap.height = 100;
  124.     $dataMap.scrollType = 3;
  125. };
  126. // 数据管理器.地图是否已经加载
  127. DataManager.isMapLoaded = function() {
  128.     this.checkError();          // 数据管理器.检查错误
  129.     return !!$dataMap;
  130. };
  131. // 数据管理器.加载事件
  132. DataManager.onLoad = function(object) {
  133.     var array;
  134.     if (object === $dataMap) {             // 如果是地图数据
  135.         this.extractMetadata(object);      // 数据管理器.提取元数据()
  136.         array = object.events;             // array = 地图事件数据组
  137.     } else {
  138.         array = object;
  139.     }
  140.     if (Array.isArray(array)) {            // 判断是否为数组
  141.         for (var i = 0; i < array.length; i++) {   // 遍历数组
  142.             var data = array[i];
  143.             if (data && data.note !== undefined) {
  144.                 this.extractMetadata(data);   // 数据管理器.提取元数据()
  145.             }
  146.         }
  147.     }
  148. };
  149. // 数据管理器.提取元数据() <元数据都在注释里>
  150. DataManager.extractMetadata = function(data) {
  151.         // 举个简单的元数据格式 <tool:rmmv>
  152.     var re = /<([^<>:]+)(:?)([^>]*)>/g;   // 全局匹配
  153.     data.meta = {};
  154.     for (;;) {
  155.         var match = re.exec(data.note);   // 匹配
  156.         if (match) {
  157.             if (match[2] === ':') {
  158.                 data.meta[match[1]] = match[3];  // data.meta["tool"] = rmmv;
  159.             } else {
  160.                 data.meta[match[1]] = true;      // 缺省时表示为 bool 且值 为 true
  161.             }
  162.         } else {
  163.             break;
  164.         }
  165.     }
  166. };
  167. // 数据管理器.检查错误
  168. DataManager.checkError = function() {
  169.     if (DataManager._errorUrl) {
  170.         throw new Error('Failed to load: ' + DataManager._errorUrl);
  171.     }
  172. };
  173. // 数据管理器.是否为战斗测试
  174. DataManager.isBattleTest = function() {
  175.     return Utils.isOptionValid('btest');
  176. };
  177. // 数据管理器.是否为事件测试
  178. DataManager.isEventTest = function() {
  179.     return Utils.isOptionValid('etest');
  180. };
  181. // 数据管理器.是否为特技数据
  182. DataManager.isSkill = function(item) {
  183.     return item && $dataSkills.contains(item);
  184. };
  185. // 数据管理器.是否为物品数据
  186. DataManager.isItem = function(item) {
  187.     return item && $dataItems.contains(item);
  188. };
  189. // 数据管理器.是否为武器数据
  190. DataManager.isWeapon = function(item) {
  191.     return item && $dataWeapons.contains(item);
  192. };
  193. // 数据管理器.是否为防具数据
  194. DataManager.isArmor = function(item) {
  195.     return item && $dataArmors.contains(item);
  196. };
  197. // 数据管理器.创建游戏对象
  198. DataManager.createGameObjects = function() {
  199.     $gameTemp          = new Game_Temp();         // Game_Temp         类 游戏临时数据类
  200.     $gameSystem        = new Game_System();       // Game_System       类 游戏系统类
  201.     $gameScreen        = new Game_Screen();       // Game_Screen       类 游戏屏幕类
  202.     $gameTimer         = new Game_Timer();        // Game_Time         类 游戏时间类
  203.     $gameMessage       = new Game_Message();      // Game_Message      类 游戏消息类
  204.     $gameSwitches      = new Game_Switches();     // Game_Switches     类 游戏开关类
  205.     $gameVariables     = new Game_Variables();    // Game_Variables    类 游戏变量类
  206.     $gameSelfSwitches  = new Game_SelfSwitches(); // Game_SelfSwitches 类 游戏独立开关类
  207.     $gameActors        = new Game_Actors();       // Game_Actors       类 游戏角色组类
  208.     $gameParty         = new Game_Party();        // Game_Party        类 游戏队伍类
  209.     $gameTroop         = new Game_Troop();        // Game_Troop        类 游戏敌群类
  210.     $gameMap           = new Game_Map();          // Game_Map          类 游戏地图类
  211.     $gamePlayer        = new Game_Player();       // Game_Player       类 游戏玩家类
  212. };
  213. // 数据管理器.开始新游戏
  214. DataManager.setupNewGame = function() {
  215.     this.createGameObjects();              // 数据管理器.创建游戏对象
  216.     this.selectSavefileForNewGame();       // 数据管理器.选择保存文件从新游戏????
  217.     $gameParty.setupStartingMembers();     // 游戏队伍类.设置开始成员
  218.     $gamePlayer.reserveTransfer($dataSystem.startMapId, $dataSystem.startX, $dataSystem.startY);     // 游戏玩家类.复位传送至(系统数据.开始地图ID, 系统数据.开始X坐标, 系统数据.开始Y坐标)
  219.     Graphics.frameCount = 0;               // Graphics(图形).帧数初始化为0
  220. };
  221. // 数据管理器.设置战斗测试
  222. DataManager.setupBattleTest = function() {
  223.     this.createGameObjects();              // 数据管理器.创建游戏对象
  224.     $gameParty.setupBattleTest();          // 游戏队伍类.设置战斗测试
  225.     BattleManager.setup($dataSystem.testTroopId, true, false);  // 战斗管理器.设置(系统数据类.测试队伍ID)
  226.     BattleManager.setBattleTest(true);     // 战斗管理器.设置战斗测试(true)
  227.     BattleManager.playBattleBgm();         // 战斗管理器.播放战斗BGM
  228. };
  229. // 数据管理器.设置事件测试
  230. DataManager.setupEventTest = function() {
  231.     this.createGameObjects();              // 数据管理器.创建游戏对象
  232.     this.selectSavefileForNewGame();       // 数据管理器.选择保存文件从新游戏????
  233.     $gameParty.setupStartingMembers();     // 游戏队伍类.设置开始成员
  234.     $gamePlayer.reserveTransfer(-1, 8, 6); // 游戏玩家类.复位传送至(-1, 8, 6)
  235.     $gamePlayer.setTransparent(false);     // 游戏玩家类.设置透明(false)
  236. };
  237. // 数据管理器.加载全局信息
  238. DataManager.loadGlobalInfo = function() {
  239.     var json;
  240.     try {
  241.         json = StorageManager.load(0);    // 存储管理器.加载()
  242.     } catch (e) {
  243.         console.error(e);                 // 控制台.输出错误信息
  244.         return [];
  245.     }
  246.     if (json) {
  247.         var globalInfo = JSON.parse(json);   // JSON.解析
  248.         for (var i = 1; i <= this.maxSavefiles(); i++) {
  249.             if (!StorageManager.exists(i)) { // 存储管理器.是否存在(ID)
  250.                 delete globalInfo[i];        // 删除信息(ID)
  251.             }
  252.         }
  253.         return globalInfo;
  254.     } else {
  255.         return [];
  256.     }
  257. };
  258. // 数据管理器.保存全局信息
  259. DataManager.saveGlobalInfo = function(info) {
  260.     StorageManager.save(0, JSON.stringify(info));  // 存储管理器.保存
  261. };
  262. // 数据管理器.是否为本游戏文件
  263. DataManager.isThisGameFile = function(savefileId) {
  264.     var globalInfo = this.loadGlobalInfo();        // 数据管理器.加载全局信息
  265.     if (globalInfo && globalInfo[savefileId]) {    // 全局信息[保存文件ID] 非 NULL
  266.         if (StorageManager.isLocalMode()) {        // 存储管理器.是否本地模式
  267.             return true;
  268.         } else {
  269.             var savefile = globalInfo[savefileId]; // 保存文件信息
  270.             return (savefile.globalId === this._globalId &&    // 保存文件信息.全局ID === 数据管理器.全局ID
  271.                     savefile.title === $dataSystem.gameTitle); // 保存文件信息.标题 === 系统数据类.游戏标题
  272.         }
  273.     } else {
  274.         return false;
  275.     }
  276. };
  277. // 数据管理器.是否为本游戏文件_扩展函数
  278. DataManager.isThisGameFileEx = function(savefileId, globalInfo) {
  279.     if (globalInfo[savefileId]) {                  // 全局信息[保存文件ID] 非 NULL
  280.         if (StorageManager.isLocalMode()) {        // 存储管理器.是否本地模式
  281.             return true;
  282.         } else {
  283.             var savefile = globalInfo[savefileId]; // 保存文件信息
  284.             return (savefile.globalId === this._globalId &&    // 保存文件信息.全局ID === 数据管理器.全局ID
  285.                     savefile.title === $dataSystem.gameTitle); // 保存文件信息.标题 === 系统数据类.游戏标题
  286.         }
  287.     }
  288.         return false;
  289. };
  290. // 数据管理器.是否保存的文件(任意)
  291. DataManager.isAnySavefileExists = function() {
  292.     var globalInfo = this.loadGlobalInfo();           // 数据管理器.加载全局信息
  293.     if (globalInfo) {
  294.         for (var i = 1; i < globalInfo.length; i++) {
  295.                         // optimize
  296.             //if (this.isThisGameFile(i)) {           
  297.                         if (this.isThisGameFileEx(i, globalInfo)) { // 数据管理器.是否为本游戏文件
  298.                 return true;
  299.             }
  300.         }
  301.     }
  302.     return false;
  303. };
  304. // 数据管理器.最新保存文件标识
  305. DataManager.latestSavefileId = function() {
  306.     var globalInfo = this.loadGlobalInfo();           // 数据管理器.加载全局信息
  307.     var savefileId = 1;
  308.     var timestamp = 0;                                // 时间戳
  309.     if (globalInfo) {
  310.         for (var i = 1; i < globalInfo.length; i++) {
  311.                         // optimize
  312.             // if (this.isThisGameFile(i) && globalInfo[i].timestamp > timestamp) {
  313.                         // 数据管理器.是否为本游戏文件(i) 且 全局信息[i]
  314.                         if (this.isThisGameFileEx(i, globalInfo) && globalInfo[i].timestamp > timestamp) {
  315.                 timestamp = globalInfo[i].timestamp;   // 设置当前最大时间戳
  316.                 savefileId = i;                        // 设置保存文件ID
  317.             }
  318.         }
  319.     }
  320.     return savefileId;
  321. };
  322. // 数据管理器.加载全部保存文件图像
  323. DataManager.loadAllSavefileImages = function() {
  324.     var globalInfo = this.loadGlobalInfo();             // 数据管理器.加载全局信息
  325.     if (globalInfo) {
  326.         for (var i = 1; i < globalInfo.length; i++) {
  327.                         // optimize
  328.             // if (this.isThisGameFile(i)) {
  329.                         if (this.isThisGameFileEx(i, globalInfo))   // 数据管理器.是否为本游戏文件(i)
  330.                 var info = globalInfo[i];
  331.                 this.loadSavefileImages(info);          // 数据管理器.加载保存文件图像组
  332.             }
  333.         }
  334.     }
  335. };
  336. // 数据管理器.加载保存文件图像组
  337. DataManager.loadSavefileImages = function(info) {
  338.     if (info.characters) {
  339.         for (var i = 0; i < info.characters.length; i++) {
  340.             ImageManager.loadCharacter(info.characters[i][0]);   // 图像管理器.加载人物图像
  341.         }
  342.     }
  343.     if (info.faces) {
  344.         for (var j = 0; j < info.faces.length; j++) {
  345.             ImageManager.loadFace(info.faces[j][0]);             // 图像管理器.加载脸部图像
  346.         }
  347.     }
  348. };
  349. // 数据管理器.保存文件最大数量
  350. DataManager.maxSavefiles = function() {
  351.     return 20;
  352. };
  353. // 数据管理器.保存游戏
  354. DataManager.saveGame = function(savefileId) {
  355.     try {
  356.         return this.saveGameWithoutRescue(savefileId);           // 数据管理器.保存游戏(无拯救)
  357.     } catch (e) {
  358.         console.error(e);
  359.         try {
  360.             StorageManager.remove(savefileId); // 数据管理器.删除
  361.         } catch (e2) {
  362.         }
  363.         return false;
  364.     }
  365. };
  366. // 数据管理器.加载游戏
  367. DataManager.loadGame = function(savefileId) {
  368.     try {
  369.         return this.loadGameWithoutRescue(savefileId);           // 数据管理器.加载游戏(无拯救)
  370.     } catch (e) {
  371.         console.error(e);
  372.         return false;
  373.     }
  374. };
  375. // 数据管理器.加载(保存文件信息)
  376. DataManager.loadSavefileInfo = function(savefileId) {
  377.     var globalInfo = this.loadGlobalInfo();
  378.     return (globalInfo && globalInfo[savefileId]) ? globalInfo[savefileId] : null;
  379. };
  380. // 数据管理权.最后保存的数据文件ID
  381. DataManager.lastAccessedSavefileId = function() {
  382.     return this._lastAccessedId;
  383. };
  384. // 数据管理器.保存游戏(无拯救)
  385. DataManager.saveGameWithoutRescue = function(savefileId) {
  386.     var json = JsonEx.stringify(this.makeSaveContents());   // 将 数据管理器.制保存内容 转换为 JSON 字符串。
  387.     if (json.length >= 200000) {
  388.         console.warn('Save data too big!');
  389.     }
  390.     StorageManager.save(savefileId, json);      // 存储管理器.保存
  391.     this._lastAccessedId = savefileId;          // 设置最后数据库ID
  392.     var globalInfo = this.loadGlobalInfo() || [];
  393.     globalInfo[savefileId] = this.makeSavefileInfo();  // 设置全局信息[保存ID] = 数据管理器.制保存文件信息
  394.     this.saveGlobalInfo(globalInfo);            // 数据管理器.保存全局信息
  395.     return true;
  396. };
  397. // 数据管理器.加载游戏(无拯救)
  398. DataManager.loadGameWithoutRescue = function(savefileId) {
  399.     var globalInfo = this.loadGlobalInfo();     // 数据管理器.加载全局信息
  400.         // optimize
  401.     // if (this.isThisGameFile(savefileId)) {
  402.         // 数据管理器.是否为本游戏文件(i)
  403.         if (this.isThisGameFileEx(savefileId, globalInfo)) {
  404.         var json = StorageManager.load(savefileId);   // 存储管理器.加载()
  405.         this.createGameObjects();                     // 数据管理器.创建游戏对象
  406.         this.extractSaveContents(JsonEx.parse(json)); // 数据管理器.提取保存内容(JsonEx.解析(json))
  407.         this._lastAccessedId = savefileId;            // 设置最后数据库ID
  408.         return true;
  409.     } else {
  410.         return false;
  411.     }
  412. };
  413. // 数据管理器.选择保存文件从新游戏???
  414. DataManager.selectSavefileForNewGame = function() {
  415.     var globalInfo = this.loadGlobalInfo();     // 数据管理器.加载全局信息
  416.     this._lastAccessedId = 1;                   // 数据管理器.最后数据ID = 1
  417.     if (globalInfo) {
  418.         var numSavefiles = Math.max(0, globalInfo.length - 1);   // 存储文件数量
  419.         if (numSavefiles < this.maxSavefiles()) {
  420.             this._lastAccessedId = numSavefiles + 1;
  421.         } else {
  422.             var timestamp = Number.MAX_VALUE;                    // 时间戳 = JS.Number.MAX_VALUE
  423.             for (var i = 1; i < globalInfo.length; i++) {
  424.                 if (!globalInfo[i]) {
  425.                     this._lastAccessedId = i;
  426.                     break;
  427.                 }
  428.                 if (globalInfo[i].timestamp < timestamp) {
  429.                     timestamp = globalInfo[i].timestamp;
  430.                     this._lastAccessedId = i;
  431.                 }
  432.             }
  433.         }
  434.     }
  435. };
  436. // 数据管理器.制保存文件信息
  437. DataManager.makeSavefileInfo = function() {
  438.     var info = {};
  439.     info.globalId   = this._globalId;
  440.     info.title      = $dataSystem.gameTitle;
  441.     info.characters = $gameParty.charactersForSavefile();
  442.     info.faces      = $gameParty.facesForSavefile();
  443.     info.playtime   = $gameSystem.playtimeText();
  444.     info.timestamp  = Date.now();
  445.     return info;
  446. };
  447. // 数据管理器.制保存内容
  448. DataManager.makeSaveContents = function() {
  449.     // A save data does not contain $gameTemp, $gameMessage, and $gameTroop.
  450.     var contents = {};
  451.     contents.system       = $gameSystem;
  452.     contents.screen       = $gameScreen;
  453.     contents.timer        = $gameTimer;
  454.     contents.switches     = $gameSwitches;
  455.     contents.variables    = $gameVariables;
  456.     contents.selfSwitches = $gameSelfSwitches;
  457.     contents.actors       = $gameActors;
  458.     contents.party        = $gameParty;
  459.     contents.map          = $gameMap;
  460.     contents.player       = $gamePlayer;
  461.     return contents;
  462. };
  463. // 数据管理器.提取保存内容
  464. DataManager.extractSaveContents = function(contents) {
  465.     $gameSystem        = contents.system;
  466.     $gameScreen        = contents.screen;
  467.     $gameTimer         = contents.timer;
  468.     $gameSwitches      = contents.switches;
  469.     $gameVariables     = contents.variables;
  470.     $gameSelfSwitches  = contents.selfSwitches;
  471.     $gameActors        = contents.actors;
  472.     $gameParty         = contents.party;
  473.     $gameMap           = contents.map;
  474.     $gamePlayer        = contents.player;
  475. };

2.配置管理器类
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // ConfigManager
  3. //
  4. // The static class that manages the configuration data.
  5. // 配置管理器
  6. // 静态类 管理配置数据
  7. // ------     选项配置
  8. function ConfigManager() {
  9.     throw new Error('This is a static class');
  10. }
  11.  
  12. ConfigManager.alwaysDash        = false;   // 始终冲刺
  13. ConfigManager.commandRemember   = false;   // 记住命令
  14. // 配置管理器.BGM 音量
  15. Object.defineProperty(ConfigManager, 'bgmVolume', {
  16.     get: function() {
  17.         return AudioManager._bgmVolume;
  18.     },
  19.     set: function(value) {
  20.         AudioManager.bgmVolume = value;
  21.     },
  22.     configurable: true
  23. });
  24. // 配置管理器.BGS 音量
  25. Object.defineProperty(ConfigManager, 'bgsVolume', {
  26.     get: function() {
  27.         return AudioManager.bgsVolume;
  28.     },
  29.     set: function(value) {
  30.         AudioManager.bgsVolume = value;
  31.     },
  32.     configurable: true
  33. });
  34. // 配置管理器.ME 音量
  35. Object.defineProperty(ConfigManager, 'meVolume', {
  36.     get: function() {
  37.         return AudioManager.meVolume;
  38.     },
  39.     set: function(value) {
  40.         AudioManager.meVolume = value;
  41.     },
  42.     configurable: true
  43. });
  44. // 配置管理器.SE 音量
  45. Object.defineProperty(ConfigManager, 'seVolume', {
  46.     get: function() {
  47.         return AudioManager.seVolume;
  48.     },
  49.     set: function(value) {
  50.         AudioManager.seVolume = value;
  51.     },
  52.     configurable: true
  53. });
  54. // 配置管理器.加载
  55. ConfigManager.load = function() {
  56.     var json;
  57.     var config = {};
  58.     try {
  59.         json = StorageManager.load(-1);   // 存储管理器.加载(-1)
  60.     } catch (e) {
  61.         console.error(e);
  62.     }
  63.     if (json) {
  64.         config = JSON.parse(json);        // 配置 = JSON.解析()
  65.     }
  66.     this.applyData(config);    // 配置管理器.应用数据()
  67. };
  68. // 配置管理器.保存
  69. ConfigManager.save = function() {
  70.     StorageManager.save(-1, JSON.stringify(this.makeData()));  // 存储管理器.保存(-1, 将 配置管理器.制保存内容 转换为 JSON 字符串。)
  71. };
  72. // 配置管理器.制作数据
  73. ConfigManager.makeData = function() {
  74.     var config = {};
  75.     config.alwaysDash = this.alwaysDash;            // 总是冲刺
  76.     config.commandRemember = this.commandRemember;  // 记住命令
  77.     config.bgmVolume = this.bgmVolume;              // BGM 音量
  78.     config.bgsVolume = this.bgsVolume;              // BGS 音量
  79.     config.meVolume = this.meVolume;                // ME  音量
  80.     config.seVolume = this.seVolume;                // SE  音量
  81.     return config;
  82. };
  83. // 配置管理器.应用数据
  84. ConfigManager.applyData = function(config) {
  85.     this.alwaysDash = this.readFlag(config, 'alwaysDash');             // 读取标记(总是冲刺)
  86.     this.commandRemember = this.readFlag(config, 'commandRemember');   // 读取标记(记住命令)
  87.     this.bgmVolume = this.readVolume(config, 'bgmVolume');             // 读取值(BGM 音量)
  88.     this.bgsVolume = this.readVolume(config, 'bgsVolume');             // 读取值(BGS 音量)
  89.     this.meVolume = this.readVolume(config, 'meVolume');               // 读取值(ME  音量)
  90.     this.seVolume = this.readVolume(config, 'seVolume');               // 读取值(SE  音量)
  91. };
  92. // 配置管理器.读取标记
  93. ConfigManager.readFlag = function(config, name) {
  94.     return !!config[name];
  95. };
  96. // 配置管理器.读取值
  97. ConfigManager.readVolume = function(config, name) {
  98.     var value = config[name];
  99.     if (value !== undefined) {
  100.         return Number(value).clamp(0, 100);    // 返回一个大小不超出(0, 100)的数字值。 (<99>:99)(<102>:100)(<-1>:0)
  101.     } else {
  102.         return 100;
  103.     }
  104. };

3.存储管理器类(翻译完后我知道 RMMV 本地存储与网络存储的原理是什么了。其中有个函数里面太复杂,我无法翻译,留个高手吧)
3.1 存储管理器类 - 未翻译函数
JAVASCRIPT 代码复制
  1. // 未翻译的函数
  2. // 存储管理器.本地存储文件目录路径
  3. StorageManager.localFileDirectoryPath = function() {
  4.     var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/save/');  // 这个正则要逆向可太为难我这正则表达式战五渣的孩子了 ⊙﹏⊙b汗
  5.     if (path.match(/^\/([A-Z]\:)/)) {
  6.         path = path.slice(1);
  7.     }
  8.     return decodeURIComponent(path);
  9. };

3.2 存储管理器类 - 完整版:
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // StorageManager
  3. //
  4. // The static class that manages storage for saving game data.
  5. // 存储管理器
  6. // 静态类 管理保存游戏数据的存储
  7. function StorageManager() {
  8.     throw new Error('This is a static class');
  9. }
  10. // 存储管理器.保存
  11. StorageManager.save = function(savefileId, json) {
  12.     if (this.isLocalMode()) {                     // 存储管理器.是否本地模式
  13.         this.saveToLocalFile(savefileId, json);   // 存储管理器.保存到本地存储文件
  14.     } else {
  15.         this.saveToWebStorage(savefileId, json);  // 存储管理器.保存到WEB存储文件
  16.     }
  17. };
  18. // 存储管理器.加载
  19. StorageManager.load = function(savefileId) {
  20.     if (this.isLocalMode()) {                       // 存储管理器.是否本地模式
  21.         return this.loadFromLocalFile(savefileId);  // 存储管理器.加载本地存储文件
  22.     } else {
  23.         return this.loadFromWebStorage(savefileId); // 存储管理器.加载WEB存储文件
  24.     }
  25. };
  26. // 存储管理器.是否存在存储文件
  27. StorageManager.exists = function(savefileId) {
  28.     if (this.isLocalMode()) {                       // 存储管理器.是否本地模式
  29.         return this.localFileExists(savefileId);    // 存储管理器.本地存储文件是否存在
  30.     } else {
  31.         return this.webStorageExists(savefileId);   // 存储管理器.WEB存储文件是否存在
  32.     }
  33. };
  34. // 存储管理器.删除存储文件
  35. StorageManager.remove = function(savefileId) {
  36.     if (this.isLocalMode()) {                       // 存储管理器.是否本地模式
  37.         this.removeLocalFile(savefileId);           // 存储管理器.删除本地存储文件
  38.     } else {
  39.         this.removeWebStorage(savefileId);          // 存储管理器.删除WEB存储文件
  40.     }
  41. };
  42. // 存储管理器.是否本地模式
  43. StorageManager.isLocalMode = function() {
  44.     return Utils.isNwjs();
  45. };
  46. // 存储管理器.保存到本地存储文件
  47. StorageManager.saveToLocalFile = function(savefileId, json) {
  48.     var data = LZString.compressToBase64(json);  // LZ-String.压缩到Base64
  49.     var fs = require('fs');                      // nodejs.require('fs')    - 文件模块
  50.     var dirPath = this.localFileDirectoryPath();    // 存储管理器.本地存储文件目录路径
  51.     var filePath = this.localFilePath(savefileId);  // 存储管理器.本地存储文件路径
  52.     if (!fs.existsSync(dirPath)) {               // nodejs 库 检测保存目录是否存在
  53.         fs.mkdirSync(dirPath);                   // nodejs 库 创建目录
  54.     }
  55.     fs.writeFileSync(filePath, data);            // nodejs 库  写到文件(同步)
  56. };
  57. // 存储管理器.加载本地存储文件
  58. StorageManager.loadFromLocalFile = function(savefileId) {
  59.     var data = null;
  60.     var fs = require('fs');                         // nodejs.require('fs')    - 文件模块
  61.     var filePath = this.localFilePath(savefileId);  // 存储管理器.本地存储文件路径
  62.     if (fs.existsSync(filePath)) {                               // nodejs 库 检测预打开文件是否存在
  63.         data = fs.readFileSync(filePath, { encoding: 'utf8' });  // nodejs 库  读文件数据(同步)  utf8 编码
  64.     }
  65.     return LZString.decompressFromBase64(data);                  // LZ-String 从Base64解压缩
  66. };
  67. // 存储管理器.本地存储文件是否存在
  68. StorageManager.localFileExists = function(savefileId) {
  69.     var fs = require('fs');                                // nodejs.require('fs')    - 文件模块
  70.     return fs.existsSync(this.localFilePath(savefileId));  // nodejs 库 检测(存储管理器.本地存储文件路径)是否存在
  71. };
  72. // 存储管理器.删除本地存储文件
  73. StorageManager.removeLocalFile = function(savefileId) {
  74.     var fs = require('fs');                                // nodejs.require('fs')    - 文件模块
  75.     var filePath = this.localFilePath(savefileId);         // 存储管理器.本地存储文件路径
  76.     if (fs.existsSync(filePath)) {                         // nodejs 库 检测指定文件是否存在
  77.         fs.unlinkSync(filePath);                           // nodejs 库 删除指定文件
  78.     }
  79. };
  80. // 存储管理器.保存到WEB存储文件
  81. StorageManager.saveToWebStorage = function(savefileId, json) {
  82.     var key = this.webStorageKey(savefileId);              // 存储管理器.WEB存储KEY
  83.     var data = LZString.compressToBase64(json);            // LZ-String.压缩到Base64
  84.     localStorage.setItem(key, data);                       // <HTML5>本地存储.设置项目(WEB_KEY, 数据)
  85. };
  86. // 存储管理器.加载WEB存储文件
  87. StorageManager.loadFromWebStorage = function(savefileId) {
  88.     var key = this.webStorageKey(savefileId);              // 存储管理器.WEB存储KEY
  89.     var data = localStorage.getItem(key);                  // <HTML5>本地存储.取项目(WEB_KEY)
  90.     return LZString.decompressFromBase64(data);            // LZ-String 从Base64解压缩
  91. };
  92. // 存储管理器.WEB存储文件是否存在
  93. StorageManager.webStorageExists = function(savefileId) {
  94.     var key = this.webStorageKey(savefileId);              // 存储管理器.WEB存储KEY
  95.     return !!localStorage.getItem(key);                    // return !!<HTML5>本地存储.取项目(WEB_KEY)
  96. };
  97. // 存储管理器.删除WEB存储文件
  98. StorageManager.removeWebStorage = function(savefileId) {
  99.     var key = this.webStorageKey(savefileId);              // 存储管理器.WEB存储KEY
  100.     localStorage.removeItem(key);                          // <HTML5>本地存储.删除项目(WEB_KEY)
  101. };
  102. // 存储管理器.本地存储文件目录路径
  103. StorageManager.localFileDirectoryPath = function() {
  104.     var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/save/');
  105.     if (path.match(/^\/([A-Z]\:)/)) {
  106.         path = path.slice(1);
  107.     }
  108.     return decodeURIComponent(path);
  109. };
  110. // 存储管理器.本地存储文件路径
  111. StorageManager.localFilePath = function(savefileId) {
  112.     var name;
  113.     if (savefileId < 0) {
  114.         name = 'config.rpgsave';       // 配置管理器
  115.     } else if (savefileId === 0) {
  116.         name = 'global.rpgsave';       // 全局信息
  117.     } else {
  118.         name = 'file%1.rpgsave'.format(savefileId);  // 格式化成 file00.rpgsave
  119.     }
  120.     return this.localFileDirectoryPath() + name;
  121. };
  122. // 存储管理器.WEB存储KEY
  123. StorageManager.webStorageKey = function(savefileId) {
  124.     if (savefileId < 0) {
  125.         return 'RPG Config';       // 配置管理器
  126.     } else if (savefileId === 0) {
  127.         return 'RPG Global';       // 全局信息
  128.     } else {
  129.         return 'RPG File%1'.format(savefileId);  // 格式化成 RPG File00.rpgsave
  130.     }
  131. };

4.图像管理器
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // ImageManager
  3. //
  4. // The static class that loads images, creates bitmap objects and retains them.
  5. // 图像管理器
  6. // 静态类 管理加载图像与创建位图对象并保存
  7. function ImageManager() {
  8.     throw new Error('This is a static class');
  9. }
  10. // 图像管理器.缓存
  11. ImageManager._cache = {};
  12. // 图像管理器.加载动画
  13. ImageManager.loadAnimation = function(filename, hue) {
  14.     return this.loadBitmap('img/animations/', filename, hue, true);
  15. };
  16. // 图像管理器.加载战斗背景图1
  17. ImageManager.loadBattleback1 = function(filename, hue) {
  18.     return this.loadBitmap('img/battlebacks1/', filename, hue, true);
  19. };
  20. // 图像管理器.加载战斗背景图2
  21. ImageManager.loadBattleback2 = function(filename, hue) {
  22.     return this.loadBitmap('img/battlebacks2/', filename, hue, true);
  23. };
  24. // 图像管理器.加载敌人图像
  25. ImageManager.loadEnemy = function(filename, hue) {
  26.     return this.loadBitmap('img/enemies/', filename, hue, true);
  27. };
  28. // 图像管理器.加载人物图像
  29. ImageManager.loadCharacter = function(filename, hue) {
  30.     return this.loadBitmap('img/characters/', filename, hue, false);
  31. };
  32. // 图像管理器.加载脸部图像
  33. ImageManager.loadFace = function(filename, hue) {
  34.     return this.loadBitmap('img/faces/', filename, hue, true);
  35. };
  36. // 图像管理器.加载远景图
  37. ImageManager.loadParallax = function(filename, hue) {
  38.     return this.loadBitmap('img/parallaxes/', filename, hue, true);
  39. };
  40. // 图像管理器.加载图片
  41. ImageManager.loadPicture = function(filename, hue) {
  42.     return this.loadBitmap('img/pictures/', filename, hue, true);
  43. };
  44. // 图像管理器.加载横版战斗人物
  45. ImageManager.loadSvActor = function(filename, hue) {
  46.     return this.loadBitmap('img/sv_actors/', filename, hue, false);
  47. };
  48. // 图像管理器.加载横版战斗敌人
  49. ImageManager.loadSvEnemy = function(filename, hue) {
  50.     return this.loadBitmap('img/sv_enemies/', filename, hue, true);
  51. };
  52. // 图像管理器.加载系统图像
  53. ImageManager.loadSystem = function(filename, hue) {
  54.     return this.loadBitmap('img/system/', filename, hue, false);
  55. };
  56. // 图像管理器.加载图像集(地图元件)
  57. ImageManager.loadTileset = function(filename, hue) {
  58.     return this.loadBitmap('img/tilesets/', filename, hue, false);
  59. };
  60. // 图像管理器.加载标题1
  61. ImageManager.loadTitle1 = function(filename, hue) {
  62.     return this.loadBitmap('img/titles1/', filename, hue, true);
  63. };
  64. // 图像管理器.加载标题2
  65. ImageManager.loadTitle2 = function(filename, hue) {
  66.     return this.loadBitmap('img/titles2/', filename, hue, true);
  67. };
  68. // 图像管理器.加载图像
  69. ImageManager.loadBitmap = function(folder, filename, hue, smooth) {
  70.     if (filename) {
  71.         var path = folder + encodeURIComponent(filename) + '.png'; // 文件夹+URI编码压缩(filename)
  72.         var bitmap = this.loadNormalBitmap(path, hue || 0);        // 图像管理器.加载正常图像
  73.         bitmap.smooth = smooth;                                    // 光滑
  74.         return bitmap;
  75.     } else {
  76.         return this.loadEmptyBitmap();                             // 图像管理器.加载空图像
  77.     }
  78. };
  79. // 图像管理器.加载空图像
  80. ImageManager.loadEmptyBitmap = function() {
  81.     if (!this._cache[null]) {
  82.         this._cache[null] = new Bitmap();
  83.     }
  84.     return this._cache[null];
  85. };
  86. // 图像管理器.加载正常图像
  87. ImageManager.loadNormalBitmap = function(path, hue) {
  88.     var key = path + ':' + hue;
  89.     if (!this._cache[key]) {
  90.         var bitmap = Bitmap.load(path);
  91.         bitmap.addLoadListener(function() {   // bitmap 添加一个回调函数,在位图被加载时调用该函数。
  92.             bitmap.rotateHue(hue);            // bitmap 变换位图的色相。
  93.         });
  94.         this._cache[key] = bitmap;
  95.     }
  96.     return this._cache[key];
  97. };
  98. // 图像管理器.清除
  99. ImageManager.clear = function() {
  100.     this._cache = {};
  101. };
  102. // 图像管理器.是否就绪
  103. ImageManager.isReady = function() {
  104.     for (var key in this._cache) {
  105.         var bitmap = this._cache[key];
  106.         if (bitmap.isError()) {
  107.             throw new Error('Failed to load: ' + bitmap.url);
  108.         }
  109.         if (!bitmap.isReady()) {
  110.             return false;
  111.         }
  112.     }
  113.     return true;
  114. };
  115. // 图像管理器.是否人物对象
  116. ImageManager.isObjectCharacter = function(filename) {
  117.     var sign = filename.match(/^[\!\$]+/);
  118.     return sign && sign[0].contains('!');
  119. };
  120. // 图像管理器.是否为人物(大图像)
  121. ImageManager.isBigCharacter = function(filename) {
  122.     var sign = filename.match(/^[\!\$]+/);
  123.     return sign && sign[0].contains('$');
  124. };
  125. // 图像管理器.是否远景滚动图(0)????
  126. ImageManager.isZeroParallax = function(filename) {
  127.     return filename.charAt(0) === '!';
  128. };

5.音频管理器
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // AudioManager
  3. //
  4. // The static class that handles BGM, BGS, ME and SE.
  5. // 音频管理器
  6. // 静态类 管理 BGM BGS ME SE
  7. function AudioManager() {
  8.     throw new Error('This is a static class');
  9. }
  10. // 音量
  11. AudioManager._bgmVolume      = 100;
  12. AudioManager._bgsVolume      = 100;
  13. AudioManager._meVolume       = 100;
  14. AudioManager._seVolume       = 100;
  15.  
  16. AudioManager._currentBgm     = null;     // 当前 BGM
  17. AudioManager._currentBgs     = null;     // 当前 BGS
  18. AudioManager._bgmBuffer      = null;     // BGM 缓存
  19. AudioManager._bgsBuffer      = null;     // BGS 缓存
  20. AudioManager._meBuffer       = null;     // ME  缓存
  21. AudioManager._seBuffers      = [];       // SE  缓存
  22. AudioManager._staticBuffers  = [];       // 静态缓存组
  23. AudioManager._replayFadeTime = 0.5;      // 重播淡入淡出时间
  24. AudioManager._path           = 'audio/'; // 音频路径
  25.  
  26. // 音频管理器.BGM 音量
  27. Object.defineProperty(AudioManager, 'bgmVolume', {
  28.     get: function() {
  29.         return this._bgmVolume;
  30.     },
  31.     set: function(value) {
  32.         this._bgmVolume = value;
  33.         this.updateBgmParameters(this._currentBgm);   // 音频管理器.刷新BGM播放参数
  34.     },
  35.     configurable: true
  36. });
  37. // 音频管理器.BGS 音量
  38. Object.defineProperty(AudioManager, 'bgsVolume', {
  39.     get: function() {
  40.         return this._bgsVolume;
  41.     },
  42.     set: function(value) {
  43.         this._bgsVolume = value;
  44.         this.updateBgsParameters(this._currentBgs);   // 音频管理器.刷新BGS播放参数
  45.     },
  46.     configurable: true
  47. });
  48. // 音频管理器.ME 音量
  49. Object.defineProperty(AudioManager, 'meVolume', {
  50.     get: function() {
  51.         return this._meVolume;
  52.     },
  53.     set: function(value) {
  54.         this._meVolume = value;
  55.         this.updateMeParameters(this._currentMe);     // 音频管理器.刷新ME播放参数
  56.     },
  57.     configurable: true
  58. });
  59. // 音频管理器.SE 音量
  60. Object.defineProperty(AudioManager, 'seVolume', {
  61.     get: function() {
  62.         return this._seVolume;
  63.     },
  64.     set: function(value) {
  65.         this._seVolume = value;
  66.     },
  67.     configurable: true
  68. });
  69. // 音频管理器.播放BGM
  70. AudioManager.playBgm = function(bgm, pos) {
  71.     if (this.isCurrentBgm(bgm)) {             // 音频管理器.是否当前BGM
  72.         this.updateBgmParameters(bgm);        // 音频管理器.刷新BGM播放参数
  73.     } else {
  74.         this.stopBgm();                       // 音频管理器.停止BGM
  75.         if (bgm.name) {
  76.             this._bgmBuffer = this.createBuffer('bgm', bgm.name);  // 音频管理器.创建缓存
  77.             this.updateBgmParameters(bgm);                         // 音频管理器.刷新BGM播放参数
  78.             if (!this._meBuffer) {
  79.                 this._bgmBuffer.play(true, pos || 0);              // 音频管理器.BGM缓存.播放
  80.             }
  81.         }
  82.     }
  83.     this.updateCurrentBgm(bgm, pos);           // 音频管理器.刷新当前BGM
  84. };
  85. // 音频管理器.重播BGM
  86. AudioManager.replayBgm = function(bgm) {
  87.     if (this.isCurrentBgm(bgm)) {              // 音频管理器.是否当前BGM
  88.         this.updateBgmParameters(bgm);         // 音频管理器.刷新BGM播放参数
  89.     } else {
  90.         this.playBgm(bgm, bgm.pos);            // 音频管理器.播放BGM
  91.         if (this._bgmBuffer) {
  92.             this._bgmBuffer.fadeIn(this._replayFadeTime);  // 音频管理器.BGM缓存.淡入
  93.         }
  94.     }
  95. };
  96. // 音频管理器.是否当前BGM
  97. AudioManager.isCurrentBgm = function(bgm) {
  98.     return (this._currentBgm && this._bgmBuffer &&
  99.             this._currentBgm.name === bgm.name);
  100. };
  101. // 音频管理器.刷新BGM播放参数
  102. AudioManager.updateBgmParameters = function(bgm) {
  103.     this.updateBufferParameters(this._bgmBuffer, this._bgmVolume, bgm);
  104. };
  105. // 音频管理器.刷新当前BGM
  106. AudioManager.updateCurrentBgm = function(bgm, pos) {
  107.     this._currentBgm = {
  108.         name: bgm.name,
  109.         volume: bgm.volume,
  110.         pitch: bgm.pitch,    // 音调
  111.         pan: bgm.pan,        // 声调
  112.         pos: pos
  113.     };
  114. };
  115. // 音频管理器.停止BGM
  116. AudioManager.stopBgm = function() {
  117.     if (this._bgmBuffer) {
  118.         this._bgmBuffer.stop();      // 音频管理器.BGM缓存.停止
  119.         this._bgmBuffer = null;
  120.         this._currentBgm = null;
  121.     }
  122. };
  123. // 音频管理器.淡出BGM
  124. AudioManager.fadeOutBgm = function(duration) {
  125.     if (this._bgmBuffer && this._currentBgm) {
  126.         this._bgmBuffer.fadeOut(duration);   // 音频管理器.BGM缓存.淡出
  127.         this._currentBgm = null;
  128.     }
  129. };
  130. // 音频管理器.淡入BGM
  131. AudioManager.fadeInBgm = function(duration) {
  132.     if (this._bgmBuffer && this._currentBgm) {
  133.         this._bgmBuffer.fadeIn(duration);    // 音频管理器.BGM缓存.淡入
  134.     }
  135. };
  136. // 音频管理器.播放BGS
  137. AudioManager.playBgs = function(bgs, pos) {
  138.     if (this.isCurrentBgs(bgs)) {
  139.         this.updateBgsParameters(bgs);       // 音频管理器.刷新BGS播放参数
  140.     } else {
  141.         this.stopBgs();                      // 音频管理器.停止BGS
  142.         if (bgs.name) {
  143.             this._bgsBuffer = this.createBuffer('bgs', bgs.name);  // 音频管理器.创建缓存
  144.             this.updateBgsParameters(bgs);                         // 音频管理器.刷新BGS播放参数
  145.             this._bgsBuffer.play(true, pos || 0);                  // 音频管理器.BGS缓存.播放
  146.         }
  147.     }
  148.     this.updateCurrentBgs(bgs, pos);                  // 音频管理器.刷新BGS播放参数
  149. };
  150. // 音频管理器.重播BGS
  151. AudioManager.replayBgs = function(bgs) {
  152.     if (this.isCurrentBgs(bgs)) {
  153.         this.updateBgsParameters(bgs);       // 音频管理器.刷新BGS播放参数
  154.     } else {
  155.         this.playBgs(bgs, bgs.pos);                         // 音频管理器.播放BGS
  156.         if (this._bgsBuffer) {
  157.             this._bgsBuffer.fadeIn(this._replayFadeTime);   // 音频管理器.BGS缓存.淡入
  158.         }
  159.     }
  160. };
  161. // 音频管理器.是否当前BGS
  162. AudioManager.isCurrentBgs = function(bgs) {
  163.     return (this._currentBgs && this._bgsBuffer &&
  164.             this._currentBgs.name === bgs.name);
  165. };
  166. // 音频管理器.刷新BGS播放参数
  167. AudioManager.updateBgsParameters = function(bgs) {
  168.     this.updateBufferParameters(this._bgsBuffer, this._bgsVolume, bgs);   // 音频管理器.刷新缓存参数
  169. };
  170. // 音频管理器.刷新当前BGS
  171. AudioManager.updateCurrentBgs = function(bgs, pos) {
  172.     this._currentBgs = {
  173.         name: bgs.name,
  174.         volume: bgs.volume,
  175.         pitch: bgs.pitch,
  176.         pan: bgs.pan,
  177.         pos: pos
  178.     };
  179. };
  180. // 音频管理器.停止BGS
  181. AudioManager.stopBgs = function() {
  182.     if (this._bgsBuffer) {
  183.         this._bgsBuffer.stop();  // 音频管理器.BGS缓存.停止
  184.         this._bgsBuffer = null;
  185.         this._currentBgs = null;
  186.     }
  187. };
  188. // 音频管理器.淡出BGS
  189. AudioManager.fadeOutBgs = function(duration) {
  190.     if (this._bgsBuffer && this._currentBgs) {
  191.         this._bgsBuffer.fadeOut(duration);  // 音频管理器.BGS缓存.淡出
  192.         this._currentBgs = null;
  193.     }
  194. };
  195. // 音频管理器.淡入BGS
  196. AudioManager.fadeInBgs = function(duration) {
  197.     if (this._bgsBuffer && this._currentBgs) {
  198.         this._bgsBuffer.fadeIn(duration);  // 音频管理器.BGS缓存.淡入
  199.     }
  200. };
  201. // 音频管理器.播放ME
  202. AudioManager.playMe = function(me) {
  203.     this.stopMe();              // 音频管理器.停止ME
  204.     if (me.name) {
  205.         if (this._bgmBuffer && this._currentBgm) {
  206.             this._currentBgm.pos = this._bgmBuffer.seek();   // 音频管理器.当前BGM.位置 = 音频管理器.BGM缓存.寻求()
  207.             this._bgmBuffer.stop();                          // 音频管理器.BGM缓存.停止
  208.         }
  209.         this._meBuffer = this.createBuffer('me', me.name);   // 音频管理器.创建缓存
  210.         this.updateMeParameters(me);                         // 音频管理器.刷新ME播放参数
  211.         this._meBuffer.play(false);                          // 音频管理器.ME缓存.播放
  212.         this._meBuffer.addStopListener(this.stopMe.bind(this));   // 音频管理器.ME缓存.添加停止回调函数(音频管理器.停止ME.绑定(this)/* bind 可以防止丢失 this */)
  213.     }
  214. };
  215. // 音频管理器.刷新ME播放参数
  216. AudioManager.updateMeParameters = function(me) {
  217.     this.updateBufferParameters(this._meBuffer, this._meVolume, me);  // 音频管理器.刷新缓存参数
  218. };
  219. // 音频管理器.淡出ME
  220. AudioManager.fadeOutMe = function(duration) {
  221.     if (this._meBuffer) {
  222.         this._meBuffer.fadeOut(duration);     // 音频管理器.ME缓存.淡出
  223.     }
  224. };
  225. // custom add
  226. // 音频管理器.淡入ME
  227. AudioManager.fadeInMe = function(duration) {
  228.     if (this._meBuffer) {
  229.         this._meBuffer.fadeIn(duration);     // 音频管理器.ME缓存.淡入
  230.     }
  231. };
  232. //-----------------------------------------------------------------------------------------------------------
  233. // 音频管理器.停止ME
  234. AudioManager.stopMe = function() {
  235.     if (this._meBuffer) {
  236.         this._meBuffer.stop();               // 音频管理器.ME缓存.停止()
  237.         this._meBuffer = null;
  238.                 // 音频管理器.BGM缓存存在 且 音频管理器.当前BGM缓存存在 且 音频管理器.BGM缓存.正在播放()
  239.         if (this._bgmBuffer && this._currentBgm && !this._bgmBuffer.isPlaying()) {
  240.             this._bgmBuffer.play(true, this._currentBgm.pos);       // 音频管理器.BGM缓存.播放()
  241.             this._bgmBuffer.fadeIn(this._replayFadeTime);           // 音频管理器.BGM缓存.淡入()
  242.         }
  243.     }
  244. };
  245. // 音频管理器.播放SE
  246. AudioManager.playSe = function(se) {
  247.     if (se.name) {
  248.                 // 过滤掉正在播放中的SE
  249.         this._seBuffers = this._seBuffers.filter(function(audio) {
  250.             return audio.isPlaying();
  251.         });
  252.         var buffer = this.createBuffer('se', se.name);  // 音频管理器.创建缓存
  253.         this.updateSeParameters(buffer, se);   // 音频管理器.刷新SE播放参数
  254.         buffer.play(false);                    // 新创建SE缓存.播放
  255.         this._seBuffers.push(buffer);          // 音频管理器.SE缓存组.投递(新创建SE)
  256.     }
  257. };
  258. // 音频管理器.刷新SE播放参数
  259. AudioManager.updateSeParameters = function(buffer, se) {
  260.     this.updateBufferParameters(buffer, this._seVolume, se);  // 音频管理器.刷新缓存参数()
  261. };
  262. // 音频管理器.停止SE
  263. AudioManager.stopSe = function() {
  264.         // ES5 新增 Array.遍历函数
  265.         // function callback(value, [index], [object])
  266.     this._seBuffers.forEach(function(buffer) {
  267.         buffer.stop();   // WebAudio/Html5Audio.停止
  268.     });
  269.     this._seBuffers = [];  // 音频管理器.SE缓存组 清空
  270. };
  271. // 音频管理器.播放静态SE
  272. AudioManager.playStaticSe = function(se) {
  273.     if (se.name) {
  274.         this.loadStaticSe(se);          // 音频管理器.加载静态SE
  275.                 // 遍历 音频管理器.静态SE组
  276.         for (var i = 0; i < this._staticBuffers.length; i++) {
  277.             var buffer = this._staticBuffers[i];
  278.             if (buffer._reservedSeName === se.name) {
  279.                 buffer.stop();          // WebAudio/Html5Audio.停止
  280.                 this.updateSeParameters(buffer, se);   // 音频管理器.刷新SE播放参数
  281.                 buffer.play(false);     // WebAudio/Html5Audio.播放
  282.                 break;
  283.             }
  284.         }
  285.     }
  286. };
  287. // 音频管理器.加载静态SE
  288. AudioManager.loadStaticSe = function(se) {
  289.     if (se.name && !this.isStaticSe(se)) {
  290.         var buffer = this.createBuffer('se', se.name);   // 音频管理器.创建缓存
  291.         buffer._reservedSeName = se.name;
  292.         this._staticBuffers.push(buffer);  // 音频管理器.静态缓存.投递(新创建SE)
  293.         if (this.shouldUseHtml5Audio()) {  // 音频管理器.是否应该使用 Html5Audio
  294.             Html5Audio.setStaticSe(buffer._url);   // Html5Audio.设置静态SE
  295.         }
  296.     }
  297. };
  298. // 音频管理器.是否为静态SE
  299. AudioManager.isStaticSe = function(se) {
  300.         // 遍历 音频管理器.静态缓存组
  301.     for (var i = 0; i < this._staticBuffers.length; i++) {
  302.         var buffer = this._staticBuffers[i];
  303.                 // 缓存.保留SE名 === SE.名
  304.         if (buffer._reservedSeName === se.name) {
  305.             return true;
  306.         }
  307.     }
  308.     return false;
  309. };
  310. // 音频管理器.停止所有音频
  311. AudioManager.stopAll = function() {
  312.     this.stopMe();   // 音频管理器.停止ME
  313.     this.stopBgm();  // 音频管理器.停止BGM
  314.     this.stopBgs();  // 音频管理器.停止BGS
  315.     this.stopSe();   // 音频管理器.停止SE
  316. };
  317. // 音频管理器.保存BGM
  318. AudioManager.saveBgm = function() {
  319.     if (this._currentBgm) {
  320.         var bgm = this._currentBgm;
  321.         return {
  322.             name: bgm.name,
  323.             volume: bgm.volume,
  324.             pitch: bgm.pitch,
  325.             pan: bgm.pan,
  326.             pos: this._bgmBuffer ? this._bgmBuffer.seek() : 0
  327.         };
  328.     } else {
  329.         return this.makeEmptyAudioObject();   // 音频管理器.制空音频对象
  330.     }
  331. };
  332. // 音频管理器.保存BGS
  333. AudioManager.saveBgs = function() {
  334.     if (this._currentBgs) {
  335.         var bgs = this._currentBgs;
  336.         return {
  337.             name: bgs.name,
  338.             volume: bgs.volume,
  339.             pitch: bgs.pitch,
  340.             pan: bgs.pan,
  341.             pos: this._bgsBuffer ? this._bgsBuffer.seek() : 0
  342.         };
  343.     } else {
  344.         return this.makeEmptyAudioObject();   // 音频管理器.制空音频对象
  345.     }
  346. };
  347. // 音频管理器.制空音频对象
  348. AudioManager.makeEmptyAudioObject = function() {
  349.     return { name: '', volume: 0, pitch: 0 };
  350. };
  351. // 音频管理器.创建缓存
  352. AudioManager.createBuffer = function(folder, name) {
  353.     var ext = this.audioFileExt();   // 音频管理器.音频文件后缀名
  354.     var url = this._path + folder + '/' + encodeURIComponent(name) + ext; // 音频管理器.路径+文件夹+URI编码压缩(name)+后缀名
  355.     if (this.shouldUseHtml5Audio() && folder === 'bgm') {                 // 音频管理器.是否应该使用HTML5Aduio 且 目录 === 'bgm'
  356.         Html5Audio.setup(url);                                            // Html5Audio.设置
  357.         return Html5Audio;
  358.     } else {
  359.         return new WebAudio(url);                                         // 创建 WebAudio
  360.     }
  361. };
  362. // 音频管理器.刷新缓存参数
  363. AudioManager.updateBufferParameters = function(buffer, configVolume, audio) {
  364.     if (buffer && audio) {
  365.         buffer.volume = configVolume * (audio.volume || 0) / 10000;
  366.         buffer.pitch = (audio.pitch || 0) / 100;
  367.         buffer.pan = (audio.pan || 0) / 100;
  368.     }
  369. };
  370. // 音频管理器.音频文件扩展
  371. AudioManager.audioFileExt = function() {
  372.     if (WebAudio.canPlayOgg() && !Utils.isMobileDevice()) {
  373.         return '.ogg';
  374.     } else {
  375.         return '.m4a';
  376.     }
  377. };
  378. // 音频管理器.是否需要使用HTML5音频
  379. AudioManager.shouldUseHtml5Audio = function() {
  380.         // 我们使用HTML5音频播放背景音乐而不是Web Audio API
  381.     // decodeAudioData()很慢在Android的Chrome。
  382.     return Utils.isAndroidChrome();
  383. };
  384. // 音频管理器.检查错误集
  385. AudioManager.checkErrors = function() {
  386.     this.checkWebAudioError(this._bgmBuffer);    // 音频管理器.检查网页音频错误(音频管理器.BGM缓存)
  387.     this.checkWebAudioError(this._bgsBuffer);    // 音频管理器.检查网页音频错误(音频管理器.BGS缓存)
  388.     this.checkWebAudioError(this._meBuffer);     // 音频管理器.检查网页音频错误(音频管理器.ME缓存)
  389.         // 音频管理器.SE缓存组.遍历数组
  390.     this._seBuffers.forEach(function(buffer) {
  391.         this.checkWebAudioError(buffer);   // 音频管理器.检查网页音频错误(buffer).绑定(this)
  392.     }.bind(this));
  393.     this._staticBuffers.forEach(function(buffer) {
  394.         this.checkWebAudioError(buffer);   // 音频管理器.检查网页音频错误(buffer).绑定(this)
  395.     }.bind(this));
  396. };
  397. // 音频管理器.检查网页音频错误
  398. AudioManager.checkWebAudioError = function(webAudio) {
  399.     if (webAudio && webAudio.isError()) {
  400.         throw new Error('Failed to load: ' + webAudio.url);
  401.     }
  402. };

6.声音管理器
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // SoundManager
  3. //
  4. // The static class that plays sound effects defined in the database.
  5. // 声音管理器
  6. // 静态类 管理数据库中定义声音效果
  7. function SoundManager() {
  8.     throw new Error('This is a static class');
  9. }
  10. // 声音管理器.预加载重要的声音
  11. SoundManager.preloadImportantSounds = function() {
  12.     this.loadSystemSound(0);
  13.     this.loadSystemSound(1);
  14.     this.loadSystemSound(2);
  15.     this.loadSystemSound(3);
  16. };
  17. // 声音管理器.加载系统声音
  18. SoundManager.loadSystemSound = function(n) {
  19.     if ($dataSystem) {
  20.         AudioManager.loadStaticSe($dataSystem.sounds[n]);   // 音频管理器.加载静态SE
  21.     }
  22. };
  23. // 声音管理器.播放系统声音
  24. SoundManager.playSystemSound = function(n) {
  25.     if ($dataSystem) {
  26.         AudioManager.playStaticSe($dataSystem.sounds[n]);   // 音频管理器.播放静态SE
  27.     }
  28. };
  29. // 声音管理器.播放光标音效
  30. SoundManager.playCursor = function() {
  31.     this.playSystemSound(0);
  32. };
  33. // 声音管理器.播放确定音效
  34. SoundManager.playOk = function() {
  35.     this.playSystemSound(1);
  36. };
  37. // 声音管理器.播放取消音效
  38. SoundManager.playCancel = function() {
  39.     this.playSystemSound(2);
  40. };
  41. // 声音管理器.蜂鸣
  42. SoundManager.playBuzzer = function() {
  43.     this.playSystemSound(3);
  44. };
  45. // 声音管理器.播放装备音效
  46. SoundManager.playEquip = function() {
  47.     this.playSystemSound(4);
  48. };
  49. // 声音管理器.播放保存音效
  50. SoundManager.playSave = function() {
  51.     this.playSystemSound(5);
  52. };
  53. // 声音管理器.播放加载音效
  54. SoundManager.playLoad = function() {
  55.     this.playSystemSound(6);
  56. };
  57. // 声音管理器.播放战斗开始音效
  58. SoundManager.playBattleStart = function() {
  59.     this.playSystemSound(7);
  60. };
  61. // 声音管理器.播放战斗逃跑音效
  62. SoundManager.playEscape = function() {
  63.     this.playSystemSound(8);
  64. };
  65. // 声音管理器.播放敌人攻击音效
  66. SoundManager.playEnemyAttack = function() {
  67.     this.playSystemSound(9);
  68. };
  69. // 声音管理器.播放敌人损伤音效
  70. SoundManager.playEnemyDamage = function() {
  71.     this.playSystemSound(10);
  72. };
  73. // 声音管理器.播放敌人死亡音效
  74. SoundManager.playEnemyCollapse = function() {
  75.     this.playSystemSound(11);
  76. };
  77. // 声音管理器.播放BOOS死亡音效1
  78. SoundManager.playBossCollapse1 = function() {
  79.     this.playSystemSound(12);
  80. };
  81. // 声音管理器.播放BOOS死亡音效2
  82. SoundManager.playBossCollapse2 = function() {
  83.     this.playSystemSound(13);
  84. };
  85. // 声音管理器.播放角色损伤音效
  86. SoundManager.playActorDamage = function() {
  87.     this.playSystemSound(14);
  88. };
  89. // 声音管理器.播放角色死亡音效
  90. SoundManager.playActorCollapse = function() {
  91.     this.playSystemSound(15);
  92. };
  93. // 声音管理器.播放恢复音效
  94. SoundManager.playRecovery = function() {
  95.     this.playSystemSound(16);
  96. };
  97. // 声音管理器.播放闪避音效
  98. SoundManager.playMiss = function() {
  99.     this.playSystemSound(17);
  100. };
  101. // 声音管理器.播放逃避音效(混乱中...与MISS 区别???)
  102. SoundManager.playEvasion = function() {
  103.     this.playSystemSound(18);
  104. };
  105. // 声音管理器.播放魔法逃避音效
  106. SoundManager.playMagicEvasion = function() {
  107.     this.playSystemSound(19);
  108. };
  109. // 声音管理器.播放反射音效
  110. SoundManager.playReflection = function() {
  111.     this.playSystemSound(20);
  112. };
  113. // 声音管理器.播放商店(购物?)音效
  114. SoundManager.playShop = function() {
  115.     this.playSystemSound(21);
  116. };
  117. // 声音管理器.播放使用物品音效
  118. SoundManager.playUseItem = function() {
  119.     this.playSystemSound(22);
  120. };
  121. // 声音管理器.播放使用特技音效
  122. SoundManager.playUseSkill = function() {
  123.     this.playSystemSound(23);
  124. };

7.文本管理器(这里有个点没搞懂,,,等待更新)
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // TextManager
  3. //
  4. // The static class that handles terms and messages.
  5. // 文本管理器
  6. // 静态类 管理术语与消息
  7. function TextManager() {
  8.     throw new Error('This is a static class');
  9. }
  10. // 文本管理器.基本术语
  11. TextManager.basic = function(basicId) {
  12.     return $dataSystem.terms.basic[basicId] || '';
  13. };
  14. // 文本管理器.参数
  15. TextManager.param = function(paramId) {
  16.     return $dataSystem.terms.params[paramId] || '';
  17. };
  18. // 文本管理器.命令术语
  19. TextManager.command = function(commandId) {
  20.     return $dataSystem.terms.commands[commandId] || '';
  21. };
  22. // 文本管理器.消息术语
  23. TextManager.message = function(messageId) {
  24.     return $dataSystem.terms.messages[messageId] || '';
  25. };
  26.  
  27. TextManager.getter = function(method, param) {
  28.     return {
  29.         get: function() {
  30.             return this[method](param);
  31.         },
  32.         configurable: true
  33.     };
  34. };
  35. // 文本管理器.货币单位
  36. Object.defineProperty(TextManager, 'currencyUnit', {
  37.     get: function() { return $dataSystem.currencyUnit; },
  38.     configurable: true
  39. });
  40.  
  41. Object.defineProperties(TextManager, {
  42.     level           : TextManager.getter('basic', 0),
  43.     levelA          : TextManager.getter('basic', 1),
  44.     hp              : TextManager.getter('basic', 2),
  45.     hpA             : TextManager.getter('basic', 3),
  46.     mp              : TextManager.getter('basic', 4),
  47.     mpA             : TextManager.getter('basic', 5),
  48.     tp              : TextManager.getter('basic', 6),
  49.     tpA             : TextManager.getter('basic', 7),
  50.     exp             : TextManager.getter('basic', 8),
  51.     expA            : TextManager.getter('basic', 9),
  52.     fight           : TextManager.getter('command', 0),
  53.     escape          : TextManager.getter('command', 1),
  54.     attack          : TextManager.getter('command', 2),
  55.     guard           : TextManager.getter('command', 3),
  56.     item            : TextManager.getter('command', 4),
  57.     skill           : TextManager.getter('command', 5),
  58.     equip           : TextManager.getter('command', 6),
  59.     status          : TextManager.getter('command', 7),
  60.     formation       : TextManager.getter('command', 8),
  61.     save            : TextManager.getter('command', 9),
  62.     gameEnd         : TextManager.getter('command', 10),
  63.     options         : TextManager.getter('command', 11),
  64.     weapon          : TextManager.getter('command', 12),
  65.     armor           : TextManager.getter('command', 13),
  66.     keyItem         : TextManager.getter('command', 14),
  67.     equip2          : TextManager.getter('command', 15),
  68.     optimize        : TextManager.getter('command', 16),
  69.     clear           : TextManager.getter('command', 17),
  70.     newGame         : TextManager.getter('command', 18),
  71.     continue_       : TextManager.getter('command', 19),
  72.     toTitle         : TextManager.getter('command', 21),
  73.     cancel          : TextManager.getter('command', 22),
  74.     buy             : TextManager.getter('command', 24),
  75.     sell            : TextManager.getter('command', 25),
  76.     alwaysDash      : TextManager.getter('message', 'alwaysDash'),
  77.     commandRemember : TextManager.getter('message', 'commandRemember'),
  78.     bgmVolume       : TextManager.getter('message', 'bgmVolume'),
  79.     bgsVolume       : TextManager.getter('message', 'bgsVolume'),
  80.     meVolume        : TextManager.getter('message', 'meVolume'),
  81.     seVolume        : TextManager.getter('message', 'seVolume'),
  82.     possession      : TextManager.getter('message', 'possession'),
  83.     expTotal        : TextManager.getter('message', 'expTotal'),
  84.     expNext         : TextManager.getter('message', 'expNext'),
  85.     saveMessage     : TextManager.getter('message', 'saveMessage'),
  86.     loadMessage     : TextManager.getter('message', 'loadMessage'),
  87.     file            : TextManager.getter('message', 'file'),
  88.     partyName       : TextManager.getter('message', 'partyName'),
  89.     emerge          : TextManager.getter('message', 'emerge'),
  90.     preemptive      : TextManager.getter('message', 'preemptive'),
  91.     surprise        : TextManager.getter('message', 'surprise'),
  92.     escapeStart     : TextManager.getter('message', 'escapeStart'),
  93.     escapeFailure   : TextManager.getter('message', 'escapeFailure'),
  94.     victory         : TextManager.getter('message', 'victory'),
  95.     defeat          : TextManager.getter('message', 'defeat'),
  96.     obtainExp       : TextManager.getter('message', 'obtainExp'),
  97.     obtainGold      : TextManager.getter('message', 'obtainGold'),
  98.     obtainItem      : TextManager.getter('message', 'obtainItem'),
  99.     levelUp         : TextManager.getter('message', 'levelUp'),
  100.     obtainSkill     : TextManager.getter('message', 'obtainSkill'),
  101.     useItem         : TextManager.getter('message', 'useItem'),
  102.     criticalToEnemy : TextManager.getter('message', 'criticalToEnemy'),
  103.     criticalToActor : TextManager.getter('message', 'criticalToActor'),
  104.     actorDamage     : TextManager.getter('message', 'actorDamage'),
  105.     actorRecovery   : TextManager.getter('message', 'actorRecovery'),
  106.     actorGain       : TextManager.getter('message', 'actorGain'),
  107.     actorLoss       : TextManager.getter('message', 'actorLoss'),
  108.     actorDrain      : TextManager.getter('message', 'actorDrain'),
  109.     actorNoDamage   : TextManager.getter('message', 'actorNoDamage'),
  110.     actorNoHit      : TextManager.getter('message', 'actorNoHit'),
  111.     enemyDamage     : TextManager.getter('message', 'enemyDamage'),
  112.     enemyRecovery   : TextManager.getter('message', 'enemyRecovery'),
  113.     enemyGain       : TextManager.getter('message', 'enemyGain'),
  114.     enemyLoss       : TextManager.getter('message', 'enemyLoss'),
  115.     enemyDrain      : TextManager.getter('message', 'enemyDrain'),
  116.     enemyNoDamage   : TextManager.getter('message', 'enemyNoDamage'),
  117.     enemyNoHit      : TextManager.getter('message', 'enemyNoHit'),
  118.     evasion         : TextManager.getter('message', 'evasion'),
  119.     magicEvasion    : TextManager.getter('message', 'magicEvasion'),
  120.     magicReflection : TextManager.getter('message', 'magicReflection'),
  121.     counterAttack   : TextManager.getter('message', 'counterAttack'),
  122.     substitute      : TextManager.getter('message', 'substitute'),
  123.     buffAdd         : TextManager.getter('message', 'buffAdd'),
  124.     debuffAdd       : TextManager.getter('message', 'debuffAdd'),
  125.     buffRemove      : TextManager.getter('message', 'buffRemove'),
  126.     actionFailure   : TextManager.getter('message', 'actionFailure'),
  127. });

8.场景管理器
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // SceneManager
  3. //
  4. // The static class that manages scene transitions.
  5. // 场景管理器
  6. // 静态类 管理场景转换
  7.  
  8. function SceneManager() {
  9.     throw new Error('This is a static class');
  10. }
  11.  
  12. SceneManager._scene             = null;   // 场景管理器.场景
  13. SceneManager._nextScene         = null;   // 场景管理器.下个场景
  14. SceneManager._stack             = [];     // 场景管理器.栈
  15. SceneManager._stopped           = false;  // 场景管理器.已经停止
  16. SceneManager._sceneStarted      = false;  // 场景管理器.场景已经开始
  17. SceneManager._exiting           = false;  // 场景管理器.正在退出
  18. SceneManager._previousClass     = null;   // 场景管理器.上节类
  19. SceneManager._backgroundBitmap  = null;   // 场景管理器.背景图
  20. SceneManager._screenWidth       = 816;    // 场景管理器.场景宽度
  21. SceneManager._screenHeight      = 624;    // 场景管理器.场景高度
  22. SceneManager._boxWidth          = 816;    // 场景管理器.容器宽度
  23. SceneManager._boxHeight         = 624;    // 场景管理器.容器高度
  24. // 场景管理器.运行
  25. SceneManager.run = function(sceneClass) {
  26.     try {
  27.         this.initialize();      // 场景管理器.初始化
  28.         this.goto(sceneClass);  // 场景管理器.跳转
  29.         this.requestUpdate();   // 场景管理器.请求更新
  30.     } catch (e) {
  31.         this.catchException(e);
  32.     }
  33. };
  34. // 场景管理器.初始化
  35. SceneManager.initialize = function() {
  36.     this.initGraphics();         // 场景管理器.初始化图形
  37.     this.checkFileAccess();      // 场景管理器.检查文件数据
  38.     this.initAudio();            // 场景管理器.初始化音频
  39.     this.initInput();            // 场景管理器.初始化输入
  40.     this.initNwjs();             // 场景管理器.初始化Nwjs
  41.     this.checkPluginErrors();    // 场景管理器.检查插件错误
  42.     this.setupErrorHandlers();   // 场景管理器.设置错误处理程序
  43. };
  44. // 场景管理器.初始化图形
  45. SceneManager.initGraphics = function() {
  46.     var type = this.preferableRendererType();   // 场景管理器.首选渲染类型
  47.     Graphics.initialize(this._screenWidth, this._screenHeight, type);  // 图形.初始化
  48.     Graphics.boxWidth = this._boxWidth;                                // 图形.窗口显示区域的宽度
  49.     Graphics.boxHeight = this._boxHeight;                              // 图形.窗口显示区域的高度
  50.     Graphics.setLoadingImage('img/system/Loading.png');                // 图形.设置正在加载中图像
  51.         // 是否需要显示 FPS
  52.     if (Utils.isOptionValid('showfps')) {
  53.         Graphics.showFps();  // 图形.显示FPS
  54.     }
  55.         // 渲染类型是否为 WebGL
  56.     if (type === 'webgl') {
  57.         this.checkWebGL();   // 场景管理器.检查WebGL
  58.     }
  59. };
  60. // 场景管理器.首选渲染类型
  61. SceneManager.preferableRendererType = function() {
  62.     if (Utils.isOptionValid('canvas')) {
  63.         return 'canvas';
  64.     } else if (Utils.isOptionValid('webgl')) {
  65.         return 'webgl';
  66.     } else if (this.shouldUseCanvasRenderer()) {
  67.         return 'canvas';
  68.     } else {
  69.         return 'auto';
  70.     }
  71. };
  72. // 场景管理器.应该使用的Canvas渲染器
  73. SceneManager.shouldUseCanvasRenderer = function() {
  74.     return Utils.isMobileDevice();
  75. };
  76. // 场景管理器.检查WebGL
  77. SceneManager.checkWebGL = function() {
  78.     if (!Graphics.hasWebGL()) {
  79.         throw new Error('Your browser does not support WebGL.');
  80.     }
  81. };
  82. // 场景管理器.检查文件数据
  83. SceneManager.checkFileAccess = function() {
  84.     if (!Utils.canReadGameFiles()) {
  85.         throw new Error('Your browser does not allow to read local files.');
  86.     }
  87. };
  88. // 场景管理器.初始化音频
  89. SceneManager.initAudio = function() {
  90.     var noAudio = Utils.isOptionValid('noaudio');
  91.     if (!WebAudio.initialize(noAudio) && !noAudio) {
  92.         throw new Error('Your browser does not support Web Audio API.');
  93.     }
  94. };
  95. // 场景管理器.初始化输入
  96. SceneManager.initInput = function() {
  97.     Input.initialize();
  98.     TouchInput.initialize();
  99. };
  100. // 场景管理器.初始化Nwjs  <node-webkit>
  101. SceneManager.initNwjs = function() {
  102.     if (Utils.isNwjs()) {
  103.         var gui = require('nw.gui'); // nodejs - nw.gui 模块
  104.         var win = gui.Window.get();  // 取gui 窗口
  105.         if (process.platform === 'darwin' && !win.menu) {
  106.             var menubar = new gui.Menu({ type: 'menubar' });
  107.             var option = { hideEdit: true, hideWindow: true };
  108.             menubar.createMacBuiltin('Game', option);
  109.             win.menu = menubar;
  110.         }
  111.     }
  112. };
  113. // 场景管理器.检查插件错误
  114. SceneManager.checkPluginErrors = function() {
  115.     PluginManager.checkErrors();
  116. };
  117. // 场景管理器.设置错误处理程序
  118. SceneManager.setupErrorHandlers = function() {
  119.     window.addEventListener('error', this.onError.bind(this));
  120.     document.addEventListener('keydown', this.onKeyDown.bind(this));
  121. };
  122. // 场景管理器.请求更新
  123. SceneManager.requestUpdate = function() {
  124.     if (!this._stopped) {
  125.         requestAnimationFrame(this.update.bind(this));
  126.     }
  127. };
  128. // 场景管理器更新
  129. SceneManager.update = function() {
  130.     try {
  131.         this.tickStart();      // 场景管理器.帧开始
  132.         this.updateInputData();// 场景管理器.刷新输入数据
  133.         this.updateMain();     // 场景管理器.主刷新
  134.         this.tickEnd();        // 场景管理器.帧结束
  135.     } catch (e) {
  136.         this.catchException(e);
  137.     }
  138. };
  139. // 场景管理器.终止
  140. SceneManager.terminate = function() {
  141.     window.close();
  142. };
  143. // 场景管理器.发生错误事件
  144. SceneManager.onError = function(e) {
  145.     console.error(e.message);
  146.     console.error(e.filename, e.lineno);
  147.     try {
  148.         this.stop();                   // 场景管理器.停止
  149.         Graphics.printError('Error', e.message);
  150.         AudioManager.stopAll();        // 音频管理器.停止所有音频
  151.     } catch (e2) {
  152.     }
  153. };
  154. // 场景管理器.键被按下事件
  155. SceneManager.onKeyDown = function(event) {
  156.     if (!event.ctrlKey && !event.altKey) {
  157.         switch (event.keyCode) {
  158.         case 116:   // F5
  159.             if (Utils.isNwjs()) {
  160.                 location.reload();   // 刷新页面
  161.             }
  162.             break;
  163.         case 119:   // F8
  164.             if (Utils.isNwjs() && Utils.isOptionValid('test')) {
  165.                 require('nw.gui').Window.get().showDevTools();   // Dev Tools
  166.             }
  167.             break;
  168.         }
  169.     }
  170. };
  171. // 场景管理器.异常捕获
  172. SceneManager.catchException = function(e) {
  173.     if (e instanceof Error) {
  174.         Graphics.printError(e.name, e.message);   // 图形.打印错误
  175.         console.error(e.stack);
  176.     } else {
  177.         Graphics.printError('UnknownError', e);   // 图形.打印错误
  178.     }
  179.     AudioManager.stopAll();                       // 音频管理器.停止所有音频
  180.     this.stop();                                  // 场景管理器.停止
  181. };
  182. // 场景管理器.帧开始
  183. SceneManager.tickStart = function() {
  184.     Graphics.tickStart(); // 图形.帧开始
  185. };
  186. // 场景管理器.帧结束
  187. SceneManager.tickEnd = function() {
  188.     Graphics.tickEnd();   // 图形.帧结束
  189. };
  190. // 场景管理器.更新输入数据
  191. SceneManager.updateInputData = function() {
  192.     Input.update();       // 输入.刷新()
  193.     TouchInput.update();  // 触摸输入.刷新()
  194. };
  195. // 场景管理器.主更新
  196. SceneManager.updateMain = function() {
  197.     this.changeScene();   // 场景管理器.改变场景
  198.     this.updateScene();   // 场景管理器.刷新场景
  199.     this.renderScene();   // 场景管理器.渲染场景
  200.     this.requestUpdate(); // 场景管理器.请求更新
  201. };
  202. // 场景管理器.改变场景
  203. SceneManager.changeScene = function() {
  204.         // 场景管理器.场景是否正在改变 且 !场景管理器.当前场景是否正忙
  205.     if (this.isSceneChanging() && !this.isCurrentSceneBusy()) {
  206.         if (this._scene) {
  207.             this._scene.terminate();                        // 场景管理器.场景.终止
  208.             this._previousClass = this._scene.constructor;  // 场景管理器.上节类 = 场景管理器.场景.构造
  209.         }
  210.         this._scene = this._nextScene;   // 场景管理器.场景 = 场景管理器.下个场景
  211.         if (this._scene) {               
  212.             this._scene.create();        // 场景管理器.场景.创建
  213.             this._nextScene = null;      // 场景管理器.下个场景 = null
  214.             this._sceneStarted = false;  // 场景管理器.场景已经开始 = false
  215.             this.onSceneCreate();        // 场景管理器.场景创建事件
  216.         }
  217.         if (this._exiting) {             // 场景管理器.正在退出中
  218.             this.terminate();            // 场景管理器.终止
  219.         }
  220.     }
  221. };
  222. // 场景管理器.更新场景
  223. SceneManager.updateScene = function() {
  224.     if (this._scene) {
  225.                 // !场景管理器.场景已经开始 且 场景管理器.场景.已经准备就绪
  226.         if (!this._sceneStarted && this._scene.isReady()) {
  227.             this._scene.start();           // 场景管理器.场景.开始
  228.             this._sceneStarted = true;     // 场景管理器.场景已经开始 = true
  229.             this.onSceneStart();           // 场景管理器.场景开始事件
  230.         }
  231.         if (this.isCurrentSceneStarted()) { // 场景管理器.当前场景是否已经开始
  232.             this._scene.update();           // 场景管理器.场景.刷新
  233.         }
  234.     }
  235. };
  236. // 场景管理器.渲染场景
  237. SceneManager.renderScene = function() {
  238.     if (this.isCurrentSceneStarted()) {     // 场景管理器.当前场景是否已经开始
  239.         Graphics.render(this._scene);       // 图形.渲染(场景管理器.场景)
  240.     } else if (this._scene) {
  241.         this.onSceneLoading();              // 场景管理器.场景加载中事件
  242.     }
  243. };
  244. // 场景管理器.场景创建事件
  245. SceneManager.onSceneCreate = function() {
  246.     Graphics.startLoading();     // 图形.开始正在读取中() // 初始化“正在读取中”状态的计时器。
  247. };
  248. // 场景管理器.场景开始事件
  249. SceneManager.onSceneStart = function() {
  250.     Graphics.endLoading();       // 图形.结束正在读取中() // 清除“正在读取中”状态的图片。
  251. };
  252. // 场景管理器.场景加载中事件
  253. SceneManager.onSceneLoading = function() {
  254.     Graphics.updateLoading();    // 图形.刷新正在读取中() // 累加“正在读取中”状态的计时器时间,必要时,显示“正在读取中”状态设置的图片。
  255. };
  256. // 场景管理器.场景是否在改变中
  257. SceneManager.isSceneChanging = function() {
  258.     return this._exiting || !!this._nextScene;
  259. };
  260. // 场景管理器.当前场景是否被占用
  261. SceneManager.isCurrentSceneBusy = function() {
  262.     return this._scene && this._scene.isBusy();
  263. };
  264. // 场景管理器.当前场景是否已经开始
  265. SceneManager.isCurrentSceneStarted = function() {
  266.     return this._scene && this._sceneStarted;
  267. };
  268. // 场景管理器.是否为下个场景
  269. SceneManager.isNextScene = function(sceneClass) {
  270.     return this._nextScene && this._nextScene.constructor === sceneClass;
  271. };
  272. // 场景管理器.是否为以前场景
  273. SceneManager.isPreviousScene = function(sceneClass) {
  274.     return this._previousClass === sceneClass;
  275. };
  276. // 场景管理器.跳转
  277. SceneManager.goto = function(sceneClass) {
  278.     if (sceneClass) {
  279.         this._nextScene = new sceneClass();  // 场景管理器.下个场景 = 实例化 sceneClass
  280.     }
  281.     if (this._scene) {
  282.         this._scene.stop();   // 场景管理器.场景.结束()
  283.     }
  284. };
  285. // 翻译下面两个让我想起了汇编
  286. // push ebp
  287. // mov ebp, esp
  288. // ......
  289. // mov esp, ebp
  290. // pop ebp
  291. // ret
  292. // 场景管理器.传递
  293. SceneManager.push = function(sceneClass) {
  294.     this._stack.push(this._scene.constructor);        // 场景管理器.栈.投递(场景管理器.场景.构造)
  295.     this.goto(sceneClass);                            // 场景管理器.跳转
  296. };
  297. // 场景管理器.弹出
  298. SceneManager.pop = function() {
  299.     if (this._stack.length > 0) {
  300.         this.goto(this._stack.pop());                 // 场景管理器.跳转(场景管理器.栈.弹出)
  301.     } else {
  302.         this.exit();
  303.     }
  304. };
  305. // 场景管理器.退出
  306. SceneManager.exit = function() {
  307.     this.goto(null);
  308.     this._exiting = true;
  309. };
  310. // 场景管理器.清除栈
  311. SceneManager.clearStack = function() {
  312.     this._stack = [];
  313. };
  314. // 场景管理器.停止
  315. SceneManager.stop = function() {
  316.     this._stopped = true;
  317. };
  318. // 场景管理器.开始准备下个场景
  319. SceneManager.prepareNextScene = function() {
  320.     this._nextScene.prepare.apply(this._nextScene, arguments);
  321. };
  322. // 场景管理器.截图
  323. SceneManager.snap = function() {
  324.     return Bitmap.snap(this._scene);
  325. };
  326. // 场景管理器.背景截图
  327. SceneManager.snapForBackground = function() {
  328.     this._backgroundBitmap = this.snap();
  329.     this._backgroundBitmap.blur();
  330. };
  331. // 场景管理器.背景图像
  332. SceneManager.backgroundBitmap = function() {
  333.     return this._backgroundBitmap;
  334. };

9.战斗管理器(这里有几个函数没有翻译-等待更新)
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // BattleManager
  3. //
  4. // The static class that manages battle progress.
  5. // 战斗管理器
  6. // 静态类 管理战斗进度消息
  7. function BattleManager() {
  8.     throw new Error('This is a static class');
  9. }
  10. // 战斗管理器.设置
  11. BattleManager.setup = function(troopId, canEscape, canLose) {
  12.     this.initMembers();           // 战斗管理器.初始化成员
  13.     this._canEscape = canEscape;  // 战斗管理器.可以逃跑
  14.     this._canLose = canLose;      // 战斗管理器.可以失败
  15.     $gameTroop.setup(troopId);    // 游戏敌群类.设置(敌群ID)
  16.     $gameScreen.onBattleStart();  // 游戏屏幕类.战斗开始事件()
  17.     this.makeEscapeRatio();       // 战斗管理器.制逃避率();
  18. };
  19. // 战斗管理器.初始化成员
  20. BattleManager.initMembers = function() {
  21.     this._phase = 'init';       // 战斗管理器.阶段
  22.     this._canEscape = false;    // 战斗管理器.可逃跑
  23.     this._canLose = false;      // 战斗管理器.可失败
  24.     this._battleTest = false;   // 战斗管理器.战斗测试
  25.     this._eventCallback = null; // 战斗管理器.事件回调
  26.     this._preemptive = false;   // 战斗管理器.先发制人
  27.     this._surprise = false;     // 战斗管理器.突然袭击
  28.     this._actorIndex = -1;      // 战斗管理器.角色索引
  29.     this._actionForcedBattler = null; // 战斗管理器.强制战斗行动
  30.     this._mapBgm = null;              // 战斗管理器.地图BGM
  31.     this._mapBgs = null;              // 战斗管理器.地图BGS
  32.     this._actionBattlers = [];        // 战斗管理器.战斗行动人员组
  33.     this._subject = null;             // 战斗管理器.行动者  Game_Actor || Game_Enemy
  34.     this._action = null;              // 战斗管理器.行动    Game_Action
  35.     this._targets = [];               // 战斗管理器.目标组
  36.     this._logWindow = null;           // 战斗管理器.日志窗口
  37.     this._statusWindow = null;        // 战斗管理器.状态窗口
  38.     this._spriteset = null;           // 战斗管理器.精灵
  39.     this._escapeRatio = 0;            // 战斗管理器.逃跑率
  40.     this._escaped = false;            // 战斗管理器.已经逃跑
  41.     this._rewards = {};               // 战斗管理器.奖励
  42. };
  43. // 战斗管理器.是否为战斗测试
  44. BattleManager.isBattleTest = function() {
  45.     return this._battleTest;
  46. };
  47. // 战斗管理器.设置战斗测试
  48. BattleManager.setBattleTest = function(battleTest) {
  49.     this._battleTest = battleTest;
  50. };
  51. // 战斗管理器.设置事件回调
  52. BattleManager.setEventCallback = function(callback) {
  53.     this._eventCallback = callback;
  54. };
  55. // 战斗管理器.设置日志窗口
  56. BattleManager.setLogWindow = function(logWindow) {
  57.     this._logWindow = logWindow;
  58. };
  59. // 战斗管理器.设置状态窗口
  60. BattleManager.setStatusWindow = function(statusWindow) {
  61.     this._statusWindow = statusWindow;
  62. };
  63. // 战斗管理器.设置精灵
  64. BattleManager.setSpriteset = function(spriteset) {
  65.     this._spriteset = spriteset;
  66. };
  67. // 战斗管理器.遇敌事件
  68. BattleManager.onEncounter = function() {
  69.     this._preemptive = (Math.random() < this.ratePreemptive());                   // 先发制人算法
  70.     this._surprise = (Math.random() < this.rateSurprise() && !this._preemptive);  // 会心一击算法
  71. };
  72. // 战斗管理器.敏捷率
  73. BattleManager.ratePreemptive = function() {
  74.     return $gameParty.ratePreemptive($gameTroop.agility());
  75. };
  76. //
  77. BattleManager.rateSurprise = function() {
  78.     return $gameParty.rateSurprise($gameTroop.agility());
  79. };
  80. // 战斗管理器.保存BGM和BGS
  81. BattleManager.saveBgmAndBgs = function() {
  82.     this._mapBgm = AudioManager.saveBgm();      // 音频管理器.保存BGM
  83.     this._mapBgs = AudioManager.saveBgs();      // 音频管理器.保存BGS
  84. };
  85. // 战斗管理器.播放战斗BGM
  86. BattleManager.playBattleBgm = function() {
  87.     AudioManager.playBgm($gameSystem.battleBgm());   // 音频管理器.播放BGM(游戏系统类.战斗BGM)
  88.     AudioManager.stopBgs();                          // 音频管理器.停止BGS
  89. };
  90. // 战斗管理器.播放胜利SE
  91. BattleManager.playVictoryMe = function() {
  92.     AudioManager.playMe($gameSystem.victoryMe());    // 音频管理器.播放ME(游戏系统类.胜利ME)
  93. };
  94. // 战斗管理器.播放失败ME
  95. BattleManager.playDefeatMe = function() {
  96.     AudioManager.playMe($gameSystem.defeatMe());    // 音频管理器.播放ME(游戏系统类.失败ME)
  97. };
  98. // 战斗管理器.重播BGM和BGS
  99. BattleManager.replayBgmAndBgs = function() {
  100.     if (this._mapBgm) {
  101.         AudioManager.replayBgm(this._mapBgm);       // 音频管理器.重播BGM(战斗管理器.地图BGM)
  102.     } else {
  103.         AudioManager.stopBgm();                     // 音频管理器.停止BGM
  104.     }
  105.     if (this._mapBgs) {                             // 战斗管理器.地图BGS
  106.         AudioManager.replayBgs(this._mapBgs);       // 音频管理器.重播BGS(战斗管理器.地图BGS)
  107.     }
  108. };
  109. // 战斗管理器.制逃避率
  110. BattleManager.makeEscapeRatio = function() {
  111.     this._escapeRatio = 0.5 * $gameParty.agility() / $gameTroop.agility();
  112. };
  113. // 战斗管理器.更新
  114. BattleManager.update = function() {
  115.     if (!this.isBusy() && !this.updateEvent()) {
  116.         switch (this._phase) {
  117.         case 'start':
  118.             this.startInput();      // 战斗管理器.开始输入
  119.             break;
  120.         case 'turn':
  121.             this.updateTurn();      // 战斗管理器.刷新回合
  122.             break;
  123.         case 'action':
  124.             this.updateAction();    // 战斗管理器.刷新行动
  125.             break;
  126.         case 'turnEnd':
  127.             this.updateTurnEnd();   // 战斗管理器.刷新回合结束
  128.             break;
  129.         case 'battleEnd':
  130.             this.updateBattleEnd(); // 战斗管理器.刷新战斗结束
  131.             break;
  132.         }
  133.     }
  134. };
  135. // 战斗管理器.更新事件
  136. BattleManager.updateEvent = function() {
  137.     switch (this._phase) {
  138.     case 'start':
  139.     case 'turn':
  140.     case 'turnEnd':
  141.         if (this.isActionForced()) {
  142.             this.processForcedAction();    // 战斗管理器.强制行动流程
  143.             return true;
  144.         } else {
  145.             return this.updateEventMain(); // 战斗管理器.主刷新事件
  146.         }
  147.     }
  148.     return this.checkAbort();              // 战斗管理器.检查是否战斗已经终止
  149. };
  150. // 战斗管理器.主刷新事件
  151. BattleManager.updateEventMain = function() {
  152.     $gameTroop.updateInterpreter();        // 游戏敌群类.刷新事件解释器
  153.     $gameParty.requestMotionRefresh();     // 游戏队伍类.请求动态刷新
  154.         // 游戏敌群类.事件正在运行 或 战斗管理器.检查战斗是否已经结束
  155.     if ($gameTroop.isEventRunning() || this.checkBattleEnd()) {
  156.         return true;
  157.     }
  158.         // 游戏敌群类.设置战斗事件
  159.     $gameTroop.setupBattleEvent();
  160.         // 游戏敌群类.事件正在运行 或 场景管理器.场景是否在改变中
  161.     if ($gameTroop.isEventRunning() || SceneManager.isSceneChanging()) {
  162.         return true;
  163.     }
  164.     return false;
  165. };
  166. // 战斗管理器.是否正忙
  167. BattleManager.isBusy = function() {
  168.         // 游戏消息类.是否正忙 或 战斗管理器.精灵.是否正忙 或 战斗管理器.日志窗口.是否正忙
  169.     return ($gameMessage.isBusy() || this._spriteset.isBusy() ||
  170.             this._logWindow.isBusy());
  171. };
  172. // 战斗管理器.是否正在输入中
  173. BattleManager.isInputting = function() {
  174.     return this._phase === 'input';
  175. };
  176. // 战斗管理器.是否在一回合中
  177. BattleManager.isInTurn = function() {
  178.     return this._phase === 'turn';
  179. };
  180. // 战斗管理器.是否一回合已经结束
  181. BattleManager.isTurnEnd = function() {
  182.     return this._phase === 'turnEnd';
  183. };
  184. // 战斗管理器.是否已经终止
  185. BattleManager.isAborting = function() {
  186.     return this._phase === 'aborting';
  187. };
  188. // 战斗管理器.是否战斗已经结束
  189. BattleManager.isBattleEnd = function() {
  190.     return this._phase === 'battleEnd';
  191. };
  192. // 战斗管理器.是否可以逃跑
  193. BattleManager.canEscape = function() {
  194.     return this._canEscape;
  195. };
  196. // 战斗管理器.是否可以失去
  197. BattleManager.canLose = function() {
  198.     return this._canLose;
  199. };
  200. // 战斗管理器.是否已经逃跑
  201. BattleManager.isEscaped = function() {
  202.     return this._escaped;
  203. };
  204. // 战斗管理器.角色
  205. BattleManager.actor = function() {
  206.     return this._actorIndex >= 0 ? $gameParty.members()[this._actorIndex] : null;
  207. };
  208. // 战斗管理器.清除角色
  209. BattleManager.clearActor = function() {
  210.     this.changeActor(-1, '');
  211. };
  212. // 战斗管理器.更改角色
  213. BattleManager.changeActor = function(newActorIndex, lastActorActionState) {
  214.     var lastActor = this.actor();      // 保存当前角色
  215.     this._actorIndex = newActorIndex;  // 设置当前角色索引
  216.     var newActor = this.actor();       // 再取出设置的角色
  217.     if (lastActor) {                   // 设置最后角色的动作状态
  218.         lastActor.setActionState(lastActorActionState);
  219.     }
  220.     if (newActor) {                    // 设置新角色的动作状态
  221.         newActor.setActionState('inputting');
  222.     }
  223. };
  224. // 战斗管理器.开始战斗
  225. BattleManager.startBattle = function() {
  226.     this._phase = 'start';
  227.     $gameSystem.onBattleStart();      // 游戏系统类.战斗开始事件
  228.     $gameParty.onBattleStart();       // 游戏队伍类.战斗开始事件
  229.     $gameTroop.onBattleStart();       // 游戏敌群类.战斗开始事件
  230.     this.displayStartMessages();      // 战斗管理器.显示开始消息
  231. };
  232. // 战斗管理器.显示启动信息
  233. BattleManager.displayStartMessages = function() {
  234.         // 游戏敌群类.敌人名称组.遍历数组
  235.     $gameTroop.enemyNames().forEach(function(name) {
  236.         $gameMessage.add(TextManager.emerge.format(name));                  // 游戏消息类.添加(消息术语管理器.出现.格式化(name)) -> 格式化成 xxx出现
  237.     });
  238.     if (this._preemptive) {        // 是否先发制人
  239.         $gameMessage.add(TextManager.preemptive.format($gameParty.name())); // 游戏消息类.添加(消息术语管理器.出现.格式化(name)) -> 格式化成 xxx先发制人
  240.     } else if (this._surprise) {   // 是否突然袭击
  241.         $gameMessage.add(TextManager.surprise.format($gameParty.name()));   // 游戏消息类.添加(消息术语管理器.出现.格式化(name)) -> 格式化成 xxx突然袭击
  242.     }
  243. };
  244. // 战斗管理器.开始输入
  245. BattleManager.startInput = function() {
  246.     this._phase = 'input';
  247.     $gameParty.makeActions();    // 游戏队伍类.做出行动
  248.     $gameTroop.makeActions();    // 游戏敌群类.做出行动
  249.     this.clearActor();           // 战斗管理器.清除角色
  250.     if (this._surprise || !$gameParty.canInput()) {   // 战斗管理器.突然袭击 或 游戏队伍类.是否可以输入
  251.         this.startTurn();        // 战斗管理器.开始一回合
  252.     }
  253. };
  254. // 战斗管理器.输入操作
  255. BattleManager.inputtingAction = function() {
  256.     return this.actor() ? this.actor().inputtingAction() : null;
  257. };
  258. // 战斗管理器.选择下个动作
  259. BattleManager.selectNextCommand = function() {
  260.     do {
  261.         if (!this.actor() || !this.actor().selectNextCommand()) {
  262.             this.changeActor(this._actorIndex + 1, 'waiting');  // 战斗管理器.更改角色
  263.             if (this._actorIndex >= $gameParty.size()) {        // 战斗管理器.当前角色索引 >= 游戏队伍类.人员数量
  264.                 this.startTurn();   // 战斗管理器.开始一回合
  265.                 break;              // 跳出循环
  266.             }
  267.         }
  268.     } while (!this.actor().canInput());
  269. };
  270. // 战斗管理器.选择上一个命令
  271. BattleManager.selectPreviousCommand = function() {
  272.     do {
  273.         if (!this.actor() || !this.actor().selectPreviousCommand()) {
  274.             this.changeActor(this._actorIndex - 1, 'undecided');  // 战斗管理器.更改角色
  275.             if (this._actorIndex < 0) {                           // 战斗管理器.当前角色索引 < 0
  276.                 return;
  277.             }
  278.         }
  279.     } while (!this.actor().canInput());
  280. };
  281. // 战斗管理器.刷新状态
  282. BattleManager.refreshStatus = function() {
  283.     this._statusWindow.refresh();   // 战斗管理器.状态窗口.刷新
  284. };
  285. // 战斗管理器.开始一回合
  286. BattleManager.startTurn = function() {
  287.     this._phase = 'turn';
  288.     this.clearActor();              // 战斗管理器.清除角色
  289.     $gameTroop.increaseTurn();      // 游戏敌群类.增加回合
  290.     this.makeActionOrders();        // 战斗管理器.作行动命令
  291.     $gameParty.requestMotionRefresh(); // 游戏队伍类.请求动态刷新
  292.     this._logWindow.startTurn();
  293. };
  294. // 战斗管理器.刷新回合
  295. BattleManager.updateTurn = function() {
  296.     $gameParty.requestMotionRefresh();  // 游戏队伍类.请求动态刷新
  297.     if (!this._subject) {               // 战斗管理器.行动者
  298.         this._subject = this.getNextSubject();   // 战斗管理器.取下个行动者
  299.     }
  300.     if (this._subject) {
  301.         this.processTurn();             // 战斗管理器.流程回合
  302.     } else {
  303.         this.endTurn();                 // 战斗管理器.结束一回合
  304.     }
  305. };
  306. // 战斗管理器.流程回合
  307. BattleManager.processTurn = function() {
  308.     var subject = this._subject;           // 战斗管理器.行动者
  309.     var action = subject.currentAction();  // 取 行动者.当前动作
  310.     if (action) {
  311.         action.prepare();                  // 动作.准备
  312.         if (action.isValid()) {
  313.             this.startAction();
  314.         }
  315.         subject.removeCurrentAction();     // 行动者.移除当前动作
  316.     } else {
  317.         subject.onAllActionsEnd();         // 行动者.全部动作结束事件
  318.         this.refreshStatus();              // 战斗管理器.刷新状态
  319.         this._logWindow.displayAutoAffectedStatus(subject);  // 战斗管理器.日志窗口.显示自动受影响状况
  320.         this._logWindow.displayCurrentState(subject);        // 战斗管理器.日志窗口.显示当前状态
  321.         this._logWindow.displayRegeneration(subject);        // 战斗管理器.日志窗口.显示恢复
  322.         this._subject = this.getNextSubject();               // 战斗管理器.行动者 = 战斗管理器.取下个行动者
  323.     }
  324. };
  325. // 战斗管理器.结束一回合
  326. BattleManager.endTurn = function() {
  327.     this._phase = 'turnEnd';       // 战斗管理器.阶段
  328.     this._preemptive = false;      // 战斗管理器.先发制人 = false
  329.     this._surprise = false;        // 战斗管理器.突然袭击 = false
  330.         // 战斗管理器.全部战斗成员.遍历
  331.     this.allBattleMembers().forEach(function(battler) {
  332.         battler.onTurnEnd();   // 战斗者.结束一回合
  333.         this.refreshStatus();  // 战斗管理器.刷新状态
  334.         this._logWindow.displayAutoAffectedStatus(battler);  // 战斗管理器.日志窗口.显示自动受影响状况
  335.         this._logWindow.displayRegeneration(battler);        // 战斗管理器.日志窗口.显示恢复
  336.     }, this);
  337. };
  338. // 战斗管理器.刷新回合结束
  339. BattleManager.updateTurnEnd = function() {
  340.     this.startInput();
  341. };
  342. // 战斗管理器.取下个行动者
  343. BattleManager.getNextSubject = function() {
  344.     for (;;) {
  345.         var battler = this._actionBattlers.shift();   // 战斗者 = 战斗管理器.战斗行动人员组.左移
  346.         if (!battler) {
  347.             return null;
  348.         }
  349.         if (battler.isBattleMember() && battler.isAlive()) {  // 战斗者.是否为战斗成员 且 战斗者.是否生存
  350.             return battler;
  351.         }
  352.     }
  353. };
  354. // 战斗管理器.全部战斗成员
  355. BattleManager.allBattleMembers = function() {
  356.     return $gameParty.members().concat($gameTroop.members());
  357. };
  358. // 战斗管理器.作行动命令
  359. BattleManager.makeActionOrders = function() {
  360.     var battlers = [];
  361.     if (!this._surprise) {    // !战斗管理器.突然袭击
  362.         battlers = battlers.concat($gameParty.members());   // 参战人员组 连接数组 游戏队伍类.成员组
  363.     }
  364.     if (!this._preemptive) {  // !战斗管理器.先发制人
  365.         battlers = battlers.concat($gameTroop.members());   // 参战人员组 连接数组 游戏敌群类.成员组
  366.     }
  367.         // 参战人员组 遍历
  368.     battlers.forEach(function(battler) {
  369.         battler.makeSpeed();    // 参战人员组.制速度
  370.     });
  371.         // 参战人员组.排序()   详见:Array.sort
  372.     battlers.sort(function(a, b) {
  373.         return b.speed() - a.speed();
  374.     });
  375.     this._actionBattlers = battlers;  // 战斗管理器.战斗行动人员组 = 参战人员组
  376. };
  377. // 战斗管理器.开始行动
  378. BattleManager.startAction = function() {
  379.     var subject = this._subject;           // 战斗管理器.行动者
  380.     var action = subject.currentAction();  // 行动者.当前动作
  381.     var targets = action.makeTargets();    // 动作.置目标组
  382.     this._phase = 'action';
  383.     this._action = action;                 // 战斗管理器.动作 = action = 行动者.当前动作
  384.     this._targets = targets;               // 战斗管理器.目标组 = targets = 行动者.当前动作.置目标组
  385.     subject.useItem(action.item());        // 行动者.使用物品(动作.物品数据)
  386.     this._action.applyGlobal();            // 战斗管理器.动作.应用全局()
  387.     this.refreshStatus();                  // 战斗管理器.刷新状态()
  388.     this._logWindow.startAction(subject, action, targets);  // 战斗管理器.日志窗口.开始行动(行动者, 动作, 目标组)
  389. };
  390. // 战斗管理器.刷新行动
  391. BattleManager.updateAction = function() {
  392.     var target = this._targets.shift();            // 目标 = 战斗管理器.目标组.左移()
  393.     if (target) {
  394.         this.invokeAction(this._subject, target);  // 战斗管理器.调用行动(战斗管理器.行动者, 目标)
  395.     } else {
  396.         this.endAction();                          // 战斗管理器.结束行动
  397.     }
  398. };
  399. // 战斗管理器.结束行动
  400. BattleManager.endAction = function() {
  401.     this._logWindow.endAction(this._subject);        // 战斗管理器.日志窗口.结束行动(战斗管理器.行动者)
  402.     this._phase = 'turn';
  403. };
  404. // 战斗管理器.调用行动
  405. BattleManager.invokeAction = function(subject, target) {
  406.     this._logWindow.push('pushBaseLine');            // 战斗管理器.日志窗口.投递()
  407.     if (Math.random() < this._action.itemCnt(target)) {
  408.         this.invokeCounterAttack(subject, target);   // 战斗管理器.调用反击(行动者, 目标)
  409.     } else if (Math.random() < this._action.itemMrf(target)) {
  410.         this.invokeMagicReflection(subject, target); // 战斗管理器.调用魔法发射(行动者, 目标)
  411.     } else {
  412.         this.invokeNormalAction(subject, target);    // 战斗管理器.调用正常行动(行动者, 目标)
  413.     }
  414.     subject.setLastTarget(target);                   // 行动者.设置最后目标(目标)
  415.     this._logWindow.push('popBaseLine');             // 战斗管理器.日志窗口.投递()
  416.     this.refreshStatus();                            // 战斗管理器.刷新状态
  417. };
  418. // 战斗管理器.调用正常行动
  419. BattleManager.invokeNormalAction = function(subject, target) {
  420.     var realTarget = this.applySubstitute(target);
  421.     this._action.apply(realTarget);
  422.     this._logWindow.displayActionResults(subject, realTarget);
  423. };
  424. // 战斗管理器.调用反击
  425. BattleManager.invokeCounterAttack = function(subject, target) {
  426.     var action = new Game_Action(target);
  427.     action.setAttack();
  428.     action.apply(subject);
  429.     this._logWindow.displayCounter(target);
  430.     this._logWindow.displayActionResults(subject, subject);
  431. };
  432. // 战斗管理器.调用魔法发射
  433. BattleManager.invokeMagicReflection = function(subject, target) {
  434.     this._logWindow.displayReflection(target);
  435.     this._action.apply(subject);
  436.     this._logWindow.displayActionResults(subject, subject);
  437. };
  438. // 战斗管理器.应用代替者
  439. BattleManager.applySubstitute = function(target) {
  440.     if (this.checkSubstitute(target)) {
  441.         var substitute = target.friendsUnit().substituteBattler();
  442.         if (substitute && target !== substitute) {
  443.             this._logWindow.displaySubstitute(substitute, target);
  444.             return substitute;
  445.         }
  446.     }
  447.     return target;
  448. };
  449. // 战斗管理器.检查代替者
  450. BattleManager.checkSubstitute = function(target) {
  451.     return target.isDying() && !this._action.isCertainHit();
  452. };
  453. // 战斗管理器.是否强制行动
  454. BattleManager.isActionForced = function() {
  455.     return !!this._actionForcedBattler;
  456. };
  457. // 战斗管理器.强制行动
  458. BattleManager.forceAction = function(battler) {
  459.     this._actionForcedBattler = battler;
  460.     var index = this._actionBattlers.indexOf(battler);
  461.     if (index >= 0) {
  462.         this._actionBattlers.splice(index, 1);
  463.     }
  464. };
  465. // 战斗管理器.强制行动流程
  466. BattleManager.processForcedAction = function() {
  467.     if (this._actionForcedBattler) {
  468.         this._subject = this._actionForcedBattler;
  469.         this._actionForcedBattler = null;
  470.         this.startAction();
  471.         this._subject.removeCurrentAction();
  472.     }
  473. };
  474. // 战斗管理器.终止
  475. BattleManager.abort = function() {
  476.     this._phase = 'aborting';
  477. };
  478. // 战斗管理器.检查是否战斗已经结束
  479. BattleManager.checkBattleEnd = function() {
  480.     if (this._phase) {
  481.         if (this.checkAbort()) {
  482.             return true;
  483.         } else if ($gameParty.isAllDead()) {
  484.             this.processDefeat();
  485.             return true;
  486.         } else if ($gameTroop.isAllDead()) {
  487.             this.processVictory();
  488.             return true;
  489.         }
  490.     }
  491.     return false;
  492. };
  493. // 战斗管理器.检查是否战斗已经终止
  494. BattleManager.checkAbort = function() {
  495.     if ($gameParty.isEmpty() || this.isAborting()) {
  496.         this.processAbort();
  497.         return true;
  498.     }
  499.     return false;
  500. };
  501. // 战斗管理器.胜利过程
  502. BattleManager.processVictory = function() {
  503.     $gameParty.removeBattleStates();
  504.     $gameParty.performVictory();
  505.     this.playVictoryMe();
  506.     this.replayBgmAndBgs();
  507.     this.makeRewards();
  508.     this.displayVictoryMessage();
  509.     this.displayRewards();
  510.     this.gainRewards();
  511.     this.endBattle(0);
  512. };
  513. // 战斗管理器.逃跑过程
  514. BattleManager.processEscape = function() {
  515.     $gameParty.removeBattleStates();
  516.     $gameParty.performEscape();
  517.     SoundManager.playEscape();
  518.     var success = this._preemptive ? true : (Math.random() < this._escapeRatio);
  519.     if (success) {
  520.         this.displayEscapeSuccessMessage();
  521.         this._escaped = true;
  522.         this.processAbort();
  523.     } else {
  524.         this.displayEscapeFailureMessage();
  525.         this._escapeRatio += 0.1;
  526.         $gameParty.clearActions();
  527.         this.startTurn();
  528.     }
  529.     return success;
  530. };
  531. // 战斗管理器.终止过程
  532. BattleManager.processAbort = function() {
  533.     this.replayBgmAndBgs();
  534.     this.endBattle(1);
  535. };
  536. // 战斗管理器.失败过程
  537. BattleManager.processDefeat = function() {
  538.     this.displayDefeatMessage();
  539.     this.playDefeatMe();
  540.     if (this._canLose) {
  541.         this.replayBgmAndBgs();
  542.     } else {
  543.         AudioManager.stopBgm();
  544.     }
  545.     this.endBattle(2);
  546. };
  547. // 战斗管理器.结束战斗
  548. BattleManager.endBattle = function(result) {
  549.     this._phase = 'battleEnd';
  550.     if (this._eventCallback) {
  551.         this._eventCallback(result);
  552.     }
  553.     if (result === 0) {
  554.         $gameSystem.onBattleWin();
  555.     } else if (this._escaped) {
  556.         $gameSystem.onBattleEscape();
  557.     }
  558. };
  559. // 战斗管理器.刷新战斗结束
  560. BattleManager.updateBattleEnd = function() {
  561.     if (this.isBattleTest()) {
  562.         AudioManager.stopBgm();
  563.         SceneManager.exit();
  564.     } else if ($gameParty.isAllDead()) {
  565.         if (this._canLose) {
  566.             $gameParty.reviveBattleMembers();
  567.             SceneManager.pop();
  568.         } else {
  569.             SceneManager.goto(Scene_Gameover);
  570.         }
  571.     } else {
  572.         SceneManager.pop();
  573.     }
  574.     this._phase = null;
  575. };
  576. // 战斗管理器.制奖励
  577. BattleManager.makeRewards = function() {
  578.     this._rewards = {};
  579.     this._rewards.gold = $gameTroop.goldTotal();
  580.     this._rewards.exp = $gameTroop.expTotal();
  581.     this._rewards.items = $gameTroop.makeDropItems();
  582. };
  583. // 战斗管理器.显示胜利消息
  584. BattleManager.displayVictoryMessage = function() {
  585.     $gameMessage.add(TextManager.victory.format($gameParty.name()));
  586. };
  587. // 战斗管理器.显示失败消息
  588. BattleManager.displayDefeatMessage = function() {
  589.     $gameMessage.add(TextManager.defeat.format($gameParty.name()));
  590. };
  591. // 战斗管理器.显示逃跑消息
  592. BattleManager.displayEscapeSuccessMessage = function() {
  593.     $gameMessage.add(TextManager.escapeStart.format($gameParty.name()));
  594. };
  595. // 战斗管理器.显示逃跑失败消息
  596. BattleManager.displayEscapeFailureMessage = function() {
  597.     $gameMessage.add(TextManager.escapeStart.format($gameParty.name()));
  598.     $gameMessage.add('\\.' + TextManager.escapeFailure);
  599. };
  600. // 战斗管理器.显示奖励消息
  601. BattleManager.displayRewards = function() {
  602.     this.displayExp();
  603.     this.displayGold();
  604.     this.displayDropItems();
  605. };
  606. // 战斗管理器.显示奖励消息-经验
  607. BattleManager.displayExp = function() {
  608.     var exp = this._rewards.exp;
  609.     if (exp > 0) {
  610.         var text = TextManager.obtainExp.format(exp, TextManager.exp);
  611.         $gameMessage.add('\\.' + text);
  612.     }
  613. };
  614. // 战斗管理器.显示奖励消息-金币
  615. BattleManager.displayGold = function() {
  616.     var gold = this._rewards.gold;
  617.     if (gold > 0) {
  618.         $gameMessage.add('\\.' + TextManager.obtainGold.format(gold));
  619.     }
  620. };
  621. // 战斗管理器.显示奖励消息-掉落的物品
  622. BattleManager.displayDropItems = function() {
  623.     var items = this._rewards.items;
  624.     if (items.length > 0) {
  625.         $gameMessage.newPage();
  626.         items.forEach(function(item) {
  627.             $gameMessage.add(TextManager.obtainItem.format(item.name));
  628.         });
  629.     }
  630. };
  631. // 战斗管理器.获得奖励
  632. BattleManager.gainRewards = function() {
  633.     this.gainExp();           // 战斗管理器.获得经验
  634.     this.gainGold();          // 战斗管理器.获得金币
  635.     this.gainDropItems();     // 战斗管理器.获得物品组
  636. };
  637. // 战斗管理器.获得经验
  638. BattleManager.gainExp = function() {
  639.     var exp = this._rewards.exp;   // 经验值 = 战斗管理器.奖励.经验值
  640.         // 游戏队伍类.全体成员组.遍历数组()
  641.     $gameParty.allMembers().forEach(function(actor) {
  642.         actor.gainExp(exp);        // 角色.获得经验(经验值)
  643.     });
  644. };
  645. // 战斗管理器.获得金币
  646. BattleManager.gainGold = function() {
  647.     $gameParty.gainGold(this._rewards.gold);  // 游戏队伍类.获得金币(战斗管理器.奖励.金币)
  648. };
  649. // 战斗管理器.获得物品组
  650. BattleManager.gainDropItems = function() {
  651.     var items = this._rewards.items;   // 物品组 = 战斗管理器.奖励.物品组
  652.         // 物品组.遍历数组
  653.     items.forEach(function(item) {
  654.         $gameParty.gainItem(item, 1);  // 游戏队伍类.获得物品(物品, 1)
  655.     });
  656. };

10.插件管理器(这里只翻译了函数名-具体没有翻译(很简单))
JAVASCRIPT 代码复制
  1. //-----------------------------------------------------------------------------
  2. // PluginManager
  3. //
  4. // The static class that manages the plugins.
  5. // 插件管理器
  6. // 静态类 - 管理插件的类
  7. function PluginManager() {
  8.     throw new Error('This is a static class');
  9. }
  10.  
  11. PluginManager._path         = 'js/plugins/';   // 插件路径
  12. PluginManager._scripts      = [];              // 脚本组
  13. PluginManager._errorUrls    = [];              // 错误网络地址
  14. PluginManager._parameters   = {};              // 参数
  15. // 插件管理器.设置
  16. PluginManager.setup = function(plugins) {
  17.     plugins.forEach(function(plugin) {
  18.         if (plugin.status && !this._scripts.contains(plugin.name)) {
  19.             this.setParameters(plugin.name, plugin.parameters);
  20.             this.loadScript(plugin.name + '.js');
  21.             this._scripts.push(plugin.name);
  22.         }
  23.     }, this);
  24. };
  25. // 插件管理器.检查错误
  26. PluginManager.checkErrors = function() {
  27.     var url = this._errorUrls.shift();
  28.     if (url) {
  29.         throw new Error('Failed to load: ' + url);
  30.     }
  31. };
  32. // 插件管理器.参数
  33. PluginManager.parameters = function(name) {
  34.     return this._parameters[name.toLowerCase()] || {};
  35. };
  36. // 插件管理器.设置参数
  37. PluginManager.setParameters = function(name, parameters) {
  38.     this._parameters[name.toLowerCase()] = parameters;
  39. };
  40. // 插件管理器.加载脚本
  41. PluginManager.loadScript = function(name) {
  42.     var url = this._path + name;
  43.     var script = document.createElement('script');
  44.     script.type = 'text/javascript';
  45.     script.src = url;
  46.     script.async = false;
  47.     script.onerror = this.onError.bind(this);
  48.     script._url = url;
  49.     document.body.appendChild(script);
  50. };
  51. // 插件管理器.错误事件
  52. PluginManager.onError = function(e) {
  53.     this._errorUrls.push(e.target._url);
  54. };

作者: 青鸫    时间: 2017-3-9 18:53
天天天天哪!!!!!大佬辛苦了!!!谢谢大佬!!给大佬端茶!
作者: walf_man    时间: 2017-3-9 19:07
此坑略大,做的非常好,翻译准确到位,而且格式工整。加油!
作者: kula1900    时间: 2017-3-9 19:09
青鸫 发表于 2017-3-9 18:53
天天天天哪!!!!!大佬辛苦了!!!谢谢大佬!!给大佬端茶!

开胃小菜,翻译全部后,上传哈。
作者: 埋头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