Alpha V1.5a

This commit is contained in:
Flatlogic Bot 2026-02-26 12:58:46 +00:00
parent b3eb7678d2
commit cefae461d5
2 changed files with 70 additions and 30 deletions

View File

@ -52,8 +52,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
} }
} }
// Derive Status and Faction from Settlements // Status is now 'sta_auto' by default, overridden only by manual MJ selection
$status = 'sta_inhabited'; // Dynamic status is calculated on the fly in the helper
$status = 'sta_auto';
$faction_id = null; $faction_id = null;
$total_non_aucun = 0; $total_non_aucun = 0;
$active_factions = []; $active_factions = [];
@ -84,22 +85,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
if ($num_cities > 0 && $total_non_aucun > 0) { if ($num_cities > 0 && $total_non_aucun > 0) {
arsort($active_factions); arsort($active_factions);
$faction_id = (int)key($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)) { if (!empty($manual_status)) {
$status = $manual_status; $status = $manual_status;
} }
@ -658,7 +646,53 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {
const factions = <?php echo json_encode($factions_db); ?>; const factions = <?php echo json_encode($factions_db); ?>;
const settlementTypes = <?php echo json_encode($settlement_types_db); ?>; const settlementTypes = <?php echo json_encode($settlement_types_db); ?>;
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) { function editSlot(num, data) {
document.getElementById('slot_num').value = num; 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('slot_id').value = data.id;
document.getElementById('field_name').value = data.name; document.getElementById('field_name').value = data.name;
document.getElementById('field_type').value = data.type; 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 // Orbital controls
document.querySelectorAll('.orb-input').forEach(input => { document.querySelectorAll('.orb-input').forEach(input => {
const fid = input.dataset.faction; const fid = input.dataset.faction;
const val = data.orbital_controls && data.orbital_controls[fid] ? data.orbital_controls[fid] : 0; const val = data.orbital_controls && data.orbital_controls[fid] ? data.orbital_controls[fid] : 0;
input.value = val; input.value = val;
updateRangeVal(input); const display = input.nextElementSibling.querySelector('.val-display');
if (display) display.innerText = val;
}); });
// Settlements // Settlements
@ -689,7 +724,11 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {
document.getElementById('field_name').value = "Vide"; document.getElementById('field_name').value = "Vide";
document.getElementById('field_type').value = "empty"; document.getElementById('field_type').value = "empty";
document.getElementById('field_status').value = ""; 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 = ''; document.getElementById('settlements_container').innerHTML = '';
} }
@ -710,7 +749,10 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {
let factionControls = ''; let factionControls = '';
factions.forEach(f => { 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 += ` factionControls += `
<div class="control-bar-row"> <div class="control-bar-row">
<div class="control-bar-label"><span class="faction-dot" style="background:${f.color}"></span> ${f.name}</div> <div class="control-bar-label"><span class="faction-dot" style="background:${f.color}"></span> ${f.name}</div>
@ -723,10 +765,7 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {
div.innerHTML = ` div.innerHTML = `
<button type="button" class="btn-remove-settlement" onclick="this.parentElement.remove()">×</button> <button type="button" class="btn-remove-settlement" onclick="this.parentElement.remove()">×</button>
<input type="hidden" name="cities[${index}][id]" value="${data ? data.id : ''}"> <input type="hidden" name="cities[${index}][id]" value="${data ? data.id : ''}">
<div class="compact-row" style="margin-bottom:10px;"> <div class="compact-row" style="margin-bottom:10px;"><div class="form-group" style="flex:2"><label>Nom de la ville</label><input type="text" name="cities[${index}][name]" value="${data ? data.name : ''}" required></div><div class="form-group" style="flex:1"><label>Type</label><select name="cities[${index}][type_id]">${typeOptions}</select></div></div>
<div class="form-group" style="flex:2"><label>Nom de la ville</label><input type="text" name="cities[${index}][name]" value="${data ? data.name : ''}" required></div>
<div class="form-group" style="flex:1"><label>Type</label><select name="cities[${index}][type_id]">${typeOptions}</select></div>
</div>
<div class="control-bars">${factionControls}</div> <div class="control-bars">${factionControls}</div>
`; `;
container.appendChild(div); container.appendChild(div);

View File

@ -32,8 +32,9 @@ function calculateCelestialStatus($planet, $db, $statuses_map) {
$orbital_controls = $planet['orbital_controls'] ?? []; $orbital_controls = $planet['orbital_controls'] ?? [];
$terrestrial_controls = $planet['terrestrial_controls'] ?? []; $terrestrial_controls = $planet['terrestrial_controls'] ?? [];
$orbital_factions = array_filter($orbital_controls, fn($v) => $v > 0); // On exclut la faction "Aucune" (ID 1) et les valeurs nulles des comptes
$terrestrial_factions = array_filter($terrestrial_controls, fn($v) => $v > 0); $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); $orb_count = count($orbital_factions);
$terr_count = count($terrestrial_factions); $terr_count = count($terrestrial_factions);
@ -127,8 +128,8 @@ function calculateCelestialStatus($planet, $db, $statuses_map) {
} }
} }
// Fallback final // Fallback final si profil présent mais aucune règle ne matche
return $planet['status']; return 'sta_inhabited';
} }
function evaluateOperator($val, $op, $target) { function evaluateOperator($val, $op, $target) {
@ -141,4 +142,4 @@ function evaluateOperator($val, $op, $target) {
case '!=': return $val != $target; case '!=': return $val != $target;
} }
return true; return true;
} }