Project1

标题: [已经解决]如何用脚本给文件改名? [打印本页]

作者: fbeds    时间: 2018-4-6 10:57
标题: [已经解决]如何用脚本给文件改名?
本帖最后由 fbeds 于 2018-4-14 13:10 编辑

如题,就是在游戏进行中给游戏文件夹目录下的某个文件改名……本人脚本盲,不知道该怎么办……
作者: Mehmet    时间: 2018-4-6 13:06
本帖最后由 Mehmet 于 2018-4-6 13:08 编辑

如果只是NW.js游戏平台可以参考下我这个.
JAVASCRIPT 代码复制
  1. //=============================================================================
  2. // Mehmet Plugins - file Rename
  3. // Mehmet_fileRename.js
  4. //=============================================================================
  5.  
  6. /*:
  7.  * @plugindesc 基于NW.js游戏平台游戏目录下的文件重命名.
  8.  * @author Mehmet
  9.  * @version 1.0
  10.  *
  11.  * @help
  12.  * Plugins Command:
  13.  * 1.文件移动
  14.  *   mehmetFileRename /img/faces/Actor3.png /img/Actor3.png
  15.  * 2.文件重命名
  16.  *   mehmetFileRename /img/faces/Actor3.png /img/faces/Actor4.png
  17.  * 3.文件夹(即有第三个实参)
  18.  *   mehmetFileRename /img/Test /img/Test1 true
  19.  */
  20.  
  21.  
  22. (function() {
  23.  
  24. var Mehmet = Mehmet || {};
  25. Mehmet.Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  26. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  27.     Mehmet.Game_Interpreter_pluginCommand.call(this, command, args);
  28.     if (command.toUpperCase() === 'MEHMETFILERENAME') {
  29.         if (Utils.isNwjs() && args[0] && args[1]) {
  30.             if (args[2]) {
  31.                 Mehmet.fileRenamefunction(args[0], args[1], true);
  32.             } else {
  33.                 Mehmet.fileRenamefunction(args[0], args[1]);
  34.             }
  35.         }
  36.     }
  37. };
  38.  
  39. Mehmet.fileRenamefunction = function(oldPath, newPath) {
  40.     var data = null;
  41.     if (arguments[2]) {
  42.         var fs = require('fs');
  43.         var oldfilePath = this.localFileDirectoryPath(oldPath);
  44.         var newfilePath = this.localFileDirectoryPath(newPath);
  45.     } else {
  46.         var oldfilePath = this.localFileDirectoryPath(oldPath);
  47.         var newfilePath = this.localFileDirectoryPath(newPath);
  48.         var fs = require('fs');
  49.     }
  50.     if (!fs.existsSync(oldfilePath)) {
  51.         return console.log("%c File not found:" + oldfilePath,"color:red;background-color:rgba(58,58,58,1)");
  52.     }
  53.     fs.rename(oldfilePath, newfilePath, function(err) {
  54.         if (err) {
  55.             console.log("%c" + err,"color:yellow;background-color:rgba(58,58,58,1)");
  56.         }
  57.     });
  58. };
  59.  
  60. Mehmet.localFileDirectoryPath = function(filePath) {
  61.     var path = require('path');
  62.     var filePath = filePath || '';
  63.     var base = path.dirname(process.mainModule.filename);
  64.     return path.join(base, filePath);
  65. };
  66.  
  67. })();

作者: fbeds    时间: 2018-4-6 14:02
Mehmet 发表于 2018-4-6 13:06
如果只是NW.js游戏平台可以参考下我这个.
//=========================================================== ...

谢谢,问题已解决。




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1