Add 'set all' buttons to cluster-gen test form
authorTheSaminator <thesaminator@users.noreply.github.com>
Wed, 6 Jul 2022 16:53:09 +0000 (12:53 -0400)
committerTheSaminator <thesaminator@users.noreply.github.com>
Wed, 6 Jul 2022 16:53:09 +0000 (12:53 -0400)
http/ShutDownUrl.http
src/commonMain/kotlin/net/starshipfights/campaign/cluster_params.kt
src/jvmMain/kotlin/net/starshipfights/campaign/cluster_gen.kt
src/jvmMain/kotlin/net/starshipfights/campaign/endpoints_campaign.kt
src/jvmMain/resources/static/init.js

index d483a8e22157d86b0e2504206a4cb13aa78c0240..0060e598b8923e449db41b2dd6c740a68bd9f8ad 100644 (file)
@@ -1 +1 @@
-GET http://localhost:8080/admin/shutdown
+POST http://localhost:8080/admin/shutdown
index 921c5c0d3fed020f497f734e106de7a19210aaa5..5c91d8fa72efcebb7e874574fa67686caa271db9 100644 (file)
@@ -88,8 +88,8 @@ value class ClusterFactions private constructor(private val factions: Map<Factio
        }
 }
 
-enum class ClusterContention(val controlSpreadChance: Double, val maxFleets: Int, val fleetStrengthMult: Double) {
-       BLOODBATH(0.9, 5, 1.0), CONTESTED(0.65, 3, 0.8), PEACEFUL(0.5, 2, 0.5);
+enum class ClusterContention(val numLanesSpreadControl: Double, val maxFleets: Int, val fleetStrengthMult: Double) {
+       BLOODBATH(3.0, 5, 1.0), CONTESTED(1.75, 3, 0.8), PEACEFUL(1.25, 2, 0.5);
        
        val displayName: String
                get() = name.lowercase().replaceFirstChar { it.uppercase() }
index 6d635799e2c66462b9600bf7a0cf74cdf18a32a8..15f1d58f215b9b0c0f7478421b1a36133622ab11 100644 (file)
@@ -375,7 +375,7 @@ class ClusterGenerator(val settings: ClusterGenerationSettings) {
                                        
                                        uncontrolledSystems -= borderId
                                        
-                                       if (Random.nextDouble() < settings.contention.controlSpreadChance / degree)
+                                       if (Random.nextDouble() < settings.contention.numLanesSpreadControl / degree)
                                                systemControllers[borderId] = systemControllers.getValue(systemId).let { faction ->
                                                        if (Random.nextBoolean())
                                                                faction
index 6729a972207aa288d4a5d7c742a30992990298bc..86c9ba5a2fe88c341393d5ce400f94e78696184f 100644 (file)
@@ -104,6 +104,16 @@ fun Routing.installCampaign() {
                                        }
                                }
                                h3 { +"Per-Faction Modes" }
+                               p {
+                                       strong { +"Set All" }
+                                       for (mode in ClusterFactionMode.values()) {
+                                               +Entities.nbsp
+                                               a(href = "#", classes = "set-all") {
+                                                       attributes["data-enable-class"] = "faction-mode-${mode.toUrlSlug()}"
+                                                       +mode.displayName
+                                               }
+                                       }
+                               }
                                for (factionFlavor in FactionFlavor.values())
                                        p {
                                                strong { +factionFlavor.displayName }
@@ -120,15 +130,56 @@ fun Routing.installCampaign() {
                                                                        required = true
                                                                        if (mode == ClusterFactionMode.ALLOW)
                                                                                checked = true
+                                                                       classes = setOf(
+                                                                               "faction-choice",
+                                                                               "faction-loyalty-${factionFlavor.loyalties.first().toUrlSlug()}",
+                                                                               "faction-shipset-${factionFlavor.shipSource.toUrlSlug()}",
+                                                                               "faction-mode-${mode.toUrlSlug()}",
+                                                                       )
                                                                }
                                                                +mode.displayName
                                                                +Entities.nbsp
                                                        }
                                                }
                                        }
+                               p {
+                                       strong { +"Set All by Faction Loyalty" }
+                                       val loyalties = FactionFlavor.values().map { it.loyalties.first() }.distinct()
+                                       for (loyalty in loyalties) {
+                                               br
+                                               +"${loyalty.shortName}:"
+                                               for (mode in ClusterFactionMode.values()) {
+                                                       +Entities.nbsp
+                                                       a(href = "#", classes = "set-all-by-faction") {
+                                                               attributes["data-filter-class"] = "faction-loyalty-${loyalty.toUrlSlug()}"
+                                                               attributes["data-enable-class"] = "faction-mode-${mode.toUrlSlug()}"
+                                                               +mode.displayName
+                                                       }
+                                               }
+                                       }
+                               }
+                               p {
+                                       strong { +"Set All by Shipset" }
+                                       val shipSets = FactionFlavor.values().map { it.shipSource }.distinct()
+                                       for (shipSet in shipSets) {
+                                               br
+                                               +"${shipSet.shortName}:"
+                                               for (mode in ClusterFactionMode.values()) {
+                                                       +Entities.nbsp
+                                                       a(href = "#", classes = "set-all-by-faction") {
+                                                               attributes["data-filter-class"] = "faction-shipset-${shipSet.toUrlSlug()}"
+                                                               attributes["data-enable-class"] = "faction-mode-${mode.toUrlSlug()}"
+                                                               +mode.displayName
+                                                       }
+                                               }
+                                       }
+                               }
                                submitInput {
                                        value = "Generate Star Cluster"
                                }
+                               script {
+                                       unsafe { +"window.sfClusterGenTest = true;" }
+                               }
                        }
                }
        }
index dd033912e8b573083a8a86a96b1545e7292b9d6c..f7cb6d666a9eba9392bfa6ed9050c9db83f2eb5b 100644 (file)
@@ -32,7 +32,7 @@
                }
 
                const canvasLoads = [];
-               for (let canvas of canvases) {
+               for (const canvas of canvases) {
                        const modelName = canvas.getAttribute("data-model");
                        if (modelName == null) continue;
 
        window.addEventListener("load", function () {
                // Localize dates and times
                const moments = document.getElementsByClassName("moment");
-               for (let moment of moments) {
+               for (const moment of moments) {
                        let date = new Date(Number(moment.innerHTML.trim()));
                        moment.innerHTML = date.toLocaleString();
                        moment.style.display = "inline";
                const nameBox = document.getElementById("name");
                const isFemaleButton = document.getElementById("sex-female");
                const generators = document.getElementsByClassName("generate-admiral-name");
-               for (let generator of generators) {
+               for (const generator of generators) {
                        const flavor = generator.getAttribute("data-flavor");
                        generator.onclick = (e) => {
                                e.preventDefault();
        window.addEventListener("load", function () {
                // Indicate maximum and used length of <textarea>s
                const textareas = document.getElementsByTagName("textarea");
-               for (let textarea of textareas) {
+               for (const textarea of textareas) {
                        if (!textarea.hasAttribute("maxLength")) continue;
 
                        const maxLengthIndicator = document.createElement("p");
        window.addEventListener("load", function () {
                // Allow POSTing with <a>s
                const anchors = document.getElementsByTagName("a");
-               for (let anchor of anchors) {
+               for (const anchor of anchors) {
                        const method = anchor.getAttribute("data-method");
                        if (method == null) continue;
 
                if (!window.sfThemeChoice) return;
 
                const themeChoices = document.getElementsByName("theme");
-               for (let themeChoice of themeChoices) {
+               for (const themeChoice of themeChoices) {
                        const theme = themeChoice.value;
                        themeChoice.addEventListener("click", () => {
                                document.documentElement.setAttribute("data-theme", theme);
                        });
                }
        });
+
+       window.addEventListener("load", function () {
+               // Allow bulk-setting of factions
+               if (!window.sfClusterGenTest) return;
+
+               const setAllButtons = document.getElementsByClassName("set-all");
+               for (const setAllButton of setAllButtons) {
+                       setAllButton.onclick = function (e) {
+                               e.preventDefault();
+
+                               const enableClass = setAllButton.getAttribute("data-enable-class");
+                               const factionChoices = document.getElementsByClassName("faction-choice");
+                               for (const factionChoice of factionChoices) {
+                                       factionChoice.checked = factionChoice.classList.contains(enableClass);
+                               }
+                       };
+               }
+
+               const setSomeButtons = document.getElementsByClassName("set-all-by-faction");
+               for (const setSomeButton of setSomeButtons) {
+                       setSomeButton.onclick = function (e) {
+                               e.preventDefault();
+
+                               const filterClass = setSomeButton.getAttribute("data-filter-class");
+                               const chosenClass = setSomeButton.getAttribute("data-enable-class");
+                               const factionChoices = document.getElementsByClassName("faction-choice");
+                               for (const factionChoice of factionChoices) {
+                                       if (factionChoice.classList.contains(filterClass))
+                                               factionChoice.checked = factionChoice.classList.contains(chosenClass);
+                               }
+                       };
+               }
+       });
 })();