扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 101|回复: 0

[转载发布] MV游戏操作录像 Record

[复制链接]
累计送礼:
0 个
累计收礼:
0 个
  • TA的每日心情
    开心
    2025-2-4 02:05
  • 签到天数: 110 天

    连续签到: 2 天

    [LV.6]常住居民II

    2327

    主题

    395

    回帖

    1万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    6
    卡币
    10465
    OK点
    16
    推广点
    0
    同能卷
    0
    积分
    13215

    灌水之王

    发表于 2024-11-21 22:28:34 | 显示全部楼层 |阅读模式
    如题,一个记录玩家操作的插件....
    bug应该很多啦...


    JAVASCRIPT 代码下载
    1. //=============================================================================
    2. // Record.js
    3. //=============================================================================
    4. /*:
    5. * @plugindesc 录像
    6. * @author wangwang
    7. *   
    8. * @param Record
    9. * @desc 插件 录像
    10. * @default 汪汪
    11. *   
    12. *
    13. * @help  
    14. * //开始录像
    15. * Record.start ()
    16. * //播放
    17. * Record.play(file) 播放一个录像文件,不选为最后这个
    18. * //结束
    19. * Record.end()  结束录像/播放
    20. *
    21. *
    22. * //录像文件列表
    23. * Record.files   是一个数组  []
    24. * //最后文件
    25. * Record.fileend ()
    26. *
    27. * //保存储存
    28. * Record.save(name ,file)   name :名称  file :一个录像文件
    29. * //保存id的录像 到 name 文件
    30. * Record.saveId(name, id)
    31. *
    32. * //保存最后的录像 到 name 文件
    33. * Record.saveEnd(name)  
    34. *
    35. *
    36. * //读取储存
    37. * Record.load(name)   name :名称     返回一个录像文件
    38. * //读取name文件 并播放  
    39. * Record.loadPlay(name)  
    40. *
    41. *
    42. */
    43. function Record(){
    44.     thrownew Error('This is a static class');
    45. }
    46. Record.mode = "空"
    47. Record.files = []
    48. Record.wait = 0
    49. /**
    50. *
    51. * 键的记录读取
    52. *
    53. */
    54. /**等待开 */
    55. Record.waitOpen = function(value){
    56.     if(value > this.wait){
    57.         this.wait = value
    58.     }
    59. }
    60. /**等待关 */
    61. Record.waitClose = function(value){
    62.     if(value >= this.wait && this.wait){
    63.         this.wait = 0
    64.     }
    65. }
    66. /**记录键 */
    67. Record.push = function(result){
    68.     var result = result === false ? 0 : result === true ? 1 : result
    69.     if(this.kind != result){
    70.         if(this.counts){
    71.             this.infos.push([this.kind, this.counts || 1])
    72.             this.pos += 1
    73.             this.counts = 0
    74.         }
    75.         this.kind = result
    76.     }
    77.     this.counts = (this.counts || 0) + 1
    78.     return result
    79. }
    80. /**还原键 */
    81. Record.pop = function(result){
    82.     if(!this.counts){
    83.         var key = this.infos[this.pos++]
    84.         if(!key){
    85.             this.end(true)
    86.             return result
    87.         }
    88.         this.counts = key[1]
    89.         this.kind = key[0]
    90.         this.counts -= 1
    91.         returnthis.kind
    92.     }else{
    93.         this.counts -= 1
    94.         returnthis.kind
    95.     }
    96. }
    97. /**获取值 */
    98. Record.value = function(that, fun, arr){
    99.     var result = this._call[fun].apply(that, arr)
    100.     if(this.wait){
    101.         if(fun != "Math_random" && fun != "Math_randomInt"){
    102.             return0
    103.         }
    104.     }
    105.     if(this.mode == "录制"){
    106.         returnthis.push(result)
    107.     }
    108.     if(this.mode == "播放"){
    109.         returnthis.pop(result)
    110.     }
    111.     return result
    112. }
    113. /**
    114. *
    115. * 录像数据处理
    116. *
    117. */
    118. /**场景名称 */
    119. Record.sn = function(constructor){
    120.         return constructor.name
    121.     }
    122.     /**名称场景 */
    123. Record.ns = function(name){
    124.     return window[name]
    125. }
    126. /**获取存档 */
    127. Record.saveData = function(scene){
    128.     $gameSystem.onBeforeSave();
    129.     var data = {}
    130.     data.scene = null
    131.     data.stack = []
    132.     if(scene){
    133.         data.scene = scene
    134.         SceneManager._stack = []
    135.     }else{
    136.         data.scene = this.sn(SceneManager._scene.constructor)
    137.         for(var i = 0; i < SceneManager._stack.length; i++){
    138.             data.stack[i] = this.sn(SceneManager._stack[i])
    139.         }
    140.     }
    141.     if(data.scene == "Scene_Title" || data.scene == "Scene_Boot"){
    142.         data.save = 0
    143.     }else{
    144.         data.save = DataManager.makeSaveContents()
    145.     }
    146.     data.config = ConfigManager.makeData()
    147.     SceneManager.goto(this.ns(data.scene));
    148.     return JsonEx.stringify(data)
    149. }
    150. /**读取存档 */
    151. Record.loadData = function(json){
    152.     DataManager.createGameObjects();
    153.     var data = JsonEx.parse(json)
    154.     if(data){
    155.         if(data.save){
    156.             DataManager.extractSaveContents(data.save);
    157.             if($gameSystem.versionId() !== $dataSystem.versionId){
    158.                 $gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
    159.                 $gamePlayer.requestMapReload();
    160.             }
    161.         }
    162.         if(data.config){
    163.             ConfigManager.applyData(data.config)
    164.         }
    165.         SceneManager._stack = []
    166.         if(data.stack){
    167.             for(var i = 0; i < data.stack.length; i++){
    168.                 SceneManager._stack[i] = this.ns(data.stack[i])
    169.             }
    170.         }
    171.         if(data.scene){
    172.             SceneManager.goto(this.ns(data.scene));
    173.         }
    174.     }
    175. }
    176. /**录像文件到json */
    177. Record.tojson = function(file){
    178.     return JSON.stringify(file)
    179. }
    180. /**json到录像文件 */
    181. Record.tofile = function(json){
    182.     return JSON.parse(json)
    183. }
    184. /**
    185. * 录像的操作
    186. */
    187. /**开始 */
    188. Record.start = function(){
    189.     this.end()
    190.     this.mode = "录制"
    191.     this.file = { save: this.saveData(), infos: this.infos = []}
    192.     this.files.push(this.file)
    193.     this.pos = 0
    194.     this.counts = 0
    195.     this.kind = 0
    196. }
    197. /**播放 */
    198. Record.play = function(file){
    199.     this.end()
    200.     if(file){this.file = file }
    201.     if(this.file){
    202.         this.loadData(this.file.save)
    203.         this.infos = this.file.infos
    204.         this.mode = "播放"
    205.         this.pos = 0
    206.         this.counts = 0
    207.         this.kind = 0
    208.     }
    209. }
    210. /**结束 */
    211. Record.end = function(v){
    212.     if(this.file){
    213.         if(this.mode == "录制"){
    214.             Record.push({})
    215.         }
    216.     }
    217.     this.mode = "空"
    218.     this.pos = 0
    219.     this.counts = 0
    220.     this.kind = 0
    221.     this.waitClose(2)
    222.         //console.log("end", this.file)
    223.     if(v){alert("end")}
    224. }
    225. /**
    226. *
    227. * 录像数据保存
    228. *
    229. */
    230. /**保存 */
    231. Record.save = function(name, file){
    232.     StorageManager.save("record_" + name, this.tojson(file))
    233. }
    234. /**保存id的录像 到 name 文件*/
    235. Record.saveId = function(name, id){
    236.     this.save(name, this.files[id])
    237. }
    238. /**最后一个文件 */
    239. Record.fileend = function(){
    240.     return Record.files[Record.files.length - 1]
    241. }
    242. /**保存最后的录像 到 name 文件 */
    243. Record.saveEnd = function(name){
    244.     this.save(name, this.fileend())
    245. }
    246. /**读取 */
    247. Record.load = function(name){
    248.     returnthis.tofile(StorageManager.load("record_" + name))
    249. }
    250. /**读取并播放 */
    251. Record.loadPlay = function(name){
    252.     this.play(this.load(name))
    253. }
    254. /**
    255. *
    256. * 录像卡点
    257. *
    258. */
    259. SceneManager.updateScene = function(){
    260.     if(this._scene){
    261.         if(!this._sceneStarted && this._scene.isReady()){
    262.             Record.waitClose(2)
    263.             this._scene.start();
    264.             this._sceneStarted = true;
    265.             this.onSceneStart();
    266.         }
    267.         if(this.isCurrentSceneStarted()){
    268.             if(this._scene.isReady()){
    269.                 Record.waitClose(1)
    270.                 this._scene.update();
    271.             }else{
    272.                 Record.waitOpen(1)
    273.             }
    274.         }
    275.     }
    276. };
    277. SceneManager.goto = function(sceneClass){
    278.     Record.waitOpen(2)
    279.     if(sceneClass){
    280.         this._nextScene = new sceneClass();
    281.     }
    282.     if(this._scene){
    283.         this._scene.stop();
    284.     }
    285. };
    286. /**
    287. *
    288. * 请求录像记录
    289. *
    290. */
    291. Record._call = {}
    292. Record._call.Math_random = Math.random
    293. Math.random = function(){
    294.     return Record.value(this, "Math_random", arguments);
    295. };
    296. Record._call.Math_randomInt = function(max){
    297.     return Math.floor(max * Record._call.Math_random())
    298. }
    299. Math.randomInt = function(max){
    300.     return Record.value(this, "Math_randomInt", arguments);
    301. };
    302. Record._call.value = function(i){
    303.     return i
    304. }
    305. Record._call.Input_isPressed = Input.isPressed
    306. Input.isPressed = function(keyName){
    307.     return Record.value(this, "Input_isPressed", arguments);
    308. };
    309. Record._call.Input_isTriggered = Input.isTriggered
    310. Input.isTriggered = function(keyName){
    311.     return Record.value(this, "Input_isTriggered", arguments);
    312. };
    313. Record._call.Input_isRepeated = Input.isRepeated
    314. Input.isRepeated = function(keyName){
    315.     return Record.value(this, "Input_isRepeated", arguments);
    316. };
    317. Record._call.Input_isLongPressed = Input.isLongPressed
    318. Input.isLongPressed = function(keyName){
    319.     return Record.value(this, "Input_isLongPressed", arguments);
    320. };
    321. Object.defineProperty(Input, 'dir4', {
    322.     get: function(){
    323.         return Record.value(this, "value", [this._dir4, "Input.dir8"]);
    324.     },
    325.     configurable: true
    326. });
    327. Object.defineProperty(Input, 'dir8', {
    328.     get: function(){
    329.         return Record.value(this, "value", [this._dir8, "Input.dir8"]);
    330.     },
    331.     configurable: true
    332. });
    333. Object.defineProperty(Input, 'date', {
    334.     get: function(){
    335.         return Record.value(this, "value", [this._date, "Input._date"]);
    336.     },
    337.     configurable: true
    338. });
    339. Record._call.TouchInput_isPressed = TouchInput.isPressed
    340. TouchInput.isPressed = function(){
    341.     return Record.value(this, "TouchInput_isPressed", arguments);
    342. };
    343. Record._call.TouchInput_isTriggered = TouchInput.isTriggered
    344. TouchInput.isTriggered = function(){
    345.     return Record.value(this, "TouchInput_isTriggered", arguments);
    346. };
    347. Record._call.TouchInput_isRepeated = TouchInput.isRepeated
    348. TouchInput.isRepeated = function(){
    349.     return Record.value(this, "TouchInput_isRepeated", arguments);
    350. };
    351. Record._call.TouchInput_isLongPressed = TouchInput.isLongPressed
    352. TouchInput.isLongPressed = function(){
    353.     return Record.value(this, "TouchInput_isLongPressed", arguments);
    354. };
    355. Record._call.TouchInput_isCancelled = TouchInput.isCancelled
    356. TouchInput.isCancelled = function(){
    357.     return Record.value(this, "TouchInput_isCancelled", arguments);
    358. };
    359. Record._call.TouchInput_isMoved = TouchInput.isMoved
    360. TouchInput.isMoved = function(){
    361.     return Record.value(this, "TouchInput_isMoved", arguments);
    362. };
    363. Record._call.TouchInput_isReleased = TouchInput.isReleased
    364. TouchInput.isReleased = function(){
    365.     return Record.value(this, "TouchInput_isReleased", arguments);
    366. };
    367. Object.defineProperty(TouchInput, 'wheelX', {
    368.     get: function(){
    369.         return Record.value(this, "value", [this._wheelX, "TouchInput._wheelX"]);
    370.     },
    371.     configurable: true
    372. });
    373. Object.defineProperty(TouchInput, 'wheelY', {
    374.     get: function(){
    375.         return Record.value(this, "value", [this._wheelY, "TouchInput._wheelY"]);
    376.     },
    377.     configurable: true
    378. });
    379. Object.defineProperty(TouchInput, 'x', {
    380.     get: function(){
    381.         return Record.value(this, "value", [this._x, "TouchInput._x"]);
    382.     },
    383.     configurable: true
    384. });
    385. Object.defineProperty(TouchInput, 'y', {
    386.     get: function(){
    387.         return Record.value(this, "value", [this._y, "TouchInput._y"]);
    388.     },
    389.     configurable: true
    390. });
    391. Object.defineProperty(TouchInput, 'date', {
    392.     get: function(){
    393.         return Record.value(this, "value", [this._date, "TouchInput._date"]);
    394.     },
    395.     configurable: true
    396. });
    复制代码


                本帖来自P1论坛作者汪汪,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=403812  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

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

    本版积分规则

    关闭

    幸运抽奖

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

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2025-3-10 11:37 , Processed in 0.131168 second(s), 54 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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