Repository navigation
Expand file tree
/
Copy pathaction-editor.html
More file actions
780 lines (660 loc) · 27.6 KB
/
Copy pathaction-editor.html
File metadata and controls
780 lines (660 loc) · 27.6 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>行动数值编辑器 | Era Path Actions Editor</title>
<link rel="icon" type="image/svg+xml" href="src/assets/favicon.svg">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Microsoft YaHei', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1400px;
margin: 0 auto;
background: rgba(255, 255, 255, 0.95);
border-radius: 15px;
padding: 20px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
.header {
text-align: center;
margin-bottom: 30px;
}
.header h1 {
color: #333;
margin-bottom: 10px;
}
.file-loader {
text-align: center;
padding: 40px;
border: 2px dashed #4CAF50;
border-radius: 10px;
margin: 20px 0;
background: #f8f8f8;
}
.file-loader h3 {
color: #333;
margin-bottom: 15px;
}
.file-loader p {
color: #666;
margin-bottom: 20px;
}
.controls {
display: flex;
gap: 15px;
margin-bottom: 30px;
flex-wrap: wrap;
align-items: center;
}
.control-group {
display: flex;
align-items: center;
gap: 10px;
}
.control-group label {
font-weight: 600;
color: #555;
}
select, input, button {
padding: 8px 12px;
border: 2px solid #ddd;
border-radius: 6px;
font-size: 14px;
}
button {
background: #4CAF50;
color: white;
cursor: pointer;
border: none;
transition: background 0.3s;
}
button:hover {
background: #45a049;
}
.load-btn {
background: #4CAF50;
}
.load-btn:hover {
background: #45a049;
}
.save-btn {
background: #ff9800;
}
.save-btn:hover {
background: #f57c00;
}
.reset-btn {
background: #f44336;
}
.reset-btn:hover {
background: #da190b;
}
.actions-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
gap: 20px;
}
.action-card {
border: 2px solid #e0e0e0;
border-radius: 10px;
padding: 20px;
background: #fafafa;
transition: transform 0.2s, box-shadow 0.2s;
}
.action-card:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}
.action-header {
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 2px solid #ddd;
}
.action-name {
font-size: 18px;
font-weight: 600;
color: #333;
margin-bottom: 5px;
}
.action-desc {
color: #666;
font-size: 14px;
line-height: 1.4;
}
.action-type {
display: inline-block;
padding: 4px 8px;
background: #e3f2fd;
color: #1976d2;
border-radius: 4px;
font-size: 12px;
font-weight: 600;
margin-top: 5px;
}
.values-section {
margin: 15px 0;
}
.values-title {
font-weight: 600;
color: #555;
margin-bottom: 10px;
font-size: 14px;
}
.values-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
gap: 10px;
}
.value-item {
display: flex;
flex-direction: column;
gap: 5px;
}
.value-label {
font-size: 12px;
color: #666;
font-weight: 500;
}
.value-input {
padding: 6px 8px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 13px;
text-align: center;
}
.costs .value-input {
background: #ffebee;
border-color: #e57373;
}
.effects .value-input {
background: #e8f5e8;
border-color: #81c784;
}
.stage-section {
margin-bottom: 40px;
}
.stage-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 15px 20px;
border-radius: 8px;
margin-bottom: 20px;
}
.stage-title {
font-size: 20px;
font-weight: 600;
}
.search-box {
width: 300px;
}
.status-bar {
position: fixed;
bottom: 20px;
right: 20px;
padding: 10px 15px;
background: #4CAF50;
color: white;
border-radius: 5px;
transform: translateY(100px);
opacity: 0;
transition: all 0.3s;
}
.status-bar.show {
transform: translateY(0);
opacity: 1;
}
.hidden {
display: none;
}
.editor-content {
display: none;
}
.editor-content.show {
display: block;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>时代之路 - 行动数值编辑器</h1>
<div style="color: #666; margin-top: 10px;">
直接读取和修改 actions.js 文件,只修改数值,保持代码结构不变
</div>
</div>
<!-- 文件加载区域 -->
<div id="file-loader" class="file-loader">
<h3>📁 加载 actions.js 文件</h3>
<p>请选择你的 actions.js 文件来开始编辑</p>
<input type="file" id="file-input" accept=".js" style="display: none;">
<button class="load-btn" onclick="document.getElementById('file-input').click()">选择 actions.js 文件</button>
</div>
<!-- 编辑器内容 -->
<div id="editor-content" class="editor-content">
<div class="controls">
<div class="control-group">
<label for="stage-filter">文明阶段:</label>
<select id="stage-filter">
<option value="all">全部阶段</option>
<option value="0">部落文明</option>
<option value="1">农业文明</option>
<option value="2">城邦文明</option>
<option value="3">帝国时代</option>
<option value="4">工业文明</option>
<option value="5">信息文明</option>
<option value="6">星际文明</option>
</select>
</div>
<div class="control-group">
<label for="type-filter">行动类型:</label>
<select id="type-filter">
<option value="all">全部类型</option>
<option value="amplify">强化(amplify)</option>
<option value="counter">抵消(counter)</option>
<option value="convert">转化(convert)</option>
<option value="invest">投资(invest)</option>
<option value="emergency">应急(emergency)</option>
<option value="synergy">协同(synergy)</option>
</select>
</div>
<div class="control-group">
<label for="search-box">搜索行动:</label>
<input type="text" id="search-box" class="search-box" placeholder="输入行动名称或描述...">
</div>
<button id="save-btn" class="save-btn">💾 保存修改的文件</button>
<button id="reset-btn" class="reset-btn">🔄 重置所有修改</button>
</div>
<div id="actions-container"></div>
</div>
</div>
<div id="status-bar" class="status-bar">
状态信息
</div>
<script>
// 全局状态
let originalFileContent = '';
let currentFileContent = '';
let actionPool = null;
let originalActionPool = null;
// 资源类型映射
const resourceNames = {
population: '人口',
food: '食物',
tech: '科技',
environment: '环境',
order: '秩序',
military: '军事',
culture: '文化'
};
// 行动类型映射
const actionTypeNames = {
amplify: '强化',
counter: '抵消',
convert: '转化',
invest: '投资',
emergency: '应急',
synergy: '协同'
};
// 文明阶段名称
const stageNames = {
0: '部落文明',
1: '农业文明',
2: '城邦文明',
3: '帝国时代',
4: '工业文明',
5: '信息文明',
6: '星际文明'
};
// 初始化
function init() {
document.getElementById('file-input').addEventListener('change', handleFileLoad);
document.getElementById('stage-filter').addEventListener('change', renderActions);
document.getElementById('type-filter').addEventListener('change', renderActions);
document.getElementById('search-box').addEventListener('input', renderActions);
document.getElementById('save-btn').addEventListener('click', saveFile);
document.getElementById('reset-btn').addEventListener('click', resetChanges);
}
// 处理文件加载
function handleFileLoad(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
originalFileContent = e.target.result;
currentFileContent = originalFileContent;
if (parseActionsFile()) {
document.getElementById('file-loader').style.display = 'none';
document.getElementById('editor-content').classList.add('show');
renderActions();
showStatus('✅ 文件加载成功!');
} else {
showStatus('❌ 文件解析失败,请确保这是有效的 actions.js 文件');
}
};
reader.readAsText(file);
}
// 渲染行动列表
function renderActions() {
const container = document.getElementById('actions-container');
const stageFilter = document.getElementById('stage-filter').value;
const typeFilter = document.getElementById('type-filter').value;
const searchText = document.getElementById('search-box').value.toLowerCase();
container.innerHTML = '';
// 按阶段组织行动
const stageKeys = stageFilter === 'all' ? Object.keys(editedActions) : [stageFilter];
stageKeys.forEach(stageKey => {
const stage = editedActions[stageKey];
if (!stage) return;
// 收集符合条件的行动
let stageActions = [];
Object.keys(stage).forEach(actionType => {
if (typeFilter !== 'all' && actionType !== typeFilter) return;
stage[actionType].forEach((action, index) => {
if (searchText && !action.name.toLowerCase().includes(searchText) &&
!action.desc.toLowerCase().includes(searchText)) return;
stageActions.push({
...action,
stageKey,
actionType,
actionIndex: index
});
});
});
if (stageActions.length === 0) return;
// 创建阶段标题
const stageSection = document.createElement('div');
stageSection.className = 'stage-section';
const stageHeader = document.createElement('div');
stageHeader.className = 'stage-header';
stageHeader.innerHTML = `
<div class="stage-title">${stageNames[stageKey]} (${stageActions.length}个行动)</div>
`;
stageSection.appendChild(stageHeader);
// 创建行动网格
const actionsGrid = document.createElement('div');
actionsGrid.className = 'actions-grid';
stageActions.forEach(action => {
const actionCard = createActionCard(action);
actionsGrid.appendChild(actionCard);
});
stageSection.appendChild(actionsGrid);
container.appendChild(stageSection);
});
}
// 创建行动卡片
function createActionCard(action) {
const card = document.createElement('div');
card.className = 'action-card';
card.innerHTML = `
<div class="action-header">
<div class="action-name">${action.name}</div>
<div class="action-desc">${action.desc}</div>
<div class="action-type">${actionTypeNames[action.actionType]}</div>
</div>
<div class="values-section costs">
<div class="values-title">消耗 (Costs)</div>
<div class="values-grid" id="costs-${action.stageKey}-${action.actionType}-${action.actionIndex}">
${renderResourceInputs(action.costs || {}, 'costs', action)}
</div>
</div>
<div class="values-section effects">
<div class="values-title">效果 (Effects)</div>
<div class="values-grid" id="effects-${action.stageKey}-${action.actionType}-${action.actionIndex}">
${renderResourceInputs(action.effects || {}, 'effects', action)}
</div>
</div>
`;
return card;
}
// 渲染资源输入框
function renderResourceInputs(resources, type, action) {
const allResources = ['population', 'food', 'tech', 'environment', 'order', 'military', 'culture'];
return allResources.map(resource => {
const value = resources[resource] || 0;
return `
<div class="value-item">
<label class="value-label">${resourceNames[resource]}</label>
<input type="number"
class="value-input"
value="${value}"
data-action-stage="${action.stageKey}"
data-action-type="${action.actionType}"
data-action-index="${action.actionIndex}"
data-resource-type="${resource}"
data-value-type="${type}"
onchange="updateActionValue(this)">
</div>
`;
}).join('');
}
// 更新行动数值
function updateActionValue(input) {
const stageKey = input.dataset.actionStage;
const actionType = input.dataset.actionType;
const actionIndex = parseInt(input.dataset.actionIndex);
const resourceType = input.dataset.resourceType;
const valueType = input.dataset.valueType;
const newValue = parseInt(input.value) || 0;
// 更新数据
const action = editedActions[stageKey][actionType][actionIndex];
if (!action[valueType]) action[valueType] = {};
if (newValue === 0) {
delete action[valueType][resourceType];
} else {
action[valueType][resourceType] = newValue;
}
// 添加变化指示器
input.classList.add('change-indicator');
setTimeout(() => input.classList.remove('change-indicator'), 1000);
// 自动保存
saveConfig();
}
// 显示文件上传界面
function showFileUploader() {
document.getElementById('file-uploader').classList.remove('hidden');
document.getElementById('actions-container').style.display = 'none';
}
// 隐藏文件上传界面
function hideFileUploader() {
document.getElementById('file-uploader').classList.add('hidden');
document.getElementById('actions-container').style.display = 'block';
}
// 处理文件上传
function uploadActionsFile(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
actionsFileContent = e.target.result;
if (parseActionPool()) {
hideFileUploader();
renderActions();
showStatus('Actions.js 文件上传成功');
}
};
reader.readAsText(file);
}
// 保存到文件
function saveToFile() {
try {
// 使用智能替换,只修改数值部分
const newFileContent = replaceValuesInFile();
// 下载修改后的文件
const blob = new Blob([newFileContent], { type: 'text/javascript' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = 'actions.js';
link.click();
URL.revokeObjectURL(url);
showStatus('修改后的 actions.js 文件已下载');
} catch (error) {
console.error('保存文件失败:', error);
showStatus('保存文件失败: ' + error.message);
}
}
// 智能替换文件中的数值,保持原有代码结构
function replaceValuesInFile() {
let newContent = actionsFileContent;
// 遍历所有修改过的行动
Object.keys(editedActions).forEach(stageKey => {
Object.keys(editedActions[stageKey]).forEach(actionType => {
editedActions[stageKey][actionType].forEach((action, index) => {
const original = originalActions[stageKey][actionType][index];
// 处理costs
if (action.costs) {
// 替换现有的值
if (original.costs) {
Object.keys(original.costs).forEach(resource => {
const oldValue = original.costs[resource];
const newValue = action.costs[resource] || 0;
if (oldValue !== newValue) {
newContent = replaceResourceValue(newContent, action.key, 'costs', resource, oldValue, newValue);
}
});
}
// 添加新的资源(如果原来没有)
Object.keys(action.costs).forEach(resource => {
if (action.costs[resource] > 0 && (!original.costs || !original.costs[resource])) {
newContent = addResourceValue(newContent, action.key, 'costs', resource, action.costs[resource]);
}
});
}
// 处理effects
if (action.effects) {
// 替换现有的值
if (original.effects) {
Object.keys(original.effects).forEach(resource => {
const oldValue = original.effects[resource];
const newValue = action.effects[resource] || 0;
if (oldValue !== newValue) {
newContent = replaceResourceValue(newContent, action.key, 'effects', resource, oldValue, newValue);
}
});
}
// 添加新的资源(如果原来没有)
Object.keys(action.effects).forEach(resource => {
if (action.effects[resource] !== 0 && (!original.effects || original.effects[resource] === undefined)) {
newContent = addResourceValue(newContent, action.key, 'effects', resource, action.effects[resource]);
}
});
}
});
});
});
return newContent;
}
// 替换特定行动的特定资源数值
function replaceResourceValue(content, actionKey, section, resource, oldValue, newValue) {
if (newValue === 0) {
// 如果新值为0,删除该资源行
const deletePattern = new RegExp(
`(key:\\s*['"]${actionKey}['"][\\s\\S]*?${section}:\\s*{[^}]*?)\\s*,?\\s*${resource}:\\s*${oldValue}\\s*,?([^}]*})`,
'g'
);
return content.replace(deletePattern, '$1$2');
} else {
// 替换数值
const pattern = new RegExp(
`(key:\\s*['"]${actionKey}['"][\\s\\S]*?${section}:\\s*{[^}]*?${resource}:\\s*)${oldValue}(\\s*[,}])`,
'g'
);
return content.replace(pattern, `$1${newValue}$2`);
}
}
// 为行动添加新的资源
function addResourceValue(content, actionKey, section, resource, value) {
if (value === 0) return content;
// 查找costs或effects对象的结束位置,在前面添加新资源
const pattern = new RegExp(
`(key:\\s*['"]${actionKey}['"][\\s\\S]*?${section}:\\s*{[^}]*?)(\\s*})`,
'g'
);
return content.replace(pattern, (match, prefix, suffix) => {
// 检查是否已经有其他资源,决定是否需要逗号
const needsComma = prefix.trim().endsWith(',') || prefix.includes(':');
const comma = needsComma ? ', ' : '';
return `${prefix}${comma}${resource}: ${value}${suffix}`;
});
}
// 加载保存的配置
function saveConfig() {
localStorage.setItem('actionEditorConfig', JSON.stringify(editedActions));
showStatus('配置已自动保存');
}
// 加载保存的配置
function loadSavedConfig() {
const saved = localStorage.getItem('actionEditorConfig');
if (saved) {
try {
editedActions = JSON.parse(saved);
} catch (e) {
console.error('加载配置失败:', e);
}
}
}
// 导出配置
function exportConfig() {
const dataStr = JSON.stringify(editedActions, null, 2);
const dataBlob = new Blob([dataStr], {type: 'application/json'});
const link = document.createElement('a');
link.href = URL.createObjectURL(dataBlob);
link.download = `era-path-actions-${new Date().toISOString().slice(0, 10)}.json`;
link.click();
showStatus('配置已导出');
}
// 导入配置
function importConfig(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
try {
const imported = JSON.parse(e.target.result);
editedActions = imported;
saveConfig();
renderActions();
showStatus('配置已导入');
} catch (error) {
alert('导入失败:文件格式错误');
}
};
reader.readAsText(file);
// 清空文件输入
event.target.value = '';
}
// 重置所有配置
function resetAll() {
if (confirm('确定要重置所有行动数值到初始状态吗?此操作不可撤销。')) {
editedActions = JSON.parse(JSON.stringify(originalActions));
localStorage.removeItem('actionEditorConfig');
renderActions();
showStatus('已重置所有配置');
}
}
// 显示状态消息
function showStatus(message) {
const statusBar = document.getElementById('status-bar');
statusBar.textContent = message;
statusBar.classList.add('show');
setTimeout(() => {
statusBar.classList.remove('show');
}, 2000);
}
// 页面加载时初始化
document.addEventListener('DOMContentLoaded', init);
// 全局函数,供HTML中的onchange使用
window.updateActionValue = updateActionValue;
</script>
</body>
</html>