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 += `