查看: 2564|回复: 0

[原创发布] MV游戏操作录像 Record

[复制链接]
梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
回帖
1464
发表于 2017-11-5 23:19:35 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

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

×
本帖最后由 汪汪 于 2017-11-5 23:30 编辑

如题,一个记录玩家操作的插件....
bug应该很多啦...


  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.     throw new 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.         return this.kind
  92.     } else {
  93.         this.counts -= 1
  94.         return this.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.             return 0
  103.         }
  104.     }
  105.     if (this.mode == "录制") {
  106.         return this.push(result)
  107.     }
  108.     if (this.mode == "播放") {
  109.         return this.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.     return this.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. });
复制代码

评分

参与人数 1赞 +1 收起 理由
白嫩白嫩的 + 1 塞糖

查看全部评分

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部