修复实体更新失效bug

This commit is contained in:
nnwang
2025-12-05 00:16:46 +08:00
parent a9e541fc9b
commit 603bad4f94

View File

@@ -908,6 +908,10 @@ export default {
const objectProperties = ref({});
const attachedComponentJson = ref([]);
// 实体编辑器JSON内容缓存
const entityJsonContent = ref('');
const componentsJsonContent = ref('');
// 默认配置和编辑器选项
const defaultSbpcfgHex = '04000000e5ffffff5300610074006900730066006100630074006f00720079002000dd84fe56167f918f6856d89ea48b73006200700063006600670000000e0300000000803f0000803f0000803f0000803f300000002f47616d652f466163746f727947616d652f2d5368617265642f426c75657072696e742f49636f6e4c696272617279000c00000049636f6e4c69627261727900010000000000000000000000000000000000000000';
@@ -958,7 +962,7 @@ export default {
set: (value) => jsonEditorContent.value = value
});
// 实体编辑器计算属性(保留进阶编辑功能
// 实体编辑器计算属性(修复setter问题
const filteredEntities = computed(() =>
blueprintData.value.objects.filter(entity => entity?.type === 'SaveEntity')
);
@@ -967,14 +971,29 @@ export default {
selectedEntityIndex.value !== null ? filteredEntities.value[selectedEntityIndex.value] : null
);
// 修复恢复正确的getter/setter逻辑
const entityJson = computed({
get: () => selectedEntity.value ? JSON.stringify(selectedEntity.value, null, 2) : '',
set: (value) => {} // 将在更新按钮点击时处理
get: () => {
if (entityJsonContent.value) {
return entityJsonContent.value;
}
return selectedEntity.value ? JSON.stringify(selectedEntity.value, null, 2) : '';
},
set: (value) => {
entityJsonContent.value = value;
}
});
const componentsJson = computed({
get: () => selectedEntity.value?.components ? JSON.stringify(selectedEntity.value.components, null, 2) : '',
set: (value) => {} // 将在更新按钮点击时处理
get: () => {
if (componentsJsonContent.value) {
return componentsJsonContent.value;
}
return selectedEntity.value?.components ? JSON.stringify(selectedEntity.value.components, null, 2) : '';
},
set: (value) => {
componentsJsonContent.value = value;
}
});
const attachedComponents = computed(() =>
@@ -1064,6 +1083,8 @@ export default {
selectedEntityIndex.value = null;
activeTab.value = 'raw';
jsonEditorContent.value = lastValidJson.value = '';
entityJsonContent.value = '';
componentsJsonContent.value = '';
blueprintData.value = createEmptyBlueprintData();
};
@@ -1078,6 +1099,8 @@ export default {
selectedEntityIndex.value = null;
activeTab.value = 'raw';
jsonEditorContent.value = '';
entityJsonContent.value = '';
componentsJsonContent.value = '';
hasJsonChanges.value = false;
};
@@ -1367,10 +1390,13 @@ export default {
updateBlueprintData(validation.data);
};
// 实体编辑器方法(保留进阶编辑功能
// 实体编辑器方法(修复更新实体按钮失效问题
const selectEntity = (index) => {
selectedEntityIndex.value = index;
activeTab.value = 'raw';
// 清除缓存内容,确保显示最新数据
entityJsonContent.value = '';
componentsJsonContent.value = '';
initObjectProperties();
initAttachedComponentJson();
};
@@ -1394,15 +1420,18 @@ export default {
});
};
// 修复:使用缓存内容而不是计算属性
const updateEntityFromJson = () => {
try {
const updatedEntity = JSON.parse(entityJson.value);
const updatedEntity = JSON.parse(entityJsonContent.value || entityJson.value);
const originalIndex = blueprintData.value.objects.findIndex(
e => e.instanceName === selectedEntity.value.instanceName
);
if (originalIndex !== -1) {
blueprintData.value.objects[originalIndex] = updatedEntity;
// 清除缓存,确保下次显示更新后的数据
entityJsonContent.value = '';
initObjectProperties();
syncJsonDisplay();
jsonEditStatus.value = '实体更新成功JSON已同步';
@@ -1415,9 +1444,11 @@ export default {
const updateComponents = () => {
try {
const updatedComponents = JSON.parse(componentsJson.value);
const updatedComponents = JSON.parse(componentsJsonContent.value || componentsJson.value);
if (selectedEntity.value) {
selectedEntity.value.components = updatedComponents;
// 清除缓存,确保下次显示更新后的数据
componentsJsonContent.value = '';
syncJsonDisplay();
jsonEditStatus.value = '组件更新成功JSON已同步';
}