From cefae461d5f42bc21d2fe58d8a572a74d81bc537 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Thu, 26 Feb 2026 12:58:46 +0000 Subject: [PATCH] Alpha V1.5a --- gm_console.php | 89 +++++++++++++++++++++++++++----------- includes/status_helper.php | 11 ++--- 2 files changed, 70 insertions(+), 30 deletions(-) diff --git a/gm_console.php b/gm_console.php index f7a37f9..daa7daf 100644 --- a/gm_console.php +++ b/gm_console.php @@ -52,8 +52,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' } } - // Derive Status and Faction from Settlements - $status = 'sta_inhabited'; + // Status is now 'sta_auto' by default, overridden only by manual MJ selection + // Dynamic status is calculated on the fly in the helper + $status = 'sta_auto'; $faction_id = null; $total_non_aucun = 0; $active_factions = []; @@ -84,22 +85,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' if ($num_cities > 0 && $total_non_aucun > 0) { arsort($active_factions); $faction_id = (int)key($active_factions); - - if (count($active_factions) > 1) { - $status = 'sta_hostile'; - } else { - if ($total_non_aucun >= ($num_cities * 100)) { - $status = 'sta_controlled'; - } else { - $status = 'sta_contested'; - } - } - } else if ($type !== 'empty') { - $status = 'sta_inhabited'; - $faction_id = null; } - // Manual status override + // Manual status override if specified by MJ if (!empty($manual_status)) { $status = $manual_status; } @@ -658,7 +646,53 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) { const factions = ; const settlementTypes = ; - function updateRangeVal(el) { el.nextElementSibling.querySelector('.val-display').innerText = el.value; } + function updateRangeVal(el) { + const display = el.nextElementSibling.querySelector('.val-display'); + if (display) display.innerText = el.value; + handleCoupledSliders(el); + } + + function handleCoupledSliders(el) { + const group = el.closest('.control-bars'); + const inputs = Array.from(group.querySelectorAll('input[type="range"]')); + const otherInputs = inputs.filter(i => i !== el); + + let newValue = parseInt(el.value); + let otherSumRequired = 100 - newValue; + + let currentOtherSum = otherInputs.reduce((s, i) => s + parseInt(i.value), 0); + + if (currentOtherSum > 0) { + let totalAdded = 0; + otherInputs.forEach((input) => { + let currentVal = parseInt(input.value); + let newVal = Math.floor((currentVal / currentOtherSum) * otherSumRequired); + input.value = newVal; + totalAdded += newVal; + }); + + // Adjustment for rounding + let diff = otherSumRequired - totalAdded; + if (diff !== 0) { + for (let i of otherInputs) { + let v = parseInt(i.value); + if (v + diff >= 0 && v + diff <= 100) { + i.value = v + diff; + break; + } + } + } + } else if (otherInputs.length > 0) { + // All others were 0, give all to the first one + otherInputs[0].value = otherSumRequired; + } + + // Update all displays in the group + inputs.forEach(i => { + const disp = i.nextElementSibling.querySelector('.val-display'); + if (disp) disp.innerText = i.value; + }); + } function editSlot(num, data) { document.getElementById('slot_num').value = num; @@ -668,14 +702,15 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) { document.getElementById('slot_id').value = data.id; document.getElementById('field_name').value = data.name; document.getElementById('field_type').value = data.type; - document.getElementById('field_status').value = data.status; // This will show the currently saved status as selected if it's manual + document.getElementById('field_status').value = data.status === 'sta_auto' ? '' : data.status; // Orbital controls document.querySelectorAll('.orb-input').forEach(input => { const fid = input.dataset.faction; const val = data.orbital_controls && data.orbital_controls[fid] ? data.orbital_controls[fid] : 0; input.value = val; - updateRangeVal(input); + const display = input.nextElementSibling.querySelector('.val-display'); + if (display) display.innerText = val; }); // Settlements @@ -689,7 +724,11 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) { document.getElementById('field_name').value = "Vide"; document.getElementById('field_type').value = "empty"; document.getElementById('field_status').value = ""; - document.querySelectorAll('.orb-input').forEach(input => { input.value = 0; updateRangeVal(input); }); + document.querySelectorAll('.orb-input').forEach(input => { + input.value = (input.dataset.faction == 1) ? 100 : 0; // Default to "Aucune" 100% + const display = input.nextElementSibling.querySelector('.val-display'); + if (display) display.innerText = input.value; + }); document.getElementById('settlements_container').innerHTML = ''; } @@ -710,7 +749,10 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) { let factionControls = ''; factions.forEach(f => { - const val = data && data.controls && data.controls[f.id] ? data.controls[f.id] : 0; + let val = data && data.controls && data.controls[f.id] ? data.controls[f.id] : 0; + // If new settlement and faction is "Aucune", default to 100 + if (!data && f.id == 1) val = 100; + factionControls += `
${f.name}
@@ -723,10 +765,7 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) { div.innerHTML = ` -
-
-
-
+
${factionControls}
`; container.appendChild(div); diff --git a/includes/status_helper.php b/includes/status_helper.php index be53a95..2cf471c 100644 --- a/includes/status_helper.php +++ b/includes/status_helper.php @@ -32,8 +32,9 @@ function calculateCelestialStatus($planet, $db, $statuses_map) { $orbital_controls = $planet['orbital_controls'] ?? []; $terrestrial_controls = $planet['terrestrial_controls'] ?? []; - $orbital_factions = array_filter($orbital_controls, fn($v) => $v > 0); - $terrestrial_factions = array_filter($terrestrial_controls, fn($v) => $v > 0); + // On exclut la faction "Aucune" (ID 1) et les valeurs nulles des comptes + $orbital_factions = array_filter($orbital_controls, fn($v, $k) => $v > 0 && $k != 1, ARRAY_FILTER_USE_BOTH); + $terrestrial_factions = array_filter($terrestrial_controls, fn($v, $k) => $v > 0 && $k != 1, ARRAY_FILTER_USE_BOTH); $orb_count = count($orbital_factions); $terr_count = count($terrestrial_factions); @@ -127,8 +128,8 @@ function calculateCelestialStatus($planet, $db, $statuses_map) { } } - // Fallback final - return $planet['status']; + // Fallback final si profil présent mais aucune règle ne matche + return 'sta_inhabited'; } function evaluateOperator($val, $op, $target) { @@ -141,4 +142,4 @@ function evaluateOperator($val, $op, $target) { case '!=': return $val != $target; } return true; -} +} \ No newline at end of file