This commit is contained in:
Azgaar 2022-09-17 14:36:32 +03:00
parent b6acd8ffff
commit 07a744151d
4 changed files with 51 additions and 40 deletions

View file

@ -2206,7 +2206,7 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 350"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 350">
<rect width="100%" height="100%" fill="#005bbb"></rect> <rect width="100%" height="100%" fill="#005bbb"></rect>
<rect y="50%" width="100%" height="50%" fill="#ffd500"></rect> <rect y="50%" width="100%" height="50%" fill="#ffd500"></rect>
<text x="50%" text-anchor="middle" font-size="9em" y="35%" fill="#f5f5f5">Support Ukraine</text> <text x="50%" text-anchor="middle" font-size="8em" y="32%" fill="#f5f5f5">Support Ukraine</text>
<text x="50%" text-anchor="middle" font-size="4em" y="78%" fill="#005bdd"> <text x="50%" text-anchor="middle" font-size="4em" y="78%" fill="#005bdd">
war.ukraine.ua/support-ukraine war.ukraine.ua/support-ukraine
</text> </text>
@ -3987,11 +3987,6 @@
></button> ></button>
<button id="convertColorsButton" data-tip="Set maximum number of colors" class="icon-signal"></button> <button id="convertColorsButton" data-tip="Set maximum number of colors" class="icon-signal"></button>
<input id="convertColors" value="100" style="display: none" /> <input id="convertColors" value="100" style="display: none" />
<button
id="convertComplete"
data-tip="Complete the conversion. All unassigned colors will be considered as ocean"
class="icon-check"
></button>
<button <button
id="convertCancel" id="convertCancel"
data-tip="Cancel the conversion. Previous heightmap will be restored" data-tip="Cancel the conversion. Previous heightmap will be restored"
@ -4013,12 +4008,23 @@
</div> </div>
<div data-tip="Select a color to re-assign the height value" id="colorsAssigned" style="display: none"> <div data-tip="Select a color to re-assign the height value" id="colorsAssigned" style="display: none">
<i>Assigned colors (<span id="colorsAssignedNumber"></span>):</i><br /> <i>Assigned colors (<span id="colorsAssignedNumber"></span>):</i>
<div id="colorsAssignedContainer" class="colorsContainer"></div>
</div> </div>
<div data-tip="Select a color to assign a height value" id="colorsUnassigned" style="display: none"> <div data-tip="Select a color to assign a height value" id="colorsUnassigned" style="display: none">
<i>Unassigned colors (<span id="colorsUnassignedNumber"></span>):</i><br /> <i>Unassigned colors (<span id="colorsUnassignedNumber"></span>):</i>
<div id="colorsUnassignedContainer" class="colorsContainer"></div>
</div> </div>
<button
id="convertComplete"
data-tip="Complete the conversion. All unassigned colors will be considered as ocean"
style="margin: 0.4em 0"
class="glow"
>
Complete the conversion
</button>
</div> </div>
<div id="biomesEditor" class="dialog stable" style="display: none"> <div id="biomesEditor" class="dialog stable" style="display: none">

View file

@ -1190,7 +1190,7 @@ export function open(options) {
.on("click", mapClicked); .on("click", mapClicked);
const colors = pallete.map(p => `rgb(${p[0]}, ${p[1]}, ${p[2]})`); const colors = pallete.map(p => `rgb(${p[0]}, ${p[1]}, ${p[2]})`);
d3.select("#colorsUnassigned") d3.select("#colorsUnassignedContainer")
.selectAll("div") .selectAll("div")
.data(colors) .data(colors)
.enter() .enter()
@ -1253,25 +1253,23 @@ export function open(options) {
this.setAttribute("data-height", height); this.setAttribute("data-height", height);
}); });
if (selectedColor.parentNode.id === "colorsUnassigned") { if (selectedColor.parentNode.id === "colorsUnassignedContainer") {
colorsAssigned.appendChild(selectedColor); colorsAssignedContainer.appendChild(selectedColor);
colorsAssigned.style.display = "block"; colorsAssigned.style.display = "block";
byId("colorsUnassignedNumber").innerHTML = colorsUnassigned.childElementCount - 2; byId("colorsUnassignedNumber").innerHTML = colorsUnassignedContainer.childElementCount - 2;
byId("colorsAssignedNumber").innerHTML = colorsAssigned.childElementCount - 2; byId("colorsAssignedNumber").innerHTML = colorsAssignedContainer.childElementCount - 2;
} }
} }
// auto assign color based on luminosity or hue // auto assign color based on luminosity or hue
function autoAssing(type) { function autoAssing(type) {
let unassigned = colorsUnassigned.querySelectorAll("div"); let unassigned = colorsUnassignedContainer.querySelectorAll("div");
if (!unassigned.length) { if (!unassigned.length) {
heightsFromImage(+convertColors.value); heightsFromImage(+convertColors.value);
unassigned = colorsUnassigned.querySelectorAll("div"); unassigned = colorsUnassignedContainer.querySelectorAll("div");
if (!unassigned.length) { if (!unassigned.length)
tip("No unassigned colors. Please load an image and click the button again", false, "error"); return tip("No unassigned colors. Please load an image and click the button again", false, "error");
return;
}
} }
const getHeightByHue = function (color) { const getHeightByHue = function (color) {
@ -1315,18 +1313,18 @@ export function open(options) {
} // if color is already added, remove it } // if color is already added, remove it
el.style.backgroundColor = el.dataset.color = colorTo; el.style.backgroundColor = el.dataset.color = colorTo;
el.dataset.height = height; el.dataset.height = height;
colorsAssigned.appendChild(el); colorsAssignedContainer.appendChild(el);
assinged[height] = true; assinged[height] = true;
}); });
// sort assigned colors by height // sort assigned colors by height
Array.from(colorsAssigned.children) Array.from(colorsAssignedContainer.children)
.sort((a, b) => +a.dataset.height - +b.dataset.height) .sort((a, b) => +a.dataset.height - +b.dataset.height)
.forEach(line => colorsAssigned.appendChild(line)); .forEach(line => colorsAssignedContainer.appendChild(line));
colorsAssigned.style.display = "block"; colorsAssigned.style.display = "block";
colorsUnassigned.style.display = "none"; colorsUnassigned.style.display = "none";
byId("colorsAssignedNumber").innerHTML = colorsAssigned.childElementCount - 2; byId("colorsAssignedNumber").innerHTML = colorsAssignedContainer.childElementCount - 2;
} }
function setConvertColorsNumber() { function setConvertColorsNumber() {
@ -1346,7 +1344,8 @@ export function open(options) {
} }
function applyConversion() { function applyConversion() {
if (colorsAssigned.childElementCount < 3) return tip("Please do the assignment first", false, "error"); if (colorsAssignedContainer.childElementCount < 3)
return tip("Please assign colors to heights first", false, "error");
viewbox viewbox
.select("#heights") .select("#heights")

View file

@ -1141,12 +1141,17 @@ div#regimentSelectorBody > div > div {
filter: sepia(1) hue-rotate(200deg); filter: sepia(1) hue-rotate(200deg);
} }
.colorsContainer {
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-column-gap: 0.3em;
grid-row-gap: 0.2em;
}
.color-div { .color-div {
width: 3em; width: 3em;
height: 1em; height: 1.5em;
display: inline-block; border: 1px #999 solid;
margin: 0 0.16em;
border: 1px #c5c5c5 groove;
cursor: pointer; cursor: pointer;
} }

View file

@ -75,10 +75,8 @@ export function editNamesbase() {
function updateInputs() { function updateInputs() {
const base = +document.getElementById("namesbaseSelect").value; const base = +document.getElementById("namesbaseSelect").value;
if (!nameBases[base]) { if (!nameBases[base]) return tip(`Namesbase ${base} is not defined`, false, "error");
tip(`Namesbase ${base} is not defined`, false, "error");
return;
}
document.getElementById("namesbaseTextarea").value = nameBases[base].b; document.getElementById("namesbaseTextarea").value = nameBases[base].b;
document.getElementById("namesbaseName").value = nameBases[base].name; document.getElementById("namesbaseName").value = nameBases[base].name;
document.getElementById("namesbaseMin").value = nameBases[base].min; document.getElementById("namesbaseMin").value = nameBases[base].min;
@ -104,20 +102,23 @@ export function editNamesbase() {
function updateNamesData() { function updateNamesData() {
const base = +document.getElementById("namesbaseSelect").value; const base = +document.getElementById("namesbaseSelect").value;
const b = document.getElementById("namesbaseTextarea").value; const rawInput = document.getElementById("namesbaseTextarea").value;
if (b.split(",").length < 3) { if (rawInput.split(",").length < 3) return tip("The names data provided is too short of incorrect", false, "error");
tip("The names data provided is too short of incorrect", false, "error");
return; const namesData = rawInput.replace(/[/|]/g, "");
} nameBases[base].b = namesData;
nameBases[base].b = b;
Names.updateChain(base); Names.updateChain(base);
} }
function updateBaseName() { function updateBaseName() {
const base = +document.getElementById("namesbaseSelect").value; const base = +document.getElementById("namesbaseSelect").value;
const select = document.getElementById("namesbaseSelect"); const select = document.getElementById("namesbaseSelect");
select.options[namesbaseSelect.selectedIndex].innerHTML = this.value;
nameBases[base].name = this.value; const rawName = this.value;
const name = rawName.replace(/[/|]/g, "");
select.options[namesbaseSelect.selectedIndex].innerHTML = name;
nameBases[base].name = name;
} }
function updateBaseMin() { function updateBaseMin() {