查看: 2476|回复: 4

[原创发布] 研究了一晚上,终于知道为什么MZ没有全键盘插件了

[复制链接]
梦石
0
星屑
731
在线时间
14 小时
注册时间
2016-11-5
回帖
7
发表于 2022-3-28 01:14:40 | 显示全部楼层 |阅读模式

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

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

×
因为改为js代码以后,全键盘功能用改底层+脚本的方式实现起来过于简单,简直有点傻瓜……
说下步骤:
(1)在rmmz_core.js中搜索如下字段
/**
* A hash table to convert from a virtual key code to a mapped key name.
*
* @type Object
*/
Input.keyMapper = {
    9: "tab", // tab
    13: "ok", // enter
    16: "shift", // shift
    17: "control", // control
    18: "control", // alt
    27: "escape", // escape
    32: "ok", // space
    33: "pageup", // pageup
    34: "pagedown", // pagedown
    37: "left", // left arrow
    38: "up", // up arrow
    39: "right", // right arrow
    40: "down", // down arrow
    45: "escape", // insert
    65: "a", // A
    81: "pageup", // Q
    87: "pagedown", // W
    88: "escape", // X
    90: "ok", // Z
    96: "escape", // numpad 0
    98: "down", // numpad 2
    100: "left", // numpad 4
    102: "right", // numpad 6
    104: "up", // numpad 8
    120: "debug" // F9
};

(2)把你想要的键的ASCII码插入上面的字段中,再起一个字符串的键名(不要和已有名字重复),比如我添加的就是【65: "a", // A】这一行,意思是把ASCII码为65的A键插入输入表中,并命名为"a"。

(3)在条件分歧的脚本中输入【Input.isPressed("a")】,其中"a"是你刚才起的键名。

(4)按下A键即可触发该条件分歧(当然还要设置好公共事件,这个不用多说了吧)。

嘛,以上,算是我个人的一点很菜很菜的小经验,大佬不用看,新人用不着,专供跟我一样懂一点代码,但既非专业又懒得深钻的朋友参考吧。

评分

参与人数 1赞 +1 收起 理由
新耀012478 + 1 精品文章

查看全部评分

梦石
0
星屑
731
在线时间
14 小时
注册时间
2016-11-5
回帖
7
 楼主| 发表于 2022-3-28 01:39:40 | 显示全部楼层
慢着,我这个思路好像有问题,目前发现只能加进去一个键,多了就不识别了。比如同时加1、2、3、A,结果只有输入1才识别。也是蛮扯的。
我继续研究一下哪里有问题。
回复

使用道具 举报

梦石
0
星屑
731
在线时间
14 小时
注册时间
2016-11-5
回帖
7
 楼主| 发表于 2022-3-28 01:49:09 | 显示全部楼层
哦,懂了,用写字板查看了一下,又用我才疏学浅的JAVA知识推测一下……
应该是加的时候用的记事本,加的所有信息打在同一行里了,倒霉催的JAVA不识别。
即成了这样:
Input.keyMapper = {
    9: "tab", // tab
    13: "ok", // enter
    16: "shift", // shift
    17: "control", // control
    18: "control", // alt
    27: "escape", // escape
    32: "ok", // space
    33: "pageup", // pageup
    34: "pagedown", // pagedown
    37: "left", // left arrow
    38: "up", // up arrow
    39: "right", // right arrow
    40: "down", // down arrow
    45: "escape", // insert

    49: "1", // 1    50: "2", // 2    51: "3", // 3    65: "a", // A
    81: "pageup", // Q
    87: "pagedown", // W
    88: "escape", // X
    90: "ok", // Z
    96: "escape", // numpad 0
    98: "down", // numpad 2
    100: "left", // numpad 4
    102: "right", // numpad 6
    104: "up", // numpad 8
    120: "debug" // F9
};

用IDE加,或者整几个换行符应该就搞定了。我上visual studio试试。
果然,之前2、3、A那几行全被当成注释了……躺平。
OK成了。
这次录入成这样,问题解决。
Input.keyMapper = {
    9: "tab", // tab
    13: "ok", // enter
    16: "shift", // shift
    17: "control", // control
    18: "control", // alt
    27: "escape", // escape
    32: "ok", // space
    33: "pageup", // pageup
    34: "pagedown", // pagedown
    37: "left", // left arrow
    38: "up", // up arrow
    39: "right", // right arrow
    40: "down", // down arrow
    45: "escape", // insert
    49: "1", // 1   
    50: "2", // 2   
    51: "3", // 3   
    65: "a", // A
    81: "pageup", // Q
    87: "pagedown", // W
    88: "escape", // X
    90: "ok", // Z
    96: "escape", // numpad 0
    98: "down", // numpad 2
    100: "left", // numpad 4
    102: "right", // numpad 6
    104: "up", // numpad 8
    120: "debug" // F9
};
回复 1 0

使用道具 举报

梦石
0
星屑
791
在线时间
51 小时
注册时间
2021-6-14
回帖
30
发表于 2022-4-9 20:27:00 | 显示全部楼层
我发过一个任意按键触发公共事件的插件哦,可以用一用
回复

使用道具 举报

梦石
0
星屑
22879
在线时间
8598 小时
注册时间
2011-12-31
回帖
3270
发表于 2022-4-11 14:24:20 | 显示全部楼层
本帖最后由 tseyik 于 2022-4-11 14:26 编辑

Uploaded_via_HKEPC_IR_Pro_Android(90e5e).jpg
Uploaded_via_HKEPC_IR_Pro_Android(44d5d).jpg
鍵

  1. //=============================================================================
  2. // Mano_InputConfig.js
  3. // ----------------------------------------------------------------------------
  4. // Copyright (c) 2017-2021 Sigureya
  5. // This software is released under the MIT License.
  6. // [url]http://opensource.org/licenses/mit-license.php[/url]
  7. // ----------------------------------------------------------------------------
  8. // Version
  9. // ver 8.0.1 2022/03/15
  10. // ----------------------------------------------------------------------------
  11. // [Twitter]: [url]https://twitter.com/Sigureya/[/url]
  12. //=============================================================================



  13. /*:
  14. * @plugindesc ゲームの操作に関する機能をまとめて管理します。
  15. * ユーザーによる拡張も支援します。
  16. * @author しぐれん([url]https://github.com/Sigureya/RPGmakerMV[/url])
  17. * @url [url]https://raw.githubusercontent.com/Sigureya/RPGmakerMZ/master/Mano_InputConfig.js[/url]
  18. *
  19. * @target MZ
  20. * @orderAfter VisuMZ_1_OptionsCore
  21. * @orderAfter MOG_TitleSplashScreen
  22. *
  23. * @command GetButtonName
  24. * @text GetButton/ボタン名の取得
  25. * @desc 指定した操作がどのボタンにあるかを返します。
  26. * Returns which button has the specified action.
  27. * @arg symbol
  28. * @type select
  29. * @option ok(決定)
  30. * @value ok
  31. * @option cancel(取り消し)
  32. * @value cancel
  33. * @option shift(ダッシュ)
  34. * @value shift
  35. * @option menu(メニュー)
  36. * @value menu
  37. * @option pageup(前)
  38. * @value pageup
  39. * @option pagedown(次)
  40. * @value pagedown
  41. * @default ok
  42. *
  43. * @arg nameVariable
  44. * @text ボタン名称/buttonName
  45. * @desc ボタン名称を受け取る変数です。
  46. * Variable to store the result.
  47. * @type variable
  48. * @default 0

  49. * @command GetButtonNameEX
  50. * @text GetButtonEX/ボタン名の取得
  51. * @desc 指定した操作がどのボタンにあるかを返します。
  52. * Returns which button has the specified action.
  53. * @arg symbol
  54. * @desc アクションのシンボル
  55. *
  56. * @arg nameVariable
  57. * @desc ボタン名称を受け取る変数です。
  58. * Variable to store the result.
  59. * @type variable
  60. * @default 0
  61. *
  62. * @command IsKeyboardValid
  63. * @desc キーボードの設定が正しい場合、指定スイッチをONにします。
  64. * @arg switchId
  65. * @type switch
  66. * @default 0
  67. * @desc 結果を保存するスイッチ
  68. * Where to save the results
  69. *
  70. * @command GamepadScene
  71. * @text GamepadScene/ゲームパッド設定を開く
  72. * @desc ゲームパッド設定のシーンを開きます。
  73. * Open the gamepad settings scene.
  74. *
  75. * @command KeyboardScene
  76. * @text KeyboardScene/キーボード設定を開く
  77. * @desc キーボード設定のシーンを開きます。
  78. * Open the keyboard settings scene.
  79. *
  80. * @param color
  81. * @text 色設定/ColorSetting
  82. * @type struct<ColorManager>
  83. * @default {"normal":"#880000","mandatory":"#22e488","move":"#22e488"}
  84. *
  85. * @param basicOk
  86. * @text 決定/ok
  87. * @type struct<BasicSymbol>
  88. * @default {"name":"{"jp":"決定","en":"OK"}","keyText":"{"jp":"","en":""}","helpText":"{"jp":"","en":""}"}
  89. *
  90. * @param basicCancel
  91. * @text 取り消し/cancle
  92. * @type struct<BasicSymbol>
  93. * @default {"name":"{"jp":"キャンセル","en":"cancel"}","keyText":"{"jp":"","en":""}","helpText":"{"jp":"","en":""}"}
  94. *
  95. * @param basicShift
  96. * @text ダッシュ/dash
  97. * @type struct<BasicSymbol>
  98. * @default {"name":"{"jp":"ダッシュ","en":"dash"}","keyText":"{"jp":"","en":""}","helpText":"{"jp":"","en":""}"}
  99. *
  100. * @param basicMenu
  101. * @text メニュー/menu
  102. * @type struct<BasicSymbol>
  103. * @default {"name":"{"jp":"メニュー","en":"menu"}","keyText":"{"jp":"","en":""}","helpText":"{"jp":"","en":""}"}
  104. *
  105. * @param basicEscape
  106. * @text メニュー(2)/menu(2)
  107. * @type struct<BasicSymbol>
  108. * @default {"name":"{"jp":"メニュー/キャンセル","en":"menu/cancel"}","keyText":"{"jp":"","en":""}","helpText":"{"jp":"","en":""}"}
  109. *
  110. * @param basicPageup
  111. * @text 次/next
  112. * @type struct<BasicSymbol>
  113. * @default {"name":"{"jp":"次","en":"next"}","keyText":"{"jp":"","en":""}","helpText":"{"jp":"","en":""}"}
  114. *
  115. * @param basicPagedown
  116. * @text 前/prev
  117. * @type struct<BasicSymbol>
  118. * @default {"name":"{"jp":"前","en":"prev"}","keyText":"{"jp":"","en":""}","helpText":"{"jp":"","en":""}"}
  119. *
  120. *
  121. *
  122. * @param mapperDelete
  123. * @text 設定を消去/delete
  124. * @type struct<MultiLangString>
  125. * @default {"en":"delete","jp":"設定を消去"}
  126. *
  127. *
  128. * @param extendsMapper
  129. * @desc ボタンイベント・追加の入力設定の登録
  130. * Registration of button events and additional input settings
  131. * @text 入力拡張/inputExtension
  132. * @type struct<InputDefine>[]
  133. * @default []
  134. *
  135. *
  136. * @param GamepadIsNotConnectedText
  137. * @text 未接続/GamepadIsNotConnected
  138. * @desc ゲームパッドが接続されていない場合の文章です。
  139. * This is the text when the gamepad is not connected.
  140. * @type struct<MultiLangNote>
  141. * @default {"jp":""ゲームパッドが接続されていません\\nボタンを押して再度試してください"","en":""The gamepad is not connected.\\nPress the button and try again.""}
  142. *
  143. * @param needButtonDetouchText
  144. * @text ボタンから手を放すように促すメッセージ
  145. * @desc キーコンフィグはボタンから手を離さない限り終了しません。
  146. * 手を放すように促すメッセージを設定します。
  147. * @type struct<MultiLangNote>
  148. * @default {"jp":""コンフィグを終了するために、\\nボタンから手を放してください。"","en":""Release the button to exit the config.""}
  149. *
  150. * @param apply
  151. * @text 設定の保存/apply
  152. * @type struct<KeyconfigCommand>
  153. * @default {"width":"4","text":"{"jp":"設定を保存","en":"save settings"}"}
  154. *
  155. * @param rollback
  156. * @text 変更を破棄/rollback
  157. * @type struct<KeyconfigCommand>
  158. * @default {"width":"4","text":"{"jp":"変更前に戻す","en":"rollback"}"}
  159. *
  160. * @param reset
  161. * @text 初期設定に戻す/reset
  162. * @type struct<KeyconfigCommand>
  163. * @default {"width":"4","text":"{"jp":"初期設定に戻す","en":"reset"}"}
  164. *
  165. * @param WASD
  166. * @type struct<KeyconfigCommand>
  167. * @default {"width":"3","text":"{"jp":"WASD","en":"WASD"}"}
  168. *
  169. * @param style
  170. * @type struct<KeyconfigCommand>
  171. * @default {"width":"3","text":"{"jp":"設定方法変更","en":"Change setting style"}"}
  172. *
  173. * @param changeLayout
  174. * @text JIS/US
  175. * @type struct<KeyconfigCommand>
  176. * @default {"width":"3","text":"{"jp":"JIS/US","en":"JIS/US"}"}
  177. *
  178. * @param exit
  179. * @text やめる/exit
  180. * @type struct<KeyconfigCommand>
  181. * @default {"width":"3","text":"{"jp":"やめる","en":"exit"}"}
  182. *
  183. *
  184. *
  185. * @param gamepadConfigCommandText
  186. * @desc ゲームパッドコンフィグを開くコマンドの名前です
  187. * @type struct<MultiLangString>
  188. * @default {"en":"gamepad config","jp":"ゲームパッドコンフィグ"}
  189. *
  190. * @param keyConfigCommandText
  191. * @desc キーコンフィグを開くコマンドの名前です
  192. * @type struct<MultiLangString>
  193. * @default {"en":"keyboard config","jp":"キーコンフィグ"}
  194. *
  195. * @param gamepadBackground
  196. * @type file
  197. * @dir img/title1/
  198. *
  199. * @param keyBackground
  200. * @type file
  201. * @dir img/title1/
  202. *
  203. * @param SettingsForYEP_OptionsCore
  204. * @type struct<DisguiseAsYEP>
  205. * @default {"gamepad":"true","Keyboard":"true"}
  206. *
  207. * @help
  208. * ※日本語テキストは下の方にあるのでスクロールしてください
  209. *
  210. *  Loads the settings at game startup as initial values.
  211. * Detects input changes regardless of where the plugin is installed.
  212. * It is OK even if the button is modified by another plug-in.
  213. *
  214. * The config data set by this plug-in is recorded in the file.
  215. * If you install a new plugin,
  216. * Please reset the config with "Reset to default" after starting the game.
  217. *
  218. * ■ What to do if strange characters such as "? KEY: Symbol" are displayed
  219. * Occurs because the input added by another plugin is unknown.
  220. * If the above display is displayed,
  221. * It can be handled by adding an element to extendsMapper.
  222. * 1. Add an element
  223. * 2. Try either of the following AB methods.
  224. * Copy the character corresponding to A: KEY and paste it into Key Setting.
  225. * B: Copy the characters corresponding to Symbol and paste them into symbol.
  226. * Be careful not to confuse the case.
  227. *
  228. * ■ What to do if a display like unknow: XXXX appears
  229. * The following causes are possible.
  230. * -Symbols were set after the game started (after Scene_Boot)
  231. * -Initialization process was not performed correctly
  232. * It may be improved by moving this plugin down.
  233. *
  234. * ■ Button operation diffusion function
  235. * If the operation is set by another plugin,
  236. * May be set on only one of the gamepad / keyboard.
  237. * In such a case, you can operate it from others by setting it in extendsMapper.
  238. * For example, suppose that the operation is set when you press only T on the keyboard.
  239. * If you want to set the operation for the buttons on the gamepad in this state, set as follows.
  240. * Key setting: T
  241. * Pad button: (any button number)
  242. * By doing this, this plugin will read the behavior set for T on the keyboard and
  243. * Set so that the same function can be used with the buttons on the gamepad.
  244. * The same is true for the opposite.
  245. *
  246. * If the operation is set on both the keyboard and the gamepad,
  247. * Determine which one to prioritize in the overwrite setting.
  248. * When using manual symbol settings (for advanced users)
  249. * Ignore the priority settings and use the contents set manually.
  250. *
  251. * ■ Common event call button
  252. * extendsMapper has an item called "Events".
  253. * If you set an event here, the event will be called when the button is pressed.
  254. * You can use it to create a function to open the map when you press the button.
  255. *
  256. * ■All functions can be used without eval ()
  257. * There are no items in this plugin that use eval ().
  258. * If you're writing a JavaScript expression for use with eval (),
  259. * you're wrong.
  260. *
  261. * ■ If you want to control the transition with a script
  262. * Used when modifying other plugins or switching scenes directly with a script.
  263. * SceneManager.push (Mano_InputConfig.Scene_GamepadConfig); // Gamepad Config
  264. * SceneManager.push (Mano_InputConfig.Scene_KeyConfig); // Keyboard config
  265. * You can now move to the specified scene.
  266. *
  267. * ゲームの起動時の設定を初期値として読み込みます。
  268. * プラグインの導入位置に関わらず、入力の変更を検知します。
  269. * 他のプラグインでボタンが改造されていてもOKです。
  270. *
  271. * このプラグインで設定したコンフィグデータは、ファイルに記録されます。
  272. * 新しいプラグインを入れた場合、
  273. * ゲーム起動後にコンフィグを「初期設定に戻す」でリセットしてください。
  274. *
  275. * ■"?KEY:Symbol"のような変な文字が表示される場合の対処法
  276. * 他のプラグインによって追加された入力が不明なために発生します。
  277. * 上記のような表示が出ている場合、
  278. * extendsMapperに要素を追加することで対応できます。
  279. * 1.要素を追加する
  280. * 2.下記のABどちらかの方法を試す。
  281. * A:KEYにあたる部分の文字をコピーして、KeySettingに貼り付ける。
  282. * B:Symbolにあたる部分の文字をコピーし、symbolに貼り付ける。
  283. *   大文字・小文字を間違えないように注意すること。
  284. *
  285. * ■unknow:XXXXのような表示が出る場合の対処法
  286. * 以下の原因が考えられます。
  287. * ・シンボルの設定がゲーム起動後(Scene_Bootより後)で行われた
  288. * ・初期化処理が正しく行われなかった
  289. * このプラグインを下の方に移動することで改善する可能性があります。
  290. *
  291. * ■ボタン操作拡散機能
  292. * 他のプラグインで操作が設定されている場合に、
  293. * ゲームパッド・キーボードの片方にしか設定されていない場合があります。
  294. * そういった場合、extendsMapperで設定を行うことで他からも操作できるようになります。
  295. * 例えば、キーボードのTにのみ押した場合の動作が設定されているとします。
  296. * この状態でゲームパッドのボタンにも操作を設定する場合、以下のように設定します。
  297. * キー設定:T
  298. * パッドボタン:(任意のボタン番号)
  299. * こうすることで、このプラグインはキーボードのTに設定されている動作を読み込み、
  300. * ゲームパッドのボタンでも同じ機能が使えるように設定を行います。
  301. * 逆の場合も同様です。
  302. *
  303. * キーボードとゲームパッドの双方に操作が設定されている場合、
  304. * どちらを優先するかを上書き設定で決めます。
  305. * シンボル手動設定(上級者向け)を使った場合、
  306. * 優先設定を無視して手動設定による内容を使います。
  307. *
  308. * ■コモンイベント呼び出しボタン
  309. * extendsMapperには「イベント」という項目があります。
  310. * ここにイベントを設定すると、ボタンが押された時にイベントを呼び出します。
  311. * ボタンを押したら地図を開く機能を作る時などに使えます。
  312. *
  313. * ■eval()無しで全機能が使えます
  314. * このプラグインにはeval()を使う項目はありません。
  315. * eval()で使うJavaScriptの式を書いている場合、あなたは間違っています。
  316. *
  317. * ■スクリプトで遷移を制御したい場合
  318. * 他のプラグインを改造したり、スクリプトで直接シーンを切り替える時に使います。
  319. * SceneManager.push(Mano_InputConfig.Scene_GamepadConfig  );  //ゲームパッドコンフィグ
  320. * SceneManager.push(Mano_InputConfig.Scene_KeyConfig );       // キーボードコンフィグ
  321. * これで、指定されたシーンに移動できます。
  322. *
  323. * 更新履歴
  324. *
  325. * 2022/03/15 ver 8.0.1
  326. * ゲームパッドコンフィグをリニューアル。
  327. * MV環境での不具合を修正
  328. *
  329. * 2022/03/08 ver 7.1.0
  330. * シンボルに対してボタンを割り当てる方式の廃止。
  331. * メンテナンスコストが大きいため。
  332. * ver8.0に向けた準備工事。
  333. *
  334. * 2022/01/18 ver7.0.1
  335. * PP_Optionとの連携関連で不具合があったのを修正。
  336. *
  337. * 2021/12/30 ver7.0.0
  338. * プラグインパラメータ「入力拡張」を中心に大改造。
  339. *
  340. * 2021/12/24 ver6.3.1
  341. * エラーメッセージの英語表記を追加。
  342. *
  343. * 2021/12/22 ver6.3.0
  344. * シンボル設定関連を更新。
  345. * ヘルプの内容を追加。
  346. *
  347. * 2021/12/18 ver6.2.1
  348. * ラムダ式関連の記述を修正した際に、バグを埋め込んでいたのを修正。
  349. * プラグインコマンドを追加。
  350. *
  351. * 2021/11/30 ver6.2.0
  352. * ManoPP_VisuMZ_OptionCore対応を実装。
  353. *
  354. * 2021/08/30 ver6.1.2
  355. * 一部環境でラムダ式がエラーを起こすため、使用しない形に修正
  356. * 一部テキストが日本語のままだったのを英語対応
  357. *
  358. * 2021/07/17 ver6.1.1
  359. * 拡張入力の上書き設定が機能していないのを修正
  360. *
  361. * 2021/06/13 ver6.1.0
  362. * シンボルからボタンの名称を取得するプラグインコマンドを追加(MZのみ)
  363. *
  364. * 2021/05/23 ver 6.0.0
  365. * ゲームパッドにシンボルに対してボタンを割り当てる機能を実装。
  366. *
  367. *
  368. * 2021/04/22 ver 5.4.0
  369. * MZのみ:タッチボタンの表示機能を試験的に実装
  370. *
  371. * 2021/04/15 ver 5.3.1
  372. * コモンイベント呼び出しを修正(簡単にしました)
  373. * イベントコマンドでコンフィグを開くと保存されない不具合を修正
  374. *
  375. * 2021/02/23 ver 5.3.0
  376. * ボタン入力がある時にコモンイベントを呼び出すプラグインコマンドを追加
  377. *
  378. * 2021/01/27 ver 5.2.0
  379. * 不明なシンボルの表示機能を強化
  380. *
  381. * 2021/01/23 ver5.1.0
  382. * 画面レイアウトを変更
  383. * 必須シンボルの扱いを調整
  384. * 不明なシンボルがある場合、画面上部へ表示するようにした
  385. *
  386. * 2020/12/25 ver5.0.3
  387. * 必須シンボルチェックの動作が正しくなかったのを修正
  388. * バージョン管理を修正し、番号付けを変更。
  389. *
  390. * 2020/12/25 ver5.0.2(旧5.2)
  391. * 拡張シンボル設定にバグがあったので修正
  392. *
  393. * 2020/11/26 ver5.0.1(旧5.1)
  394. * プラグインが起動できないバグがあったので修正
  395. *
  396. * 2020/11/24 ver5.0
  397. * プラグインパラメータを再設計。
  398. * 内部実装であるsymbolを意識する必要が無くなりました。
  399. *
  400. * 2020/08/23 ver4.0
  401. * ツクールMZに対応。
  402. * 基本システムはMZ向けに最適化し、MVはラッパーで調整
  403. *
  404. * 2020/05/25 ver 3.2
  405. * YEP_OptionCoreと競合するので、対策処理を追加。
  406. *
  407. * 2020/04/01 ver 3.1
  408. * 英語対応につきヘルプを追加。
  409. *
  410. * 2020/03/14 ver3.0
  411. * WASD移動を設定できる機能を追加。
  412. * キーコンフィグの内部実装を大幅改造。
  413. *
  414. * 2020/02/26 ver2.9
  415. * コンフィグから抜けた際にボタンが連打されてしまう問題を対策。
  416. * RPGアツマールにおいて、他のゲームとコンフィグ設定が混ざる問題を修正。
  417. * 別プラグインとの競合があったので対策
  418. * symbolAutoSelectがキーコンフィグで機能していなかったのを修正。
  419. *
  420. * 2019/07/12 ver2.8.1
  421. * ゲームパッドのハードごとの識別情報を表示する機能を追加。
  422. *
  423. * 2019/07/06 ver2.8
  424. * 外部プラグインによって追加されたmapperのsymbolを強制的に取り込む機能。
  425. * プラグインパラメータで無効化できます。
  426. *
  427. * 2019/03/19 ver2.7
  428. * キーボードに任意の初期設定を割り当てる機能を追加。
  429. *
  430. * 2018/09/28 ver2.6
  431. * ゲームパッドコンフィグを改造すると誤作動があったので、誤作動を減らす修正。
  432. * プラグインの位置に関わらず初期設定の変更を捕まえられるように。
  433. *
  434. * 2018/06/25 ver 2.5
  435. * 色々あった細かいバグ修正を重ねた最新版。
  436. *
  437. * 2017/10/21 ver 2.2 更新
  438. * 外部から追加したシンボルがsymbolsと重複していた場合、追加しないようにした。
  439. * USキー配列に仮対応。
  440. *
  441. * 2017/10/18 ver 2.1 更新
  442. * キーボードで目立ったバグの報告がなかったため、2.0に。
  443. * 外部からコンフィグを改造できる機能を導入。
  444. *
  445. * 2017/10/13 ver 1.9 更新
  446. * キーボードのコンフィグにも対応。
  447. * 仕様が固まっていないので、1.9とします。
  448. * 2017/10/05 ver 1.0 公開
  449. *
  450. */
  451. /*~struct~BasicSymbol:
  452. * @param name
  453. * @type struct<MultiLangString>
  454. * @default {"jp":"","en":""}
  455. *
  456. * @param keyText
  457. * @text キーの表示/keyText
  458. * @desc キーコンフィグの際の表示名を定義します(空欄OK)
  459. * Define the display name for key config (blank OK)
  460. * @type struct<MultiLangString>
  461. * @default {"jp":"","en":""}
  462. *
  463. * @param helpText
  464. * @text 詳細/helpText
  465. * @desc 画面上部に表示する説明文
  466. * Description to be displayed at the top of the screen
  467. * @type struct<MultiLangNote>
  468. * @default {"jp":"","en":""}
  469. *
  470. */

  471. /*~struct~TouchButton:
  472. * @param image
  473. * @type file
  474. * @dir img/
  475. * @desc 通常時は上の半分、押されている間は下の半分が使われます。
  476. * upper is used normally, and lower is used when pressed.
  477. * @default system
  478. *
  479. * @param x
  480. * @type number
  481. * @default 0
  482. *
  483. * @param y
  484. * @type number
  485. * @default 0
  486. *
  487. */
  488. /*~struct~EventCaller:
  489. * @param id
  490. * @text 呼び出すイベント/event
  491. * @desc ボタンを押した際に呼び出すコモンイベント(マップのみ)
  492. * Common event to call when a button is pressed(MapOnly)
  493. * @type common_event
  494. * @default 0
  495. *
  496. * @param inputType
  497. * @text 入力方式/inputType
  498. * @desc 呼び出し時のボタンの入力形式。
  499. * Button input format when calling.
  500. * @type select
  501. * @option 押されている/pressed
  502. * @value 0
  503. * @option トリガー/triggerd
  504. * @value 1
  505. * @option リピート/repeated
  506. * @value 2
  507. * @default 0
  508. */
  509. /*~struct~KeyboradSetting:

  510. * @param keys
  511. * @type string
  512. * @desc 半角英字で設定。例 Ef65
  513. * Set the key corresponding to the action (ex:Ef65)
  514. *
  515. *
  516. * @param text
  517. * @text キーの表示/keyText
  518. * @desc キーコンフィグの際の表示名を定義します(空欄OK)
  519. * Define the display name for key config (blank OK)
  520. * @type struct<MultiLangString>
  521. * @default {"jp":"","en":""}
  522. *
  523. */
  524. /*
  525. * TODO:あとでキー設定にカラーを追加
  526. * @param color
  527. * @type combo
  528. * @option #FF00FF
  529. * @default
  530. *
  531. */

  532. /*~struct~AdvancedSetting:
  533. * @param symbol
  534. * @text シンボル/symbol
  535. * @desc ボタンを押した場合の動作(上級者向け)
  536. * Operation when the button is pressed (for advanced users)
  537. * @type string
  538. * @default
  539. *
  540. * @param overwrite
  541. * @text 上書き/overwrite
  542. * @desc どのボタンのシンボルを基準にするか
  543. * Which button symbol to base on
  544. * @type select
  545. * @option 上書きしない/none
  546. * @value 0
  547. * @option ゲームパッド/gamepad
  548. * @value 1
  549. * @option キーボード/Keyboard
  550. * @value 2
  551. * @option イベント/event
  552. * @value 3
  553. * @default 0
  554. *
  555. * @param mandatory
  556. * @text 必須フラグ/mandatory
  557. * @type boolean
  558. * @default false
  559. */

  560. /*~struct~InputDefine:
  561. *
  562. * @param keys
  563. * @text キー設定/KeySetting
  564. * @desc 廃止予定。同名の新しいパラメータを使用してください。
  565. * Scheduled to be abolished. Use the new parameter.
  566. *
  567. * @param keySetting
  568. * @text キー設定/keySetting
  569. * @type struct<KeyboradSetting>
  570. * @default {"keys":"","color":"","text":"{"jp":"","en":""}"}
  571. *
  572. * @param button
  573. * @text パッドボタン/padButton
  574. * @desc ボタン設定。配置と名前は任天堂のスタイルを想定。
  575. * Button settings. The layout and name the style of Nintendo.
  576. * @type select
  577. * @default NaN
  578. * @option none
  579. * @value NaN
  580. * @option 0(B/×)
  581. * @value 0
  582. * @option 1(A/○)
  583. * @value 1
  584. * @option 2(X/□)
  585. * @value 2
  586. * @option 3(Y/△)
  587. * @value 3
  588. * @option 4(L1)
  589. * @value 4
  590. * @option 5(R1)
  591. * @value 5
  592. * @option 6(L2)
  593. * @value 6
  594. * @option 7(R2)
  595. * @value 7
  596. * @option 8(select)
  597. * @value 8
  598. * @option 9(start)
  599. * @value 9
  600. * @option 10(L3)
  601. * @value 10
  602. * @option 11(R3)
  603. * @value 11
  604. * @option 16(center)
  605. * @value 16
  606. *
  607. * @param name
  608. * @text 行動名/actionName
  609. * @desc 言語別に行動の説明を入力します
  610. * Enter a description of the action by language
  611. * @type struct<MultiLangString>
  612. * @default {"jp":"","en":""}
  613. *
  614. * @param helpText
  615. * @text 詳細/helpText
  616. * @desc 画面上部に表示する説明文
  617. * Description to be displayed at the top of the screen
  618. * @type struct<MultiLangString>
  619. * @default {"jp":"","en":""}
  620. *
  621. * @param event
  622. * @text イベント/event
  623. * @desc ボタンを押した際にコモンイベントを実行します。
  624. * Executes a common event when the button is pressed.
  625. * @type struct<EventCaller>
  626. * @default {"id":"0","inputType":"0"}
  627. *
  628. * @param touchButton
  629. * @text タッチボタン/touchButton
  630. * @type struct<TouchButton>
  631. * @desc MZのみ:画面上にタッチUI向けのボタンを追加します
  632. *
  633. * @param adovanced
  634. * @text 上級者向け/adovanced
  635. * @desc 多くの場合、これを変更する必要はありません。
  636. * In most cases you do not need to change this.
  637. * @type struct<AdvancedSetting>
  638. * @default {"symbol":"","overwrite":"0","mandatory":"false"}
  639. *
  640. * @param enabled
  641. * @text 有効化
  642. * @desc テスト用に一時的に無効化したい場合などで使います。
  643. * @type boolean
  644. * @default true
  645. */


  646. /*
  647. * @param sourcePlugin
  648. * @desc 指定した名前のプラグインがONの場合のみ、有効化します
  649. * @type combo
  650. * @default
  651. */


  652. /*~struct~MultiLangNote:
  653.   * @param jp
  654.   *  @text 日本語
  655.   *  @type multiline_string
  656.   *  @type note
  657.   *  @param en
  658.   *  @type multiline_string
  659.   *  @type note
  660. */
  661. /*~struct~MultiLangNoteFull:
  662.   * @param jp
  663.   *  @text 日本語
  664.   *  @type multiline_string
  665.   *  @type note

  666.   *  @param en
  667.   *  @type multiline_string
  668.   *  @type note

  669.   *  @param ch
  670.   *  @text 中文
  671.   *  @type multiline_string
  672.   *  @type note

  673.   *  @param ko
  674.   *  @text 한국
  675.   *  @type multiline_string
  676.   *  @type note

  677.   *  @param ge
  678.   *  @text Deutsche
  679.   *  @type multiline_string
  680.   *  @type note

  681.   *  @param fr
  682.   *  @text français
  683.   *  @type multiline_string
  684.   *  @type note

  685.   *  @param ru
  686.   *  @text русский
  687.   *  @type multiline_string
  688.   *  @type note
  689. */

  690. /*~struct~MultiLangString:
  691.   * @param jp
  692.   * @text 日本語

  693.   * @param en
  694.   * @text English
  695. */

  696. /*~struct~MultiLangStringFull:
  697.   * @param jp
  698.     @text 日本語

  699.     @param en
  700.     @text English

  701.     @param ch
  702.     @text 中文

  703.     @param ko
  704.     @text 한국

  705.     @param ge
  706.     @text Deutsche

  707.     @param fr
  708.     @text français

  709.     @param ru
  710.     @text русский
  711. */
  712. /*~struct~KeyconfigCommand:
  713.   *
  714.   * @param width
  715.   * @desc コマンドの幅
  716.   * @type number
  717.   * @min 0
  718.   * @max 10
  719.   * @default 3
  720.   *
  721.   * @param text
  722.   * @type struct<MultiLangString>
  723.   * @default {}
  724.   *
  725. */
  726. /*~struct~ColorManager:
  727.   *
  728.   * @param normal
  729.   * @default #880000
  730.   *
  731.   * @param mandatory
  732.   * @text 必須シンボル/mandatory
  733.   * @default #22e488
  734.   *
  735.   * @param move
  736.   * @text 移動/move
  737.   * @default #22e488
  738.   *
  739.   * @param extends
  740.   * @text 拡張シンボル/extends
  741.   * @default #22e488
  742.   *
  743.   *
  744. */
  745. /*~struct~DisguiseAsYEP:
  746. * @param gamepad
  747. * @desc Impersonate the configuration as if it were GamepadConfig.js (by Yanfly).
  748. * @type boolean
  749. * @default true
  750. *
  751. * @param Keyboard
  752. * @desc Impersonate the configuration as if it were YEP_KeyboardConfig.js (by Yanfly).
  753. * @type boolean
  754. * @default true
  755. */
  756. //@ts-ignore
  757. var Imported = Imported || {};
  758. if(Imported.Mano_InputConfig){
  759.     throw new Error("Mano_InputConfig is Duplicate")
  760. }
  761. Imported.Mano_InputConfig = true;

  762. var Mano_InputConfig=( function(){
  763.     'use strict'

  764.     /**
  765.      * @typedef {Object} MyRectType
  766.      * @property {Number} x
  767.      * @property {Number} y
  768.      * @property {Number} width
  769.      * @property {Number} height
  770.      * @property {()=>MyRectType} clone
  771.      */

  772.     const GetEnabledPlugins =function(){
  773.         /**
  774.          * @type {Set<String>}
  775.          */
  776.         const set=new Set();
  777.         for (const iterator of $plugins) {
  778.             if(iterator.status){
  779.                 set.add(iterator.name);
  780.             }
  781.         }
  782.         return set;
  783.     }

  784.     /**
  785.      * @type {String}
  786.      */
  787.     const  PLUGIN_NAME= ('Mano_InputConfig');
  788.     function getCurrentScriptName(){
  789.         //@ts-ignore
  790.        const pluginName = decodeURIComponent(document.currentScript.src).match(/([^/]+)\.js$/);
  791.        if(pluginName){ return pluginName[1];}
  792.        return '';
  793.     }
  794.     /**
  795.      * @param {String} officialFileName
  796.      */
  797.     function TestFileNameValid(officialFileName){
  798.         const currentFileName=getCurrentScriptName();
  799.         if(officialFileName ===currentFileName){ return;}
  800.         const message= `Do not rename the plugin file.<br>`+
  801.                         `Current file name: currentFileName<br>`+
  802.                         `Original file name: officialFileName<br>`+
  803.                         `プラグインファイルの名前を変更してはいけません<br>`+
  804.                         `現在のファイル名: currentFileName<br>`+
  805.                         `本来のファイル名: officialFileName`
  806.         throw new Error(message);
  807.     }
  808.     TestFileNameValid(PLUGIN_NAME);
  809.     //@ts-ignore
  810.     const IS_Atsumaru = location.hostname==="html5.nicogame.jp";

  811.     function getParam(){
  812.         return PluginManager.parameters(PLUGIN_NAME);
  813.     }
  814.    
  815. /**
  816. * @param {Window_Base|Window_Selectable} window_
  817. * @param {MyRectType} rect
  818. * @param {(srect:Rectangle)=>void} initFuncton
  819. */
  820. function window_initializeMVMZ(window_,rect,initFuncton){
  821.     if(Utils.RPGMAKER_NAME==="MZ"){
  822.         initFuncton.call(window_,rect);
  823.         return
  824.     }
  825.     if(Utils.RPGMAKER_NAME==="MV"){
  826.         initFuncton.call(window_,rect.x,rect.y,rect.width,rect.height);
  827.         return;
  828.     }
  829.     throw( new Error("Unknow RPG MAKER:"+Utils.RPGMAKER_NAME));
  830. }
  831. class Scene_MenuBaseMVMZ extends Scene_MenuBase{
  832.     bottomAreaHeight(){
  833.         return 20;
  834.     }
  835.     createHelpWindow(){
  836.         const helpRect = this.helpWindowRect ? this.helpWindowRect():null;
  837.         const hw = InputConfigManager.getWorkaround().createHelpWindow(helpRect);
  838.         this.addWindow(hw);
  839.         this._helpWindow=hw;
  840.     }
  841.     /**
  842.      * @returns {Number}
  843.      */
  844.     mainAreaTop(){
  845.         if(Utils.RPGMAKER_NAME ==="MV"){
  846.             return this._helpWindow.y + this._helpWindow.height;
  847.         }
  848.         return super.mainAreaTop();
  849.     }
  850.     isBottomButtonMode(){
  851.         return false;
  852.     }
  853.     helpAreaHeight(){
  854.         return this.calcWindowHeight(this.helpWindowLines(), false);
  855.     }
  856.     isBottomHelpMode(){
  857.         return false;
  858.     }
  859.     helpWindowLines(){
  860.         return 3;
  861.     }
  862.     /**
  863.      * @param {Number} numLines
  864.      * @param {Boolean} selectable
  865.      */
  866.      calcWindowHeight(numLines,selectable){
  867.         if(selectable){
  868.             return Window_Selectable.prototype.fittingHeight(( numLines))
  869.         }
  870.         return Window_Base.prototype.fittingHeight(numLines);
  871.     }
  872. }

  873. /**
  874. *
  875. * @param {InputMapperType} obj
  876. */
  877. function objectClone(obj){

  878.     /**
  879.      * @type {Record<Number,String>}
  880.      */
  881.     const result ={};
  882.     Object.keys(obj).forEach(function(key){
  883.         result[key] = obj[key];
  884.     })
  885.     return result;
  886. }

  887. //言語判定
  888. //本体の処理タイミングがおかしいので、コピペしてきた
  889. const isJapanese = function() {
  890.     return $dataSystem.locale.match(/^ja/);
  891. };
  892. const isChinese = function() {
  893.     return $dataSystem.locale.match(/^zh/);
  894. };

  895. const isKorean = function() {
  896.     return $dataSystem.locale.match(/^ko/);
  897. };

  898. const isRussian = function() {
  899.     return $dataSystem.locale.match(/^ru/);
  900. };
  901. class MultiLanguageText{
  902.     /**
  903.      *
  904.      * @param {String} en
  905.      * @param {String} jp
  906.      */
  907.     constructor(en,jp){
  908.         this.setNameEN(en);
  909.         this.setNameJP(jp);
  910.         this.setDefaultName("");
  911.     }
  912.     static create(objText){
  913.         if(!objText){
  914.             return null;
  915.         }
  916.         const obj = JSON.parse(objText);
  917.         const en =noteOrString(obj.en||"");
  918.         const jp =noteOrString( obj.jp||"");
  919.         const mtext = new MultiLanguageText(en,jp);
  920.         return mtext;
  921.     }
  922.     isEmpty(){
  923.         return (!this.ja_JP)&&(!this.en_US);
  924.     }
  925.     /**
  926.      * @param {String} name
  927.      */
  928.     setNameJP(name){
  929.         this.ja_JP =name;
  930.     }
  931.     /**
  932.      * @param {String} name
  933.      */
  934.     setNameEN(name){
  935.         this.en_US =name;
  936.     }
  937.     /**
  938.      * @param {String} name
  939.      */
  940.     setDefaultName(name){
  941.         this._defaultName=name;
  942.     }
  943.     isUnknow(){
  944.         return this._defaultName[0]==="?";
  945.     }
  946.     refresh(){
  947.         if(!this.isUnknow()){
  948.             this.setDefaultName(this.currentName());
  949.         }
  950.     }
  951.     currentName(){
  952.         if(isJapanese() && this.ja_JP ){
  953.             return this.ja_JP;
  954.         }
  955.         return this.en_US;
  956.     }
  957.     name(){
  958.         return this._defaultName;
  959.     }
  960. }
  961. class TouchButton{
  962.     /**
  963.      * @param {String} filePath
  964.      * @param {Number} x
  965.      * @param {Number} y
  966.      */
  967.     constructor(filePath,x,y){
  968.         const result= (/(.*)\/(.*)/).exec(filePath);
  969.         if(result){
  970.             this.setFilePath("img/"+result[1]+"/",result[2]);
  971.         }else{
  972.             this.setFilePath("","");
  973.         }
  974.         this._x = x;
  975.         this._y = y;
  976.         this.setSymbolObject(null);
  977.     }
  978.     /**
  979.      *
  980.      * @param {String} objText
  981.      * @returns
  982.      */
  983.     static create(objText){
  984.         if(!objText){
  985.             return null;
  986.         }
  987.         const obj = JSON.parse(objText);
  988.         const x  =Number(obj.x);
  989.         const y = Number(obj.y);
  990.         const button = new TouchButton(obj.image,x,y);
  991.         return button;   
  992.     }
  993.     /**
  994.      * @param {String} folder
  995.      * @param {String} fileName
  996.      */
  997.     setFilePath(folder,fileName){
  998.         this._folder =folder;
  999.         this._fileName = fileName;
  1000.     }
  1001.     isValid(){
  1002.         return !!this._fileName;
  1003.     }
  1004.     /**
  1005.      * @param {ExtendsSymbol} symbol
  1006.      */
  1007.     setSymbolObject(symbol){
  1008.         this._symbol = symbol;
  1009.     }
  1010.     isVisible(){
  1011.         return true;
  1012.     }
  1013.     bitmap(){
  1014.         //@ts-ignore
  1015.         return ImageManager.loadBitmap(this._folder,this._fileName);
  1016.     }
  1017.     rect(){
  1018.         return new Rectangle();
  1019.     }
  1020.     symbol(){
  1021.         return this._symbol.symbol();
  1022.     }
  1023.     symbolObject(){
  1024.         return this._symbol;
  1025.     }
  1026.     x(){
  1027.         return this._x;
  1028.     }
  1029.     y(){
  1030.         return this._y;
  1031.     }
  1032.     isEnabled(){
  1033.         return true;
  1034.     }
  1035.     clearPress(){
  1036.         const symbol = this.symbol();
  1037.         Input._currentState[symbol]=false;
  1038.     }
  1039.     virtualPress(){
  1040.         const symbol = this.symbol();
  1041.         if(!Input._currentState[symbol]){
  1042.             Input._currentState[symbol]=TouchInput.isPressed();
  1043.         }
  1044.     }
  1045. }
  1046. class ButtonManager_T{
  1047.     constructor(){
  1048.         this.setList([]);
  1049.     }
  1050.     /**
  1051.      *
  1052.      * @param {TouchButton[]} list
  1053.      */
  1054.     setList(list){
  1055.         this._list =list;
  1056.     }
  1057.     getList(){
  1058.         return this._list;
  1059.     }

  1060.     /**
  1061.      * @param {TouchButton} button
  1062.      */
  1063.     addButton(button){
  1064.         this._list.push(button);
  1065.     }
  1066.     isTouchButtonEnabled(){
  1067.         return  Utils.RPGMAKER_NAME ==="MZ" && this._list.length > 0;
  1068.     }
  1069. }
  1070. const ButtonManager = new ButtonManager_T();

  1071. //todo
  1072. //必須シンボル不足の際に、色で知らせたほうが良さそう
  1073. class SymbolColorManager_T{
  1074.     constructor(normal,mandatory,move,extendsSymbol){
  1075.         this._normal =(normal ||"#880000")
  1076.         this._mandatory=(mandatory||"#22e488");
  1077.         this._move=(move ||"#22e488");
  1078.         this._extends =extendsSymbol;
  1079.     }
  1080.     /**
  1081.      *
  1082.      * @param {String} objText
  1083.      * @returns
  1084.      */
  1085.     static create(objText){
  1086.         if(!objText){
  1087.             return new SymbolColorManager_T(null,null,null);
  1088.         }
  1089.         const obj =JSON.parse(objText);
  1090.         const normal =(obj.normal||null);
  1091.         const mandatory=(obj.mandatory||null);
  1092.         const move=(obj.move||null);
  1093.         const extendsSymbol = (obj.extends);

  1094.         return new SymbolColorManager_T(normal,mandatory,move,extendsSymbol);
  1095.     }

  1096.     paramatorInvalidColor(){
  1097.         return "#FF00FF";
  1098.     }
  1099.     emptyColor(){
  1100.         return "#000000";
  1101.     }
  1102.     mandatoryColor(){
  1103.         return this._mandatory;
  1104.     }
  1105.     normalColor(){
  1106.         return this._normal;
  1107.     }
  1108.     moveSymbolColor(){
  1109.         if(this._move){
  1110.             return this._move;
  1111.         }
  1112.         return this.mandatoryColor();
  1113.     }
  1114. }

  1115. //TODO
  1116. const SymbolColorManager =  SymbolColorManager_T.create(getParam().color);
  1117. //デバッグ用の情報を扱うクラス
  1118. class DebugSymbol{
  1119.     /**
  1120.      *
  1121.      * @param {I_SymbolDefine} symbol
  1122.      * @param {String} type
  1123.      */
  1124.     constructor(symbol,type){
  1125.         this._symbol =symbol;
  1126.         this._type =type;
  1127.     }
  1128.     symbolName(){
  1129.         return this._symbol.name();
  1130.     }
  1131.     exInfos(){
  1132.         //return this._symbol.
  1133.     }


  1134. }
  1135. //TODO:基本・拡張の双方で使うので、1クラス追加
  1136. class SymbolFill{
  1137.     constructor(keys,button){

  1138.     }
  1139. }

  1140. class I_SymbolDefine{

  1141.     createDebugSymbol(){
  1142.         return new DebugSymbol(this,this.constructor.name);
  1143.     }
  1144.     isDeleter(){
  1145.         return false;
  1146.     }
  1147.     isParamatorValid(){
  1148.         if(!this.symbol()){
  1149.             return false;
  1150.         }
  1151.         if(!this.name()){
  1152.             return false;
  1153.         }
  1154.         if(this.isUnknow()){
  1155.             return false;
  1156.         }
  1157.         return true;
  1158.     }
  1159.     symbolBackColor(){
  1160.         return this.backColor();
  1161.     }
  1162.     // /**
  1163.     //  * @desc keyconfigで使う背景色
  1164.     //  */
  1165.     // keyBackColor(){
  1166.     //     return "#ffd530" ;
  1167.     // }
  1168.     customBackColor(){
  1169.         return "";
  1170.     }
  1171.     backColor(){
  1172.         const  custom = this.customBackColor();
  1173.         if(custom){
  1174.             return custom;
  1175.         }
  1176.         if(this.isMandatory()){
  1177.             return SymbolColorManager.mandatoryColor()
  1178.         }
  1179.         if(this.isEmpty()){
  1180.             return SymbolColorManager.emptyColor();
  1181.         }
  1182.         return SymbolColorManager.normalColor();
  1183.     }
  1184.     textColor(){
  1185.         return "#ffd530";
  1186.     }
  1187.     isUnknow(){
  1188.         return false;
  1189.     }
  1190.     name(){
  1191.         return "";
  1192.     }
  1193.     hasName(){
  1194.         return !!this.name();
  1195.     }
  1196.     isEnabled(){
  1197.         return !this.isEmpty() ;
  1198.     }
  1199.     symbol(){
  1200.         return "";
  1201.     }
  1202.     isMandatory(){
  1203.         return false;
  1204.     }
  1205.     debugInfo(){
  1206.         return "";
  1207.     }
  1208.     isEmpty(){
  1209.         return !this.symbol();
  1210.     }
  1211.     displayKeyName(){
  1212.         return this.symbol();
  1213.     }
  1214.     errorText(){
  1215.         if(!symbolManager.isInitialized()){
  1216.             return setting.errorText.initFauled.currentName();
  1217.         }
  1218.         if(this.isEmpty()){
  1219.             return setting.errorText.symbolEmpty.currentName();
  1220.         }
  1221.         if(!this.hasName()){
  1222.             return setting.errorText.nameEmpty.currentName()+this.symbol();
  1223.         }
  1224.         return "";
  1225.     }
  1226.     helpText(){
  1227.         return ""
  1228.     }
  1229.     getHelpText(){
  1230.         const errorText = this.errorText();
  1231.         if(errorText){
  1232.             return errorText;
  1233.         }
  1234.         return this.helpText();
  1235.     }
  1236.     createErrorObject(){

  1237.     }

  1238.     isPressed(){
  1239.         return Input.isPressed(this.symbol());
  1240.     }
  1241.     isRepeated(){
  1242.         return Input.isRepeated(this.symbol());
  1243.     }
  1244.     isTriggered(){
  1245.         return Input.isTriggered(this.symbol());
  1246.     }
  1247. }


  1248. class MoveSymbol extends I_SymbolDefine{
  1249.     /**
  1250.      * @param {String} symbol
  1251.      * @param {String} name
  1252.      */
  1253.     constructor(symbol,name){
  1254.         super();
  1255.         this._symbol =symbol;
  1256.         this._name =name;
  1257.     }
  1258.     backColor(){
  1259.         return SymbolColorManager.moveSymbolColor();
  1260.     }
  1261.     symbol(){
  1262.         return this._symbol;
  1263.     }
  1264.     name(){
  1265.         return this._name;
  1266.     }
  1267.     displayKeyName(){
  1268.         return this._name;
  1269.     }
  1270.     // isMandatory(){
  1271.     //     return true;
  1272.     // }
  1273. }
  1274. function createMoveSymbols(){
  1275.     const up = new MoveSymbol("up","↑");
  1276.     const down = new MoveSymbol("down","↓");
  1277.     const left =new MoveSymbol("left","←");
  1278.     const right =new MoveSymbol("right","→");
  1279.     return [up,down,left,right];
  1280. }
  1281. class SymbolDeleteObject extends I_SymbolDefine{
  1282.     isEnabled(){
  1283.         return true;
  1284.     }
  1285.     isDeleter(){
  1286.         return true;
  1287.     }
  1288.     name(){
  1289.         return setting.text.mapperDelete.currentName();
  1290.     }
  1291.     symbol(){
  1292.         return null;
  1293.     }
  1294.     errorText(){
  1295.         return "";
  1296.     }
  1297.     helpText(){
  1298.         return this.name();
  1299.     }
  1300. }
  1301. class EscapeSymbol extends I_SymbolDefine{
  1302.     /**
  1303.      * @param {MultiLanguageText} name
  1304.      * @param {MultiLanguageText} helpText
  1305.      * @param {MultiLanguageText} keyText
  1306.      */
  1307.     constructor(name,helpText,keyText){
  1308.         super();
  1309.         this._name =name;
  1310.         this._helpText =xxxxMtext(helpText);
  1311.         this._keyText = xxxxMtext(keyText);

  1312.     }
  1313.     static create(objText){
  1314.         if(!objText){
  1315.             const name = new MultiLanguageText("menu/cancel","メニュー/キャンセル");
  1316.             return new EscapeSymbol(name,null,null);
  1317.         }
  1318.         const obj=JSON.parse(objText);

  1319.         const name =  MultiLanguageText.create(obj.name);
  1320.         const helpText =MultiLanguageText.create(obj.helpText);
  1321.         const keyText =MultiLanguageText.create(obj.keyText);
  1322.         return new EscapeSymbol(name,helpText,keyText);
  1323.     }

  1324.     name(){
  1325.         return this._name.currentName();
  1326.     }
  1327.     symbol(){
  1328.         return "escape";
  1329.     }
  1330.     backColor(){
  1331.         return SymbolColorManager.mandatoryColor();
  1332.     }
  1333. }
  1334. /**
  1335. *
  1336. * @param {MultiLanguageText} mText
  1337. */
  1338. function xxxxMtext(mText){
  1339.     if(mText){
  1340.         if(!mText.isEmpty()){
  1341.             return mText
  1342.         }
  1343.     }
  1344.     return null;
  1345. }
  1346. class BasicSymbol extends I_SymbolDefine{
  1347.     /**
  1348.      * @param {String} symbol
  1349.      * @param {MultiLanguageText} name
  1350.      * @param {MultiLanguageText} keyText
  1351.      * @param {MultiLanguageText} helpText
  1352.      * @param {String} exKeys
  1353.      * @param {Number} exButton
  1354.      */
  1355.     constructor(symbol,name,keyText,helpText,exKeys ,exButton){
  1356.         super();
  1357.         this._symbol = symbol;
  1358.         //名前が未設定の場合、シンボルで初期化してしまう
  1359.         this._name =name ? name : new MultiLanguageText(symbol,symbol);
  1360.         //テキストが空っぽならnullにして、基底クラスの処理に任せる
  1361.         this._keyText = xxxxMtext( keyText);
  1362.         this._helpText=xxxxMtext(helpText);
  1363.         this._exKeys=exKeys;
  1364.         this._buttonId =exButton;
  1365.     }
  1366.     static create(symbol,objText){
  1367.         if(!objText){
  1368.             return new BasicSymbol(symbol,null,null,null,null,null);
  1369.         }
  1370.         const obj = JSON.parse(objText);
  1371.         const name =MultiLanguageText.create(obj.name);
  1372.         const keyText =MultiLanguageText.create(obj.keyText);
  1373.         const helpText =MultiLanguageText.create(obj.helpText);
  1374.         const exKeys =String(obj.exKeys||"");
  1375.         const exButton =Number(obj.exButton );
  1376.         return new BasicSymbol(symbol,name,keyText,helpText,exKeys,exButton);
  1377.     }
  1378.     isMandatory(){
  1379.         return true;
  1380.     }
  1381.     helpText(){
  1382.         return super.helpText();
  1383.     }
  1384.     name(){
  1385.         return this._name.currentName();
  1386.     }
  1387.     symbol(){
  1388.         return this._symbol;
  1389.     }
  1390.     displayKeyName(){
  1391.         if(this._keyText){
  1392.             return this._keyText.currentName();
  1393.         }
  1394.         return super.displayKeyName();
  1395.     }
  1396. }
  1397. function createBasicSymbols(){
  1398.     const param    = getParam();
  1399.     const ok       = BasicSymbol.create("ok",param.basicOk);
  1400.     const cancel   = BasicSymbol.create("cancel",param.basicCancel);
  1401.     const shift    = BasicSymbol.create("shift",param.basicShift);
  1402.     const menu     = BasicSymbol.create("menu",param.basicMenu);
  1403.     const pageup   = BasicSymbol.create("pageup",param.basicPageup);
  1404.     const pagedown = BasicSymbol.create("pagedown",param.basicPagedown);
  1405.     const esacape  = EscapeSymbol.create(param.basicEscape);
  1406.     return [ok,cancel,shift,menu,pageup,pagedown,esacape];
  1407. }

  1408. class EventCaller{
  1409.     /**
  1410.      * @param {Number} eventId
  1411.      * @param {Number} triggereType
  1412.      */
  1413.     constructor(eventId,triggereType){
  1414.         this._eventId = eventId;
  1415.         this._inputType = triggereType;
  1416.     }
  1417.     /**
  1418.      * @param {String} objText
  1419.      * @returns
  1420.      */
  1421.     static create(objText){
  1422.         if(!objText){
  1423.             return new EventCaller(0,0);
  1424.         }
  1425.         const obj =JSON.parse(objText);

  1426.         const eventId =Number(obj.id);
  1427.         const inputType =Number(obj.inputType);
  1428.         return new EventCaller(eventId,inputType);
  1429.     }
  1430.     isValidEvent(){
  1431.         return this._eventId > 0;
  1432.     }
  1433.     eventId(){
  1434.         return this._eventId;
  1435.     }
  1436.     callEvent(){
  1437.         if(!$gameTemp.isCommonEventReserved()){
  1438.             $gameTemp.reserveCommonEvent(this._eventId);
  1439.         }
  1440.     }
  1441.     /**
  1442.      * @param {String} symbol
  1443.      */
  1444.     updateEvent(symbol){
  1445.         if(this._eventId >0 && this.needsEventCall(symbol)){
  1446.             this.callEvent();
  1447.         }
  1448.     }
  1449.     /**
  1450.      * @param {String} symbol
  1451.      * @returns
  1452.      */
  1453.     needsEventCall(symbol){
  1454.         switch (this._inputType) {
  1455.             case 0:
  1456.                 return Input.isPressed(symbol);   
  1457.             case 1:
  1458.                 return Input.isTriggered(symbol)
  1459.             case 2:
  1460.                 return Input.isRepeated(symbol);
  1461.         }
  1462.         return false;
  1463.     }
  1464.     typeIsPressed(){
  1465.         return this._inputType === 0;
  1466.     }
  1467.     typeIsTriggered(){
  1468.         return this._inputType === 1;
  1469.     }
  1470.     typeIsRepeated(){
  1471.         return this._inputType === 2;
  1472.     }
  1473. }
  1474. class KeySetting{
  1475.     /**
  1476.      *
  1477.      * @param {String} keys
  1478.      * @param {String} color
  1479.      * @param {MultiLanguageText} text
  1480.      */
  1481.     constructor(keys,color,text){
  1482.         this._keys=keys.toUpperCase();
  1483.         this._color = color;
  1484.         this._mText=text;
  1485.     }
  1486.     static create(objText){
  1487.         if(!objText){
  1488.             return new KeySetting("",null,new MultiLanguageText("",""));
  1489.         }
  1490.         const obj =JSON.parse(objText);
  1491.         const keys =obj.keys;
  1492.         const color = (obj.color||null);
  1493.         const mtext = MultiLanguageText.create(obj.text);

  1494.         return new KeySetting(keys,color,mtext);


  1495.     }
  1496.     backColor(){
  1497.         return this._color;
  1498.     }
  1499.     keys(){
  1500.         return this._keys;
  1501.     }
  1502.     keyText(){
  1503.         if(this._mText){
  1504.             return this._mText.currentName();
  1505.         }
  1506.         return "";
  1507.     }


  1508. }
  1509. class AdovancedSetting{
  1510.     /**
  1511.      *
  1512.      * @param {String} symbol
  1513.      * @param {Number} overwriteType
  1514.      * @param {boolean} mandatory
  1515.      */
  1516.     constructor(symbol,overwriteType,mandatory){
  1517.         this._symbol =symbol;
  1518.         //シンボルが手動で設定されている場合、上書きで確定
  1519.         this._overwriteType=(!!symbol) ? 9: overwriteType;
  1520.         this._mandatory=  mandatory;
  1521.     }
  1522.     /**
  1523.      * @param {String} objText
  1524.      * @returns
  1525.      */
  1526.     static create(objText){
  1527.         if(!objText){
  1528.             return new AdovancedSetting(null,0,false);
  1529.         }
  1530.         const obj=JSON.parse(objText);
  1531.         const symbol=(obj.symbol);
  1532.         const overwiteType =Number(obj.overwrite||0);
  1533.         const mandatory = (obj.mandatory==="true");
  1534.         return new AdovancedSetting(symbol,overwiteType,mandatory);
  1535.     }
  1536.     isSymbolValid(){
  1537.         return !symbolManager.isBasicSymbol(this._symbol);
  1538.     }
  1539.     symbol(){
  1540.         return this._symbol;
  1541.     }
  1542.     isOverwriteEnabled(){
  1543.         return this._overwriteType !==0;
  1544.     }
  1545.     /**
  1546.      *
  1547.      * @param {Boolean} value
  1548.      */
  1549.     setMandatory(value){
  1550.         this._mandatory=value;
  1551.     }
  1552.     isMandatory(){
  1553.         return this._mandatory;
  1554.     }
  1555.     overwriteType(){
  1556.         return this._overwriteType;
  1557.     }

  1558. }

  1559. /**
  1560. * @param {String} objText
  1561. */
  1562. const createExtendsSymbol=function(objText){
  1563.     const obj = JSON.parse(objText);
  1564.     //名前が滅茶苦茶だけど、==="true"が使えない状態なのでやむを得ずこれ
  1565.     const enabled =(obj.enabled ==="false");
  1566.     if(enabled){
  1567.         return {
  1568.             exSymbol:null,
  1569.             button:null
  1570.         };
  1571.     }
  1572.     const adovanced = AdovancedSetting.create(obj.adovanced);
  1573.     const buttonId =Number(obj.button);

  1574.     const mtext = MultiLanguageText.create(obj.name);
  1575.     const keys =String(obj.keys||"");
  1576.     //const keyText =String(obj.keyText||"");
  1577.     const helpText =MultiLanguageText.create(obj.helpText||"{}");
  1578.     const keySetting = KeySetting.create(obj.keySetting);

  1579.     const eventObj =EventCaller.create(obj.event);
  1580.     const def = new ExtendsSymbol(adovanced,mtext, buttonId, keys,eventObj ,enabled,helpText,keySetting);

  1581.     /**
  1582.      * @type {String}
  1583.      */
  1584.     const touchButtonText=(obj.touchButton)
  1585.     const button = TouchButton.create(touchButtonText);//:null;
  1586.     if(button && button.isValid()){
  1587.         button.setSymbolObject(def);
  1588.     }

  1589.     return {
  1590.         exSymbol:def,
  1591.         button:button,
  1592.     }
  1593. }

  1594. class ExtendsSymbol extends I_SymbolDefine{
  1595.     /**
  1596.      * @param {AdovancedSetting} adovanced
  1597.      * @param {MultiLanguageText} actionName
  1598.      * @param {Number} buttonId
  1599.      * @param {String} keys
  1600.      * @param {EventCaller} eventCaller
  1601.      * @param {Boolean} enabled
  1602.      * @param {MultiLanguageText} helpText
  1603.      * @param {KeySetting} keySetting
  1604.      */
  1605.     constructor(adovanced,actionName,buttonId,keys ,eventCaller,enabled,helpText,keySetting){
  1606.         super();
  1607.         this._event = eventCaller;
  1608.         this._symbol =null;
  1609.         this._keys = (keys ||"").toUpperCase();
  1610.         this._buttonId =buttonId;
  1611.         this._actionName = actionName;
  1612.         //this._keyText=keyText;
  1613.         this._helpText =helpText;
  1614.         this._advanced =adovanced;
  1615.         this._keySetting=keySetting;
  1616.     }

  1617.     getKeys(){
  1618.         return this._keys + this._keySetting.keys();
  1619.     }
  1620.     overwriteType(){
  1621.         return this._advanced.overwriteType();
  1622.     }
  1623.     isOverwriteEnabled(){
  1624.         return this._advanced.isOverwriteEnabled();
  1625.     }

  1626.     isMandatory(){
  1627.         return this._advanced.isMandatory();
  1628.     }
  1629.     displayKeyName(){
  1630.         const keyText = this._keySetting.keyText();
  1631.         if(keyText){
  1632.             return keyText;
  1633.         }
  1634.         return super.displayKeyName();
  1635.     }
  1636.     eventParam(){
  1637.         return this._event;
  1638.     }
  1639.     helpText(){
  1640.         if(this._helpText){
  1641.             return this._helpText.currentName();            
  1642.         }
  1643.         return null;
  1644.     }
  1645.     hasName(){
  1646.         return !!this._actionName.currentName();
  1647.     }
  1648.     name(){
  1649.         const name= this._actionName.currentName();
  1650.         if(!this._symbol){
  1651.             return `empty(${this.overwriteType()}):${name}`;
  1652.         }
  1653.         if(!name){
  1654.             return `unnamed:${this._symbol}`;
  1655.         }
  1656.         return name;
  1657.     }
  1658.     customBackColor(){
  1659.         return this._keySetting.backColor();
  1660.     }
  1661.     symbol(){
  1662.         return this._symbol;
  1663.     }
  1664.     /**
  1665.      * @param {(symbol:string)=>Boolean} isBasicSymbol
  1666.      * @returns {String}
  1667.      */
  1668.     readManualySymbol(isBasicSymbol){
  1669.         const symbol = this._advanced.symbol();
  1670.         if(isBasicSymbol(symbol)){
  1671.             return null;
  1672.         }
  1673.         return symbol;
  1674.     }
  1675.     /**
  1676.      * @param {(symbol:string)=>Boolean} isBasicSymbol
  1677.      * @returns {String}
  1678.      */
  1679.     padSymbol(isBasicSymbol){
  1680.         const symbol =Input.gamepadMapper[this._buttonId];
  1681.         if(!isBasicSymbol(symbol)){
  1682.             return symbol;
  1683.         }
  1684.         return null;
  1685.     }
  1686.     /**
  1687.      * @param {(symbol:string)=>Boolean} isBasicSymbol
  1688.      * @returns {String}
  1689.      */
  1690.     firstKeySymbol(isBasicSymbol){
  1691.         const keys = this.getKeys();
  1692.         const charLen =keys.length;
  1693.         for(let i =0; i <charLen; ++i){
  1694.            const char_=  keys.charCodeAt(i);
  1695.            const symbol = Input.keyMapper[char_];
  1696.            if(symbol){
  1697.                 if(!isBasicSymbol(symbol)){
  1698.                     return symbol;
  1699.                 }
  1700.            }
  1701.         }
  1702.         return null;
  1703.     }
  1704.     evantCallSymbol(){
  1705.         if(this._event){
  1706.             const eventId =this._event.eventId()
  1707.             if(eventId > 0){
  1708.                  return "call"+eventId;
  1709.             }
  1710.         }
  1711.         return null
  1712.     }

  1713.     /**
  1714.      * @param {(symbol:String)=>Boolean} isBasicSymbol
  1715.      * @returns {String}
  1716.      * @description 優先シンボルの読み込み
  1717.      */
  1718.     readPreferredSymbol(isBasicSymbol){
  1719.         const manualSymbol=this.readManualySymbol(isBasicSymbol);
  1720.         if(manualSymbol){
  1721.             return manualSymbol;
  1722.         }
  1723.         switch (this._advanced.overwriteType()) {
  1724.             case 1:
  1725.                 return this.padSymbol(isBasicSymbol);
  1726.             case 2:
  1727.                 return this.firstKeySymbol(isBasicSymbol);
  1728.             case 3:
  1729.                 return this.evantCallSymbol()
  1730.         }
  1731.         return "";
  1732.     }
  1733.     /**
  1734.      * @param {(symbol:String)=>Boolean} isBasicSymbol
  1735.      * @returns {String}
  1736.      */
  1737.     readMySymbol(isBasicSymbol){
  1738.         //上書き用の優先されるシンボルを取り出す
  1739.         const xxxx=this.readPreferredSymbol(isBasicSymbol);
  1740.         if(xxxx){
  1741.             return xxxx;
  1742.         }
  1743.         //無かったら、この順番で適当に読み込む
  1744.         const pad = this.padSymbol(isBasicSymbol);
  1745.         if(pad){
  1746.             return pad;
  1747.         }
  1748.         const key =this.firstKeySymbol(isBasicSymbol)
  1749.         if(key){
  1750.             return key;
  1751.         }
  1752.         const eventCall =this.evantCallSymbol();
  1753.         if(eventCall){
  1754.             return eventCall;
  1755.         }
  1756.         return "";
  1757.     }
  1758.     /**
  1759.      * @param {(symbol:String)=>Boolean} mapper
  1760.      */
  1761.     loadSymbol(mapper){
  1762.         if(!this._symbol){
  1763.             const symbol =this.readMySymbol(mapper);
  1764.             this._symbol = symbol;
  1765.         }
  1766.         if(this.isEmpty()){
  1767.             this._advanced.setMandatory(false);
  1768.         }
  1769.     }
  1770.     mapperWrite(mapper,targetKey){
  1771.         //上書きが許可されてない場合
  1772.         if(!this.isOverwriteEnabled()){
  1773.             //指定位置のシンボルがあるか調べる
  1774.             const oldSymbol =mapper[targetKey];       
  1775.             if(oldSymbol){
  1776.                 //上書きせずに終了
  1777.                 return;
  1778.             }
  1779.         }
  1780.         //TODO:mapperをmainMapperクラスにする
  1781.         //これで直接触るのを避ける
  1782.         mapper[targetKey]= this._symbol;       
  1783.     }

  1784.     fillSymbol(){
  1785.         if(!this._symbol){return;}
  1786.         if(!isNaN( this._buttonId)){
  1787.             this.mapperWrite(Input.gamepadMapper,this._buttonId);
  1788.         }
  1789.         const keys=this.getKeys();
  1790.         const len = keys.length;
  1791.         for(let i =0; i< len;++i){
  1792.             const charcode =keys.charCodeAt(i);
  1793.             this.mapperWrite(Input.keyMapper,charcode);
  1794.         }
  1795.     }
  1796.     updateEventCall(){
  1797.         if(this._event){
  1798.             const symbol = this.symbol();
  1799.             if(symbol){
  1800.                 this._event.updateEvent(symbol);
  1801.             }
  1802.         }
  1803.     }
  1804.     errorText(){

  1805.         //シンボル手動設定で、標準シンボルと同じ文字列が指定されている
  1806.         if(!this._advanced.isSymbolValid()){

  1807.             const current= setting.errorText.advanceSymbolInvalid.currentName();
  1808.             return `${current}\nsymbol:${this._symbol}`;
  1809.         }
  1810.         return super.errorText();
  1811.     }
  1812.     isEnabled(){
  1813.         return super.isEnabled() && this._advanced.isSymbolValid();
  1814.     }
  1815.     debugInfo(){
  1816.         return `ot:${this.overwriteType()},id:${this._buttonId},keys:${this.getKeys()}`;
  1817.     }

  1818. }

  1819. /**
  1820. * @description 指定したシンボルを持つキーの一覧を取得
  1821. * @param {String} symbol
  1822. */
  1823. function KeyWithTheSymbolPlaced(symbol){
  1824.     let keys ="";
  1825.     for (const iterator of Object.entries(Input.keyMapper)) {
  1826.         if(iterator[1]===symbol){
  1827.             const keyN =Number(iterator[0]);
  1828.             const char = String.fromCodePoint(keyN);   
  1829.             keys +=char;
  1830.         }
  1831.     }
  1832.     return keys;
  1833. }

  1834. /**
  1835. * @description 指定したシンボルを持つパッドボタン番号を取得
  1836. * @param {String} symbol
  1837. */
  1838. function buttonWithTheSymbolPlaced(symbol){
  1839.     for (const iterator of Object.entries(Input.gamepadMapper)) {
  1840.         if(iterator[1]===symbol){
  1841.             return Number(iterator[0]);
  1842.         }
  1843.     }
  1844.     return NaN;
  1845. }

  1846. class UnknowSymbol extends I_SymbolDefine{
  1847.     /**
  1848.      * @param {String} symbol
  1849.      */
  1850.     constructor(symbol){
  1851.         super();
  1852.         //TODO:初期化処理を変えて、下記の関数をメソッドへと移行する
  1853.         this._kesy = KeyWithTheSymbolPlaced(symbol);
  1854.         this._buttonId = buttonWithTheSymbolPlaced(symbol);
  1855.         this._symbol = symbol;
  1856.     }
  1857.     symbol(){
  1858.         return this._symbol;
  1859.     }
  1860.    
  1861.     name(){
  1862.         return "?"+this.buttonIdText()+this._kesy+":"+this.symbol();
  1863.     }
  1864.     buttonIdText(){
  1865.         if(isNaN(this._buttonId)){
  1866.             return "";
  1867.         }
  1868.         return "("+this._buttonId +")";
  1869.     }
  1870.     isUnknow(){
  1871.         return true;
  1872.     }

  1873.     debugInfo(){
  1874.         return "button:"+this._buttonId +",keys:"+this._kesy;
  1875.     }
  1876.     helpText(){
  1877.         return setting.errorText.unknowSymbol.currentName()+"\n" + this.debugInfo();
  1878.     }
  1879. }
  1880. class BasicSymbolList{

  1881.     constructor(ok,cancel,shift,pageup,pagedown,menu,shift_){


  1882.     }
  1883. }

  1884. class SymbolManager_T {
  1885.     /**
  1886.      * @param {I_SymbolDefine[]} basicSymbols
  1887.      * @param {MoveSymbol[]} moveSymbols
  1888.      */
  1889.     constructor(basicSymbols,moveSymbols){
  1890.         /**
  1891.          * @type {Map<String,I_SymbolDefine>}
  1892.          */
  1893.         this._symbolDictionary = new Map();
  1894.         /**
  1895.          * @type {UnknowSymbol[]}
  1896.          */
  1897.         this._unknowList=[];
  1898.         this.setExtendSymbols([]);
  1899.         this._basicSymbols = basicSymbols
  1900.         this._moveSymbols = moveSymbols
  1901.         this.addDictionaryItems(this._basicSymbols);
  1902.         this.addDictionaryItems(this._moveSymbols);
  1903.         this._initialized=false;
  1904.         this._event=null;
  1905.     }
  1906.     /**
  1907.      * @param {String} symbolString
  1908.     */
  1909.     isBasicSymbol(symbolString){
  1910.         if(!symbolString){
  1911.             return false;
  1912.         }

  1913.         return this._basicSymbols.some( function(symbolObject){
  1914.             return symbolObject.symbol() ===symbolString;
  1915.         } )
  1916.         // const symbolObect = this.findSymbol(symbolString);
  1917.         // if(symbolObect){
  1918.         //     return this._basicSymbols.contains(symbolObect);
  1919.         // }
  1920.         // return false;
  1921.     }
  1922.    
  1923.     /**
  1924.      * @param {ExtendsSymbol[]} list
  1925.      */
  1926.     setExtendSymbols(list){
  1927.         this._extendSymbols =list;
  1928.     }

  1929.     onBoot(){
  1930.         if(this._initialized){
  1931.             return;
  1932.         }
  1933.         this.loadExtendsSymbols();
  1934.         this.loadUnknowSymbols();
  1935.         //初期化成功フラグ
  1936.         //競合で頻繁に問題を起こすため
  1937.         this._initialized =true;
  1938.     }
  1939.     isInitialized(){
  1940.         return this._initialized;
  1941.     }
  1942.     loadExtendsSymbols(){
  1943.         const selfObject =this;
  1944.         const isBasicSymbol = function(symbol){
  1945.             return selfObject.isBasicSymbol(symbol);
  1946.         };
  1947.         const numExSymbols=this._extendSymbols.length;
  1948.         for (const iterator of this._extendSymbols) {
  1949.             iterator.loadSymbol(isBasicSymbol);
  1950.         }
  1951.         if(numExSymbols!==this._extendSymbols.length){
  1952.             throw new Error("要素数を書き換えてはいけません")
  1953.         }
  1954.         for (const iterator of this._extendSymbols) {
  1955.             iterator.fillSymbol();
  1956.         }
  1957.         //他のプラグインによる設定が完了した後で呼び出される
  1958.         //なので、このタイミングで行う必要がある
  1959.         this.addDictionaryItems(this._extendSymbols);
  1960.     }
  1961.     loadUnknowSymbols(){
  1962.         /**
  1963.          * @type {String[]}
  1964.          */
  1965.         const padSymbols = Object.values(Input.gamepadMapper);
  1966.         /**
  1967.          * @type {String[]}
  1968.          */
  1969.         const keySymbols =Object.values(Input.keyMapper)
  1970.         //mapperにある全てのシンボルを列挙する
  1971.         const set = new Set(keySymbols);
  1972.         for (const iterator of padSymbols) {
  1973.             set.add(iterator);
  1974.         }
  1975.         //Managerにあるシンボルを列挙した中から消す
  1976.         for (const iterator of this.getSymbolList()) {
  1977.             const symbol = iterator.symbol();
  1978.             if (symbol) {
  1979.                 set.delete(symbol);
  1980.             }
  1981.         }

  1982.         //移動シンボル4種を消す
  1983.         // for (const iterator of this._moveSymbols) {
  1984.         //     const symbol = iterator.symbol();
  1985.         //     if(symbol){
  1986.         //         set.delete(symbol);
  1987.         //     }
  1988.         // }
  1989.         for (const iterator of this.systemSymbols()) {
  1990.             set.delete(iterator);
  1991.         }
  1992.         //ラムダ式が使えないので、この方法でthisを捕まえておく
  1993.         const seleObject=this;

  1994.         set.forEach(function(symbol){
  1995.             const obj =new UnknowSymbol(symbol)
  1996.             seleObject._unknowList.push( obj);
  1997. //            seleObject._symbolDictionary.set(symbol,obj);
  1998.         });
  1999.         this.addDictionaryItems(this._unknowList)
  2000.     }

  2001.    

  2002.     callButtonEvent(){
  2003.         for (const iterator of this._extendSymbols) {
  2004.             //既に予約されている場合、あるいはupdateEventCall()で予約されたら処理を止める
  2005.             if($gameTemp.isCommonEventReserved()){
  2006.                 break;
  2007.             }
  2008.             iterator.updateEventCall();
  2009.         }
  2010.     }
  2011.     /**
  2012.      * @param {I_SymbolDefine[]} list
  2013.      */
  2014.     addDictionaryItems(list){
  2015.         for (const iterator of list) {
  2016.             const symbol = iterator.symbol();
  2017.             if(symbol){
  2018.                 this._symbolDictionary.set(symbol,iterator);
  2019.             }
  2020.         }
  2021.     }

  2022.     /**
  2023.      * @returns {I_SymbolDefine[]}
  2024.      */
  2025.     getSymbolList(){
  2026.         return this._basicSymbols.concat(
  2027.             this._extendSymbols,
  2028.             this._unknowList,
  2029.             this._moveSymbols
  2030.             //,[ new SymbolDeleteObject() ]
  2031.             );
  2032.     }

  2033.     /**
  2034.      * @param {String} symbol
  2035.      */
  2036.     actionName(symbol){
  2037.         if(!symbol){ return "";}
  2038.         const item = this.findSymbol(symbol);
  2039.         if(item){  return item.name();}

  2040.         //TODO:この表記になるとガチで正体不明になるので対策
  2041.         //この場合、初期化が正しく行われていない可能性
  2042.         return "unknow:"+symbol;
  2043.     }
  2044.     /**
  2045.      * @param {String} symbol
  2046.      */
  2047.     findSymbol(symbol){
  2048.         return this._symbolDictionary.get(symbol);
  2049.     }

  2050.     systemSymbols(){
  2051.         return ["debug","control","tab"];
  2052.     }

  2053.     /**
  2054.      * @param {String} symbol
  2055.      */
  2056.     isMandatorySymbol(symbol){
  2057.         if(!symbol){
  2058.             return false;
  2059.         }
  2060.         const def = this._symbolDictionary.get(symbol);
  2061.         if(def){
  2062.             return def.isMandatory();
  2063.         }
  2064.         return false;
  2065.     }
  2066.     /**
  2067.      * @returns {I_SymbolDefine[]}
  2068.      */
  2069.     allMandatorySymbols(){
  2070.         return this.getSymbolList().filter( function(def){ return def.isMandatory()});
  2071.     }

  2072.     /**
  2073.      * @param {Set<String>} set
  2074.      * @returns
  2075.      */
  2076.     isValidMapper_v3(set){
  2077.         const m=this.allMandatorySymbols()
  2078.         for (const iterator of m) {
  2079.             const symbol = iterator.symbol();
  2080.             if(Input._isEscapeCompatible(symbol)){
  2081.                 if(set.has("escape")){
  2082.                     continue;
  2083.                 }
  2084.             }
  2085.             if(!set.has(symbol)){
  2086.                 return false;
  2087.             }
  2088.         }
  2089.         return true;
  2090.     }
  2091. }

  2092. const symbolManager = new SymbolManager_T(
  2093.     createBasicSymbols(),
  2094.     createMoveSymbols()
  2095. );

  2096. /**
  2097. * @param {SymbolManager_T} symbolManager
  2098. * @param {ButtonManager_T} buttonManager
  2099. */
  2100. function setupExtendsSymbols(symbolManager,buttonManager){
  2101.     const param = getParam();
  2102.     /**
  2103.      * @type {String[]}
  2104.      */
  2105.     const textList = JSON.parse(param.extendsMapper);

  2106.     const buttons =[];
  2107.     const symbols=[];
  2108.     for (const iterator of textList) {
  2109.         const item=createExtendsSymbol(iterator);
  2110.         if(item.exSymbol){
  2111.             symbols.push(item.exSymbol);
  2112.         }
  2113.         if(item.button){
  2114.             buttons.push(item.button);
  2115.         }
  2116.     }
  2117.     symbolManager.setExtendSymbols(symbols);
  2118.     buttonManager.setList(buttons);
  2119. }
  2120. setupExtendsSymbols(symbolManager,ButtonManager);


  2121. if(ButtonManager.isTouchButtonEnabled()){

  2122.     class Sprite_EX_Base extends Sprite_Clickable{
  2123.         /**
  2124.          * @param {Bitmap} bitmap
  2125.          */
  2126.         constructor(bitmap){
  2127.             super();
  2128.             this.bitmap =bitmap;
  2129.             this._imageHeight =0;
  2130.             this.setupBitmapOnLoad();
  2131.         }
  2132.         setupBitmapOnLoad(){
  2133.             if(this.bitmap.isReady()){
  2134.                 this.onLoadeed();
  2135.             }else{
  2136.                 //ラムダ禁止
  2137.                 const selfObject=this;
  2138.                 this.bitmap.addLoadListener(function(bitmap){
  2139.                     selfObject.onLoadeed();
  2140.                 } );
  2141.             }
  2142.         }
  2143.         onLoadeed(){
  2144.             //画像を上下半々で使うように設定
  2145.             this._imageHeight=this.bitmap.height /2;
  2146.             this.setColdFrame();
  2147.         }
  2148.         setColdFrame(){
  2149.             this.setFrame(0,0,this.bitmap.width,this._imageHeight)
  2150.         }
  2151.         setHotFrame(){
  2152.             this.setFrame(0,this._imageHeight,this.bitmap.width,this._imageHeight);
  2153.         }
  2154.         updateFrame(){
  2155.             if(this.isPressed()){
  2156.                 this.setHotFrame();
  2157.             }else{
  2158.                 this.setColdFrame();
  2159.             }
  2160.         }
  2161.     }

  2162.     class Sprite_EX_ButtonMZ extends Sprite_EX_Base{
  2163.         /**
  2164.          * @param {TouchButton} touchButton
  2165.          */
  2166.          constructor(touchButton){
  2167.              super(touchButton.bitmap());
  2168.              this._button = touchButton;
  2169.              this.resetPosition();

  2170.         }
  2171.         resetPosition(){
  2172.             this.x = this._button.x();
  2173.             this.y = this._button.y();
  2174.         }
  2175.         onPress(){
  2176.             this._button.virtualPress();
  2177.         }
  2178.         onClick(){
  2179.             Input.virtualClick(this._button.symbol()  );
  2180.         }
  2181.         update(){
  2182.             super.update();
  2183.             if(!this.isPressed()){
  2184.                 this._button.clearPress();
  2185.             }
  2186.             this.updateFrame();
  2187.         }
  2188.     }
  2189.     class Spriteset_TouchButton extends PIXI.Container{
  2190.         constructor(){
  2191.             super();
  2192.             this._buttons =[];
  2193.             const buttons = ButtonManager.getList();
  2194.             for (const iterator of buttons) {
  2195.                 const sprite = new Sprite_EX_ButtonMZ(iterator);
  2196.                 this.addChild(sprite);
  2197.                 this._buttons.push(sprite);
  2198.             }
  2199.         }
  2200.         get z(){
  2201.             return 1;
  2202.         }
  2203.         update(){
  2204.             for (const iterator of this._buttons) {
  2205.                 iterator.update();
  2206.             }
  2207.         }
  2208.         isAnyButtonPressed(){
  2209.             //ラムダ禁止
  2210.             return this._buttons.some(function (button){
  2211.                  return button.isPressed()
  2212.             });
  2213.         }
  2214.     }

  2215.     const Scene_Map_createButtons = Scene_Map.prototype.createButtons;
  2216.     Scene_Map.prototype.createButtons =function(){
  2217.         Scene_Map_createButtons.call(this);
  2218.         if(ConfigManager.touchUI){
  2219.             const spriteset = new Spriteset_TouchButton();
  2220.             this.addWindow(spriteset);
  2221.             //@ts-ignore
  2222.             this._touchButtonsMA = spriteset;
  2223.         }
  2224.     };
  2225.     const Scene_Map_isAnyButtonPressed=Scene_Map.prototype.isAnyButtonPressed;
  2226.     Scene_Map.prototype.isAnyButtonPressed =function(){
  2227.         const result= Scene_Map_isAnyButtonPressed.call(this);
  2228.         if(result){
  2229.             return true;
  2230.         }
  2231.         //@ts-ignore
  2232.         return this._touchButtonsMA && this._touchButtonsMA.isAnyButtonPressed();
  2233.     };

  2234. }
  2235. //ボタンとキーの共通基底クラス
  2236. class I_InputButton{

  2237.     name(){
  2238.         return "";
  2239.     }
  2240.     mapperId(){
  2241.         return NaN;
  2242.     }
  2243. }
  2244. /**
  2245. * @typedef {Object} SymbolCodePair
  2246. * @property {Number} code
  2247. * @property {String} symbol
  2248. */

  2249. class I_ReadonlyMapper{
  2250.     /**
  2251.      * @param {Number} buttonId
  2252.      * @returns
  2253.      */
  2254.     symbolString(buttonId){
  2255.         return "";
  2256.     }
  2257.     /**
  2258.      * @param {I_InputButton} button
  2259.      */
  2260.     symbolString_V8(button){
  2261.         return this.symbolString(button.mapperId());
  2262.     }
  2263.     /**
  2264.      * @returns {Iterable<SymbolCodePair>}
  2265.      */
  2266.     xxList(){
  2267.         return null;
  2268.     }
  2269.     /**
  2270.      * @param {String} symbol
  2271.      * @param {I_InputButton[]} buttonList
  2272.      * @returns
  2273.      */
  2274.     buttonFromSymbol_XX(symbol,buttonList){
  2275.         if(!symbol){
  2276.             return null;
  2277.         }
  2278.         for (const button of buttonList) {
  2279.             const id = button.mapperId();
  2280.             if(symbol===this.symbolString(id)){
  2281.                 return button;
  2282.             }
  2283.         }
  2284.         return null;
  2285.     }
  2286.     /**
  2287.      * @description Map<>を生成するための補助関数
  2288.      * @returns {Map<Number,String>}
  2289.      * @param {InputMapperType} mapper
  2290.      */
  2291.     createMapSupport(mapper){
  2292.         const map =new Map();
  2293.         for (const iterator of Object.entries(mapper)) {
  2294.             const code = Number(iterator[0]);
  2295.             if(!isNaN(code)){
  2296.                 map.set(code,iterator[1]);
  2297.             }
  2298.         }
  2299.         return map;
  2300.     }
  2301.     applyGamepad(){
  2302.         if(this.isValidMapper()){
  2303.             Input._latestButton=null;
  2304.             const mapper = this.cloneMapper();
  2305.             Input.gamepadMapper =mapper;
  2306.         }
  2307.     }
  2308.     applyKeyboard(){
  2309.         if(this.isValidMapper()){
  2310.             Input._latestButton=null;
  2311.             const mapper = this.cloneMapper();
  2312.             Input.keyMapper =mapper;
  2313.         }
  2314.     }
  2315.     /**
  2316.      * @returns {InputMapperType}
  2317.      */
  2318.     cloneMapper(){
  2319.         throw new Error("未実装")
  2320.     }
  2321.     isValidMapper(){
  2322.         return false;
  2323.     }
  2324. }

  2325. //ゲーム実行中のマッパーに直接触れるヤツ
  2326. //主にFillSymbol用
  2327. //初期状態も、これに持たせてしまう
  2328. class MainMapperBase{
  2329.     constructor(){
  2330.         this._defaultMapper=null;
  2331.     }
  2332.     target(){
  2333.         return {};
  2334.     }

  2335.     /**
  2336.      *
  2337.      * @param {Number} key
  2338.      * @param {String} symbolString
  2339.      */
  2340.     change(key,symbolString){
  2341.         const target=this.target();
  2342.         target[key]=symbolString;
  2343.     }
  2344.     saveDefault(){
  2345.         this._defaultMapper =new DefaultMapper(this.target());
  2346.     }
  2347.     loadDefault(){
  2348.         this.reset(this._defaultMapper.cloneMapper());
  2349.     }
  2350.     /**
  2351.      * @param {InputMapperType} mapper
  2352.      */
  2353.     reset(mapper){
  2354.     }
  2355. }
  2356. class MainGamepadMapper extends MainMapperBase{
  2357.     target(){
  2358.         return Input.gamepadMapper;
  2359.     }
  2360.     reset(){
  2361.         
  2362.     }
  2363. }

  2364. class DefaultMapper extends I_ReadonlyMapper{
  2365.     /**
  2366.      *
  2367.      * @param {InputMapperType} obj
  2368.      */
  2369.     constructor(obj){
  2370.         super();
  2371.         this._mapper= ( objectClone(obj));
  2372.     }
  2373.     mapper(){
  2374.         return this._mapper;
  2375.     }
  2376.     cloneMapper(){
  2377.         return objectClone(this._mapper);
  2378.     }
  2379. }


  2380. class InputDeviceBase extends I_ReadonlyMapper{
  2381.     constructor(){
  2382.         super();
  2383.         this.setDefaultMapper(null);
  2384.     }
  2385.     /**
  2386.      * @param {DefaultMapper} mapper
  2387.      */
  2388.     setDefaultMapper(mapper){
  2389.         this._defaultMapper=mapper;

  2390.     }

  2391.     /**
  2392.      * @desc ABC順に並んだリスト
  2393.      * @returns {I_InputButton[]}
  2394.      */
  2395.     indexList(){
  2396.         return [];
  2397.     }
  2398.     /**
  2399.      * @returns {I_InputButton[]}
  2400.      */
  2401.     buttonList(){
  2402.         return []
  2403.     }
  2404.     /**
  2405.      * @param {Number} buttonId
  2406.      * @returns {I_InputButton}
  2407.      */
  2408.     buttonAt(buttonId){
  2409.         return null
  2410.     }
  2411.     numButtons(){
  2412.         return this.buttonList().length;
  2413.     }
  2414.     /**
  2415.      * @returns {I_ReadonlyMapper}
  2416.      */
  2417.     defaultMapper_v2(){
  2418.         return null;
  2419.     }
  2420.     defaultMapper(){
  2421.         return {};
  2422.     }
  2423.     currentMapper(){
  2424.         return {}
  2425.     }

  2426.     /**
  2427.      * @param {String} symbol
  2428.      * @returns
  2429.      */
  2430.     getButtonBySymbol(symbol){
  2431.         const indexList = this.indexList();

  2432.         return this.buttonFromSymbol_XX(symbol,indexList);
  2433.     }
  2434.     /**
  2435.      * @param {Number} buttonId
  2436.      * @returns {String}
  2437.      */
  2438.     symbolString(buttonId){
  2439.         const mapper = this.currentMapper();
  2440.         const symbol = mapper[buttonId];
  2441.         if(symbol){
  2442.             return symbol;
  2443.         }
  2444.         return "";
  2445.     }
  2446.     createTemporaryMapper(){
  2447.         const tmp = new TemporaryMappper(this.currentMapper());
  2448.         return tmp;
  2449.     }
  2450. }
  2451. class GamepadButtonObj extends I_InputButton{
  2452.     /**
  2453.      * @param {Number} buttonId
  2454.      * @param {String} name
  2455.      */
  2456.     constructor(buttonId,name){
  2457.         super();
  2458.         /**
  2459.          * @private
  2460.          */
  2461.         this._name =name;
  2462.         /**
  2463.          * @private
  2464.          */
  2465.          this._buttonId=buttonId;
  2466.     }

  2467.     name(){
  2468.         return this._name;
  2469.     }
  2470.     mapperId(){
  2471.         return this.buttonId();
  2472.     }
  2473.    
  2474.     buttonId(){
  2475.         return this._buttonId;
  2476.     }
  2477.     text(){
  2478.         const buttonNumber= this._buttonId.toString().padStart(2,"  ");
  2479.         return buttonNumber +":"+this.name();
  2480.     }
  2481.     color(){
  2482.         return "#000000";
  2483.     }
  2484. }
  2485. //ハードメーカーの違いに対応するためのやつ



  2486. /**
  2487. * @template {I_InputButton} T_Button
  2488. */
  2489. class I_DeviceLayout{
  2490.     deviceSymbol(){
  2491.         return "";
  2492.     }
  2493.     name(){
  2494.         return "";
  2495.     }
  2496.     /**
  2497.      * @param {Number} index
  2498.      * @returns {T_Button}
  2499.      */
  2500.     button(index){
  2501.         return null;
  2502.     }
  2503.     numButtons(){
  2504.         return 0;
  2505.     }
  2506. }
  2507. /**
  2508. * @template {I_InputButton} T_Button
  2509. * @extends {I_DeviceLayout<T_Button>}
  2510. */
  2511. class DeviceLayout extends I_DeviceLayout{
  2512.     /**
  2513.      * @param {T_Button[]} list
  2514.      * @param {String} name
  2515.      * @param {String} symbol
  2516.      */
  2517.     constructor(list,name,symbol){
  2518.         super();
  2519.         this._name=name;
  2520.         this._list=list;
  2521.         this._symbol=symbol;
  2522.     }
  2523.     /**
  2524.      * @returns {T_Button[]}
  2525.      */
  2526.     buttons(){
  2527.         return this._list;
  2528.     }
  2529.     name(){
  2530.         return this._name;
  2531.     }
  2532.     deviceSymbol(){
  2533.         return this._symbol;
  2534.     }
  2535.     numButtons(){
  2536.         return this._list.length;
  2537.     }
  2538.     /**
  2539.      * @param {Number} index
  2540.      */
  2541.     button(index){
  2542.         return this._list[index];
  2543.     }
  2544.     /**
  2545.      * @param {Number} code
  2546.      */
  2547.     getButtonByCode(code){
  2548.         for (const iterator of this._list) {
  2549.             if(iterator.mapperId()===code){
  2550.                 return iterator;
  2551.             }
  2552.         }
  2553.         return null;
  2554.     }
  2555. }
  2556. /**
  2557. *
  2558. * @param {String} symbol
  2559. * @param {String} name
  2560. * @param {String} button0
  2561. * @param {String} button1
  2562. * @param {String} button2
  2563. * @param {String} button3
  2564. */
  2565. function createGamepadLayout(symbol,name,button0,button1,button2,button3){

  2566.     const buttons=[
  2567.         new GamepadButtonObj(0,button0),
  2568.         new GamepadButtonObj(1,button1),
  2569.         new GamepadButtonObj(2,button2),
  2570.         new GamepadButtonObj(3,button3),
  2571.         new GamepadButtonObj(4,"L1"),
  2572.         new GamepadButtonObj(5,"R1"),
  2573.         new GamepadButtonObj(6,"L2"),
  2574.         new GamepadButtonObj(7,"R2"),
  2575.         new GamepadButtonObj(8,"select"),
  2576.         new GamepadButtonObj(9,"start"),
  2577.         new GamepadButtonObj(10,"L3"),
  2578.         new GamepadButtonObj(11,"R3")
  2579.     ];
  2580.     return new DeviceLayout(buttons,name,symbol);
  2581. }
  2582. /**
  2583. *
  2584. * @param {String} symbol
  2585. * @param {String} name
  2586. */
  2587. function createButtonNumberLayout(symbol,name){
  2588.     const buttonNumber=[0,1,2,3,4,5,6,7,8,9,10,11];
  2589.     const buttons =buttonNumber.map( function(number){
  2590.         const buttonName = String(number);
  2591.         return new GamepadButtonObj(number,buttonName);
  2592.     });
  2593.     return new DeviceLayout(buttons,name,symbol);
  2594. }

  2595. //ボタンの名前を入れておくクラス
  2596. //また、編集可能なボタンを制御する際にも使う
  2597. //TODO:ボタン名称を作り直す
  2598. //何度も名前が違うと文句を言われるので、Xスタイル・Nスタイル・Pスタイルを用意
  2599. class Gamepad extends InputDeviceBase{
  2600.     /**
  2601.      * @param {GamepadLayoutSelector} layout
  2602.      */
  2603.     constructor(layout){
  2604.         super();
  2605.         this._selector=layout;
  2606.         this._defaultMapper_V2=null;
  2607.     }
  2608.     onBoot(){

  2609.     }
  2610.     buttonList(){
  2611.         const d= this._selector.currentLayout();
  2612.         if(d){
  2613.             return d.buttons();
  2614.         }
  2615.         return [];
  2616.     }
  2617.     // /**
  2618.     //  * @param {Number} buttonId
  2619.     //  * @returns
  2620.     //  */
  2621.     // buttonObject(buttonId){
  2622.     //     return this._list[buttonId];
  2623.     // }
  2624.     // indexList(){
  2625.     //     return this._list;
  2626.     // }
  2627.     /**
  2628.      * @param {Number} code
  2629.      */
  2630.     getButtonByCode(code){
  2631.         if(code <=11){
  2632.             return this._selector.getButtonByCode(code);
  2633. //            return this._selector.
  2634. //            return this.currentGGG().getButtonByCode(code);
  2635.         }

  2636.         return null;
  2637.         
  2638.     }
  2639.     /**
  2640.      * @param {number} index
  2641.      */
  2642.     buttonAt(index){
  2643.         return this._selector.buttonAt(index);
  2644.         //return this.currentGGG().button(index);
  2645.     }
  2646.     /**
  2647.      * @param {Number} index
  2648.      */
  2649.     buttonName(index){
  2650.         const b = this.buttonAt(index);
  2651.         if(b){ return b.name();}
  2652.         return "";
  2653.     }
  2654.     // buttonList(){
  2655.     //     return this._list;
  2656.     // }
  2657.     defaultMapper(){
  2658.         return Mano_InputConfig.defaultGamepadMapper;
  2659.     }
  2660.     currentMapper(){
  2661.         return Input.gamepadMapper;
  2662.     }
  2663.     isConected(){
  2664.         const pad = createPadState(0);
  2665.         return !!pad;
  2666.     }
  2667.     deviceName(){
  2668.         const pad = createPadState(0);
  2669.         if(pad){
  2670.             return pad.id
  2671.         }
  2672.         return "";
  2673.     }
  2674.     defaultMapper_v2(){
  2675.         const tmp = new TemporaryMappper(this.defaultMapper());
  2676.         return tmp;
  2677.     }
  2678.     numButtons(){
  2679.         return this._selector.numButtons();
  2680.     }
  2681. }



  2682. /**
  2683. * @return {string[]}
  2684. */
  2685. function createMandatorySymbols(params){
  2686.     return ["ok","cancel","menu"];
  2687. }
  2688. /**
  2689. * @param {String} text
  2690. * @returns {String}
  2691. */
  2692. function noteOrString(text){
  2693.     if(text ==undefined){
  2694.         return "undefined"
  2695.     }
  2696.     const last = text[text.length-1]
  2697.     if(text[0]==='"'&&last ==='"'){
  2698.         return JSON.parse(text);
  2699.     }
  2700.     return String(text);
  2701. }
  2702. function createText(params){
  2703.     const guid = new MultiLanguageText("This is an unknown symbol. Add an item to the input extension","不明なシンボルです 入力拡張に項目を追加してください");

  2704.     return{
  2705.         gamepadConfigCommandText:MultiLanguageText.create(params.gamepadConfigCommandText),
  2706.         keyConfigCommandText:MultiLanguageText.create(params.keyConfigCommandText),
  2707.         mapperDelete:MultiLanguageText.create(params.mapperDelete),
  2708.         //TODO:安定したら今後のバージョンで消す
  2709.         gamepadIsNotConnected: MultiLanguageText.create(params.GamepadIsNotConnectedText),
  2710.         needButtonDetouch:MultiLanguageText.create(params.needButtonDetouchText),
  2711.         unknowguid:guid,
  2712.     }
  2713. }
  2714. class ErrorObject{
  2715.    
  2716.     constructor(mtext,errorCategory){

  2717.     }
  2718.     errorNumber(){
  2719.         //E1

  2720.         //E9 その他のエラー
  2721.     }
  2722.     createErrorMessage(symbol){

  2723.     }
  2724.     //一覧表示用の内容を返す
  2725.     itemText(){

  2726.     }
  2727.     //解決方法を返す
  2728.     helpText(){

  2729.     }
  2730. }

  2731. function createErrorTexts(){
  2732.     const advanceSymbolInvalid =new MultiLanguageText("","拡張シンボルは標準シンボルと異なる内容でなければいけません。");
  2733.     const initFauled =new MultiLanguageText("The initialization process was not performed correctly. \nThere is a possibility of a plugin conflict. \nMove the plugin down may help.","初期化処理が正しく行われませんでした。\nプラグインの競合の可能性があります。\nプラグインを下の方に移動すると解決する場合があります。");
  2734.     const unknowSymbol = new MultiLanguageText("This is an unknown symbol. Add an item to the input extension","不明なシンボルです 入力拡張に項目を追加してください");
  2735.     const symbolEmpty=new MultiLanguageText("The symbol is not set \n Check the contents of the inputExtension from the plugin parameters","シンボルが設定されていません\nプラグインパラメータから拡張設定の内容を確認してください");
  2736.     const nameEmpty= new MultiLanguageText("The name for display is not set\nsymbol:","表示用の名称が設定されていません\nsymbol:");

  2737.     return {
  2738.         advanceSymbolInvalid:advanceSymbolInvalid,
  2739.         initFauled:initFauled,
  2740.         unknowSymbol:unknowSymbol,
  2741.         symbolEmpty:symbolEmpty,
  2742.         nameEmpty:nameEmpty,
  2743.     }

  2744. }
  2745. class InputDevice_Readonly{
  2746.     constructor(mapper){
  2747.         this._mapper=mapper;
  2748.     }
  2749.     mapper(){
  2750.         return this._mapper;
  2751.     }

  2752. }

  2753. class DeviceXXX{
  2754.     constructor(){
  2755.         this._defaultKeyMapper=null;
  2756.         this._defaultGamepadMapper=null;
  2757.         this.setKeyLayout(null,null);
  2758.     }
  2759.     /**
  2760.     * @param {Key_Layout} jis
  2761.      * @param {Key_Layout} us
  2762.      */
  2763.     setKeyLayout(jis,us){
  2764.         this._keyLayoutJIS=jis;
  2765.         this._keyLayoutUS =us;
  2766.     }
  2767.     onBoot(){
  2768.         this.setupDefaultMapper()
  2769.     }
  2770.     setupDefaultMapper(){
  2771.         this._defaultKeyMapper= new InputDevice_Readonly(  Object.freeze(objectClone(Input.keyMapper)));
  2772.         this._defaultGamepadMapper =new InputDevice_Readonly(  Object.freeze(objectClone(Input.gamepadMapper)));
  2773.     }
  2774.     keyMapper(){
  2775.         return this._defaultKeyMapper;
  2776.     }
  2777.     gamepadMapper(){
  2778.         return this._defaultGamepadMapper;
  2779.     }
  2780. }
  2781. /**
  2782. * @template {I_InputButton} T_Button
  2783. */
  2784. class LayoutSelecter{
  2785.     /**
  2786.      * @param {DeviceLayout<T_Button>[]} list
  2787.      */
  2788.     constructor(list){
  2789.         this._list=list;
  2790.         this._index=0;
  2791.     }
  2792.     /**
  2793.      *
  2794.      * @param {String} symbolText
  2795.      */
  2796.     selectOfSymbol(symbolText){
  2797.         for (let index = 0; index < this._list.length; index++) {
  2798.             const element = this._list[index];
  2799.             if(element && element.deviceSymbol()===symbolText){
  2800.                 this._index =index;
  2801.                 return;
  2802.             }
  2803.         }
  2804.         this._index=-1;
  2805.     }
  2806.     changeNext(){
  2807.         this._index+=1;
  2808.         if(this._index >= this._list.length){
  2809.             this._index=0;
  2810.         }

  2811.     }
  2812.     /**
  2813.      * @param {Number} code
  2814.      * @returns
  2815.      */
  2816.     getButtonByCode(code){
  2817.         const d =this.currentLayout();
  2818.         if(d){
  2819.             return d.getButtonByCode(code);
  2820.         }
  2821.         return null;
  2822.     }
  2823.     currentLayout(){
  2824.         return this._list[this._index];
  2825.     }
  2826.     currentDeviceSymbol(){
  2827.         const device=this.currentLayout();
  2828.         if(device){
  2829.             return device.deviceSymbol();
  2830.         }
  2831.         return "";
  2832.     }
  2833.     buttonAt(index) {
  2834.         const device =this.currentLayout();
  2835.         if(device){
  2836.             return device.button(index);
  2837.         }
  2838.         return null;
  2839.     }
  2840.     numButtons(){
  2841.         const device=this.currentLayout();
  2842.         if(device){
  2843.             return device.numButtons();
  2844.         }
  2845.         return 0;
  2846.     }
  2847.     /**
  2848.      * @param {Number} index
  2849.      * @returns
  2850.      */
  2851.     buttonName(index) {
  2852.         const device=this.currentLayout();
  2853.         if(device){
  2854.             //TODO:
  2855.             //return device.button(index)
  2856.         }
  2857.         return "";
  2858.     }
  2859. }

  2860. /**
  2861. * @typedef {LayoutSelecter<GamepadButtonObj>} GamepadLayoutSelector
  2862. */


  2863. const setting = (function(){
  2864.     const params = getParam();
  2865.     const keyText ={
  2866.         up:"↑",
  2867.         down:"↓",
  2868.         right:"→",
  2869.         left:"←"
  2870.     };

  2871.     const buttonUsedForALT =new MultiLanguageText("","");
  2872.     buttonUsedForALT.setNameJP("このボタンには%1が割り当て済みです");
  2873.     buttonUsedForALT.setNameEN("%1 has been assigned to this button");

  2874.     const nintendo=createGamepadLayout("N","nintendo","B","A","Y","X");
  2875.     const playstation=createGamepadLayout("P","playstation","×","○","□","△");
  2876.     const xbox =createGamepadLayout("X","xbox","A","B","X","Y");
  2877.     const numberGamepad =createButtonNumberLayout("Number","ButtonNumber");

  2878.     const gamepadLayoutSelector = new LayoutSelecter([numberGamepad,nintendo,playstation,xbox]);

  2879.     const gamepad= new Gamepad(gamepadLayoutSelector);
  2880.     const result= {
  2881.         gamepadSelector:gamepadLayoutSelector,
  2882.         gamepad :gamepad,
  2883.         device:new DeviceXXX(),
  2884.         errorText:createErrorTexts(),
  2885.         text:createText(params),
  2886.         buttonUsedForALT:buttonUsedForALT,
  2887.         keyWindowLineHeight:22,
  2888.         keyText:keyText,
  2889.         emptySymbolText:String(params.textEmpty),
  2890.         mandatorySymbols:createMandatorySymbols(params),
  2891.         windowSymbolListWidht:Number(params.windowSymbolListWidth),
  2892.         gamepadBackground:String(params.gamepadBackground),
  2893.         keyBackground:String(params.keyBackground),
  2894.         //needButtonDetouch:MultiLanguageText.create(params.needButtonDetouchText),
  2895.         //gamepadIsNotConnected: MultiLanguageText.create(params.GamepadIsNotConnectedText),
  2896.         //gamepadConfigCommandText:MultiLanguageText.create(params.gamepadConfigCommandText),
  2897.         //keyConfigCommandText:MultiLanguageText.create(params.keyConfigCommandText),
  2898.         //mapperDelete:MultiLanguageText.create(params.mapperDelete),
  2899.         numVisibleRows:16,//Number(params.numVisibleRows),
  2900.         cols:4,
  2901.     };
  2902.     return result;
  2903. })();
  2904. function currentGamepadConfigText(){
  2905.     return setting.text.gamepadConfigCommandText.currentName();
  2906. }
  2907. function currentKeyConfigText(){
  2908.     return setting.text.keyConfigCommandText.currentName();
  2909. }

  2910. /**
  2911. * @typedef {Object} ConfigSavedata
  2912. * @property {String} keyboardLayout
  2913. * @property {String} padLayout
  2914. * @property {Object} gamepadConfig
  2915. * @property {Object} keyboardConfig
  2916. */

  2917. /**
  2918. * @param {String} base
  2919. */
  2920. function makeCONFIG_KEY(base) {
  2921.     if(IS_Atsumaru){
  2922.         //@ts-ignore
  2923.         return base +location.pathname;
  2924.     }
  2925.     return base;
  2926. }

  2927. class I_MVMZ_Workaround{
  2928.     /**
  2929.      * @returns {Window_Help}
  2930.      * @param {Rectangle} rect
  2931.      */
  2932.     createHelpWindow(rect){
  2933.         return null;
  2934.     }
  2935.     /**
  2936.      * @param {Scene_MenuBase} scene
  2937.      */
  2938.     mainAreaHeigth(scene){
  2939.         return 0;

  2940.     }
  2941.     /**
  2942.      * @param {Number} numLines
  2943.      * @param {Boolean} selectable
  2944.      */
  2945.     calcWindowHeight(numLines,selectable){
  2946.         if(selectable){
  2947.             return Window_Selectable.prototype.fittingHeight(( numLines))
  2948.         }
  2949.         return Window_Base.prototype.fittingHeight(numLines);
  2950.     }

  2951. }
  2952. class MV_Impriment extends I_MVMZ_Workaround{
  2953.     /**
  2954.      * @param {Rectangle} rect
  2955.      * @returns
  2956.      */
  2957.     createHelpWindow(rect){
  2958.         const lines =this.helpWindowLines()
  2959.         return new Window_Help(lines);
  2960.     }
  2961.     mainAreaHeigth(){
  2962.         const helpAreaHeight = this.calcWindowHeight(this.helpWindowLines());
  2963.         return Graphics.boxHeight -helpAreaHeight;
  2964.     }
  2965.     helpWindowLines(){
  2966.         return 3;
  2967.     }
  2968. }

  2969. class MZ_Impriment extends I_MVMZ_Workaround{
  2970.     /**
  2971.      *
  2972.      * @param {Rectangle} rect
  2973.      * @returns {Window_Help}
  2974.      */
  2975.     createHelpWindow(rect){
  2976.         return new Window_Help(rect);
  2977.     }
  2978.     /**
  2979.      *
  2980.      * @param {Scene_MenuBase} scene
  2981.      */
  2982.     mainAreaHeigth(scene){
  2983.         return scene.mainAreaHeight();
  2984.     }
  2985.     /**
  2986.      * @param {Window_Base} window
  2987.      */
  2988.     colorSrc(window){
  2989.         return ColorManager;
  2990.     }
  2991. }

  2992. class InputConfigReadOnly{
  2993.     /**
  2994.      * @param {I_MVMZ_Workaround} workaround
  2995.      */
  2996.     constructor(workaround){
  2997.         this._workaround=workaround;
  2998.     }
  2999.     workaround(){
  3000.         return this._workaround;
  3001.     }

  3002. }

  3003. class InputConfigManager_T{
  3004.     /**
  3005.      * @param {InputConfigReadOnly} readonlyData
  3006.      */
  3007.     constructor(readonlyData){
  3008.         this._readonly=readonlyData;
  3009.         /**
  3010.          * @type {ConfigSavedata}
  3011.          */
  3012.         this._saveData=null;
  3013.         this._defaultGamepad =null;
  3014.     }
  3015.     getWorkaround(){
  3016.         return this._readonly.workaround();
  3017.     }
  3018.     makeDefaultMapper(){
  3019.         this._defaultGamepad= new DefaultMapper(Input.gamepadMapper);
  3020.     }
  3021.     defaultGamepadMapper(){
  3022.         return this._defaultGamepad;
  3023.     }

  3024.     /**
  3025.      * @param {Rectangle} rect
  3026.      * @returns
  3027.      */
  3028.     createHelpWindow(rect){
  3029.         return this._readonly.workaround().createHelpWindow(rect,3);
  3030.     }

  3031.     makeSaveData(){
  3032.         if(!this._saveData){
  3033.             /**
  3034.              * @type {ConfigSavedata}
  3035.              */
  3036.             const save = {
  3037.                 gamepadConfig:{},
  3038.                 keyboardConfig:{},
  3039.                 padLayout:"",
  3040.                 keyboardLayout:"",
  3041.             }
  3042.             this._saveData =save;
  3043.         }
  3044.     }


  3045.     /**
  3046.      * @param {ConfigSavedata} config
  3047.      */
  3048.     setConfigObject(config){
  3049.         this._saveData=config;
  3050.     }
  3051.     defaultKeyLayout() {
  3052.         //オプション系プラグインで先行してmakeData()するタイプへの対策
  3053.         if($gameSystem && $gameSystem.isJapanese()){
  3054.             return 'JIS';
  3055.         }
  3056.         return 'US';
  3057.     }

  3058.     createTemporalyGamepadMapper(){
  3059.         const mapper = new TemporaryMappper(this._saveData.gamepadConfig);
  3060.         return mapper;
  3061.     }
  3062.     applyGamepadConfig(){



  3063.     }
  3064.     isAllButtonDetouch(){
  3065.         return Input._latestButton===null;
  3066.     }

  3067.     isAnyButtonLongPressed(){
  3068.         return Input._pressedTime >60;
  3069.     }

  3070. }

  3071. const InputConfigManager =(function(){

  3072.     const mvmz = (Utils.RPGMAKER_NAME==="MV") ? new MV_Impriment() :new MZ_Impriment();
  3073.     const readonlyData =new InputConfigReadOnly(mvmz)

  3074.     return new InputConfigManager_T(readonlyData);
  3075. }())

  3076. const MA_INPUTCONFIG_CONTENTS =makeCONFIG_KEY("MANO_INPUTCONFIG");

  3077. const MA_INPUTCONFIG_STYLE =makeCONFIG_KEY( "MA_INPUTCONFIG_STYLE");
  3078. const MA_KEYBOARD_CONFIG =makeCONFIG_KEY('KEYBOARD_CONFIG');
  3079. const MA_GAMEPAD_CONFIG = makeCONFIG_KEY('GAMEPAD_CONFIG');
  3080. const MA_KEYBOARD_LAYOUT =makeCONFIG_KEY('KEYBOARD_LAYOUT');

  3081. function readGamePadConfig( config ){
  3082.     const value = config[MA_GAMEPAD_CONFIG];
  3083.     if(value){
  3084.         return value;
  3085.     }
  3086.     return null;
  3087. }
  3088. function readKeyboardConfig(config){
  3089.     const value =config[MA_KEYBOARD_CONFIG];
  3090.     if(value){
  3091.         return value;
  3092.     }
  3093.     return null;
  3094. }
  3095. /**
  3096. * @param {String} value
  3097. */
  3098. //@ts-ignore
  3099. ConfigManager.setInputConfigStyle =function(value){
  3100.     this[MA_INPUTCONFIG_STYLE]=value;
  3101. };
  3102. //@ts-ignore
  3103. ConfigManager.setKeyLayoutMA =function(layout){
  3104.     //@ts-ignore
  3105.     ConfigManager.keyLayout_MA =layout;
  3106. };

  3107. function defaultKeyLayout() {
  3108.     //オプション系プラグインで先行してmakeData()するタイプへの対策
  3109.     if($gameSystem && $gameSystem.isJapanese()){
  3110.         return 'JIS';
  3111.     }
  3112.     return 'US';
  3113. }
  3114. //saveconfig
  3115. const  ConfigManager_makeData = ConfigManager.makeData;
  3116. ConfigManager.makeData =function(){
  3117.     const result = ConfigManager_makeData.call(this);
  3118.     result[MA_INPUTCONFIG_STYLE] = ConfigManager[MA_INPUTCONFIG_STYLE] ||"normal";
  3119.     result[MA_GAMEPAD_CONFIG] =Input.gamepadMapper;
  3120.     result[MA_KEYBOARD_CONFIG] = Input.keyMapper;
  3121.     //@ts-ignore
  3122.     result[MA_KEYBOARD_LAYOUT] = ConfigManager.keyLayout_MA ||defaultKeyLayout();
  3123.     return result;
  3124. };
  3125. //loadconfig
  3126. const ConfigManager_applyData = ConfigManager.applyData;
  3127. ConfigManager.applyData =function(config){
  3128.     ConfigManager_applyData.call(this,config);
  3129.     const gamepad =readGamePadConfig(config);
  3130.     if(gamepad){
  3131.         Input.gamepadMapper = gamepad;
  3132.     }
  3133.     const keyMapper =readKeyboardConfig(config);
  3134.     if(keyMapper){
  3135.         Input.keyMapper =keyMapper;
  3136.     }
  3137.     //@ts-ignore
  3138.     ConfigManager.setInputConfigStyle( config[MA_INPUTCONFIG_STYLE]);
  3139.     //@ts-ignore
  3140.     ConfigManager.setKeyLayoutMA(config[MA_KEYBOARD_LAYOUT]||'JIS');
  3141.     Input.clear();
  3142. };
  3143. //@ts-ignore
  3144. const ColorSrc = window["ColorManager"] || null;
  3145. /**
  3146. * @returns {Window_Base}
  3147. * @param {Window_Base|Window_Selectable} window_base
  3148. */
  3149. function getColorSrc(window_base){
  3150.     return ColorSrc||window_base;
  3151. }

  3152. class TemporaryMappperBase extends I_ReadonlyMapper{
  3153.     /**
  3154.      *
  3155.      * @param {String} symbol
  3156.      * @returns
  3157.      */
  3158.     hasSymbol(symbol){
  3159.         return false;
  3160.     }
  3161.     isValidMapper(){
  3162.         return false;
  3163.     }
  3164.     /**
  3165.      * @param {Number} code
  3166.      * @param {String} symbol
  3167.      */
  3168.     change(code,symbol){

  3169.     }
  3170.     /**
  3171.      * @returns {InputMapperType}
  3172.      */
  3173.     createNormalizedMapper(){
  3174.         return {}
  3175.     }
  3176.     reset(mapper){

  3177.     }
  3178. }
  3179. /**
  3180. * @typedef {Record<Number,String> } InputMapperType
  3181. */
  3182. //TODO:mapperのリセット用に保存してあるデータを何とかする
  3183. //主にリセットで使うので、それに向いた構造に改造したい

  3184. class TemporaryMappper extends TemporaryMappperBase{
  3185.     /**
  3186.      * @private
  3187.      * @param {InputMapperType} mapper
  3188.      */
  3189.     static createMap(mapper){
  3190.         /**
  3191.          * @type {Map<Number,String>}
  3192.          */
  3193.         const map =new Map();
  3194.         for (const iterator of Object.entries(mapper)) {
  3195.             const code = Number(iterator[0]);
  3196.             if(!isNaN(code)){
  3197.                 map.set(code,iterator[1]);
  3198.             }
  3199.         }
  3200.         return map;
  3201.     }
  3202.     /**
  3203.      *
  3204.      * @param {InputMapperType} mapper
  3205.      */
  3206.     constructor(mapper){
  3207.         super();
  3208.         this.reset(mapper);
  3209.     }
  3210.     createSymbolsSet(){
  3211.         const set =new Set(this._map.values());
  3212.         return set;
  3213.     }
  3214.     /**
  3215.      * @param {I_ReadonlyMapper} mapper
  3216.      */
  3217.     readOtherMapper(mapper){

  3218.     }
  3219.     /**
  3220.      * @param {DefaultMapper} mapper
  3221.      */
  3222.     reset_V2(mapper){
  3223.         this.reset(mapper.cloneMapper());

  3224.     }
  3225.     /**
  3226.      * @param {InputMapperType} mapper
  3227.      */
  3228.     reset(mapper){
  3229.         this._map = TemporaryMappper.createMap(mapper);
  3230.     }
  3231.     /**
  3232.      * @param {Number} code
  3233.      * @param {String} symbol
  3234.      */
  3235.     change(code,symbol){
  3236.         this._map.set( Number(code),symbol);
  3237.     }
  3238.     /**
  3239.      *
  3240.      * @param {I_InputButton} botton
  3241.      * @param {I_SymbolDefine} symbolObject
  3242.      */
  3243.     change_V8(botton,symbolObject){
  3244.         this.change(botton.mapperId(),symbolObject.symbol());
  3245.     }
  3246.     createNormalizedMapper(){
  3247.         /**
  3248.          * @type {InputMapperType}
  3249.          */
  3250.         const result ={};
  3251.         for (const iterator of this._map.entries()) {
  3252.             const n =(iterator[0]);
  3253.             const symbol =iterator[1];
  3254.             if(!isNaN(n) &&symbol){
  3255.                 result[n] = symbol;
  3256.             }
  3257.         }
  3258.         return result;
  3259.     }
  3260.     cloneMapper(){
  3261.         return this.createNormalizedMapper();
  3262.     }
  3263.     /**
  3264.      *
  3265.      * @param {I_InputButton} button
  3266.      */
  3267.     getSymbolObjectByCode_V8(button){
  3268.         return this.getSymbolObjectByCode(button.mapperId());
  3269.     }

  3270.     /**
  3271.      * @param {Number} codeId
  3272.      * @returns
  3273.      */
  3274.     getSymbolObjectByCode(codeId){
  3275.         const symbol = this._map.get(codeId);
  3276.         return symbolManager.findSymbol(symbol);
  3277.     }
  3278.     /**
  3279.      * @param {Number} codeId
  3280.      */
  3281.     symbolString(codeId){
  3282.         const symbol = this.getSymbolObjectByCode(codeId);
  3283.         if(symbol){
  3284.             return symbol.symbol();
  3285.         }
  3286.         return ""
  3287.     }
  3288.     /**
  3289.      * @param {Number} code
  3290.      * @returns {String}
  3291.      */
  3292.     findSymbolByCode(code){
  3293.         return this._map.get(code);
  3294.     }
  3295.     /**
  3296.      * @param {Number} code
  3297.      * @returns
  3298.      */
  3299.     findObjectByCode(code){
  3300.         const symbolString = this.findSymbolByCode(code);
  3301.         return symbolManager.findSymbol(symbolString);
  3302.     }
  3303.     // /**
  3304.     //  * @param {String} symbol
  3305.     //  */
  3306.     // findFromSymbol(symbol){
  3307.     //     for (const iterator of this._map.entries()) {
  3308.     //         if(iterator[1]===symbol){
  3309.     //             return iterator[0];
  3310.     //         }
  3311.     //     }
  3312.     //     return NaN;
  3313.     // }
  3314.     findObjectFromSymbol(symbolString){
  3315.         
  3316.     }

  3317.     /**
  3318.      * @param {String} symbol
  3319.      * @param {Number} code
  3320.      */
  3321.     canSymbolChange(symbol,code){
  3322.         return !this.areSymbolAndCode(symbol,code);
  3323.     }
  3324.     /**
  3325.      * @param {String} symbol
  3326.      * @param {Number} code
  3327.      */
  3328.      areSymbolAndCode(symbol,code){
  3329.         const aa = this._map.get(code);
  3330.         return aa ===symbol;
  3331.     }
  3332.     /**
  3333.      * @param {Number} code
  3334.      */
  3335.     daleteByCode(code){
  3336.         this._map.delete(code);
  3337.     }


  3338.     /**
  3339.      * @param {String} symbol
  3340.      */
  3341.     hasSymbol(symbol){
  3342.         const isEscapeCompatible = Input._isEscapeCompatible(symbol);
  3343.         for (const iterator of this._map.values()) {
  3344.             if(iterator ===symbol){
  3345.                 return true;
  3346.             }
  3347.             if(isEscapeCompatible){
  3348.                 if(iterator ==="escape"){
  3349.                     return true;
  3350.                 }
  3351.             }
  3352.         }
  3353.         return false;
  3354.     }
  3355.     isValidMapper(){
  3356.         return symbolManager.isValidMapper_v3(this.createSymbolsSet());
  3357.     }
  3358. }

  3359. class Window_Selectable_InputConfigVer extends Window_Selectable{
  3360.     /**
  3361.      * @param {Rectangle} rect
  3362.      */
  3363.     constructor(rect){
  3364.         super(rect);
  3365.     }
  3366.     /**
  3367.      * @returns {Number}
  3368.      */
  3369.     bottom(){
  3370.         return this.y + this.height;
  3371.     }
  3372.     /**
  3373.      * @param {MyRectType} rect
  3374.      */
  3375.     initialize(rect){
  3376.         window_initializeMVMZ(this,rect,super.initialize);
  3377.     }
  3378.     isOkTriggered(){
  3379.         return Input.isTriggered("ok");
  3380.     }
  3381.     isCancelTriggered(){
  3382.         return Input.isTriggered('cancel');
  3383.     }
  3384.     textPadding(){
  3385.         return 6;
  3386.     }
  3387.     /**
  3388.      * @param {MyRectType} rect
  3389.      * @param {String} color
  3390.      */
  3391.     drawSymbolBack(rect, color) {
  3392.         this.changePaintOpacity(false);
  3393.         this.contents.fillRect(rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2, color);
  3394.         this.changePaintOpacity(true);
  3395.     }
  3396.     /**
  3397.      * @returns {typeof ColorManager}
  3398.      * @desc MV/MZ共用処理。ソースコードはMZ向けで記述。
  3399.      */
  3400.     colorSrc(){
  3401.         //@ts-ignore
  3402.         return getColorSrc(this);
  3403.     }
  3404.     /**
  3405.      * @param {I_SymbolDefine} symbolObject
  3406.      * @param {Number} x
  3407.      * @param {Number} y
  3408.      * @param {Number} width
  3409.      */
  3410.     drawSymbolObject(symbolObject,x,y,width){
  3411.         this.changePaintOpacity(symbolObject.isEnabled());
  3412.         this.drawText(symbolObject.name(),x,y,width);
  3413.     }

  3414.     numberWidth(){
  3415.         return 26;
  3416.     }
  3417.     /**
  3418.      * @param {I_InputButton} button
  3419.      * @param {Number} x
  3420.      * @param {Number} y
  3421.      * @param {Number} width
  3422.      */
  3423.      drawButton_V3(button,x,y,width){
  3424.         const numberWidth  = this.numberWidth();
  3425.         this.drawText(button.mapperId(),x,y,numberWidth);
  3426.         const nameWidth= width -numberWidth
  3427.         const nameX = x + numberWidth;
  3428.         this.drawText(":"+button.name(),nameX,y,nameWidth);
  3429.     }
  3430. }
  3431. class Window_InputConfigBase extends Window_Selectable_InputConfigVer{

  3432.     /**
  3433.      * @param {MyRectType} rect
  3434.      */
  3435.     initialize(rect){
  3436.         this.initializeMapper();
  3437.         super.initialize(rect);
  3438.     }
  3439.     initializeMapper(){
  3440.     }
  3441.    
  3442.     mainItems(){
  3443.         return 0;
  3444.     }

  3445.     /**
  3446.      * @returns {Key_Command[]}
  3447.      */
  3448.     commandList(){
  3449.         return [];
  3450.     }
  3451.     /**
  3452.      * @param {Number} index
  3453.      * @returns
  3454.      */
  3455.     command(index){
  3456.         const commandList = this.commandList();
  3457.         const commandIndex = this.commandIndex(index);
  3458.         return commandList[commandIndex];
  3459.     }
  3460.     commandLength(){
  3461.         return this.commandList().length;
  3462.     }

  3463.     /**
  3464.      * @param {Number} index
  3465.      */
  3466.     commandIndex(index){
  3467.         return index - this.mainItems();
  3468.     }
  3469.     exitCommandIndex(){
  3470.         return -1;
  3471.     }
  3472.     /**
  3473.      * @param {Number} index
  3474.      */
  3475.     isExitCommand(index){
  3476.         return this.exitCommandIndex() ===index;
  3477.     }
  3478.     /**
  3479.      *
  3480.      * @param { Number} index
  3481.      */
  3482.     drawCommand(index){
  3483.         //メモ ボタン一覧を示すリストと、保存などに使うコマンドは別の配列
  3484.         //なので、描画機能は分けてある
  3485.         const command = this.command(index);
  3486.         if(command){
  3487.             this.changePaintOpacity(true);
  3488.             const rect = this.itemRectWithPadding(index);
  3489.             const text =command.text();
  3490.             this.drawText(text,rect.x,rect.y,rect.width);
  3491.         }
  3492.     }
  3493.     processCommandOk(){
  3494.         const command = this.command(this.index());
  3495.         if(command ){
  3496.             if(this.isHandled(command.handle)){
  3497.                 this.updateInputData();
  3498.                 this.deactivate();
  3499.                 this.callHandler(command.handle);   
  3500.             }
  3501.         }else{
  3502.             this.playBuzzerSound();
  3503.         }
  3504.     }
  3505.     callDrawItem(index){

  3506.     }
  3507.     callDrawCommand(){

  3508.     }
  3509.     playLayoutChangeSound(){
  3510.         SoundManager.playEquip();
  3511.     }
  3512.     playResetSound(){
  3513.         SoundManager.playEquip();
  3514.     }
  3515.     playApplySound(){
  3516.         SoundManager.playEquip();
  3517.     }
  3518.     playSymbolSetSound(){
  3519.         SoundManager.playOk();
  3520.     }
  3521.     /**
  3522.      * @returns {Number}
  3523.      */
  3524.     currentButtonCode(){
  3525.         throw (new Error("not imple"));
  3526.     }
  3527.    
  3528.     processCancel() {
  3529.         this.updateInputData();
  3530.         if (this.isExitCommand(this._index)) {
  3531.             this.callCancelHandler();
  3532.         } else {
  3533.             SoundManager.playCancel();
  3534.             const cancellationIndex = this.exitCommandIndex();
  3535.             this.select(cancellationIndex);
  3536.         }
  3537.     }
  3538.     /**
  3539.      * @returns {String}
  3540.      * @param {Number} index
  3541.      */
  3542.     symbolString(index){
  3543.         throw new Error( "method not impriments!")
  3544.     }

  3545.     currentSymbolString(){
  3546.         return this.symbolString(this._index);
  3547.     }
  3548.     currentSymbolObject(){
  3549.         const symbol = this.currentSymbolString();
  3550.         return symbolManager.findSymbol(symbol)
  3551.     }
  3552.     /**
  3553.      * @param {Boolean} value
  3554.      */
  3555.     redrawApplyCommand(value){

  3556.     }
  3557.     /**
  3558.      * @returns {InputDeviceBase}
  3559.      */
  3560.     inputDevice(){
  3561.         throw new Error("input device unknow!")
  3562.     }
  3563.     // buttonItems(){
  3564.     //     return 0;
  3565.     // }
  3566.     /**
  3567.      * @returns {TemporaryMappper}
  3568.      */
  3569.     temporaryMappper(){
  3570.         return null;
  3571.     }
  3572.     mapperSrc(){
  3573.         return {};
  3574.     }
  3575.     /**
  3576.      * @param {String} symbol
  3577.      */
  3578.     hasSymbol(symbol){
  3579.         return this.temporaryMappper().hasSymbol(symbol);
  3580.     }
  3581.     canApplySetting(){
  3582.         return this.isValidMapper();
  3583.     }
  3584.     isValidMapper(){
  3585.         return this.temporaryMappper().isValidMapper();
  3586.     }
  3587.     resetMapper(){
  3588.         this.temporaryMappper().reset(this.defaultMapper());
  3589.     }
  3590.     resetMapper_V2(){

  3591.     }
  3592.     defaultMapper(){
  3593.         return this.inputDevice().defaultMapper();
  3594.     }
  3595.     cloneMapper(){
  3596.         return this.temporaryMappper().createNormalizedMapper();
  3597.     }
  3598.     updateHelp(){
  3599.         const obj = this.currentSymbolObject();
  3600.         if(obj){
  3601.             this._helpWindow.setText(obj.getHelpText());
  3602.         }else{
  3603.             this._helpWindow.clear();
  3604.         }
  3605.     }
  3606. }
  3607. class Window_InputSymbolListBase extends Window_Selectable_InputConfigVer{
  3608.     /**
  3609.      * @param {Rectangle} rect
  3610.      */
  3611.     initialize(rect) {
  3612.         this.makeItemList();
  3613.         super.initialize(rect);
  3614.         this.deactivate();
  3615.         this.deselect();
  3616.         this.refresh();
  3617.     }
  3618.     makeItemList(){
  3619.         this._list = symbolManager.getSymbolList();
  3620.     }
  3621.     maxItems(){
  3622.         return this._list.length;
  3623.     }
  3624.     /**
  3625.      * @param {Number} index
  3626.      */
  3627.     symbolObject(index){
  3628.         return this._list[index];
  3629.     }
  3630.     currentSymbolObject(){
  3631.         return this.symbolObject(this.index());
  3632.     }
  3633.     /**
  3634.      * @param {String} symbol
  3635.      */
  3636.     indexOfSymbol(symbol){
  3637.         const numItms = this.maxItems();
  3638.         for (let i = 0; i < numItms; i++) {
  3639.             const symbolObj = this.symbolObject(i);
  3640.             if(symbolObj && symbolObj.symbol()===symbol){
  3641.                 return i;
  3642.             }
  3643.         }
  3644.         return -1;
  3645.     }
  3646.     /**
  3647.      * @param {String} symbol
  3648.      */
  3649.     selectSymbol(symbol){
  3650.         if(symbol){
  3651.             const index = this.indexOfSymbol(symbol);
  3652.             if(index >=0){
  3653.                 this.select(index);
  3654.                 return;
  3655.             }
  3656.         }
  3657.         this.select(0);
  3658.     }
  3659.     /**
  3660.      * @param {Number} index
  3661.      */
  3662.     drawItem(index){
  3663.         const item = this.symbolObject(index);
  3664.         if(item){
  3665.             const rect = this.itemRectWithPadding(index);
  3666.             this.drawSymbolObject(item,rect.x,rect.y,rect.width);
  3667.         }
  3668.     }
  3669.     isCurrentItemEnabled(){
  3670.         return this.isItemEnabled(this._index);
  3671.     }
  3672.     currentItemIsDeleter(){
  3673.         const item = this.symbolObject(this.index());
  3674.         if(item){
  3675.             return item.isDeleter();
  3676.             //有効化されていて、シンボルがnullなのはdeleteにしかない
  3677.             //return item.isEnabled() && (!item.symbol());
  3678.         }
  3679.         return false;
  3680.     }
  3681.     /**
  3682.      * @param {Number} index
  3683.      */
  3684.     isItemEnabled(index){
  3685.         const symbol = this.symbolObject(index);
  3686.         if(symbol){
  3687.             return symbol.isEnabled();
  3688.         }
  3689.         return false;
  3690.     }
  3691.     updateHelp(){
  3692.         const symbol = this.currentSymbolObject()
  3693.         if(symbol){
  3694.             this._helpWindow.setText(symbol.getHelpText());
  3695.         }else{
  3696.             this._helpWindow.clear();
  3697.         }
  3698.     }
  3699. }
  3700. class Window_InputSymbolList extends Window_InputSymbolListBase{
  3701.     makeItemList(){
  3702.         super.makeItemList();
  3703.         //TODO:初期設定に戻す(ボタン単位)を追加 原理的には可能
  3704.         this._list.push(new SymbolDeleteObject());
  3705.     }
  3706.     maxCols(){
  3707.         return 4;
  3708.     }

  3709. }

  3710. function createPadState(padId) {
  3711.     //@ts-ignore
  3712.     if (!navigator.getGamepads) {
  3713.         return null;
  3714.     }
  3715.     //@ts-ignore
  3716.     const gamepads =navigator.getGamepads();
  3717.     if(!gamepads){return null}
  3718.     return  gamepads[padId];
  3719. }

  3720. class V8_Item{
  3721.     /**
  3722.      * @param {String} handlerSymbol
  3723.      */
  3724.     constructor(handlerSymbol){
  3725.         this._commandSymbol=handlerSymbol;

  3726.     }
  3727.     refresh(){}
  3728.     leftText(){
  3729.         return "";
  3730.     }
  3731.     rigthText(){
  3732.         return "";
  3733.     }
  3734.     xxOpacity(){
  3735.         return true;
  3736.     }
  3737.     helpText(){
  3738.         return "";
  3739.     }
  3740.     handlerSymbol(){
  3741.         return this._commandSymbol;
  3742.     }
  3743.     /**
  3744.      * @returns {GamepadButtonObj}
  3745.      */
  3746.     button(){
  3747.         return null;
  3748.     }
  3749. }
  3750. class V8Item_Button extends V8_Item{

  3751.     /**
  3752.      * @param {GamepadButtonObj} button
  3753.      * @param {TemporaryMappper} mapper
  3754.      */
  3755.     constructor(button,mapper){
  3756.         super("button");
  3757.         this._button=button;
  3758.         this._mapper =mapper;
  3759.         this.refresh();
  3760.     }
  3761.     refresh(){
  3762.         this._symbolObject= this._mapper.getSymbolObjectByCode_V8(this._button);
  3763.     }
  3764.     helpText(){
  3765.         if(this._symbolObject){
  3766.             return this._symbolObject.helpText();
  3767.         }
  3768.         return "";
  3769.     }
  3770.     button(){
  3771.         return this._button;
  3772.     }
  3773.     leftText(){
  3774.         return this._button.name();
  3775.     }
  3776.     rigthText(){
  3777.         const symbolName = this._symbolObject ?this._symbolObject.name():"";
  3778.         return `:${symbolName}`;
  3779.     }
  3780. }

  3781. class V8Item_Command extends V8_Item{
  3782.     /**
  3783.      *
  3784.      * @param {Key_Command} command
  3785.      */
  3786.     constructor(command){
  3787.         super(command.handle);
  3788.         this._command=command;
  3789.         
  3790.     }
  3791.     leftText(){
  3792.         return this._command.name();
  3793.     }
  3794.     handlerSymbol(){
  3795.         return this._command.handle;
  3796.     }
  3797. }
  3798. class V8_Itemn_LayoutCommand extends V8Item_Command{
  3799.     /**
  3800.      * @param {Key_Command} command
  3801.      */
  3802.     constructor(command){
  3803.         super(command);
  3804.         this.setLayout(null);
  3805.     }
  3806.     /**
  3807.      *
  3808.      * @param {DeviceLayout<GamepadButtonObj>} layout
  3809.      */
  3810.     setLayout(layout){
  3811.         this._layout=layout;
  3812.     }
  3813.     helpText(){
  3814.         if(this._layout){
  3815.             return this._layout.name();
  3816.         }
  3817.         return "";
  3818.     }
  3819. }

  3820. class V8_Item_ApplyCommand extends V8Item_Command{

  3821.     /**
  3822.      * @param {Key_Command} command
  3823.      * @param {I_ReadonlyMapper} mapper
  3824.      */
  3825.     constructor(command,mapper){
  3826.         super(command);
  3827.         this._mapper=mapper;
  3828.     }
  3829.     refresh(){

  3830.     }

  3831.     xxOpacity(){
  3832.         return this._mapper.isValidMapper();
  3833.     }
  3834. }


  3835. class Window_GamepadConfig_V8 extends Window_Selectable_InputConfigVer{

  3836.     /**
  3837.      * @param {Rectangle} rect
  3838.      */
  3839.     initialize(rect){
  3840.         this._tmpMapper= new TemporaryMappper(Input.gamepadMapper);
  3841.         this._layoutCommand = new V8_Itemn_LayoutCommand(CommandManager.buttonLayout());
  3842.         this._exitCommand = new V8Item_Command(CommandManager.exit());
  3843.         this._resetCommand = new V8Item_Command(CommandManager.reset());
  3844.         this._applyCommand = new V8_Item_ApplyCommand(CommandManager.apply(),this._tmpMapper);
  3845.         const layout= setting.gamepadSelector.currentLayout();
  3846.         /**
  3847.          * @type {V8_Item[]}
  3848.          */
  3849.         this._v8List=[];
  3850.         super.initialize(rect);
  3851.         this.setLayout(layout);
  3852.     }
  3853.     maxCols(){
  3854.         return 4;
  3855.     }
  3856.     getMapper(){
  3857.         return this._tmpMapper;
  3858.     }
  3859.     isCurrentCommandExit(){
  3860.         return this.currentItem() ===this._exitCommand;
  3861.     }
  3862.     selectExitCommand(){
  3863.         const index= this._v8List.lastIndexOf(this._exitCommand);
  3864.         if(index>=0){
  3865.             this.select(index);
  3866.         }
  3867.     }
  3868.     refresh(){
  3869.         this.makeV8Item();
  3870.         super.refresh();
  3871.     }
  3872.     /**
  3873.      * @private
  3874.      */
  3875.     makeV8Item(){
  3876.         const self_=this;
  3877.         const baseList =this._layout.buttons().map(  function(b){
  3878.             /**
  3879.              * @type {V8_Item}
  3880.              */
  3881.             const result= new V8Item_Button(b,self_._tmpMapper);
  3882.             return result;
  3883.         });
  3884.         baseList.push(this._applyCommand,this._resetCommand,this._layoutCommand,this._exitCommand);
  3885.         this._v8List=baseList;
  3886.     }

  3887.     maxItems(){
  3888.         return this._v8List.length;
  3889.     }
  3890.     /**
  3891.      * @param {Number} index
  3892.      * @returns
  3893.      */
  3894.     drawItem(index){
  3895.         const item = this.itemAt(index);
  3896.         if(!item){return}
  3897.         const right = item.rigthText();
  3898.         const left = item.leftText();

  3899.         const rect = this.itemRectWithPadding(index);

  3900.         this.changePaintOpacity(item.xxOpacity());
  3901.         const rightWidth = (!!right) ? rect.width *0.7 : 0;
  3902.         this.drawText(left,rect.x,rect.y, rect.width - rightWidth);

  3903.         if(!!right){
  3904.             const rightX =rect.x + rect.width -rightWidth;
  3905.             this.drawText(right,rightX,rect.y,rightWidth);
  3906.         }
  3907.     }

  3908.     isOkEnabled(){
  3909.         return true;
  3910.     }

  3911.     callOkHandler(){
  3912.         const item=this.currentItem();
  3913.         if(item){
  3914.             const handlerSymbol = item.handlerSymbol();
  3915.             if(this.isHandled(handlerSymbol)){
  3916.                 this.callHandler(handlerSymbol);
  3917.             }
  3918.         }
  3919.     }
  3920.     /**
  3921.      * @private
  3922.      * @param {Number} index
  3923.      */
  3924.     itemAt(index){
  3925.         return this._v8List[index];
  3926.     }
  3927.     currentItem(){
  3928.         return this.itemAt(this.index());
  3929.     }
  3930.     currentButton(){
  3931.         const item = this.currentItem();
  3932.         if(item){
  3933.             return item.button();
  3934.         }
  3935.         return null;
  3936.     }
  3937.     isCurrentItemEnabled(){
  3938.         const item =this.currentItem();
  3939.         if(item){
  3940.             return item.xxOpacity();
  3941.         }

  3942.         return false;
  3943.     }
  3944.     gamepad(){
  3945.         return setting.gamepadSelector
  3946.     }
  3947.     /**
  3948.      * @param {GamepadButtonObj} button
  3949.      */
  3950.     buttonName(button){
  3951.         return button.name();
  3952.     }

  3953.     /**
  3954.      * @param {DeviceLayout<GamepadButtonObj>} layout
  3955.      */
  3956.     setLayout(layout){
  3957.         this._layout =layout;
  3958.         this._layoutCommand.setLayout(layout);
  3959.         this.makeV8Item();
  3960.         this.refresh();
  3961.     }

  3962.     updateHelp(){
  3963.         const item = this.currentItem();
  3964.         if(item){
  3965.             this._helpWindow.setText(item.helpText());
  3966.         }
  3967.     }

  3968. }

  3969. class Scene_GamepadConfig_V8 extends Scene_MenuBaseMVMZ{

  3970.     symbolListHeight(){
  3971.         const mainAreaHeight=InputConfigManager.getWorkaround().mainAreaHeigth(this);
  3972.         return mainAreaHeight- this.mainWindowHeight();
  3973.     }
  3974.     mainWindowHeight(){
  3975.         return this.calcWindowHeight(4,true);
  3976.     }
  3977.     mainWindowRect(){
  3978.         const x = 0;
  3979.         const y= this.mainAreaTop();
  3980.         const width = Graphics.boxWidth;
  3981.         const height =this.mainWindowHeight()
  3982.         return new Rectangle(x,y,width,height);
  3983.     }



  3984.     createGamepadWindow(){
  3985.         const rect= this.mainWindowRect();
  3986.         const ww = new Window_GamepadConfig_V8(rect);
  3987.         ww.setHandler("button",this.onGamepadButton.bind(this));
  3988.         ww.setHandler("cancel",this.onGamepadCancel.bind(this));
  3989.         ww.setHandler("exit",this.onGamepadCancel.bind(this));
  3990.         ww.setHandler(CommandManager.apply().handle,this.onApply.bind(this));
  3991.         ww.setHandler(CommandManager.reset().handle,this.onReset.bind(this));
  3992.         ww.setHandler(CommandManager.buttonLayout().handle,this.onChangeLayoutOk.bind(this));
  3993.         this.addWindow(ww);
  3994.         this._gamepadWindow=ww;
  3995.     }
  3996.     createSymbolListRect(){
  3997.         const width =Graphics.boxWidth;
  3998.         const height = this.symbolListHeight();
  3999.         const x =0;
  4000.         const y = Graphics.boxHeight -height;

  4001.         return new Rectangle(x,y,width,height);
  4002.     }
  4003.     createSymbolListWindow(){
  4004.         const rect = this.createSymbolListRect();
  4005.         const sw = new Window_InputSymbolList(rect);
  4006.         sw.setHandler("ok",this.onSymbolListOk.bind(this));
  4007.         sw.setHandler("cancel",this.onSymbolListCnacel.bind(this));
  4008.         this._sybmolWindow=sw;
  4009.         this.addWindow(sw);
  4010.     }

  4011.     create(){
  4012.         super.create();
  4013.         this.createAllWindows();
  4014.     }
  4015.     createAllWindows(){
  4016.         this.createHelpWindow();
  4017.         this.createGamepadWindow();
  4018.         this.createSymbolListWindow();
  4019.         this.linkWindow();
  4020.     }
  4021.     linkWindow(){
  4022.         this._sybmolWindow.setHelpWindow(this._helpWindow);
  4023.         this._gamepadWindow.setHelpWindow(this._helpWindow);
  4024.         this._gamepadWindow.activate();
  4025.         this._gamepadWindow.select(0);
  4026.     }
  4027.     xx(){
  4028.         return setting.gamepadSelector
  4029.     }
  4030.     onGamepadReset(){
  4031.         const mapper = this._gamepadWindow.getMapper();
  4032.         mapper.reset_V2(InputConfigManager.defaultGamepadMapper());
  4033.         this._gamepadWindow.refresh();
  4034.         this._gamepadWindow.activate();
  4035.     }
  4036.     onGamepadButton(){
  4037.         const button = this._gamepadWindow.currentButton();
  4038.         if(!button){
  4039.             this._gamepadWindow.activate();
  4040.             return;
  4041.         }
  4042.         const mapper = this._gamepadWindow.getMapper();
  4043.         //そのボタンからシンボルを決定する
  4044.         const symbol= mapper.getSymbolObjectByCode_V8(button);
  4045.         const symbolString = symbol ? symbol.symbol():"";

  4046.         this._sybmolWindow.selectSymbol(symbolString);
  4047.         this._sybmolWindow.show();
  4048.         this._sybmolWindow.activate();
  4049.     }
  4050.     onGamepadCancel(){
  4051.         if(this._gamepadWindow.isCurrentCommandExit()){
  4052.             this.popScene();
  4053.             return;
  4054.         }
  4055.         this._gamepadWindow.selectExitCommand();
  4056.         this._gamepadWindow.activate();
  4057.     }

  4058.     onSymbolListOk(){
  4059.         //tmpMapperを捕まえる
  4060.         const mapper = this._gamepadWindow.getMapper();

  4061.         //シンボルとボタンを特定する
  4062.         const button =this._gamepadWindow.currentButton();
  4063.         const symbol =this._sybmolWindow.currentSymbolObject();
  4064.         if(button && symbol){
  4065.             SoundManager.playEquip();
  4066.             //書き換えを行う
  4067.             mapper.change_V8(button,symbol);
  4068.             //gamepadWindowを再描画
  4069.             this._gamepadWindow.refresh();
  4070.         }
  4071.         //制御を移す
  4072.         this._sybmolWindow.deselect();
  4073.         this._gamepadWindow.activate();
  4074.     }

  4075.     onSymbolListCnacel(){
  4076.         this._sybmolWindow.deselect();
  4077.         this._sybmolWindow.hide();
  4078.         this._gamepadWindow.activate();
  4079.     }
  4080.     onReset(){
  4081.         //マッパーを捕まえる
  4082.         const mapper=this._gamepadWindow.getMapper();
  4083.         const defaultMapper=InputConfigManager.defaultGamepadMapper()
  4084.         //デフォルトのマッパーを持ってくる
  4085.         //書き込む
  4086.         mapper.reset_V2(defaultMapper);

  4087.         //再描画する
  4088.         this._gamepadWindow.refresh();
  4089.         this._gamepadWindow.activate();
  4090.     }
  4091.     onApply(){
  4092.         //mapperを取得
  4093.         const mapper= this._gamepadWindow.getMapper();
  4094.         //状態が正しいかを確認
  4095.         if(mapper.isValidMapper()){
  4096.             mapper.applyGamepad();
  4097.             this.popScene();
  4098.         }else{
  4099.             this._gamepadWindow.activate();
  4100.         }

  4101.     }
  4102.     onChangeLayoutOk(){
  4103.         this.xx().changeNext();
  4104.         this._gamepadWindow.setLayout(this.xx().currentLayout() );
  4105.         this._gamepadWindow.activate();
  4106.     }
  4107. }

  4108. class Scene_InputConfigBase_MA extends Scene_MenuBaseMVMZ{
  4109.     constructor(){
  4110.         super();
  4111.         //popSceneModeとapplyOnExitは別
  4112.         //前者はシーン切り替え検知で、後者は一度設定が変更されたことの検知
  4113.         //混ぜてはいけない
  4114.         this._popSceneMode=false;
  4115.     }
  4116.     isALTmode(){
  4117.         return false;
  4118.     }
  4119.     /**
  4120.      * @param {String} value
  4121.      */
  4122.     setAltMode(value){
  4123.         //@ts-ignore
  4124.         ConfigManager.setInputConfigStyle(value);
  4125.     }
  4126.     start(){
  4127.         const mode = this.isALTmode() ? "ALT":"normal";
  4128.         this.setAltMode(mode);
  4129.         super.start();
  4130.     }
  4131.     /**
  4132.      * @param {String} text
  4133.      */
  4134.     setHelpText(text){
  4135.         this._helpWindow.setText(text)
  4136.     }
  4137.     /**
  4138.      * @returns {Bitmap}
  4139.      */
  4140.     backBitmap(){
  4141.         return null;
  4142.     }
  4143.     createBackground(){
  4144.         const bitmap = this.backBitmap();
  4145.         if(!bitmap){
  4146.             super.createBackground();
  4147.             return;
  4148.         }
  4149.         const sprite = new Sprite(bitmap);
  4150.         this._backgroundSprite = sprite;
  4151.         this.addChild(sprite);
  4152.     }
  4153.     defaultMapper(){
  4154.         return this.mainWidnow().defaultMapper();
  4155.     }

  4156.     symbolListWidth(){
  4157.         return Graphics.boxWidth;
  4158.     }

  4159.     helpWindowInitParam(){
  4160.         if(Utils.RPGMAKER_NAME ==="MV"){
  4161.             return this.helpWindowLines();
  4162.         }
  4163.         return this.helpWindowRect();
  4164.     }
  4165.     createHelpWindow(){
  4166.         this._helpWindow = new Window_Help(this.helpWindowInitParam());
  4167.         this.addWindow(this._helpWindow);
  4168.     }
  4169.     mainWindowHeight(){
  4170.         return this.subWindowTop() - this.mainAreaTop();
  4171.     }

  4172.     mainWindowRect(){
  4173.         const x = 0;
  4174.         const y= this.mainAreaTop();
  4175.         const width = Graphics.boxWidth;
  4176.         const height =this.mainWindowHeight();
  4177.         return new Rectangle(x,y,width,height);
  4178.     }
  4179.     subWindowTop(){
  4180.         return Graphics.boxHeight -this.subWindowHeight();
  4181.     }
  4182.     subWindowHeight(){
  4183.         return this.calcWindowHeight(3,true);
  4184.     }

  4185.     subWindowRect() {
  4186.         const width = Graphics.boxWidth;
  4187.         const height = this.subWindowHeight();
  4188.         const x =0;
  4189.         const y = this.subWindowTop();
  4190.         return new Rectangle(x,y,width,height);
  4191.     }

  4192.     createSymbolListWindow() {
  4193.         const rect = this.subWindowRect();
  4194.         const asw = new Window_InputSymbolList(rect);
  4195.         asw.setHandler('ok', this.onSymbolListOk.bind(this));
  4196.         asw.setHandler('cancel', this.onSymbolListCancel.bind(this));
  4197.         asw.hide();
  4198. //        asw.refresh();
  4199.         asw.setHelpWindow(this._helpWindow);
  4200.         this.addWindow(asw);
  4201.         this._symbolListWindow = asw;
  4202.     }
  4203.     popScene(){
  4204.         this._popSceneMode=true;
  4205.     }

  4206.     resetMapper(){
  4207.         const mainWindow = this.mainWidnow();
  4208.         mainWindow.resetMapper();
  4209.         mainWindow.playResetSound();
  4210.         mainWindow.refresh();
  4211.         mainWindow.redrawApplyCommand(mainWindow.isValidMapper());
  4212.         mainWindow.activate();
  4213.     }

  4214.     applyConfig(){
  4215.         const mainWindow = this.mainWidnow();
  4216.         if(mainWindow.isValidMapper()){
  4217.             mainWindow.playApplySound();
  4218.             this._applyOnExit = true;
  4219.             this.popScene();
  4220.         }else{
  4221.             mainWindow.playBuzzerSound();
  4222.             mainWindow.activate();
  4223.         }
  4224.     }
  4225.     isAllButtonDetouch(){
  4226.         return Input._latestButton===null;
  4227.     }

  4228.     isAnyButtonLongPressed(){
  4229.         return Input._pressedTime >60;
  4230.     }

  4231.     updateSceneChange(){
  4232.         if(this._popSceneMode ){
  4233.             if(this.isAnyButtonLongPressed()){
  4234.                 if(this._helpWindow){
  4235.                     this._helpWindow.setText(setting.text.needButtonDetouch.currentName());
  4236.                 }
  4237.             }
  4238.             if(this.isAllButtonDetouch()){
  4239.                 super.popScene();
  4240.                 return;
  4241.             }
  4242.         }
  4243.     }
  4244.     update(){
  4245.         this.updateSceneChange();
  4246.         super.update();
  4247.     }

  4248.     onConfigOk(){
  4249.         this.selectSymbol();
  4250.     }
  4251.     onConfigCancel() {
  4252.         SoundManager.playCancel();
  4253.         SceneManager.pop();
  4254.     }
  4255.     selectSymbol() {
  4256.         const currentSymbol = this.mainWidnow().currentSymbolString();
  4257.         this._symbolListWindow.show();
  4258.         this._symbolListWindow.activate();
  4259.         this._symbolListWindow.selectSymbol(currentSymbol);
  4260.     }
  4261.     /**
  4262.      * @return {Window_InputConfigBase}
  4263.      */
  4264.     mainWidnow() {
  4265.         return null;
  4266.     }

  4267.     /**
  4268.      * @returns {Window_Selectable}
  4269.      */
  4270.     subWindow(){
  4271.         return null;
  4272.     }

  4273.     currentSymbolObject(){
  4274.         return this._symbolListWindow.currentSymbolObject();
  4275.     }
  4276.     currentButtonCode(){
  4277.         throw (new Error("not imple"));
  4278.         return -1;
  4279.     }

  4280.     /**
  4281.      * @param {String} symbol
  4282.      * @param {Number} code
  4283.      */
  4284.     changeSymbolV9(symbol,code){

  4285.     }

  4286.     callChangeSymbol_v5(){


  4287.         const symbol =this.currentSymbolObject();
  4288.         if(!symbol){ return;}
  4289.         const code  = this.currentButtonCode();        
  4290.         if(isNaN(code)){return;}

  4291.         const mapper = this.mapperClass();
  4292.         //明示的な削除処理をあらかじめ用意する
  4293.         //実装を変える時にミスしがちなので、こうする
  4294.         if(symbol.isDeleter()){
  4295.             mapper.daleteByCode(code);
  4296.             this.redrawXXX();
  4297.             return;
  4298.         }

  4299.         const symbolString = symbol.symbol();
  4300.         if(mapper.canSymbolChange(symbolString,code)){
  4301.             mapper.change(code,symbolString);
  4302.             this.redrawXXX();
  4303.         }
  4304.     }
  4305.     redrawXXX(){
  4306.         const mainWindow = this.mainWidnow();
  4307.         mainWindow.redrawCurrentItem();
  4308.         mainWindow.redrawApplyCommand( mainWindow.canApplySetting() );
  4309.     }

  4310.     onSymbolListOk() {
  4311.         this.callChangeSymbol_v5();
  4312.         this.endSubWindowSelect();
  4313.     }
  4314.     onSymbolListCancel() {
  4315.         this.endSubWindowSelect();
  4316.     }
  4317.     endSubWindowSelect() {
  4318.         const sub = this.subWindow();
  4319.         sub.deselect();
  4320.         sub.hide();
  4321.         // this._symbolListWindow.deselect();
  4322.         // this._symbolListWindow.hide();
  4323.         this.mainWidnow().activate();
  4324.     }
  4325.     mapperClass(){
  4326.         return this.mainWidnow().temporaryMappper();
  4327.     }

  4328.     terminate(){
  4329.         super.terminate();
  4330.         if(this._applyOnExit){
  4331.             this.saveMapper();
  4332.             ConfigManager.save();
  4333.         }
  4334.     }
  4335.     saveMapper(){
  4336.         //override
  4337.     }
  4338. }


  4339. class Key_Base extends I_InputButton{
  4340.     /**
  4341.      * @returns {String}
  4342.      */
  4343.     get handle(){
  4344.         return "ok";
  4345.     }
  4346.     get locked(){
  4347.         return false;
  4348.     }
  4349.     get char(){
  4350.         return "";
  4351.     }
  4352.     get isLink(){
  4353.         return false;
  4354.     }
  4355.     get keycord(){
  4356.         return 0;
  4357.     }
  4358.     name(){
  4359.         return this.char;
  4360.     }
  4361.     mapperId(){
  4362.         return this.keycord;
  4363.     }
  4364.     /**
  4365.      * @param {Window_KeyConfig_MA} keyWindow
  4366.      * @param {Number} index
  4367.      */
  4368.     draw(keyWindow,index){
  4369.         this.drawBasicChar(keyWindow,index);
  4370.     }
  4371.     /**
  4372.      * @param {Window_KeyConfig_MA} keyWindow
  4373.      * @param {Number} index
  4374.      */
  4375.     redraw(keyWindow,index){
  4376.         this.drawBasicChar(keyWindow,index);
  4377.     }
  4378.     /**
  4379.      * @param {Number} index
  4380.      * @desc 一部の複数マスにまたがるキーのための機能 基本実装しないでいい
  4381.      */
  4382.     setIndex(index){

  4383.     }
  4384.     /**
  4385.      * @param {Window_KeyConfig_MA} keyWindow
  4386.      * @param {Number} index
  4387.      */
  4388.     drawBasicChar(keyWindow,index){
  4389.         const s = keyWindow.symbolObjectFromKeyNumber(this.keycord);
  4390.         const rect = keyWindow.itemRect(index);
  4391.         keyWindow.drawInputDefine(this,s,rect);
  4392.     }
  4393.     /**
  4394.      * @param {Window_KeyConfig_MA} keyWindow
  4395.      * @param {Number} index
  4396.      */
  4397.     rect(keyWindow,index){
  4398.         return keyWindow.baseRect(index);
  4399.     }
  4400. }
  4401. class Key_Null extends Key_Base{
  4402.     get locked(){
  4403.         return true;
  4404.     }
  4405.     /**
  4406.      * @param {Window_KeyConfig_MA} keyWindow
  4407.      * @param {Number} index
  4408.      */
  4409.     draw(keyWindow,index){}
  4410. }

  4411. class Key_Char extends Key_Base{
  4412.     /**
  4413.      * @param {String} char
  4414.      * @param {Number} keycord
  4415.      */
  4416.     constructor(char,keycord){
  4417.         super();
  4418.         this._char = char;
  4419.         this._keycord = keycord;
  4420.     }
  4421.     get char(){
  4422.         return this._char;
  4423.     }
  4424.     get keycord(){
  4425.         return this._keycord;
  4426.     }
  4427. }

  4428. class Key_Locked extends Key_Char{
  4429.     get locked(){
  4430.         return true;
  4431.     }
  4432. }

  4433. class Key_Big extends Key_Char{
  4434.     /**
  4435.      * @param {String} char
  4436.      * @param {Number} keycord
  4437.      * @param {Number} width
  4438.      * @param {Number} height
  4439.      * @param {boolean} looked
  4440.      */
  4441.     constructor(char,keycord,width,height,looked){
  4442.         super(char,keycord);
  4443.         this._widthEx=Math.max(width,1);
  4444.         this._heightEx=Math.max(height,1);
  4445.         this._locked = looked||false;
  4446.     }
  4447.     get locked(){
  4448.         return this._locked;
  4449.     }
  4450.     /**
  4451.      * @param {Window_KeyConfig_MA} keyWindow
  4452.      */
  4453.     rect(keyWindow){
  4454.         const rect = keyWindow.baseRect(this._index);
  4455.         rect.width *=this._widthEx;
  4456.         rect.height *= this._heightEx;
  4457.         return rect;
  4458.     }
  4459.     /**
  4460.      * @param {Number} index
  4461.      */
  4462.     setIndex(index){
  4463.         if(isNaN( this._index)){
  4464.             this._index = index;

  4465.         }
  4466.     }
  4467.     /**
  4468.      * @param {Window_KeyConfig_MA} keyWindow
  4469.      * @param {Number} index
  4470.      */
  4471.     draw(keyWindow,index){
  4472.         if(index ===this._index){
  4473.             super.draw(keyWindow,index);
  4474.         }
  4475.     }
  4476.     /**
  4477.      * @param {Window_KeyConfig_MA} keyWindow
  4478.      * @param {Number} index
  4479.      */
  4480.     redraw(keyWindow,index){
  4481.         super.draw(keyWindow,this._index);
  4482.     }
  4483. }

  4484. class Key_Command extends Key_Base{
  4485.     /**
  4486.      * @param {String} handlerName
  4487.      * @param {MultiLanguageText} mtext
  4488.      * @param {Number} width
  4489.      */
  4490.     constructor(handlerName,mtext,width){
  4491.         super();
  4492.         this._callBackHandle =handlerName;
  4493.         this._widthEx =width;
  4494.         this._mtext = mtext;
  4495.     }
  4496.     static create(objText,handler){
  4497.         const obj = JSON.parse(objText);
  4498.         return new Key_Command(
  4499.             handler,
  4500.             MultiLanguageText.create(obj.text),
  4501.             Number(obj.width)
  4502.         );
  4503.     }
  4504.     get char(){
  4505.         return this._mtext.currentName();
  4506.     }
  4507.     text(){
  4508.         return this.char;
  4509.     }


  4510.     get isLink(){
  4511.         return this._widthEx >1;
  4512.     }
  4513.     get locked(){
  4514.         return false;
  4515.     }
  4516.     get keycord(){
  4517.         return 0;
  4518.     }
  4519.     get isCommand(){
  4520.         return true;
  4521.     }
  4522.     get handle(){
  4523.         return this._callBackHandle;
  4524.     }
  4525.     /**
  4526.      * @param {Window_KeyConfig_MA} keyConfigWindow
  4527.      */
  4528.     onOk(keyConfigWindow){
  4529.         keyConfigWindow.callHandler(this._callBackHandle);
  4530.     }
  4531.     /**
  4532.      * @param {Number} index
  4533.      */
  4534.     setIndex(index){
  4535.         if(isNaN(this._index)){
  4536.             this._index = index;
  4537.         }
  4538.     }

  4539.     /**
  4540.      * @param {Window_KeyConfig_MA} keyWindow
  4541.      * @param {Number} index
  4542.      */
  4543.     rect(keyWindow,index){
  4544.         const rect = keyWindow.baseRect(this._index);
  4545.         rect.width *=this._widthEx;
  4546.         return rect;
  4547.     }
  4548.     /**
  4549.      * @param {Window_KeyConfig_MA} keyWindow
  4550.      * @param {Number} index
  4551.      */
  4552.     draw(keyWindow,index){
  4553.       if(index ===this._index){
  4554.         const rect = this.rect(keyWindow,index);
  4555.         keyWindow.drawCommandXX(this.char,rect);
  4556.       }
  4557.     }
  4558.     helpText(){
  4559.         return "コマンドのヘルプ";
  4560.     }
  4561. }
  4562. //TODO:ゲームパッドのボタン配置切り換え…というか、ハードメーカー別の対応
  4563. function createButtonLayoutChangeCommand(){
  4564.     const mText = new MultiLanguageText("Change button notation","ボタン表記変更");
  4565.     const command = new Key_Command("ButtonLayout",mText,3);
  4566.     return command;
  4567. }

  4568. class Key_CommandManager_T{
  4569.     constructor(){
  4570.         const params = getParam();
  4571.         this._apply =Key_Command.create(params.apply,"apply");
  4572.         this._wasd=Key_Command.create(params.WASD,"WASD");
  4573.         this._exit=Key_Command.create(params.exit,"exit");
  4574.         this._reset=Key_Command.create(params.reset,"reset");
  4575.         //this._alt = Key_Command.create(params.style,"ALT");
  4576.         this._changeButtonLayout =createButtonLayoutChangeCommand();
  4577.         this._changeLayout=Key_Command.create(params.changeLayout,"keylayout");

  4578.     }
  4579.     buttonLayout(){
  4580.         return this._changeButtonLayout;
  4581.     }
  4582.     keylayout(){
  4583.         return this._changeLayout;
  4584.     }
  4585.     getKeylayoutText(){
  4586.         return this._changeLayout.text();
  4587.     }
  4588.     wasd(){
  4589.         return this._wasd;
  4590.     }
  4591.     getWasdText(){
  4592.         return this._wasd.text();
  4593.     }
  4594.     reset(){
  4595.         return this._reset;
  4596.     }
  4597.     getResetText(){
  4598.         return this._reset.text();
  4599.     }
  4600.     apply(){
  4601.         return this._apply
  4602.     }
  4603.     getApplyText(){
  4604.         return this._apply.text();
  4605.     }
  4606.     // alt(){
  4607.     //     return this._alt;
  4608.     // }
  4609.     exit(){
  4610.         return this._exit;
  4611.     }
  4612.     getExitText(){
  4613.         return this._exit.text();
  4614.     }
  4615.     createCommandList_ForKeyLayout(){
  4616.         const commandList =[
  4617.             this._reset,
  4618.             this._apply,
  4619.             this._wasd,
  4620.             this._changeLayout,
  4621.             this._exit
  4622.         ];
  4623.         const result =[];
  4624.         for (const iterator of commandList) {
  4625.             for(var i=0; i <iterator._widthEx;++i){
  4626.                 result.push(iterator);
  4627.             }
  4628.         }
  4629.         return result;
  4630.     }
  4631.     createCommandList_ForGamepad(){
  4632.         const layout = this.buttonLayout();
  4633.         const exit =this.exit();
  4634.         const reset =this.reset()
  4635.         //const alt = this.alt();
  4636.         const apply = this.apply();
  4637.         return [
  4638.             apply,
  4639.             reset,
  4640.             layout,
  4641.             exit
  4642.         ];

  4643.     }
  4644. }
  4645. const CommandManager =(function(){

  4646.     return new Key_CommandManager_T();
  4647. })()
  4648. /**
  4649. * @param {string} char
  4650. * @param {number} keycord
  4651. */
  4652. function keyinfo(char,keycord){
  4653.     return new Key_Char(char,keycord);
  4654. }


  4655. const WASD_KEYMAP={
  4656.     81:"pageup",    //Q
  4657.     69:"pagedown",  //E
  4658.     87:"up",        //W
  4659.     65:"left",      //A
  4660.     83:"down",      //S
  4661.     68:"right",     //D
  4662. };

  4663. const KEYS ={
  4664.     SPACE: new Key_Big("Space",32,4,1,false),
  4665.     ENTER_JIS: new Key_Big('Enter',13,2,2,true),
  4666.     ENTER_US:new Key_Big("Entre",13,3,1,true),
  4667.     NULL:new Key_Null(),
  4668.     UP:new Key_Locked(setting.keyText.up,38),
  4669.     DOWN:new Key_Locked(setting.keyText.down,40),
  4670.     LEFT:new Key_Locked(setting.keyText.left,37),
  4671.     RIGHT:new Key_Locked(setting.keyText.right,39),
  4672.     TENKEY0:new Key_Big('0',96,2,1,false),
  4673.     TENKEY1:keyinfo('1',97),
  4674.     TENKEY2:keyinfo('2',98),
  4675.     TENKEY3:keyinfo('3',99),
  4676.     TENKEY4:keyinfo('4',100),
  4677.     TENKEY5:keyinfo('5',101),
  4678.     TENKEY6:keyinfo('6',102),
  4679.     TENKEY7:keyinfo('7',103),
  4680.     TENKEY8:keyinfo('8',104),
  4681.     TENKEY9:keyinfo('9',105),
  4682.     TENKEY_DOT:keyinfo('.',110),
  4683.     TAB:keyinfo("TAB",9),
  4684.     _0:keyinfo('0',48),
  4685.     _1:keyinfo('1',49),
  4686.     _2:keyinfo('2',50),
  4687.     _3:keyinfo('3',51),
  4688.     _4:keyinfo('4',52),
  4689.     _5:keyinfo('5',53),
  4690.     _6:keyinfo('6',54),
  4691.     _7:keyinfo('7',55),
  4692.     _8:keyinfo('8',56),
  4693.     _9:keyinfo('9',57),

  4694.     A:keyinfo('A',65),
  4695.     B:keyinfo('B',66),
  4696.     C:keyinfo('C',67),
  4697.     D:keyinfo('D',68),
  4698.     E:keyinfo('E',69),
  4699.     F:keyinfo('F',70),
  4700.     G:keyinfo('G',71),
  4701.     H:keyinfo('H',72),
  4702.     I:keyinfo('I',73),
  4703.     J:keyinfo('J',74),
  4704.     K:keyinfo('K',75),
  4705.     L:keyinfo('L',76),
  4706.     M:keyinfo('M',77),
  4707.     N:keyinfo('N',78),
  4708.     O:keyinfo('O',79),
  4709.     P:keyinfo('P',80),
  4710.     Q:keyinfo('Q',81),
  4711.     R:keyinfo('R',82),
  4712.     S:keyinfo('S',83),
  4713.     T:keyinfo('T',84),
  4714.     U:keyinfo('U',85),
  4715.     V:keyinfo('V',86),
  4716.     W:keyinfo('W',87),
  4717.     X:keyinfo('X',88),
  4718.     Y:keyinfo('Y',89),
  4719.     Z:keyinfo('Z',90),

  4720.     SHIFT:new Key_Locked('Shift',16),
  4721.     CTRL:new Key_Locked('CTRL',17),
  4722.     INSERT:keyinfo('Ins',45),
  4723.     BACK:keyinfo('Back',8),
  4724.     HOME:keyinfo('Home',36),
  4725.     END:keyinfo('End',35),
  4726.     PAGEUP:keyinfo('PgUp',33),
  4727.     PAGEDOWN:keyinfo('PgDn',34),
  4728.     ESC:keyinfo('esc',27),

  4729.     ATMARK:keyinfo("@", 192),

  4730.     TENKEY_MINUS :keyinfo('-',109),
  4731.     TENKEY_PLUS :keyinfo('+',107),
  4732.     MINUS :keyinfo('-',189),
  4733.     COMMA :keyinfo(',',188),
  4734.     SEMICOLON:keyinfo(';',186),

  4735.     SLASH:keyinfo('/',191),
  4736.     BACKSLASH:keyinfo('\\',226),
  4737.     DOT :keyinfo('.',190),
  4738.    
  4739.     COLON:keyinfo(':',58),
  4740.     CARET:keyinfo('^',222),
  4741.     APOSTROPHE:keyinfo("'",222),

  4742.     EQUAL_JIS:keyinfo('=',189),
  4743.    
  4744.     SQUARE_BRACKETS_OPEN :keyinfo('[',219),
  4745.     SQUARE_BRACKETS_CLOSE :keyinfo(']',221),
  4746. };
  4747. const keyXXXX =[
  4748.     KEYS.A,KEYS.B,KEYS.C,KEYS.D,
  4749.     KEYS.E,KEYS.F,KEYS.G,
  4750.     KEYS.H,KEYS.I,KEYS.J,KEYS.K,
  4751.     KEYS.L,KEYS.M,KEYS.N,
  4752.     KEYS.O,KEYS.P,KEYS.Q,KEYS.R,
  4753.     KEYS.S,KEYS.T,KEYS.U,
  4754.     KEYS.V,KEYS.W, KEYS.X,KEYS.Y,KEYS.Z,
  4755.     KEYS._0,KEYS._1,KEYS._2,KEYS._3,KEYS._4,
  4756.     KEYS._5,KEYS._6,KEYS._7,KEYS._8,KEYS._9
  4757. ];
  4758. class Key_Layout extends InputDeviceBase{
  4759.     /**
  4760.      * @param {Key_Base[]} keyList
  4761.      */
  4762.     static keylayout_SetupIndex(keyList){
  4763.         for (let index = 0; index < keyList.length; index++) {
  4764.             const element = keyList[index];
  4765.             element.setIndex(index);
  4766.         }
  4767.     }

  4768.     indexList(){
  4769.         return keyXXXX;
  4770.     }
  4771.     button(buttonCode){
  4772.         return null;
  4773.     }
  4774.     /**
  4775.      * @param {String} layoutName
  4776.      * @param {Key_Base[]} srcList
  4777.      */
  4778.     constructor(layoutName,srcList){
  4779.         super();
  4780.         this._name = layoutName;
  4781.         this._buttonItems = srcList.length;
  4782.         const list = srcList.concat(CommandManager.createCommandList_ForKeyLayout());
  4783.         Key_Layout.keylayout_SetupIndex(list);
  4784.         this._list =list;//Object.freeze( list);
  4785.         this._enterKeyIndex = this._list.indexOf(KEYS.ENTER_JIS);
  4786.     }

  4787.     numButtons(){
  4788.         return this._buttonItems;
  4789.     }
  4790.     buttonList(){
  4791.         return this._list;
  4792.     }
  4793.     /**
  4794.      * @param {Key_Big} enter
  4795.      */
  4796.     setEnterKey(enter){
  4797.         this._enter=enter;
  4798.     }
  4799.     defaultMapper(){
  4800.         return Mano_InputConfig.defaultKeyMapper;
  4801.     }
  4802.     currentMapper(){
  4803.         return Input.keyMapper;
  4804.     }
  4805. }

  4806. const KEY_LAYOUT_JIS=(function(){
  4807.     const list =[
  4808.         KEYS.ESC,
  4809.         KEYS._1 ,
  4810.         KEYS._2 ,
  4811.         KEYS._3 ,
  4812.         KEYS._4,
  4813.         KEYS._5,
  4814.         KEYS._6,
  4815.         KEYS._7,
  4816.         KEYS._8,
  4817.         KEYS._9,
  4818.         KEYS._0,
  4819.         KEYS.MINUS,
  4820.         KEYS.CARET,
  4821.         KEYS.INSERT ,
  4822.         KEYS.BACK ,
  4823.         KEYS.HOME ,
  4824.         KEYS.END ,
  4825.         KEYS.PAGEUP ,
  4826.         KEYS.PAGEDOWN ,
  4827.    
  4828.         KEYS.TAB,
  4829.    
  4830.         KEYS.Q ,
  4831.         KEYS.W ,
  4832.         KEYS.E ,
  4833.         KEYS.R ,
  4834.         KEYS.T ,
  4835.         KEYS.Y ,
  4836.         KEYS.U ,
  4837.         KEYS.I ,
  4838.         KEYS.O ,
  4839.         KEYS.P ,
  4840.         KEYS.ATMARK,
  4841.         KEYS.SQUARE_BRACKETS_OPEN,
  4842.         KEYS.ENTER_JIS,
  4843.         KEYS.ENTER_JIS,
  4844.         KEYS.TENKEY7 ,
  4845.         KEYS.TENKEY8 ,
  4846.         KEYS.TENKEY9 ,
  4847.         KEYS.TENKEY_MINUS,
  4848.         KEYS.NULL,
  4849.         KEYS.A ,
  4850.         KEYS.S ,
  4851.         KEYS.D ,
  4852.         KEYS.F ,
  4853.         KEYS.G ,
  4854.         KEYS.H ,
  4855.         KEYS.J ,
  4856.         KEYS.K ,
  4857.         KEYS.L ,
  4858.         KEYS.SEMICOLON,
  4859.         KEYS.COLON,
  4860.         KEYS.SQUARE_BRACKETS_CLOSE,
  4861.         KEYS.ENTER_JIS,
  4862.         KEYS.ENTER_JIS,
  4863.         KEYS.TENKEY4 ,
  4864.         KEYS.TENKEY5 ,
  4865.         KEYS.TENKEY6 ,
  4866.         KEYS.TENKEY_PLUS,
  4867.    
  4868.         KEYS.SHIFT ,
  4869.         KEYS.Z ,
  4870.         KEYS.X ,
  4871.         KEYS.C ,
  4872.         KEYS.V ,
  4873.         KEYS.B ,
  4874.         KEYS.N ,
  4875.         KEYS.M ,
  4876.         KEYS.COMMA,
  4877.         KEYS.DOT,
  4878.         KEYS.SLASH,
  4879.         
  4880.         KEYS.BACKSLASH,
  4881.         KEYS.SHIFT,
  4882.         KEYS.UP,
  4883.         KEYS.NULL,
  4884.         
  4885.         KEYS.TENKEY1 ,
  4886.         KEYS.TENKEY2 ,
  4887.         KEYS.TENKEY3 ,
  4888.         KEYS.NULL,
  4889.    
  4890.         KEYS.CTRL  ,
  4891.         KEYS.NULL,
  4892.         KEYS.NULL,
  4893.         KEYS.NULL,
  4894.         KEYS.SPACE,
  4895.         KEYS.SPACE,
  4896.         KEYS.SPACE,
  4897.         KEYS.SPACE,
  4898.         KEYS.NULL,
  4899.         KEYS.NULL,
  4900.         KEYS.NULL,
  4901.         KEYS.NULL,
  4902.         KEYS.LEFT,
  4903.         KEYS.DOWN,
  4904.         KEYS.RIGHT,
  4905.         KEYS.TENKEY0,
  4906.         KEYS.TENKEY0,
  4907.         KEYS.TENKEY_DOT,
  4908.         KEYS.NULL,
  4909.     ];
  4910.     const layout= new Key_Layout("JIS",list);
  4911.     layout.setEnterKey(KEYS.ENTER_JIS);
  4912.     return Object.freeze( layout);
  4913. })();
  4914. const KEY_LAYOUT_US =(function(){
  4915.     const list =[    KEYS.ESC,
  4916.         KEYS._1 ,
  4917.         KEYS._2 ,
  4918.         KEYS._3 ,
  4919.         KEYS._4,
  4920.         KEYS._5,
  4921.         KEYS._6,
  4922.         KEYS._7,
  4923.         KEYS._8,
  4924.         KEYS._9,
  4925.         KEYS._0,
  4926.         KEYS.MINUS,
  4927.         KEYS.EQUAL_JIS,
  4928.         KEYS.INSERT ,
  4929.         KEYS.BACK ,
  4930.         KEYS.HOME ,
  4931.         KEYS.END ,
  4932.         KEYS.PAGEUP ,
  4933.         KEYS.PAGEDOWN ,
  4934.    
  4935.         KEYS.TAB,
  4936.         KEYS.Q ,
  4937.         KEYS.W ,
  4938.         KEYS.E ,
  4939.         KEYS.R ,
  4940.         KEYS.T ,
  4941.         KEYS.Y ,
  4942.         KEYS.U ,
  4943.         KEYS.I ,
  4944.         KEYS.O ,
  4945.         KEYS.P ,
  4946.         KEYS.SQUARE_BRACKETS_OPEN,
  4947.         KEYS.SQUARE_BRACKETS_CLOSE,
  4948.         KEYS.BACKSLASH,
  4949.         KEYS.NULL,
  4950.         KEYS.TENKEY7 ,
  4951.         KEYS.TENKEY8 ,
  4952.         KEYS.TENKEY9 ,
  4953.         KEYS.TENKEY_MINUS,
  4954.         KEYS.NULL,
  4955.         KEYS.A ,
  4956.         KEYS.S ,
  4957.         KEYS.D ,
  4958.         KEYS.F ,
  4959.         KEYS.G ,
  4960.         KEYS.H ,
  4961.    
  4962.         KEYS.J ,
  4963.         KEYS.K ,
  4964.         KEYS.L ,
  4965.         KEYS.SEMICOLON,
  4966.         KEYS.APOSTROPHE,
  4967.         KEYS.ENTER_US,
  4968.         KEYS.ENTER_US,
  4969.         KEYS.ENTER_US,
  4970.         KEYS.TENKEY4 ,
  4971.         KEYS.TENKEY5 ,
  4972.         KEYS.TENKEY6 ,
  4973.         KEYS.TENKEY_PLUS,

  4974.         KEYS.SHIFT ,
  4975.         KEYS.Z ,
  4976.         KEYS.X ,
  4977.         KEYS.C ,
  4978.         KEYS.V ,
  4979.         KEYS.B ,
  4980.         KEYS.N ,
  4981.         KEYS.M ,
  4982.         KEYS.COMMA,
  4983.         KEYS.DOT,
  4984.         KEYS.SLASH,
  4985.         
  4986.         KEYS.NULL,
  4987.         KEYS.SHIFT,
  4988.         KEYS.UP,
  4989.         KEYS.NULL,
  4990.         
  4991.         KEYS.TENKEY1 ,
  4992.         KEYS.TENKEY2 ,
  4993.         KEYS.TENKEY3 ,
  4994.         KEYS.NULL,
  4995.         
  4996.         KEYS.CTRL  ,
  4997.         KEYS.NULL,
  4998.         KEYS.NULL,
  4999.         KEYS.NULL,
  5000.         KEYS.SPACE,
  5001.         KEYS.SPACE,
  5002.         KEYS.SPACE,
  5003.         KEYS.SPACE,
  5004.         KEYS.NULL,
  5005.         KEYS.NULL,
  5006.         KEYS.NULL,
  5007.         KEYS.NULL,
  5008.         KEYS.LEFT,
  5009.         KEYS.DOWN,
  5010.         KEYS.RIGHT,
  5011.         KEYS.TENKEY0,
  5012.         KEYS.TENKEY0,
  5013.         KEYS.TENKEY_DOT,
  5014.         KEYS.NULL,
  5015.     ];
  5016.     const layout =new Key_Layout("US",list);
  5017.     layout.setEnterKey(KEYS.ENTER_US);
  5018.     return Object.freeze( layout);
  5019. })();

  5020. /**
  5021. * @returns {Readonly<InputDeviceBase>}
  5022. */
  5023. function getCurrentDevice(){
  5024.     if(setting.gamepad.isConected()){
  5025.         return setting.gamepad;
  5026.     }
  5027.     return KEY_LAYOUT_JIS;
  5028. }
  5029. //TODO:カーソル移動に異常があるので修正する
  5030. class Window_KeyConfig_MA extends Window_InputConfigBase {

  5031.     initializeMapper(){
  5032.         const device = this.inputDevice();
  5033.         this._mapper217 = device.createTemporaryMapper();
  5034.          //new TemporaryMappper(device.currentMapper());
  5035.     }
  5036.     temporaryMappper(){
  5037.         return this._mapper217;
  5038.     }
  5039.     /**
  5040.      * @param {Rectangle} rect
  5041.      */
  5042.     initialize(rect) {
  5043.         //@ts-ignore
  5044.         this.setKeyLayout(ConfigManager.keyLayout_MA);
  5045.         super.initialize(rect);
  5046.         this.refresh();
  5047.         this.activate();
  5048.         this.select(0);
  5049.     }

  5050.     lineHeight(){
  5051.         return setting.keyWindowLineHeight;
  5052.     }

  5053.     mainFontFace(){
  5054.         if(Utils.RPGMAKER_NAME ==="MV"){
  5055.             return this.standardFontFace();
  5056.         }
  5057.         return $gameSystem.mainFontFace();
  5058.     }
  5059.     resetFontSettings(){
  5060.         this.contents.fontFace = this.mainFontFace();
  5061.         this.contents.fontSize = this.lineHeight()-2;//$gameSystem.mainFontSize();
  5062.         this.resetTextColor();
  5063.     }
  5064.     setWASD_Move(){
  5065.         for (const key in WASD_KEYMAP) {
  5066.             if (WASD_KEYMAP.hasOwnProperty(key)) {
  5067.                 const element = WASD_KEYMAP[key];
  5068.                 this._mapper217.change(Number(key),element);
  5069.             }
  5070.         }
  5071.         this.refresh();
  5072.     }
  5073.     /**
  5074.      * @param {String} layoutText
  5075.      */
  5076.     setKeyLayout(layoutText){
  5077.         this._layout = layoutText ==="JIS"? KEY_LAYOUT_JIS : KEY_LAYOUT_US;
  5078.     }
  5079.     inputDevice(){
  5080.         return this._layout;
  5081.     }
  5082.     getKeyLayout() {
  5083.         return this._layout._name;
  5084.     }
  5085.     itemTextAlign() {
  5086.         return 'center';
  5087.     }
  5088.     exitCommandIndex(){
  5089.         return CommandManager.exit()._index;
  5090.     }
  5091.     processChangeLayout() {
  5092.         this.playLayoutChangeSound();
  5093.         const L = this.getKeyLayout();
  5094.         if (L !== 'JIS') {
  5095.             this.setKeyLayout('JIS');
  5096.         }
  5097.         else {
  5098.             this.setKeyLayout('US');
  5099.         }
  5100.         this.refresh();
  5101.     }
  5102.     processOk() {
  5103.         const index = this.index();
  5104.         if (index < 0) {
  5105.             return;
  5106.         }
  5107.         const item = this.item(index);
  5108.         if(!item){
  5109.             this.playBuzzerSound();
  5110.             return;
  5111.         }
  5112.         if(item.locked){
  5113.             this.playBuzzerSound();
  5114.             return;
  5115.         }
  5116.         if(item.handle==="ok"){
  5117.             this.playSymbolSetSound()
  5118.             this.updateInputData();
  5119.             this.deactivate();
  5120.             this.callOkHandler();
  5121.             return
  5122.         }
  5123.         this.callHandler(item.handle);
  5124.     }
  5125.     itemHeight() {
  5126.         return this.lineHeight() * 2;
  5127.     }
  5128.     maxPageRows() {
  5129.         return 100;
  5130.     }
  5131.     maxCols() {
  5132.         return 19;
  5133.     }
  5134.     numVisibleRows() {
  5135.         return this._layout._list.length;
  5136.     }
  5137.     /**
  5138.      * @param {Number} index
  5139.      */
  5140.     baseRect(index){
  5141.         return super.itemRect(index);
  5142.     }
  5143.     /**
  5144.      * @param {Number} index
  5145.      */
  5146.     itemRect(index){
  5147.         const item = this.item(index);
  5148.         if(!item){
  5149.             return new Rectangle(Number.MIN_SAFE_INTEGER,Number.MIN_SAFE_INTEGER,0,0);
  5150.         }
  5151.         return item.rect(this,index);
  5152.     }
  5153.     maxItems() {
  5154.         return this._layout.buttonList().length;
  5155.     }
  5156.     spacing() {
  5157.         return 0;
  5158.     }
  5159.     /**
  5160.      * @param {number}index
  5161.      */
  5162.     keyNumber(index) {
  5163.         return this.item(index).keycord;
  5164.     }
  5165.     currentButtonCode() {
  5166.         return this.keyNumber(this.index());
  5167.     }
  5168.     keyName(index) {
  5169.         return this.item(index).char;
  5170.     }

  5171.     cursorUp(wrap) {
  5172.         if (wrap || this._index >= this.maxCols()) {
  5173.             this.cursorMoveCheck(-this.maxCols());
  5174.         }
  5175.     }
  5176.     cursorDown(wrap) {
  5177.         if (wrap || this._index < this.maxItems() - this.maxCols()) {
  5178.             this.cursorMoveCheck(this.maxCols());
  5179.         }
  5180.     }
  5181.     cursorLeft(wrap) {
  5182.         if (wrap || this._index > 0) {
  5183.             this.cursorMoveCheck(-1);
  5184.         }
  5185.     }
  5186.     cursorRight(wrap) {
  5187.         if (wrap || this._index < this.maxItems() - 1) {
  5188.             this.cursorMoveCheck(1);
  5189.         }
  5190.     }
  5191.     nextIndex(current, moveDir) {
  5192.         const maxItems = this.maxItems();
  5193.         return (current + moveDir + maxItems) % maxItems;
  5194.     }
  5195.     cursorMoveCheck(moveDir) {
  5196.         const current = this.index();
  5197.         let next = this.nextIndex(current, moveDir);
  5198.         const last = Math.abs(this.maxItems() / moveDir);
  5199.         for (var i = 0; i < last; ++i) {
  5200.             const itemA = this.item(current);
  5201.             const itemB = this.item(next);
  5202.             if (itemB === KEYS.NULL) {
  5203.                 break;
  5204.             }
  5205.             if (itemA !== itemB) {
  5206.                 break;
  5207.             }
  5208.             next = this.nextIndex(next, moveDir);
  5209.         }
  5210.         this.select(next);
  5211.     }
  5212.     symbolTextColor() {
  5213.         return this.textColor(4);
  5214.     }
  5215.     /**
  5216.      * @param {I_SymbolDefine} inputDef
  5217.      * @param {Rectangle} rect
  5218.      */
  5219.     drawKeyback(inputDef,rect){
  5220.         if(!inputDef){
  5221.             this.drawSymbolBack(rect,SymbolColorManager.emptyColor());
  5222.             return;
  5223.         }
  5224.         if(inputDef.isParamatorValid()){
  5225.             this.drawSymbolBack(rect,inputDef.backColor());
  5226.         }else{
  5227.             this.drawSymbolBack(rect,SymbolColorManager.paramatorInvalidColor());
  5228.         }
  5229.     }
  5230.     /**
  5231.      * @param {Key_Base} key
  5232.      * @param {I_SymbolDefine} inputDef
  5233.      * @param {Rectangle} rect
  5234.      */
  5235.     drawInputDefine(key,inputDef,rect){
  5236.         this.drawKeyback(inputDef,rect);
  5237.         this.drawText(key.char,rect.x,rect.y,rect.width,"center");
  5238.         if(inputDef && !inputDef.isEmpty()){
  5239.             const symbolY = rect.y + this.lineHeight()-6;
  5240.             this.drawText(inputDef.displayKeyName(),rect.x,symbolY,rect.width,"center");
  5241.         }
  5242.     }

  5243.     /**
  5244.      * @param {Number} index
  5245.      * @returns
  5246.      */
  5247.     symbolString(index){
  5248.         const keyNumber = this.keyNumber(index);
  5249.         return this.temporaryMappper().findSymbolByCode(keyNumber);
  5250.     }
  5251.     /**
  5252.      * @param {Number} index
  5253.      */
  5254.     symbolObject(index) {
  5255.         const keyNumber = this.keyNumber(index);
  5256.         return this.symbolObjectFromKeyNumber(keyNumber);
  5257.     }

  5258.     symbolObjectFromKeyNumber(keyNumber){
  5259.         const symbol = this.temporaryMappper().findSymbolByCode(keyNumber)
  5260.         return symbolManager.findSymbol(symbol);
  5261.     }

  5262.     /**
  5263.      * @param {Number} index
  5264.      * @desc 画面に表示するシンボル文字列の取得
  5265.      */
  5266.     symbolText(index) {
  5267.         const symbol = this.symbolString(index);
  5268.         return symbol;
  5269.     }
  5270.     /**
  5271.      * @param {Number} index
  5272.      */
  5273.     item(index){
  5274.         return this._layout.buttonList()[index];
  5275.     }
  5276.     /**
  5277.      * @param {Number} index
  5278.      */
  5279.     drawItem(index){
  5280.         const item = this.item(index);
  5281.         if(item){
  5282.             item.draw(this,index);
  5283.         }
  5284.     }
  5285.     redrawItem(index){
  5286.         const item = this.item(index);
  5287.         if(item){
  5288.             this.clearItem(index);
  5289.             item.redraw(this,index);
  5290.         }
  5291.     }

  5292.     commandBackColor() {
  5293.         return getColorSrc(this).gaugeBackColor();
  5294.     }
  5295.     commandColor() {
  5296.         return getColorSrc(this).normalColor();
  5297.     }
  5298.     /**
  5299.      * @param {String} commandName
  5300.      * @param {MyRectType} rect
  5301.      */
  5302.     drawCommandXX(commandName, rect) {
  5303.         this.drawSymbolBack(rect, this.commandBackColor());
  5304.         this.changeTextColor(this.commandColor());
  5305.         this.drawText(commandName, rect.x, rect.y, rect.width, 'center');
  5306.     }
  5307. }

  5308. class Scene_KeyConfig_MA extends Scene_InputConfigBase_MA{
  5309.     helpWindowLines(){
  5310.         return 2;
  5311.     }
  5312.     backBitmap(){
  5313.         if(setting.keyBackground){
  5314.             return ImageManager.loadTitle1(setting.keyBackground);
  5315.         }
  5316.         return null;
  5317.     }

  5318.     create() {
  5319.         super.create();
  5320.         this.createHelpWindow();
  5321.         this.createKeyboradConfigWindow();
  5322.         this.createSymbolListWindow();
  5323.     }
  5324.     onKeyLayoutOk(){
  5325.         this._keyconfigWindow.processChangeLayout();
  5326.     }
  5327.     configKey(){
  5328.         return MA_KEYBOARD_CONFIG;
  5329.     }
  5330.     saveMapper(){
  5331.         Input.keyMapper = this._keyconfigWindow.cloneMapper();
  5332.     }
  5333.     setWASD_Move(){
  5334.         this._keyconfigWindow.setWASD_Move();
  5335.         this._keyconfigWindow.playApplySound();
  5336.     }
  5337.     keyconfigWindowRect(){
  5338.         return this.mainWindowRect();
  5339.     }
  5340.     calcKeyWindowHeight(){
  5341.         const lineHeight =0;
  5342.         return 12*24;
  5343.     }
  5344.     createKeyboradConfigWindow() {
  5345.         const rect = this.keyconfigWindowRect();
  5346.         const kcw = new Window_KeyConfig_MA(rect);
  5347.         kcw.setHandler('cancel', this.onConfigCancel.bind(this));
  5348.         kcw.setHandler('ok', this.onConfigOk.bind(this));
  5349.         kcw.setHandler(CommandManager.reset().handle, this.resetMapper.bind(this));
  5350.         kcw.setHandler(CommandManager.apply().handle, this.applyConfig.bind(this));
  5351.         kcw.setHandler(CommandManager.wasd().handle,this.setWASD_Move.bind(this));
  5352.         kcw.setHandler(CommandManager.keylayout().handle,this.onKeyLayoutOk.bind(this));
  5353.         kcw.setHandler(CommandManager.exit().handle,this.onConfigCancel.bind(this));
  5354.         kcw.setHelpWindow(this._helpWindow);
  5355.         this.addWindow(kcw);
  5356.         this._keyconfigWindow = kcw;
  5357.     }
  5358.     mainWidnow() {
  5359.         return this._keyconfigWindow;
  5360.     }
  5361.     subWindow(){
  5362.         return this._symbolListWindow;
  5363.     }
  5364.     currentButtonCode(){
  5365.         return this._keyconfigWindow.currentButtonCode();
  5366.     }
  5367. }



  5368.     const Window_Options_addVolumeOptions=Window_Options.prototype.addVolumeOptions;
  5369.     Window_Options.prototype.addVolumeOptions=function(){
  5370.         Window_Options_addVolumeOptions.call(this);
  5371.         this.addCommand(currentGamepadConfigText(),MA_GAMEPAD_CONFIG,true);
  5372.         this.addCommand(currentKeyConfigText(),MA_KEYBOARD_CONFIG,true);
  5373.     }
  5374.     const Window_Options_statusText=Window_Options.prototype.statusText;
  5375.     /**
  5376.      * @param {Number} index
  5377.      * @returns
  5378.      */
  5379.     Window_Options.prototype.statusText =function(index){
  5380.         const symbol=this.commandSymbol(index)
  5381.         if(symbol===MA_GAMEPAD_CONFIG){
  5382.             return "";
  5383.         }
  5384.         if(symbol===MA_KEYBOARD_CONFIG){
  5385.             return "";
  5386.         }
  5387.         return Window_Options_statusText.call(this,index);
  5388.     }

  5389.     const Window_Options_processOk = Window_Options.prototype.processOk;
  5390.     Window_Options.prototype.processOk =function(){
  5391.         Window_Options_processOk.call(this);
  5392.         if(SceneManager.isSceneChanging()){
  5393.             return;
  5394.         }
  5395.         if(this.currentSymbol()===MA_GAMEPAD_CONFIG){
  5396.             this.playOkSound();
  5397.             Mano_InputConfig.gotoGamepad();
  5398.             return;
  5399.         }
  5400.         if(this.currentSymbol()===MA_KEYBOARD_CONFIG){
  5401.             this.playOkSound();
  5402.             Mano_InputConfig.gotoKey();
  5403.             return;
  5404.         }
  5405.     };
  5406. function setupPP_option(){
  5407.     //これ以外の方法だと、変数が宣言されていないエラーで死ぬ
  5408.     if(!Imported.PP_Option){
  5409.         return;
  5410.     }
  5411.     if(PP_Option && PP_Option.Manager){
  5412.         PP_Option.Manager.addOptionEX(MA_GAMEPAD_CONFIG, currentGamepadConfigText,function(w,s,i){
  5413.             Mano_InputConfig.gotoGamepad();
  5414.         });
  5415.         PP_Option.Manager.addOptionEX(MA_KEYBOARD_CONFIG, currentKeyConfigText,function(w,s,i){
  5416.             Mano_InputConfig.gotoKey();
  5417.         });   
  5418.     }
  5419. }
  5420. function setupDefaultMapper(){
  5421.     //メモ
  5422.     //この処理はConfigManager.load()よりも先に行う必要がある。
  5423.     //MVでの挙動が怪しい予感はする
  5424.     symbolManager.onBoot();
  5425.     //TODO:これの型を変更する 変数の保存場所も変更する
  5426.     Mano_InputConfig.defaultGamepadMapper =Object.freeze( objectClone(Input.gamepadMapper));
  5427.     Mano_InputConfig.defaultKeyMapper= Object.freeze(objectClone(Input.keyMapper));
  5428.     InputConfigManager.makeDefaultMapper();
  5429. }
  5430. const DataManager_loadDatabase=DataManager.loadDatabase;
  5431. DataManager.loadDatabase =function(){
  5432.     DataManager_loadDatabase.call(this);
  5433.     //メモ・MV/MZの双方で、ここの方がタイミングとして安全
  5434.     setupDefaultMapper();
  5435.     setupPP_option();
  5436. };
  5437. const Game_Map_setupStartingEvent =Game_Map.prototype.setupStartingEvent;
  5438. Game_Map.prototype.setupStartingEvent =function(){
  5439.     symbolManager.callButtonEvent();
  5440.     return Game_Map_setupStartingEvent.call(this);
  5441. };

  5442. // const Scene_Boot_onDatabaseLoaded =Scene_Boot.prototype.onDatabaseLoaded ||(function(){});
  5443. // Scene_Boot.prototype.onDatabaseLoaded =function(){  
  5444. //     setupDefaultMapper();
  5445. //     if(Imported.PP_Option ){
  5446. //         this.PP_Option_InputConfig();
  5447. //     }
  5448. //     Scene_Boot_onDatabaseLoaded.call(this);
  5449. // };

  5450. class Window_DebugSymbols extends Window_InputSymbolListBase{


  5451. }
  5452. //TODO:エラー診断 パラメータの問題を検出して、解決方法を提示
  5453. class Scene_ErrorDetection extends Scene_MenuBaseMVMZ{


  5454. }


  5455. /**
  5456. * @param {String} symbol
  5457. * @returns
  5458. */
  5459. const GetButtonNameMV =function(symbol){
  5460.     const device = getCurrentDevice();
  5461.     const button = device.getButtonBySymbol(symbol);
  5462.     if(button){
  5463.         return button.name();
  5464.     }
  5465.     return "";
  5466. };

  5467. /**
  5468. * @param {{symbol:String, nameVariable:Number}} arg
  5469. */
  5470. const GetButtonName =function(arg){
  5471.     const device =getCurrentDevice();
  5472.     const button = device.getButtonBySymbol(arg.symbol);
  5473.     if(button){
  5474.         $gameVariables.setValue(arg.nameVariable,button.name());
  5475.     }
  5476. };



  5477. if(Utils.RPGMAKER_NAME =="MV"){
  5478.     (function(){


  5479.         // const Scene_Boot_start =Scene_Boot.prototype.start;
  5480.         // Scene_Boot.prototype.start =function(){
  5481.         //     Scene_Boot_start.call(this);
  5482.         //     setupDefaultMapper();
  5483.         // };
  5484.         Window_Selectable_InputConfigVer.prototype.drawItemBackground =function(){};

  5485.         Window_Selectable_InputConfigVer.prototype.maxVisibleItems =function(){
  5486.             const visibleRows = Math.ceil(this.contentsHeight() / this.itemHeight());
  5487.             return visibleRows * this.maxCols();        
  5488.         };
  5489.         Window_Selectable_InputConfigVer.prototype.itemRectWithPadding = Window_Selectable_InputConfigVer.prototype.itemRectForText;
  5490.     })();
  5491. }else{
  5492.     PluginManager.registerCommand( PLUGIN_NAME,"IsGamepadValid",function(arg){
  5493.         const sid = (arg.switchId);
  5494.         const set = new Set( Object.values(Input.gamepadMapper))
  5495.         const value = symbolManager.isValidMapper_v3(set);
  5496.         $gameSwitches.setValue(sid,value);
  5497.     });
  5498.     PluginManager.registerCommand( PLUGIN_NAME,"IsKeyboardValid",function(arg){
  5499.         const sid = (arg.switchId);
  5500.         const set = new Set( Object.values(Input.keyMapper))
  5501.         const value = symbolManager.isValidMapper_v3(set);
  5502.         $gameSwitches.setValue(sid,value);
  5503.     });
  5504.     PluginManager.registerCommand( PLUGIN_NAME,"GetButtonName",GetButtonName);
  5505.     PluginManager.registerCommand( PLUGIN_NAME,"GetButtonNameEX",GetButtonName);

  5506.     PluginManager.registerCommand(PLUGIN_NAME,"GamepadScene",function(){
  5507.         Mano_InputConfig.gotoGamepad();
  5508.     })

  5509.     PluginManager.registerCommand(PLUGIN_NAME,"KeyboardScene",function(){
  5510.         Mano_InputConfig.gotoKey();
  5511.     })


  5512. }

  5513. const exportClass ={
  5514.     //MV用・ヘルプへの記載予定なし
  5515.     GetButtonNameMV:GetButtonNameMV,
  5516.     Scene_ConfigBase:Scene_InputConfigBase_MA,
  5517.     Scene_KeyConfig:Scene_KeyConfig_MA,
  5518.     Scene_GamepadConfig: Scene_GamepadConfig_V8,
  5519.     //Scene_GamepadConfig_ALT:Scene_GamepadConfig_ALT,
  5520.     // Window_InputSymbolList:Window_InputSymbolList,
  5521.     // Window_GamepadConfig:Window_GamepadConfig_MA,
  5522.     Window_KeyConfig:Window_KeyConfig_MA,
  5523.     defaultKeyMapper:{},
  5524.     defaultGamepadMapper:{},
  5525.     gotoKey:function(){
  5526.         SceneManager.push(Mano_InputConfig.Scene_KeyConfig );
  5527.     },
  5528.     gotoGamepad:function(){
  5529.         SceneManager.push(Scene_GamepadConfig_V8 );

  5530.         //SceneManager.push(Mano_InputConfig.Scene_GamepadConfig );
  5531.     },
  5532. };

  5533. return exportClass;
  5534. })();

  5535. {
  5536. //Sorry for the dirty implementation.
  5537. //Since there were many questions from users who use YEP_OptionCore together on how to set plug-in parameters, we are responding by the following method.
  5538.     const param = PluginManager.parameters("Mano_InputConfig");
  5539.     if(param && param.SettingsForYEP_OptionsCore){
  5540.         const obj =JSON.parse(param.SettingsForYEP_OptionsCore);

  5541.         //インポート情報を偽装し、GamepadConfig/KeybordConfigと認識させる
  5542.         if(obj.gamepad==="true"){
  5543.             Imported.GamepadConfig = true;
  5544.             //@ts-ignore
  5545.             window["Scene_GamepadConfig"] =Mano_InputConfig.Scene_GamepadConfig;
  5546.             //何かよくわからない関数が追加されているので、適当に追加する
  5547.             //@ts-ignore
  5548.             Input.isControllerConnected =Input.isControllerConnected||function(){return true;};
  5549.         }
  5550.         if(obj.Keyboard==="true"){
  5551.             Imported.YEP_KeyboardConfig = true;
  5552.             //@ts-ignore
  5553.             window["Scene_KeyConfig"] = Mano_InputConfig.Scene_KeyConfig;   
  5554.         }
  5555.     }
  5556. }

复制代码
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部