-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
271 lines (245 loc) · 8.38 KB
/
index.html
File metadata and controls
271 lines (245 loc) · 8.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JSON → 仪式模板生成器</title>
<style>
body {
font-family: sans-serif;
padding: 10px;
display: flex;
flex-direction: column;
align-items: center;
max-width: 100%;
margin: 0;
}
textarea {
width: 95%;
max-width: 800px;
height: 250px;
margin: 10px 0;
padding: 10px;
font-family: monospace;
font-size: 14px;
box-sizing: border-box;
resize: vertical;
}
pre {
width: 95%;
max-width: 800px;
padding: 10px;
background: #f5f5f5;
border: 1px solid #ccc;
overflow-x: auto;
white-space: pre-wrap;
word-wrap: break-word;
margin-top: 10px;
}
.button-group {
display: flex;
align-items: center;
margin-bottom: 10px;
width: 95%;
max-width: 800px;
}
button {
padding: 8px 20px;
font-size: 14px;
margin-right: 10px;
cursor: pointer;
}
@media (max-width: 600px) {
textarea, pre {
height: 200px;
font-size: 13px;
}
button {
padding: 6px 12px;
font-size: 13px;
}
}
#copyTip {
font-size: 14px;
color: green;
}
</style>
</head>
<body>
<h2>JSON → 仪式模板生成器</h2>
<fieldset style="
border: 1px solid #ccc;
padding: 10px;
font-size: 12px;
color: #555;
width: 95%;
max-width: 800px;
box-sizing: border-box;
">
<legend>使用说明</legend>
* 自动填写标题,剧情,id,时限,耗时,提示,槽位描述,合并相同槽位<br>
* 自动生成前判,结算(原始condition, result, action在生成的注释中)<br>
* waiting_round=0:不生成超时和超时剧情<br>
* auto_begin=0:不生成自动启动<br>
* <a href="https://wiki.biligame.com/sultansgame/index.php?title=%E7%94%A8%E6%88%B7:11880951/%E4%BB%AA%E5%BC%8F%E6%A8%A1%E6%9D%BF%E7%94%9F%E6%88%90%E5%99%A8" target="_blank">使用教程</a><br>
</fieldset>
<textarea id="jsonInput" placeholder="在这里粘贴JSON"></textarea>
<div class="button-group">
<button onclick="processJSON()">生成模板</button>
<button onclick="copyOutput()">复制结果</button>
<span id="copyTip"></span>
</div>
<pre id="output"></pre>
<script>
function copyOutput() {
const output = document.getElementById('output');
if(!output.textContent.trim()) return;
navigator.clipboard.writeText(output.textContent).then(() => {
const tip = document.getElementById('copyTip');
tip.textContent = '已复制到剪贴板!';
setTimeout(()=>{ tip.textContent = ''; }, 2000);
}, (err) => {
alert('复制失败:' + err);
});
}
function processJSON() {
let raw = document.getElementById('jsonInput').value;
// 去掉 // 注释
let noComments = raw.replace(/\/\/.*$/gm, '');
// 去掉多余逗号
let noTrailingCommas = noComments.replace(/,(\s*[\]}])/g, '$1');
let obj;
try {
obj = JSON.parse(noTrailingCommas);
} catch(e) {
document.getElementById('output').textContent = 'JSON 解析错误:\n' + e;
return;
}
let template = generateTemplate(obj);
document.getElementById('output').textContent = template;
}
function generateTemplate(data) {
const tips = data.tips_text || [];
const slots = data.cards_slot || {};
const priors = data.settlement_prior || [];
const settlements = data.settlement || [];
const settlementExtre = data.settlement_extre || [];
let groupMap = { "吸入": [], "需要": [], "可选": [] };
for (let key in slots) {
const s = slots[key];
let type = "";
if (s.open_adsorb === 1) type = "吸入";
else if (s.open_adsorb === 0 && s.is_empty === 0) type = "需要";
else if (s.open_adsorb === 0 && s.is_empty === 1) type = "可选";
if (type) groupMap[type].push({ index: key.slice(1), text: s.text });
}
function buildLines(type) {
let arr = groupMap[type];
if (!arr.length) return "";
arr.sort((a,b)=>a.index-b.index);
let lines = [];
let i=0;
while(i<arr.length){
let start = i;
let end = i;
while(end+1<arr.length && arr[end+1].text === arr[start].text && arr[end+1].index == parseInt(arr[end].index)+1){
end++;
}
let idx = (start===end)? arr[start].index : arr[start].index+"-"+arr[end].index;
lines.push(`|${type}${idx}=`);
lines.push(`|描述${idx}=${arr[start].text}`);
if(type!=="吸入") lines.push(`|气泡${idx}=`);
i = end+1;
}
return lines.join("\n");
}
let slotTemplate = buildLines("吸入") + "\n" + buildLines("需要") + "\n" + buildLines("可选");
// 提示处理逻辑
let tipLines = "";
if(tips.length === 1){
tipLines = `|提示=${tips[0]}`;
} else if(tips.length > 1){
for(let i=0;i<tips.length;i++){
tipLines += `|提示${i+1}=${tips[i]||""}\n`;
}
tipLines = tipLines.trim();
}
// 把 action 展平成一行
function formatAction(action){
if(!action) return "";
let parts = [];
for (let k in action){
let v = action[k];
if(typeof v === "object" && v!==null && !Array.isArray(v)){
let inner = Object.entries(v).map(([ik,iv])=>`${ik}:${iv}`).join(", ");
parts.push(`${k}{${inner}}`);
} else {
parts.push(`${k}:${v}`);
}
}
return `<!--action: {${parts.join(", ")}} -->`;
}
// settlement_prior 映射到前置
function buildSettlement(settlement, isPrior){
if(!settlement.length) return "";
let blocks = settlement.map(p=>{
let conds = Object.entries(p.condition||{}).map(([k,v])=>`${k}:${v}`).join(";");
let results = Object.entries(p.result||{}).map(([k,v])=>{
if(Array.isArray(v)) return `${k}:${v.join(",")}`;
return `${k}:${v}`;
}).join(", ");
let title = p.result_title ? `<big><b>•${p.result_title}</b></big><br>` : "";
let text = (p.result_text||"").replace(/\n/g,"<br>");
let actionStr = (p.action && Object.keys(p.action).length > 0) ? formatAction(p.action) : "";
if(isPrior) return `<!-- [条件] ${conds}--> <!-- [结果] ${results} --> ${actionStr}{{折叠剧情|{{引用块|${title}${text} }} }}`;
return `<!-- [条件] ${conds}--> <!-- [结果] ${results} --> ${actionStr}\n{{折叠剧情|{{引用块|${title}${text} }} }}`;
});
if(isPrior) return blocks.join("");
else return blocks.join("\n");
}
let priorLines = buildSettlement(priors, true);
if (priorLines) {
priorLines += "";
}
let settlementLines = buildSettlement(settlements, false);
let settlementExtreLines = buildSettlement(settlementExtre, false);
let allSettlementLines = settlementLines;
if(settlementExtreLines) { // 连接时判断 settlementExtreLines 是否为空
allSettlementLines += `<!--额外结算-->` + buildSettlement(settlementExtre)
}
let timeoutLines = "";
if (data.waiting_round != null && data.waiting_round !== 0) {
timeoutLines = `|超时=\n|超时剧情=`;
}
let tpl = `{{仪式新
|前置弹窗=
|标题=${data.name || ""}
|剧情={{#lst:仪式|${data.id || ""}}}
|id=${data.id || ""}
|前置=
|时限=${data.waiting_round != null ? data.waiting_round : ""}
|耗时=${data.round_number != null ? data.round_number : ""}
${timeoutLines}
${data.auto_begin===1? "|自动启动=1":""}
${tipLines}
|槽位信息={{复杂仪式槽位信息模板
${slotTemplate}
}}
|详见=
|检定=
|骰子文本=
|前判=${priorLines}
|结算=
${allSettlementLines}
|备注=
|附录=
}}`;
return tpl;
}
</script>
<!-- 页脚 -->
<footer style="text-align:center; padding:10px; font-size:12px; color:#888; font-style:italic; margin-top:20px;">
项目地址:<a href="https://github.com/laicwew/Json2WikiModule" target="_blank" style="color:#888;">https://github.com/laicwew/Json2WikiModule</a>
</footer>
</body>
</html>