设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 100|回复: 0

[转载发布] Consistent Audio Plugin

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    8258

    主题

    864

    回帖

    3万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    30523
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    39675

    灌水之王

    发表于 6 天前 | 显示全部楼层 |阅读模式
    Consistent Audio (CA) v1.01
    Author:
    Michael Morris @Blue Booth Studios


    Introduction
    Hailed by some as "the most useful plugin of all time," Consistent Audio (CA) is one of two planned plugins for consistent map state between map transitions, saves, and loads (the second being Consistent Weather (CW)).  In est, CA automatically ensures that the BGM and BGS you last have playing on a map will always play for that map.  If the BGM or BGS changes, it will become the new "last BGM/BGS" for that map.  If you transition to another map, and then back to the first map, BGM/BGS will be lost without the use of parallel events.  Not anymore!  Likewise, loading a saved game can often result in different BGM/BGS without use of the same events.  This is also no longer a problem.  BGM/BGS Fadein and Fadeout?  Automated for you.  BGM/BGS will fade out and then in when changing maps.  Fadein is also automatically called whenever a new BGM/BGS plays.  Tracking any custom volumes, pitch, and pan for both BGM/BGS are also automated.

    To be blunt, the value of this plugin does not lay in its ability to do something that could not be done without events, but rather, to simplify development and testing.  With CA, having the BGM/BGS you expect to have playing, playing, is a much simpler task; in fact, no audio parallel events, switches, or variables are necessary!

    The only commands you need to make to BGM/BGS are the play and fadeout commands.  This logic can be as complicated or simple as you need.  Once the BGM/BGS starts playing, everything else is taken care of for you.

    Features
    - Uses triage to determine what BGM/BGS to play; if CA has a BGM/BGS stored for the target map already, it will play that BGM/BGS.  If no BGM/BGS is already stored, it will attempt to play the Map BGM/BGS (defined in Map Properties).  If neither of the two are set, CA will play nothing.  If and when an event on the target map later plays a BGM/BGS, CA will store that BGM/BGS.

    - CA saves an array of all map audio settings into player save files, when the player elects to save the game.  This reduces the change for inconsistencies arising from resetting the game after a BGM/BGS change takes effect, and allows for saving more than one map audio state (very important when returning to other maps).  The downside to this is that it will increase the size of player save files, but given that the save data is in text format, save files are not expected to bloat to unreasonable levels.

    - BGM/BGS are remembered for every single map in your project.  In comparison, the "Save BGM/BGS" and "Replay BGM/BGS" commands in RMMV will only remember the current map's audio.

    - BGM/BGS are remembered across save, loads, and program exits.  In comparison, the "Save BGM/BGS" and "Replay BGM/BGS" commands in RMMV will not remember across any of these scenarios.

    - Apart from merely playing BGM/BGS, changes to volume, pitch, pan are also stored and remembered.

    - Automatically fades out BGM/BGS, and fades in new BGM/BGS during map transitions.

    - Autoplay BGM/BGS (Map settings) are now also set to (automatically) fade-in when loading from a save file.

    - Sets all audio fades to one universal fade-in duration of your choice.

    - Compatible with projects that already use parallel events, switches, or variables to track audio state.

    - Storage settings can be overwritten.  Using the "ConsistentAudio IgnoreNext," "ConsistentAudio IgnoreNextBGM," and
    "ConsistentAudio IgnoreNextBGS") commands will instruct CA not to store the next BGM/BGS change (IgnoreNextBGM and IgnoreNextBGS provide greater granularity over this override).  After the next change is ignored, CA will resume storing changes.

    - Fast.  No perceptible performance drop was noted during tests.


    How to Use
    - Copy script into your game js/plugins directory.
    - Import and configure plugin.

    Requirements
    This script has no external requirements.

    Screenshots
    N/A


    Demo
    See attachments.
    To run the demo, create a new project in RPGMaker MV, and extract the provided
    archive to the root folder of the new project.  If prompted to overwrite any files, select yes.

    Script
    Spoiler                Code:       
    1. //=============================================================================
    2. // Bluebooth Plugins - Consistent Audio
    3. // BBS_ConsistentAudio.js
    4. //=============================================================================
    5. //=============================================================================
    6. /*:
    7. * @plugindesc v1.01 Keep BGS/BGM consistent when transitioning between maps,
    8. * after loading a saved file, transitioning to and from menus, etc.  In other words
    9. * this eliminates the need for checks on every map to confirm the right BGM/BGS/BGM
    10. * is playing.
    11. * @author Michael Morris
    12. *
    13. * @param Universal Fade Duration
    14. * @desc How many frames audio should take to fade in and out.  6 by default.
    15. * Default: 6
    16. * @default 6
    17. *
    18. * @param ---Debug Settings---
    19. * @default
    20. *
    21. * @param Debug Mode
    22. * @desc Enable to activate console variable logging.  Use for debugging odd behaviour.
    23. * true to enable console variable logging.
    24. * @default false
    25. *
    26. * @help
    27. * ============================================================================
    28. * Introduction
    29. * ============================================================================
    30. *
    31. * One of my biggest pet peeves with RPG Maker MV is that it doesn't track the most
    32. * recent weather and BGS/BGM when transitioning to an interior and then back to
    33. * the exterior map again, or during save and loads!  This is mostly a problem on
    34. * maps where these conditions can change based on scripts (ie. the map is normally
    35. * a "day" map, but with a time change is now a "night" map).  It would be really
    36. * helpful if such settings could be tracked for you.  So I made it happen.
    37. * This cuts down on debugging time (you won't need to check every door during
    38. * every condition change to see which door loses changes), and
    39. * just makes development life more pleasant.
    40. *
    41. * ============================================================================
    42. * Plugin Commands
    43. * ============================================================================
    44. *
    45. *  consistentAudio ignoreNext                Do not save the next audio change for BGM or BGS, whichever comes first.
    46. *  consistentAudio ignoreNextBgm            Do not save the next audio change for BGM only.
    47. *  consistentAudio ignoreNextBgs            Do not save the next audio change for BGS only.
    48. *
    49. * ============================================================================
    50. * Versions
    51. * ============================================================================
    52. * 1.01 - Plugin finished.
    53. *
    54. */
    55. //=============================================================================
    56. //=============================================================================
    57. //=============================================================================
    58. var Imported = Imported || {} ;
    59. var BBS = BBS || {};
    60. Imported.ConsistentAudio = 1;
    61. BBS.ConsistentAudio = BBS.ConsistentAudio || {};
    62. (function() {
    63.      
    64.     //=============================================================================
    65.     // Parameter Variables
    66.     //=============================================================================
    67.     var parameters = PluginManager.parameters('BBS_ConsistentTimeWeather');
    68.     // Save variables (weather)
    69.     var universalDuration        = Number(parameters['Universal Fade Duration'] || 6);
    70.     // Other
    71.     var debugging                = eval(String(parameters['Debug Mode'] || 'false'));
    72.     // Track audio
    73.     var $mapConditions = null;
    74.     var ignoreNextBgm = false;
    75.     var ignoreNextBgs = false;
    76.    
    77.     //=============================================================================
    78.     // Game_Interpreter
    79.     //=============================================================================
    80.     var BBS_CA_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    81.     Game_Interpreter.prototype.pluginCommand = function(command, args) {
    82.         if (command === 'consistentAudio') {
    83.             switch (args[0])
    84.             {
    85.                 case 'ignoreNext':
    86.                     ignoreNextBgm = true;
    87.                     ignoreNextBgs = true;
    88.                     break;
    89.                 case 'ignoreNextBgm':
    90.                     ignoreNextBgm = true;
    91.                     break;
    92.                 case 'ignoreNextBgs':
    93.                     ignoreNextBgs = true;
    94.                     break;
    95.             };
    96.         }
    97.         else {
    98.             BBS_CA_Game_Interpreter_pluginCommand.call(this, command, args);
    99.         }
    100.     };
    101.     // Fadeout BGM - need to update BGM Saved Audio.
    102.     var BBS_CA_GameInterpreter_command242 = Game_Interpreter.prototype.command242;
    103.     Game_Interpreter.prototype.command242 = function() {
    104.         if (ignoreNextBgm === true) {
    105.             ignoreNextBgm = false;
    106.             return BBS_CA_GameInterpreter_command242.call(this);
    107.         }
    108.    
    109.         // Make sure $gameMap exists
    110.         if (SceneManager._scene instanceof Scene_Map) {
    111.             $mapConditions.setBGM($gameMap.mapId(), AudioManager.makeEmptyAudioObject());
    112.         }
    113.    
    114.         return BBS_CA_GameInterpreter_command242.call(this);
    115.     };
    116.     // Fadeout BGS - need to update BGS Saved Audio.
    117.     var BBS_CA_GameInterpreter_command246 = Game_Interpreter.prototype.command246;
    118.     Game_Interpreter.prototype.command246 = function() {
    119.         if (ignoreNextBgs === true) {
    120.             ignoreNextBgs = false;
    121.             return BBS_CA_GameInterpreter_command246.call(this);
    122.         }
    123.    
    124.         // Make sure $gameMap exists
    125.         if (SceneManager._scene instanceof Scene_Map) {
    126.             $mapConditions.setBGS($gameMap.mapId(), AudioManager.makeEmptyAudioObject());
    127.         }
    128.    
    129.         return BBS_CA_GameInterpreter_command246.call(this);
    130.     };
    131.     //=============================================================================
    132.     // Map_Conditions
    133.     //=============================================================================
    134.     function Map_Conditions() {
    135.         this.initialize.apply(this, arguments);
    136.     };
    137.     Map_Conditions.prototype.initialize = function() {
    138.         this._savedBGMs = {};
    139.         this._savedBGSs = {};
    140.     };
    141.     Map_Conditions.prototype = Object.create(Map_Conditions.prototype);
    142.     Map_Conditions.prototype.constructor = Map_Conditions;
    143.     Map_Conditions.prototype.getBGM = function(mapId) {
    144.         console.log(this._savedBGMs);
    145.         if (this._savedBGMs[mapId] !== undefined) {
    146.             return this._savedBGMs[mapId];
    147.         }
    148.         console.log("getBGM with mapId " + mapId + " not found.");
    149.         return undefined;
    150.     };
    151.     Map_Conditions.prototype.getBGS = function(mapId) {
    152.         if (this._savedBGSs[mapId] !== undefined) {
    153.             return this._savedBGSs[mapId];
    154.         }
    155.         console.log("getBGS with mapId " + mapId + " not found.");
    156.         return undefined;
    157.     };
    158.     Map_Conditions.prototype.setBGM = function(mapId, bgm) {
    159.         this._savedBGMs[mapId] = {
    160.             name: bgm.name,
    161.             volume: bgm.volume,
    162.             pitch: bgm.pitch,
    163.             pan: bgm.pan,
    164.             pos: 0
    165.         };
    166.    
    167.     };
    168.     Map_Conditions.prototype.setBGS = function(mapId, bgs) {   
    169.         this._savedBGSs[mapId] = {
    170.             name: bgs.name,
    171.             volume: bgs.volume,
    172.             pitch: bgs.pitch,
    173.             pan: bgs.pan,
    174.             pos: 0
    175.         };
    176.     };
    177.     //=============================================================================
    178.     // Game_Player
    179.     //=============================================================================
    180.     var BBS_CA_performTransfer = Game_Player.prototype.performTransfer;
    181.     Game_Player.prototype.performTransfer = function() {
    182.         AudioManager.fadeOutBgm(universalDuration);
    183.         AudioManager.fadeOutBgs(universalDuration);
    184.         BBS_CA_performTransfer.call(this);
    185.     };
    186.     //=============================================================================
    187.     // Data_Manager
    188.     //=============================================================================
    189.     var BBS_CA_DataManager_makeSaveContents = DataManager.makeSaveContents;
    190.     DataManager.makeSaveContents = function() {
    191.         var contents = BBS_CA_DataManager_makeSaveContents.call(this);
    192.         contents.savedBGMs = $mapConditions._savedBGMs;
    193.         contents.savedBGSs = $mapConditions._savedBGSs;
    194.    
    195.         if (debugging === true) {
    196.             console.log("Saved BGM and BGS conditions.");
    197.         }
    198.    
    199.         return contents;
    200.     };
    201.     var BBS_CA_DataManager_extractSaveContents = DataManager.extractSaveContents;
    202.     DataManager.extractSaveContents = function(contents) {
    203.         BBS_CA_DataManager_extractSaveContents.call(this, contents);
    204.         $mapConditions = new Map_Conditions();
    205.    
    206.         console.log(contents.savedBGMs);
    207.         $mapConditions._savedBGMs = contents.savedBGMs;
    208.         $mapConditions._savedBGSs = contents.savedBGSs;
    209.    
    210.         if (debugging === true) {
    211.             console.log("Extracted BGM and BGS saved conditions.");
    212.         }
    213.     };
    214.     var BBS_CA_DataManager_createGameObjects = DataManager.createGameObjects;
    215.     DataManager.createGameObjects = function() {
    216.         BBS_CA_DataManager_createGameObjects.call(this);
    217.         // Create global map conditions class
    218.         $mapConditions = new Map_Conditions();
    219.    
    220.         if (debugging === true) {
    221.             console.log("Created Map Conditions object.");
    222.         }
    223.     };
    224.     //=============================================================================
    225.     // Game_System
    226.     //=============================================================================
    227.     // For handling custom data...
    228.     Game_System.prototype.storeBgm = function(mapId) {
    229.         if (ignoreNextBgm === true) {
    230.             ignoreNextBgm = false;
    231.             return;
    232.         }
    233.    
    234.         var bgm = AudioManager.saveBgm();
    235.         $mapConditions.setBGM(mapId, bgm);
    236.    
    237.         if (debugging === true) {
    238.             console.log("Stored BGM for " + mapId);
    239.       
    240.             console.log(mapId);
    241.             console.log(JSON.stringify(bgm));
    242.         }
    243.     };
    244.     Game_System.prototype.storeBgs = function(mapId) {
    245.         if (ignoreNextBgs === true) {
    246.             ignoreNextBgs = false;
    247.             return;
    248.         }
    249.    
    250.         var bgs = AudioManager.saveBgs();
    251.         $mapConditions.setBGS(mapId, bgs);
    252.    
    253.         if (debugging === true) {
    254.             console.log("Stored BGS for " + mapId);
    255.             console.log(mapId);
    256.             console.log(JSON.stringify(bgs));
    257.         }
    258.     };
    259.     Game_System.prototype.retrieveBgm = function(mapId) {
    260.         console.log($mapConditions.getBGM(mapId));
    261.         var bgm = $mapConditions.getBGM(mapId);
    262.    
    263.         console.log($dataMap);
    264.    
    265.         // If we don't already have the BGM logged, log the BGM of the current map.  If that's not set, play nothing.
    266.         if (bgm === undefined) {
    267.             if ($dataMap.autoplayBgm) {
    268.                 bgm = $dataMap.bgm;
    269.             } else {
    270.                 bgm = AudioManager.makeEmptyAudioObject();
    271.             }
    272.         }
    273.    
    274.         AudioManager.playBgm(bgm, bgm.pos);
    275.         AudioManager.fadeInBgm(universalDuration);
    276.     };
    277.     Game_System.prototype.retrieveBgs = function(mapId) {
    278.         var bgs = $mapConditions.getBGS(mapId);
    279.    
    280.         // If we don't already have the BGS logged, log the BGS of the current map.  If that's not set, play nothing.
    281.         if (bgs === undefined) {
    282.             if ($dataMap.autoplayBgs) {
    283.                 bgs = $dataMap.bgs;
    284.             } else {
    285.                 bgs = AudioManager.makeEmptyAudioObject();
    286.             }
    287.         }
    288.         AudioManager.playBgs(bgs, bgs.pos);
    289.         AudioManager.fadeInBgs(universalDuration);
    290.     };
    291.     //=============================================================================
    292.     // AudioManager
    293.     //=============================================================================
    294.     var BBS_CA_AudioManager_initialize = AudioManager.initialize;
    295.     AudioManager.initialize = function() {
    296.         BBS_CA_AudioManager_initialize.call(this);
    297.         AudioManager._replayFadeTime = universalDuration;
    298.     };
    299.     var BBS_CA_AudioManager_playBgm = AudioManager.playBgm;
    300.     AudioManager.playBgm = function(bgm, pos) {
    301.         BBS_CA_AudioManager_playBgm.call(this, bgm, pos);
    302.    
    303.         if (SceneManager._scene instanceof Scene_Map) {
    304.             $gameSystem.storeBgm($gameMap.mapId());
    305.         }
    306.    
    307.         this.fadeInBgm(universalDuration);
    308.     };
    309.     var BBS_CA_AudioManager_playBgs = AudioManager.playBgs;
    310.     AudioManager.playBgs = function(bgs, pos) {
    311.         BBS_CA_AudioManager_playBgs.call(this, bgs, pos);
    312.    
    313.         if (SceneManager._scene instanceof Scene_Map) {
    314.             $gameSystem.storeBgs($gameMap.mapId());
    315.         }
    316.    
    317.         this.fadeInBgs(universalDuration);
    318.     };
    319.     var BBS_CA_AudioManager_stopBgm = AudioManager.stopBgm;
    320.     AudioManager.stopBgm = function() {
    321.         BBS_CA_AudioManager_stopBgm.call(this);
    322.         //$gameSystem.storeBgm(this.makeEmptyAudioObject(), 0);
    323.     };
    324.     var BBS_CA_AudioManager_stopBgs = AudioManager.stopBgs;
    325.     AudioManager.stopBgs = function() {
    326.         BBS_CA_AudioManager_stopBgs.call(this);
    327.         //$gameSystem.storeBgs(this.makeEmptyAudioObject(), 0);
    328.     };
    329.     //=============================================================================
    330.     // Game_Map
    331.     //=============================================================================
    332.     // Overwrite necessary to force loading of correct audio!
    333.     Game_Map.prototype.autoplay = function() {
    334.         var mapId = $gameMap.mapId();
    335.    
    336.         $gameSystem.retrieveBgm(mapId);
    337.         $gameSystem.retrieveBgs(mapId);
    338.     };
    339.     //=============================================================================
    340.     // Scene_Map
    341.     //=============================================================================
    342.     Scene_Map.prototype.reloadCondition = function() {
    343.         $gameSystem.retrieveBgm($gameMap.mapId());
    344.         $gameSystem.retrieveBgs($gameMap.mapId());
    345.     }
    346.     Scene_Map.prototype.saveCondition = function() {
    347.         $gameSystem.storeBgm($gameMap.mapId());
    348.         $gameSystem.storeBgs($gameMap.mapId());
    349.     };
    350.     // Save current state of map before transitioning to another map, to battle, or to menu.
    351.     var BBS_CTW_Scene_Map_updateScene = Scene_Map.prototype.updateScene;
    352.     Scene_Map.prototype.updateScene = function() {
    353.         this.checkGameover();        // Do not save condition if game over.
    354.         this.saveCondition();
    355.    
    356.         BBS_CTW_Scene_Map_updateScene.call(this);
    357.     };
    358. })(BBS.ConsistentAudio);
    359. //=============================================================================
    360. // End of File
    361. //=============================================================================
    复制代码







    Change Log
    1.01

      - Plugin finished.


    Known Bugs / TODO
    Suggestions, bug reports, and feature requests are welcomed!


    Compatibility Issues
    None known.


    Credit and Thanks
    - Micheal Morris @Blue Booth Studios


    Author's Notes
    Free for non-commercial as long as credit is given.
    Please contact me regarding commercial usage.

    No extra JSON file necessary.


    本贴来自国际rpgmaker官方论坛作者:bluebooth处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/consistent-audio-plugin.77448/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-1 18:48 , Processed in 0.110047 second(s), 52 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表