Merge branch 'master' of https://github.com/Azgaar/Fantasy-Map-Generator into submap-refactoring

This commit is contained in:
Azgaar 2024-11-11 13:30:47 +01:00
commit fb48f5d57a
18 changed files with 511 additions and 73 deletions

View file

@ -3,7 +3,7 @@
const GPT_MODELS = ["gpt-4o-mini", "chatgpt-4o-latest", "gpt-4o", "gpt-4-turbo", "gpt-4", "gpt-3.5-turbo"];
const SYSTEM_MESSAGE = "I'm working on my fantasy map.";
function geneateWithAi(defaultPrompt, onApply) {
function generateWithAi(defaultPrompt, onApply) {
updateValues();
$("#aiGenerator").dialog({
@ -26,13 +26,14 @@ function geneateWithAi(defaultPrompt, onApply) {
}
});
if (modules.geneateWithAi) return;
modules.geneateWithAi = true;
if (modules.generateWithAi) return;
modules.generateWithAi = true;
function updateValues() {
byId("aiGeneratorResult").value = "";
byId("aiGeneratorPrompt").value = defaultPrompt;
byId("aiGeneratorKey").value = localStorage.getItem("fmg-ai-kl") || "";
byId("aiGeneratorTemperature").value = localStorage.getItem("fmg-ai-temperature") || "1.2";
const select = byId("aiGeneratorModel");
select.options.length = 0;
@ -52,6 +53,12 @@ function geneateWithAi(defaultPrompt, onApply) {
const prompt = byId("aiGeneratorPrompt").value;
if (!prompt) return tip("Please enter a prompt", true, "error", 4000);
const temperature = parseFloat(byId("aiGeneratorTemperature").value);
if (isNaN(temperature) || temperature < 0 || temperature > 2) {
return tip("Temperature must be a number between 0 and 2", true, "error", 4000);
}
localStorage.setItem("fmg-ai-temperature", temperature.toString());
try {
button.disabled = true;
const resultArea = byId("aiGeneratorResult");
@ -70,7 +77,7 @@ function geneateWithAi(defaultPrompt, onApply) {
{role: "system", content: SYSTEM_MESSAGE},
{role: "user", content: prompt}
],
temperature: 1.2,
temperature: temperature,
stream: true // Enable streaming
})
});

View file

@ -160,7 +160,7 @@ function editNotes(id, name) {
}
};
geneateWithAi(prompt, onApply);
generateWithAi(prompt, onApply);
}
function downloadLegends() {

View file

@ -116,20 +116,20 @@ function selectStyleElement() {
if (
[
"armies",
"routes",
"lakes",
"biomes",
"borders",
"cults",
"relig",
"cells",
"coastline",
"prec",
"coordinates",
"cults",
"gridOverlay",
"ice",
"icons",
"coordinates",
"zones",
"gridOverlay"
"lakes",
"prec",
"relig",
"routes",
"zones"
].includes(styleElement)
) {
styleStroke.style.display = "block";
@ -140,7 +140,7 @@ function selectStyleElement() {
// stroke dash
if (
["routes", "borders", "temperature", "legend", "population", "coordinates", "zones", "gridOverlay"].includes(
["borders", "cells", "coordinates", "gridOverlay", "legend", "population", "routes", "temperature", "zones"].includes(
styleElement
)
) {
@ -788,7 +788,7 @@ styleShadowInput.on("input", function () {
styleFontAdd.on("click", function () {
addFontNameInput.value = "";
addFontURLInput.value = "";
$("#addFontDialog").dialog({
title: "Add custom font",
width: "26em",

View file

@ -1,7 +1,7 @@
"use strict";
function editZones() {
closeDialogs();
closeDialogs("#zonesEditor, .stable");
if (!layerIsOn("toggleZones")) toggleZones();
const body = byId("zonesBodySection");