Skip to content

Commit b5f6ed1

Browse files
committed
更新:使事件指令可產生 MV/MZ 的註冊程式碼
1. 使事件指令可依據是否支援 MZ 產生 MV 與 MZ 的註冊程式碼 2. 增加 MV 插件指令的程式碼插入選項 3. 修正 `help` 與 `plugindesc` 的名稱 4. 修正部份樣式
1 parent e1f8164 commit b5f6ed1

3 files changed

Lines changed: 88 additions & 34 deletions

File tree

index.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
position: fixed;
5252
left: calc(75% + 5px);
5353
top: 8px;
54+
border-color: transparent;
5455
}
5556

5657
button:hover,
@@ -83,6 +84,7 @@
8384

8485
border: 1px solid #aaaeb3;
8586
border-bottom: none;
87+
box-sizing: border-box;
8688
}
8789

8890
.root_title {
@@ -115,7 +117,7 @@
115117
}
116118

117119
.sub_title {
118-
width: 133px;
120+
width: 140px;
119121
}
120122

121123
.origin_name {
@@ -362,12 +364,12 @@
362364
@media (max-width: 500px) {
363365
#build_result_button {
364366
left: auto;
365-
right: 5px;
367+
right: 8px;
366368
border: 1px solid #aaaeb3;
367369
}
368370

369371
.root {
370-
width: 95%;
372+
width: calc(100% - 16px);
371373
}
372374

373375
#root_meta textarea {
@@ -416,15 +418,15 @@
416418
<!-- url -->
417419
<!-- help -->
418420
<div class="help block">
419-
<span class="help_title title">概述<span class="origin_name">(help)</span></span>
421+
<span class="help_title title">說明<span class="origin_name">(help)</span></span>
420422
<div class="help_input data_input data">
421423
<input type="text" placeholder="One line of descript">
422424
</div>
423425
</div>
424426
<!-- help -->
425427
<!-- desc -->
426428
<div class="desc block">
427-
<span class="desc_title title">說明<span class="origin_name">(plugindesc)</span></span>
429+
<span class="desc_title title">概述<span class="origin_name">(plugindesc)</span></span>
428430
<div class="desc_input data_input data">
429431
<textarea placeholder="Detail of this plugin"></textarea>
430432
</div>
@@ -480,7 +482,7 @@
480482

481483
<div class="param block root_operation">
482484
<button type="button" onclick="ParameterControl.onRootAddClick()">Add</button>
483-
<button type="button" onclick="ParameterControl.onRootDelClick()">Del All</button>
485+
<button type="button" onclick="ParameterControl.onRootDelClick()">Del_All</button>
484486
</div>
485487

486488
</div>

src/editorConfig.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,37 @@ const createDependencyProposals = range => [
9494
insertText: "const ${1:originMethod} = ${2:Target_Class.prototype.methodName}\n" +
9595
"${2:Target_Class.prototype.methodName} = function (){\n" +
9696
" return ${1:originMethod}.apply(this, arguments)\n" +
97-
"}\n",
97+
"}",
9898
insertTextRules:
9999
monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
100100
range,
101101
},
102102
{
103-
label: "!command",
103+
label: "!commandMZ",
104104
kind: monaco.languages.CompletionItemKind.Snippet,
105-
documentation: "設定插件指令",
105+
documentation: "設定 MZ 插件指令",
106106
insertText: 'PluginManager.registerCommand(FILENAME, "${1:commandName}", function ({ ${2:parameters} }) {\n' +
107107
"\n" +
108-
"})\n",
108+
"})",
109109
insertTextRules:
110110
monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
111111
range,
112-
}
112+
},
113+
{
114+
label: "!commandMV",
115+
kind: monaco.languages.CompletionItemKind.Snippet,
116+
documentation: "設定 MV 插件指令",
117+
insertText: "const ${1:originMethod} = Game_Interpreter.prototype.pluginCommand\n" +
118+
"Game_Interpreter.prototype.pluginCommand = function (cmd, args) {\n" +
119+
' if(cmd !== "${2:commandName}") return ${1:originMethod}.apply(this, arguments)\n' +
120+
"\n" +
121+
" // your process going here..." +
122+
"\n" +
123+
"}",
124+
insertTextRules:
125+
monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
126+
range,
127+
},
113128
]
114129

115130

src/index.js

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ class CommandControl {
875875

876876
class BasicInfoBuilder {
877877

878+
/** @type {boolean} */
878879
static get getIsTargetMZ() { return EL_TARGET?.checked || false }
879880
static get getAuthor() { return Fnc.getIfNotEmpty(EL_AUTHOR?.value) }
880881
static get getURL() { return Fnc.getIfNotEmpty(EL_URL?.value) }
@@ -1050,7 +1051,7 @@ class CommandBuilder {
10501051
static buildBlockParams(block) {
10511052
return [...block.getElementsByClassName("command_parameter_group")]
10521053
.map(ParameterBuilder.buildSingleParam)
1053-
.map(res => res.replaceAll("@param ", "@arg "))
1054+
.map(res => res?.replaceAll("@param ", "@arg "))
10541055
.join("")
10551056
}
10561057

@@ -1061,12 +1062,21 @@ class CommandBuilder {
10611062
.join(", ")
10621063
}
10631064

1064-
static buildBlockCode(id, name, paramsName) {
1065-
const body = EDITOR_COMMANDS.get(`id_${id}_command_editor`)?.getValue() || ""
1065+
static buildBlockCode(id, name, paramsName, isMZ) {
1066+
const body = EDITOR_COMMANDS.get(`id_${id}_command_editor`)?.getValue().replaceAll("\r\n", "\r\n ") || ""
10661067

1067-
return ` PluginManager.registerCommand(FILENAME, "${name}", function ({ ${paramsName} }){
1068-
${body.replaceAll("\r\n", "\r\n ")}
1069-
})`
1068+
const mz = isMZ
1069+
? ` PluginManager.registerCommand(FILENAME, "${name}", function (${paramsName.length > 0 ? `{ ${paramsName} }` : ""}){
1070+
${body}
1071+
})`
1072+
: false
1073+
1074+
const mv = `
1075+
if(cmd === "${name}") {${paramsName.length > 0 ? `\n var [${paramsName}] = args` : ""}
1076+
${body}
1077+
}`
1078+
1079+
return { mz, mv }
10701080
}
10711081

10721082
/**
@@ -1081,9 +1091,10 @@ class CommandBuilder {
10811091

10821092
/**
10831093
* @param {HTMLElement} block
1084-
* @returns {{note: string, code: string}}
1094+
* @param {boolean} isMZ
1095+
* @returns {{note: string, code: false, cmdMZ: string, cmdMV: string }}}
10851096
*/
1086-
static buildSingleCommand(block) {
1097+
static buildSingleCommand(block, isMZ) {
10871098
const name = CommandBuilder.getCommandName(block)
10881099
if (!name) return false
10891100

@@ -1093,7 +1104,7 @@ class CommandBuilder {
10931104
const params = CommandBuilder.buildBlockParams(block)
10941105

10951106
const paramsName = CommandBuilder.getAllParamsName(block) // params.map(p => p.name).join(", ")
1096-
const code = CommandBuilder.buildBlockCode(block.dataset.id, name, paramsName)
1107+
const { mv, mz } = CommandBuilder.buildBlockCode(block.dataset.id, name, paramsName, isMZ)
10971108

10981109
return {
10991110
note: "\n * "
@@ -1108,7 +1119,9 @@ class CommandBuilder {
11081119

11091120
return `\n * @${n} ${v}`
11101121
}).join(""),
1111-
code
1122+
code: false,
1123+
cmdMV: mv,
1124+
cmdMZ: mz,
11121125
}
11131126
}
11141127

@@ -1130,27 +1143,46 @@ class CommandBuilder {
11301143
}
11311144

11321145
/**
1133-
* @param {HTMLElement} block
1146+
* @type {(isMZ: boolean) => (block: HTMLElement) => { note: string; code: string | false; cmdMZ: ?string; cmdMV: ?string } | false}
11341147
*/
1135-
static buildSingleBlock(block) {
1136-
switch (block.dataset.type) {
1137-
case "command": return CommandBuilder.buildSingleCommand(block)
1138-
case "code": return CommandBuilder.buildSingleCode(block)
1139-
1140-
default: return false
1148+
static buildSingleBlock(isMZ) {
1149+
return block => {
1150+
switch (block.dataset.type) {
1151+
case "command": return CommandBuilder.buildSingleCommand(block, isMZ)
1152+
case "code": return CommandBuilder.buildSingleCode(block)
1153+
1154+
default: return false
1155+
}
11411156
}
11421157
}
11431158

1159+
/** @returns {[string, string, string, string,]} */
11441160
static build() {
1145-
return [...document.querySelectorAll("#root_command > div.command.block[data-type]")]
1146-
.map(CommandBuilder.buildSingleBlock)
1161+
const isMZ = BasicInfoBuilder.getIsTargetMZ
1162+
1163+
let list = [...document.querySelectorAll("#root_command > div.command.block[data-type]")]
1164+
.map(CommandBuilder.buildSingleBlock(isMZ))
11471165
.reduce((all, cur) => {
11481166
if (!cur) return all
11491167

11501168
all[0] += cur.note
1151-
all[1] += cur.code + "\n\n"
1169+
if (cur.code) all[1] += cur.code + "\n\n"
1170+
1171+
if (cur.cmdMZ) all[2] += cur.cmdMZ + "\n\n"
1172+
if (!cur.cmdMV) return all
1173+
1174+
all[3] += all[3] === ""
1175+
? ` const pluginCommand = Game_Interpreter.prototype.pluginCommand
1176+
Game_Interpreter.prototype.pluginCommand = function (cmd, args) {
1177+
${cur.cmdMV}`
1178+
: "\n\n " + cur.cmdMV
1179+
11521180
return all
1153-
}, ["", ""])
1181+
}, ["", "", "", ""])
1182+
1183+
if (list[3] !== "") list[3] += "\n\n return pluginCommand.apply(this, arguments)\n }"
1184+
1185+
return list
11541186
}
11551187
}
11561188

@@ -1185,19 +1217,24 @@ class Builder {
11851217
}
11861218

11871219
static build() {
1188-
const [commandsNote, commandsCode] = CommandBuilder.build()
1220+
const basicNote = BasicInfoBuilder.build()
11891221
const parameterNote = ParameterBuilder.build()
1222+
const [commandsNote, commandsCode, commandMZ, commandMV] = CommandBuilder.build()
11901223

11911224
const isHadCode = commandsCode.length > 0
11921225
const isHadParam = parameterNote.length > 0
1226+
const isHadMZCommand = commandMZ.length > 0
1227+
const isHadMVCommand = commandMV.length > 0
11931228

11941229
const code =
11951230
(isHadCode || isHadParam ? `\n const FILENAME = document.currentScript.src.split("/").pop().replace(".js", "")` : "")
11961231
+ (isHadParam ? "\n const PARAMETERS = PluginManager.parameters(FILENAME)" : "")
11971232
+ (isHadCode ? `\n\n${commandsCode}` : "")
1233+
+ (isHadMVCommand ? `\n\n if (Utils.RPGMAKER_NAME === "MV") {\n${commandMV}\n }` : "")
1234+
+ (isHadMZCommand ? `\n\n if (Utils.RPGMAKER_NAME === "MZ") {\n${commandMZ} }` : "")
11981235

11991236
const note = [
1200-
BasicInfoBuilder.build(),
1237+
basicNote,
12011238
parameterNote,
12021239
commandsNote,
12031240
]

0 commit comments

Comments
 (0)