From ce07c20fff7239155e73fafe592c47650a90f298 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Sun, 11 Dec 2022 01:37:30 +0300 Subject: [PATCH] feat(#891): edit diplomatic relations in bulk --- index.html | 2 +- modules/ui/diplomacy-editor.js | 65 ++++++++++++++++++++++++++-------- versioning.js | 2 +- 3 files changed, 53 insertions(+), 16 deletions(-) diff --git a/index.html b/index.html index 18ea0f0f..c6c9915b 100644 --- a/index.html +++ b/index.html @@ -7884,7 +7884,7 @@ - + diff --git a/modules/ui/diplomacy-editor.js b/modules/ui/diplomacy-editor.js index 9ae32eb7..d5b7b183 100644 --- a/modules/ui/diplomacy-editor.js +++ b/modules/ui/diplomacy-editor.js @@ -213,33 +213,70 @@ function editDiplomacy() { function selectRelation(subjectId, objectId, currentRelation) { const states = pack.states; - const subject = states[subjectId]; - const header = `
${subject.fullName}
`; + const object = states[objectId]; - const options = Object.entries(relations) + const relationsSelector = Object.entries(relations) .map( - ([relation, {color, inText, tip}]) => - `
` + ([relation, {color, inText, tip}]) => /* html */ ` +
+ +
+ ` ) .join(""); - const object = states[objectId]; - const footer = `
${object.fullName}
`; + const objectsSelector = states + .filter(s => s.i && !s.removed && s.i !== subjectId) + .map( + s => /* html */ ` +
+ + +
+ ` + ) + .join(""); - alertMessage.innerHTML = /* html */ `
${header} ${options} ${footer}
`; + alertMessage.innerHTML = /* html */ ` +
+
+ + + + ${subject.fullName} +
+ +
+
${relationsSelector}
+
${objectsSelector}
+
+
+ `; $("#alert").dialog({ width: fitContent(), title: `Change relations`, buttons: { Apply: function () { - const newRelation = document.querySelector('input[name="relationSelect"]:checked')?.value; - changeRelation(subjectId, objectId, currentRelation, newRelation); + const formData = new FormData(byId("relationsForm")); + const newRelation = formData.get("relationSelect"); + const objectIds = [...formData.getAll("objectSelect")].map(Number); + + for (const objectId of objectIds) { + changeRelation(subjectId, objectId, currentRelation, newRelation); + } $(this).dialog("close"); }, Cancel: function () { diff --git a/versioning.js b/versioning.js index 70a3027b..6dbf5bbf 100644 --- a/versioning.js +++ b/versioning.js @@ -1,7 +1,7 @@ "use strict"; // version and caching control -const version = "1.88.03"; // generator version, update each time +const version = "1.88.04"; // generator version, update each time { document.title += " v" + version;