From 3ee78ae04cbd96f02ea3d75bb85b4c4c957afb8e Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Tue, 17 Mar 2026 10:08:03 +0800 Subject: [PATCH] fix: improve handling of town editor coordinates and data integrity --- js/towns_script.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/js/towns_script.js b/js/towns_script.js index 2a5c809..635af17 100644 --- a/js/towns_script.js +++ b/js/towns_script.js @@ -507,9 +507,10 @@ document.addEventListener('DOMContentLoaded', () => { function openEditor(item) { var gradient = getTownGradient(item || {}); - editorFounders = item ? item.founders.slice() : []; - editorMembers = item ? item.members.slice() : []; - editorIntroduction = item ? item.introduction.map(function(i) { return {type: i.type, content: i.content}; }) : []; + var coordinates = item && item.coordinates ? item.coordinates : { x: '', y: '', z: '' }; + editorFounders = item && Array.isArray(item.founders) ? item.founders.slice() : []; + editorMembers = item && Array.isArray(item.members) ? item.members.slice() : []; + editorIntroduction = item && Array.isArray(item.introduction) ? item.introduction.map(function(i) { return {type: i.type, content: i.content}; }) : []; document.getElementById('editor-town-title').value = item ? item.title : ''; document.getElementById('editor-town-logo').value = item ? (item.logo || '') : ''; @@ -525,9 +526,9 @@ document.addEventListener('DOMContentLoaded', () => { secretCheckbox.checked = item ? (item.coordinatesSecret === true) : false; toggleCoordsRow(); - document.getElementById('editor-town-x').value = item ? item.coordinates.x : ''; - document.getElementById('editor-town-y').value = item ? item.coordinates.y : ''; - document.getElementById('editor-town-z').value = item ? item.coordinates.z : ''; + document.getElementById('editor-town-x').value = item ? coordinates.x : ''; + document.getElementById('editor-town-y').value = item ? coordinates.y : ''; + document.getElementById('editor-town-z').value = item ? coordinates.z : ''; renderTagsList('editor-founders-tags', editorFounders); renderTagsList('editor-members-tags', editorMembers);