diff --git a/modules/resources-generator.js b/modules/resources-generator.js index 60b933a3..1c166ffd 100644 --- a/modules/resources-generator.js +++ b/modules/resources-generator.js @@ -136,7 +136,7 @@ break; } } - pack.resources.sort((a, b) => (a.i > b.i ? 1 : -1)); + pack.resources.sort((a, b) => (a.i > b.i ? 1 : -1)).forEach(r => delete r.fn); console.timeEnd("generateResources"); }; @@ -144,5 +144,5 @@ const getStroke = color => d3.color(color).darker(2).hex(); const get = i => pack.resources.find(resource => resource.i === i); - return {generate, getDefault, defaultModels, getStroke, get}; + return {generate, getDefault, defaultModels, methods, getStroke, get}; }); diff --git a/modules/ui/resources-editor.js b/modules/ui/resources-editor.js index fdbfc1d1..4d63a2ac 100644 --- a/modules/ui/resources-editor.js +++ b/modules/ui/resources-editor.js @@ -11,7 +11,10 @@ function editResources() { modules.editResources = true; $("#resourcesEditor").dialog({ - title: "Resources Editor", resizable: false, width: fitContent(), close: closeResourcesEditor, + title: "Resources Editor", + resizable: false, + width: fitContent(), + close: closeResourcesEditor, position: {my: "right top", at: "right-10 top+10", of: "svg"} }); @@ -22,22 +25,27 @@ function editResources() { document.getElementById("resourcesPercentage").addEventListener("click", togglePercentageMode); document.getElementById("resourcesExport").addEventListener("click", downloadResourcesData); - body.addEventListener("click", function(ev) { - const el = ev.target, cl = el.classList, line = el.parentNode, i = +line.dataset.id; + body.addEventListener("click", function (ev) { + const el = ev.target, + cl = el.classList, + line = el.parentNode, + i = +line.dataset.id; const resource = Resources.get(+line.dataset.id); if (cl.contains("resourceCategory")) return changeCategory(resource, line, el); if (cl.contains("resourceModel")) return changeModel(resource, line, el); }); - body.addEventListener("change", function(ev) { - const el = ev.target, cl = el.classList, line = el.parentNode; + body.addEventListener("change", function (ev) { + const el = ev.target, + cl = el.classList, + line = el.parentNode; const resource = Resources.get(+line.dataset.id); if (cl.contains("resourceName")) return changeName(resource, el.value, line); }); // add line for each resource function resourcesEditorAddLines() { - const addTitle = (string, max) => string.length < max ? "" : `title="${string}"`; + const addTitle = (string, max) => (string.length < max ? "" : `title="${string}"`); let lines = ""; // // {i: 33, name: "Saltpeter", icon: "resource-saltpeter", color: "#e6e3e3", value: 8, chance: 2, model: "habitability", bonus: {artillery: 3}} @@ -74,7 +82,10 @@ function editResources() { // body.querySelectorAll("div.states").forEach(el => el.addEventListener("click", selectResourceOnLineClick)); body.querySelectorAll("svg.icon").forEach(el => el.addEventListener("click", resourceChangeColor)); - if (body.dataset.type === "percentage") {body.dataset.type = "absolute"; togglePercentageMode();} + if (body.dataset.type === "percentage") { + body.dataset.type = "absolute"; + togglePercentageMode(); + } applySorting(resourcesHeader); $("#resourcesEditor").dialog({width: fitContent()}); } @@ -99,10 +110,17 @@ function editResources() { `; - $("#alert").dialog({resizable: false, title: "Change category", + $("#alert").dialog({ + resizable: false, + title: "Change category", buttons: { - Cancel: function() {$(this).dialog("close");}, - Apply: function() {applyChanges(); $(this).dialog("close");} + Cancel: function () { + $(this).dialog("close"); + }, + Apply: function () { + applyChanges(); + $(this).dialog("close"); + } } }); @@ -117,20 +135,26 @@ function editResources() { function changeModel(resource, line, el) { const defaultModels = Resources.defaultModels; const model = line.dataset.model; - const modelOptions = Object.keys(defaultModels).map(m => ``).join(""); + const modelOptions = Object.keys(defaultModels).sort().map(m => ``).join(""); const wikiURL = "https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Resources:-spread-functions"; + const onSelect = "resouceModelFunction.innerHTML = Resources.defaultModels[this.value] || ' '; resouceModelCustomName.value = ''; resouceModelCustomFunction.value = ''"; alertMessage.innerHTML = `
@@ -138,23 +162,29 @@ function editResources() {