diff --git a/index.html b/index.html index 4467aee6..f4c9bda7 100644 --- a/index.html +++ b/index.html @@ -2749,7 +2749,7 @@ - + diff --git a/modules/ui/diplomacy-editor.js b/modules/ui/diplomacy-editor.js index e28fe2d3..657f6b73 100644 --- a/modules/ui/diplomacy-editor.js +++ b/modules/ui/diplomacy-editor.js @@ -268,6 +268,10 @@ function editDiplomacy() { else chronicle.push(change()); refreshDiplomacyEditor(); + if (diplomacyMatrix.offsetParent) { + document.getElementById("diplomacyMatrixBody").innerHTML = ""; + showRelationsMatrix(); + } } function regenerateRelations() { @@ -276,18 +280,16 @@ function editDiplomacy() { } function resetRelations() { - pack.states[0].diplomacy = []; + const selectedId = +body.querySelector("div.Self")?.dataset?.id; + if (!selectedId) return; + const states = pack.states; - for (const state of pack.states) { - if (!state.i || state.removed) continue; - - const newRelations = state.diplomacy.map(relations => { - if (relations === "x") return "x"; - return "Neutral"; - }); - - state.diplomacy = newRelations; - } + states[selectedId].diplomacy.forEach((relations, index) => { + if (relations !== "x") { + states[selectedId].diplomacy[index] = "Neutral"; + states[index].diplomacy[selectedId] = "Neutral"; + } + }); refreshDiplomacyEditor(); } @@ -339,7 +341,7 @@ function editDiplomacy() { function showRelationsMatrix() { const states = pack.states.filter(s => s.i && !s.removed); const valid = states.map(state => state.i); - const body = document.getElementById("diplomacyMatrixBody"); + const diplomacyMatrixBody = document.getElementById("diplomacyMatrixBody"); let table = `
| `; table += states.map(state => ` | ${state.name} | `).join("") + `||
|---|---|---|---|
| ${state.name} | ` + + `|||
| ${state.name} | ` + state.diplomacy .filter((v, i) => valid.includes(i)) .map((relation, index) => { const relationObj = relations[relation]; if (!relationObj) return `${relation} | `; - const stateName = pack.states[valid[index]].fullName; - const tip = `${state.fullName} ${relationObj.inText} ${stateName}`; - return `${relation} | `; + const objectState = pack.states[valid[index]]; + const tip = `${state.fullName} ${relationObj.inText} ${objectState.fullName}`; + return `${relation} | `; }) .join("") + "