找回密码
 注册用户
查看: 155|回复: 0

[RMMZ] 导出事件对话文本

[复制链接]

85

主题

7

回帖

1268

积分

资深会员

积分
1268
发表于 2024-7-19 23:51:53 | 显示全部楼层 |阅读模式
导出事件及公共事件中的文章、选择项文本


脚本:exportTexts.js

  1. /*:
  2. * @target MZ
  3. * @plugindesc 导出显示文章和选择项的文本
  4. *
  5. * 更多插件请访问 www.hknmtt.com
  6. * @author 烁灵
  7. *
  8. * @help exportTexts.js
  9. * 启用插件后,进入标题界面,会在游戏文件夹内生成包含所有文本的 exportText.txt
  10. *
  11. */
  12. (function() {
  13.     var _index = 1;

  14.     const fs = require("fs");
  15.    
  16.     sl_initialize = Scene_Title.prototype.initialize;
  17.     Scene_Title.prototype.initialize = function() {
  18.         sl_initialize.call(this);
  19.         this.loadMap($dataMapInfos[_index].id);
  20.         this._exportData = [];
  21.     };
  22.    
  23.     Scene_Title.prototype.loadMap = function(id) {
  24.         const src = "Map%1.json".format(id.padZero(3));
  25.         const xhr = new XMLHttpRequest();
  26.         const url = "data/" + src;
  27.         $dataMap = null;
  28.         xhr.open("GET", url);
  29.         xhr.overrideMimeType("application/json");
  30.         xhr.onload = () => this.onXhrLoad(xhr, name, src, url);
  31.         xhr.send();
  32.     };

  33.     Scene_Title.prototype.onXhrLoad = function(xhr, name, src, url) {
  34.         if (xhr.status < 400) {
  35.             $dataMap = JSON.parse(xhr.responseText);
  36.             this.onMapLoaded();
  37.         }
  38.     };

  39.     Scene_Title.prototype.onMapLoaded = function() {
  40.         this.process_mapInfo();

  41.         _index += 1;
  42.         if ($dataMapInfos[_index]) {
  43.             this.loadMap($dataMapInfos[_index].id);
  44.         } else {
  45.             $dataCommonEvents.forEach(eventPage => {
  46.                 if (eventPage) {
  47.                     this.writePageText(eventPage);
  48.                 }
  49.             })
  50.             fs.writeFileSync("exportText.txt", this._exportData.join("\r\n"));
  51.         }

  52.     }
  53.     Scene_Title.prototype.writePageText = function(page) {
  54.         page.list.forEach(command => {
  55.             console.log(command)
  56.             if (command.code == 401) {
  57.                 // 显示文章
  58.                 this.write(command.parameters[0]);
  59.             }
  60.             if (command.code == 102) {
  61.                 // 选项
  62.                 command.parameters[0].forEach(param => {
  63.                     this.write(param);
  64.                 });
  65.             }
  66.         })
  67.     }
  68.     Scene_Title.prototype.write = function(str) {
  69.         console.log("write " + str);
  70.         this._exportData.push(str);
  71.     }
  72.     Scene_Title.prototype.process_mapInfo = function() {
  73.         console.log($dataMap);
  74.         $dataMap.events.forEach(event => {
  75.             if (event) {
  76.                 event.pages.forEach(page => {
  77.                     if (page) {
  78.                         this.writePageText(page);
  79.                     }
  80.                 });
  81.             }
  82.         })
  83.     };
  84. })();
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册用户

本版积分规则

Archiver|QQ群: 48625831|爱上RPG|哈库纳玛塔塔 |网站地图 Clicky

GMT+8, 2024-9-8 11:01 , Processed in 0.051792 second(s), 18 queries .

Powered by Discuz! X3.5

Copyright © 2001-2020, Tencent Cloud.

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