更新离线编辑器:炸弹数值标注及原始关卡转换九种默认映射
This commit is contained in:
@@ -224,11 +224,38 @@ function displayedEntities() {
|
||||
if (state.view === 'preview') {
|
||||
if (!state.result?.board) return [];
|
||||
return [...state.result.board.units.map((unit, index) => ({ collection: 'characters', index,
|
||||
entry: [unit.artifactId, unit.col, unit.row, unit.sourceOrientation, unit.sourceExtra] })),
|
||||
entry: [unit.artifactId, unit.col, unit.row, unit.sourceOrientation, unit.sourceExtra], unit })),
|
||||
...state.result.board.aoes.map((unit, index) => ({ collection: 'aoes', index,
|
||||
entry: [unit.mechanismId, unit.col, unit.row, unit.sourceOrientation] }))];
|
||||
}
|
||||
return ['characters', 'aoes'].flatMap(collection => state.level[collection].map((entry, index) => ({ collection, index, entry })));
|
||||
const units = new Map((state.result?.board?.units || []).map(unit => [unit.id, unit]));
|
||||
return ['characters', 'aoes'].flatMap(collection => state.level[collection].map((entry, index) => ({ collection, index, entry,
|
||||
unit: collection === 'characters' ? units.get('u-' + String(index + 1).padStart(6, '0')) : null })));
|
||||
}
|
||||
function bombLabel(definition, unit) {
|
||||
if (definition.boardBehavior === 'collisionBomb') {
|
||||
const count = unit?.collisionHp ?? definition.behaviorParams?.collisionHp;
|
||||
return Number.isFinite(count) ? count + '次' : '待校验';
|
||||
}
|
||||
if (definition.boardBehavior === 'countdownBomb') {
|
||||
const duration = unit?.timer?.duration;
|
||||
return Number.isFinite(duration) ? duration + '秒' : '待校验';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
function drawBombLabel(definition, unit, col, row, footprint) {
|
||||
const text = bombLabel(definition, unit);
|
||||
if (!text) return;
|
||||
ctx.save();
|
||||
ctx.translate(col + footprint.width / 2, row + footprint.height / 2 + .23);
|
||||
// 局内预览会旋转棋盘,数字反向旋转以保持正向可读。
|
||||
ctx.rotate(-transform.angle);
|
||||
ctx.font = 'bold 0.24px "Microsoft YaHei",sans-serif'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
|
||||
const width = Math.min(.92, Math.max(.56, ctx.measureText(text).width + .12));
|
||||
ctx.fillStyle = definition.boardBehavior === 'collisionBomb' ? '#8f3027' : '#075f68';
|
||||
ctx.fillRect(-width / 2, -.17, width, .34);
|
||||
ctx.fillStyle = '#ffffff'; ctx.fillText(text, 0, 0, width - .1);
|
||||
ctx.restore();
|
||||
}
|
||||
function spriteAngle(definition, direction) {
|
||||
const footprint = definition.footprintsByOrientation[direction];
|
||||
@@ -238,7 +265,7 @@ function spriteAngle(definition, direction) {
|
||||
|| (definition.boardBehavior === 'fence' && [2, 4].includes(Number(direction))) ? -90 : 0;
|
||||
return definition.visual?.spriteRotationMode === 'directional' ? ({ 1: 180, 2: 90, 3: 0, 4: -90 }[direction] + Number(definition.visual?.spriteForwardOffsetDeg || 0)) : 0;
|
||||
}
|
||||
function drawEntity(entry, selected = false, ghost = false, invalid = false) {
|
||||
function drawEntity(entry, selected = false, ghost = false, invalid = false, unit = null) {
|
||||
const definition = definitionFor(entry), footprint = definition?.footprintsByOrientation[entry[3]];
|
||||
if (!footprint) return;
|
||||
const [id, col, row, direction] = entry;
|
||||
@@ -290,6 +317,7 @@ function drawEntity(entry, selected = false, ghost = false, invalid = false) {
|
||||
ctx.fillStyle = invalid ? '#b84138' : selected ? '#007780' : '#5a7970';
|
||||
ctx.font = 'bold 0.23px sans-serif'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
|
||||
if (definition.boardBehavior !== 'burrowingBlocker') ctx.fillText({ 1: '↓', 2: '→', 3: '↑', 4: '←' }[direction], col + footprint.width - .19, row + .2);
|
||||
drawBombLabel(definition, unit, col, row, footprint);
|
||||
if (selected) {
|
||||
ctx.lineWidth = .045; ctx.strokeStyle = '#07858c'; ctx.strokeRect(col + .018, row + .018, footprint.width - .036, footprint.height - .036);
|
||||
}
|
||||
@@ -340,7 +368,7 @@ function draw() {
|
||||
for (const entity of entities) {
|
||||
const selected = state.selected?.collection === entity.collection && state.selected?.index === entity.index;
|
||||
if (state.drag?.type === 'object' && selected && !preview && state.drag.moved) continue;
|
||||
drawEntity(entity.entry, selected, false, invalidEntries.has(entity.collection + ':' + entity.index));
|
||||
drawEntity(entity.entry, selected, false, invalidEntries.has(entity.collection + ':' + entity.index), entity.unit);
|
||||
}
|
||||
if (!preview && state.drag?.type === 'object' && state.drag.moved) drawEntity(state.drag.candidate, true, true, !state.drag.valid);
|
||||
if (!preview && state.material && state.hover) {
|
||||
|
||||
Reference in New Issue
Block a user